Monday, May 27, 2013

Building proj.dll for 64 bit windows




1-Download source code from (http://trac.osgeo.org/proj/)
At the time of writing this post 4.8.0 was latest (http://download.osgeo.org/proj/proj-4.8.0.tar.gz)

2-Extract all files to c:\proj
(this is important to follow this path or you need to change this file path in make files)

3-find the x64 nmake path on your system, you can use "where" command it will list all nmake versions that you have on your machine. make sure you are using x64 command prompt or it will list only x86 nmake files.

Even if you are unable to find the x64 command prompt x64 version of nmake resides inside amd64 folder on the same path. Following are example path for nmake.

x86
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe
x64
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\nmake.exe

4-Once you find the path of x64 verion of nmake, first you need to prepare environment variables.
Execute the following command
c:\proj\src>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat
 5-Build the source
C:\proj\src>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\nmake.exe /f makefile.vc
 6-Find the 64 bit dll at "C:\proj\src\proj.dll"

You can also download the 64 bit version of this file from here. proj.dll x64

Standard Electrical Formulas Used for Power Consumption Calculations


TO DETERMINE:
SINGLE-PHASE
THREE-PHASE
DIRECT
CURRENT
KVA
I x E
1000
I x E x 1.73
1000
--------
Kilowatts
I x E x PF
1000
I x E x 1.73 x PF
1000
I x E
1000
Horsepower
I x E x %EFF x PF
746
I x E x 1.732 x %EFF x PF
746
I x E x %EFF
746
Amperes (when HP is known)
HP x 746
E x %EFF x PF
HP x 746
1.73 x E x %EFF x PF
HP x 746
E x %EFF
Amperes (when kW is known)
KW x 1000
E x PF
KW x 1000
1.73 x E x PF
KW x 1000
E
Amperes (when KVA is known)
KVA x 1000
E
KVA x 1000
1.73 x E
--------
1 HP = 7457 Watts
1000 Watts (1KW) = 1.25 KVA with PE=0.8
1 KW = 1 KVA with PE=1.0
Usually observed in generators
1 HP = 571.42
No PE given

Summerizing all worksheet columns into first worksheet

Sub Macro1()
Dim ws As Worksheet
Dim wsInfo As Worksheet
Set wsInfo = ActiveWorkbook.Sheets(1)
Dim Counter As Integer
Counter = 1
For Each ws In ActiveWorkbook.Sheets
Dim columnCounter As Integer
Dim wsColumnCounter As Integer
columnCounter = 2
wsInfo.Cells(Counter, "A").Value = ws.Name

wsColumnCounter = 1
Do While ws.Cells(1, i) <> ""
wsInfo.Cells(Counter, columnCounter).Value = ws.Cells(1, wsColumnCounter)
columnCounter = columnCounter + 1
wsColumnCounter = wsColumnCounter + 1
Loop

Counter = Counter + 1
Next
End Sub


"This code is not tested"

Monday, April 8, 2013

RegEx to find empty/swallowed exception blocks with Visual Studio 2012



RegEx:
catch\s\(.*Exception.*\)*\s*(\n?)*\{\s*(//.*)*\s*\n?\}

It will match following formats

catch (Exception)
{
}

catch (Exception){}

catch (Exception)
{
//any c# comments
}

catch (Exception){
}

catch (Exception){
 //any c# comments
}

catch (Exception ex)
{
}
catch (Exception ex){
//any c# comments
}


 For details on searching in visual studio 2012 using regex:
http://msdn.microsoft.com/en-us/library/vstudio/2k3te2cs.aspx

Monday, July 12, 2010

How to modify URL in QuickLaunch links programmatically

A MOSS 2007 project has been deployed into production and I need to provide them a patch to fix up some Quick Launch links and some other functionality. The only way I had is to build a WSP with code to make my changes to the Serve where ever it is deployed. During achieving QuickLaunch Fixes I faced a little issues and decided to publish the solution to help others

We can access the quick launch from the "navigation" object available in "web" object.

web.Navigation.QuickLaunch
The QuickLaunch object is of type SPNavgationNodeCollection wich contains the collection of SPNavigationNode. There is a built in method "Update" provided in SPNavigationNode class to save any changes made in SpNavigationObject properties to the database. I tried to use the method after updating the URL of QuickLaunch link

SPNavigationNode Node = web.Navigation.QuickLaunch[Counter];
Node.Url = "NewURL/Confirmation.aspx";
Node.Update();
But it didn't work for me. I googled this issue a lot but no luck :(. After a lot of thinking on this issue and exploring the Update method using reflector I came to know that update method actually calls UpdateNavigationNode() that resides inside SPRequest object.

this.Navigation.Web.Request.UpdateNavigationNode(this.Navigation.Web.Url, this.Id, this.m_dtParented, this.Title, this.Url, ref this.m_PropertyArray, out str)





Unfortunately SPRequest object is marked with "internal" access modifier and we can not access it from another assembly. but i have to call it directly to update the content database with my URL change so I decided to use reflection to access the internal object

Object Request = null;
Request=web.GetType().GetField("m_Request",System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Instance).GetValue(web);

After successfully getting the Request object I also need to execute the UpdateNavigationNode() method using reflection because it is also marked with "internal" access modifier

Request.GetType().GetMethod("UpdateNavigationNode").Invoke(Request, new Object[] { node.Navigation.Web.Url, node.Id, node.LastModified, node.Title, URL, (m_PropertyArray), str });
Finally the method looks like this
void UpdateQuickLaunchNodeURL(SPWeb web, SPNavigationNode node, string URL)
{
Object Request = null;
Request = web.GetType().GetField("m_Request", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(web);
object m_PropertyArray = new object();
string str = "";
Request.GetType().GetMethod("UpdateNavigationNode").Invoke(Request, new Object[] { node.Navigation.Web.Url, node.Id, node.LastModified, node.Title, URL, (m_PropertyArray), str });
web.Update();
}
And this code worked for definitely. Hope it will help others.

Friday, June 18, 2010

how to match lookup value using CAML

When you query a Lookup field using CAML by default it will be executed for matching the text of lookup that is not desired in many cases like my.

<Query>
<Where>
<Eq>
<FieldRef Name="LookupFieldName" />
<Value Type="Lookup">1</Value>
</Eq>
</Where>
</Query>

We need to just set a property "LookupId" to true in FieldRef Tag like the following


<Query>
<Where>
<Eq>
<FieldRef Name="LookupFieldName" LookupId="True" />
<Value Type="Lookup">1</Value>
</Eq>
</Where>
</Query>

This will instruct the CAML engine to use the value property of lookup to execute the match.

Thursday, June 17, 2010

Setting 20+ Lookup value at client side, JQuery

I have faced the issue many time when setting the value into sharepoint controls at client side. Here i will explain how to set the value in 20+ lookup control at client side using JQuery. First I tried to setting a value into its textbox and then firing a change event of textbox but that doesn't work. If you use JQuery to raise change event like this

$("[Title='TitleOfControl']").val("NewValue").change();

This event carry the srcElement property null that results in crash of "HandleChange" function in the start.

And if you try to raise the event like this

$("[Title='TitleOfControl']")[0]fireEvent('onchange');

There are many prerequisites to this approach like you have to first raise the click of lookup that will render the options in the DOM internally and then you have to select the appropriate option like this

var LookupInput = $("[Title='TitleOfControl']");
LookupInput.next().click();
$("select[id='" + LookupInput.attr("opt") + "']").find("option[value='"+ SelectedValue +"']").attr("selected","true");

and then raise the change event. This approach will only work if there are no duplicate text in the lookup otherwise it will fail.

Finally then i come to the following straight forward and working solution

var LookupInput = $("[Title='TitleOfControl']");
LookupInput.attr("match","SelectedText");
LookupInput.val("SelectedText");
$("input[id='" + LookupInput.attr("opthid") + "']").val("SelectedValue");

In this solution you need to set the value in TextBox, "opt" attribute of TextBox and in Hidden field "opthid" that is mentioned in attribute of TextBox. This solution worked for me like charm. Hope it will help others too.

HandleChange function that is called when lookup's textbox value changes
function HandleChange()
{
var ctrl=event.srcElement;
var str=ctrl.value;
var opt=document.getElementById(ctrl.opt);
ctrl.match=FilterChoice(opt, ctrl, str, "");
}