Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Friday, November 30, 2012

to UTC/JSON Date

 

// to UTC/JSON Date

Number.prototype.addZero = function () { return (this < 10) ? "0" +

this : this; };

var convertDate = function (d) {

var d, s, u, uh, um, us;

//d = new Date();

s = d.getFullYear() + "-";

s += (d.getMonth() + 1).addZero() + "-"; //getMonth returns an

integer in the range 0-11

s += d.getDate().addZero() + "T";

s += d.getHours().addZero() + ":";

s += d.getMinutes().addZero() + ":";

s += d.getSeconds().addZero();

u = 0 - d.getTimezoneOffset(); //getTimezoneOffset will

be positive if you are behind UTC, and negative if you are ahead of

UTC.

us = (u >= 0) ? "+" : "-";

u = Math.abs(u);

uh = Math.floor(u / 60).addZero();

um = (u % 60).addZero();

s += us;

s += uh + ":";

s += um;

alert(s);

return (s);

};



// call

convertDate(new Date());

to UTC/JSON Date

<pre class="brush: c#">

// to UTC/JSON Date

Number.prototype.addZero = function () { return (this < 10) ? "0" +

this : this; };

var convertDate = function (d) {

var d, s, u, uh, um, us;

//d = new Date();

s = d.getFullYear() + "-";

s += (d.getMonth() + 1).addZero() + "-"; //getMonth returns an

integer in the range 0-11

s += d.getDate().addZero() + "T";

s += d.getHours().addZero() + ":";

s += d.getMinutes().addZero() + ":";

s += d.getSeconds().addZero();

u = 0 - d.getTimezoneOffset(); //getTimezoneOffset will

be positive if you are behind UTC, and negative if you are ahead of

UTC.

us = (u >= 0) ? "+" : "-";

u = Math.abs(u);

uh = Math.floor(u / 60).addZero();

um = (u % 60).addZero();

s += us;

s += uh + ":";

s += um;

alert(s);

return (s);

};



// call

convertDate(new Date());

</pre>

Parse XmlHttp Response


// Parse XmlHttp Response
function parseResponse(responseXML, attributename) {

debugger;
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(responseXML);
x = xmlDoc.getElementsByTagName("a:KeyValuePairOfstringanyType");
for (i = 0; i < x.length; i++) {
if (x[i].childNodes[0].text == attributename) {
//we decode the base 64 contents and alert the HTML of the Iframe
alert(x[i].childNodes[1].text);
}

}
}

Parse XmlHttp Response

<pre class="brush: c#">

// Parse XmlHttp Response

function parseResponse(responseXML, attributename) {



debugger;

xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async = "false";

xmlDoc.loadXML(responseXML);

x = xmlDoc.getElementsByTagName("a:KeyValuePairOfstringanyType");

for (i = 0; i < x.length; i++) {

if (x[i].childNodes[0].text == attributename) {

//we decode the base 64 contents and alert the HTML of the Iframe

alert(x[i].childNodes[1].text);

}



}

}

</pre>

XmlHttp Request


// XmlHttp Request
var AjaxRequest = function (crmSvcUrl, soapString) {
var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
XmlHttp.open("POST", crmSvcUrl, false);
XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
XmlHttp.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
XmlHttp.setRequestHeader("Content-Length", soapString.length);
XmlHttp.send(soapString);
var resultXml = XmlHttp.responseXML;
return resultXml;
};

XmlHttp Request

<pre class="brush: c#">

// XmlHttp Request

var AjaxRequest = function (crmSvcUrl, soapString) {

var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

XmlHttp.open("POST", crmSvcUrl, false);

XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

XmlHttp.setRequestHeader("SOAPAction",

"http://schemas.microsoft.com/crm/2007/WebServices/Fetch");

XmlHttp.setRequestHeader("Content-Length", soapString.length);

XmlHttp.send(soapString);

var resultXml = XmlHttp.responseXML;

return resultXml;

};

</pre>

Create SOAP Envelop


// Create SOAP Envelop
var createSOAP = function (fxml) {
var soap2 = "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
soap2 += GenerateAuthenticationHeader();
soap2 += "";
soap2 += "xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">";
soap2 += "";
soap2 += fxml;
soap2 += "
";
soap2 += "";
soap2 += "
";
soap2 += "";
return soap2;
};

Create SOAP Envelop

<pre class="brush: c#">

// Create SOAP Envelop

var createSOAP = function (fxml) {

var soap2 = "<soap:Envelope

xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"

xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"

xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";

soap2 += GenerateAuthenticationHeader();

soap2 += "<soap:Body>";

soap2 += "<Fetch

xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">";

soap2 += "<fetchXml>";

soap2 += fxml;

soap2 += "</fetchXml>";

soap2 += "</Fetch>";

soap2 += "</soap:Body>";

soap2 += "</soap:Envelope>";

return soap2;

};

</pre>

return if day is weekday


// return if day is weekday
var Weekday = function (chkDt) {
if (chkDt.getDay() > 0 && chkDt.getDay() < 6) {
//"Sorry, it's a weekday.";
return true;
}
else {
//"Hooray, it's a weekend!";
return false;
}
}; //Ef

return if day is weekday

<pre class="brush: c#">

// return if day is weekday

var Weekday = function (chkDt) {

if (chkDt.getDay() > 0 && chkDt.getDay() < 6) {

//"Sorry, it's a weekday.";

return true;

}

else {

//"Hooray, it's a weekend!";

return false;

}

}; //Ef

</pre>

JSON date fromat to date Object

<pre class="brush: c#">

//JSON date fromat to date Object

var jsondtobj = function (txt) {

var year, month, day;

var filler = '.*?'; // Non-greedy match on filler

var yre2 = '((?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3})))(?![\\d])';

// Year 1

var yp = new RegExp(filler + yre2, ["i"]);

var ym = yp.exec(txt);

if (ym != null) {

var year1 = ym[1];

year = year1.replace(/</, "&lt;");

}





var mre2 = '(?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))(?![\\d])'; //

Uninteresting: day

var mre4 = '((?:(?:[0-2]?\\d{1})|(?:[3][01]{1})))(?![\\d])'; // Month 1



var mp = new RegExp(filler + mre2 + filler + mre4, ["i"]);

var mm = mp.exec(txt);

if (mm != null) {

var mon1 = mm[1];

month = mon1.replace(/</, "&lt;") - 1;

}





var dre2 = '(?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))(?![\\d])'; //

Uninteresting: day

var dre4 = '(?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))(?![\\d])'; //

Uninteresting: day

var dre6 = '((?:(?:[0-2]?\\d{1})|(?:[3][01]{1})))(?![\\d])'; // Day 1



var dp = new RegExp(filler + dre2 + filler + dre4 + filler + dre6, ["i"]);

var dm = dp.exec(txt);

if (dm != null) {

var day1 = dm[1];

day = day1.replace(/</, "&lt;");

}

var dateObject = new Date(); dateObject.setDate(day);

dateObject.setMonth(month); dateObject.setYear(year);

return dateObject;

}; //

</pre>

Extend Date Object with new function using Namespace


// Extend Date Object with new function using Namespace
//Date.prototype.daysBetween
Date.prototype.daysBetween = function (date1, date2) {
//Get 1 day in milliseconds
var one_day = 1000 * 60 * 60 * 24;

// Convert both dates to milliseconds
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();

// Calculate the difference in milliseconds
var difference_ms = date2_ms - date1_ms;
//take out milliseconds
difference_ms = difference_ms / 1000;
var seconds = Math.floor(difference_ms % 60);
difference_ms = difference_ms / 60;
var minutes = Math.floor(difference_ms % 60);
difference_ms = difference_ms / 60;
var hours = Math.floor(difference_ms % 24);
var days = Math.floor(difference_ms / 24);

return days + ' days, ' + hours + ' hours, ' + minutes + ' minutes, and ' + seconds + ' seconds';
};

Extend Date Object with new function using Namespace

<pre class="brush: c#">
// Extend Date Object with new function using Namespace
//Date.prototype.daysBetween
Date.prototype.daysBetween = function (date1, date2) {
    //Get 1 day in milliseconds
    var one_day = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime();
    var date2_ms = date2.getTime();

    // Calculate the difference in milliseconds
    var difference_ms = date2_ms - date1_ms;
    //take out milliseconds
    difference_ms = difference_ms / 1000;
    var seconds = Math.floor(difference_ms % 60);
    difference_ms = difference_ms / 60;
    var minutes = Math.floor(difference_ms % 60);
    difference_ms = difference_ms / 60;
    var hours = Math.floor(difference_ms % 24);
    var days = Math.floor(difference_ms / 24);

    return days + ' days, ' + hours + ' hours, ' + minutes + ' minutes, and ' + seconds + ' seconds';
};

</pre>

Create new Queue using Early Bound


// ** Create new Queue ** using Early Bound

//Create new queues and store their returned GUIDs in variables for later use.

Queue sourceQueue = new Queue

{

Name = "Example Queue 1",

Description = "This is an example queue.",

};



Guid _QueueId = _service.Create(sourceQueue);

Console.WriteLine("Created {0}", sourceQueue.Name);