
Thank you very much, "MyMobiler" team...
private void backgroundWorker1_DoWork(object sender, BCD.ComponentModel.DoWorkEventArgs e) { HttpWebRequest myRequest = null; HttpWebResponse myResponse = null; string newurl = (string)e.Argument; string fileName = "", filePath = ""; try { bool redirecting = true; while (redirecting) { try { myRequest = (HttpWebRequest)WebRequest.Create(newurl); // we accept any type of file myRequest.Accept = "*/*"; // set the timeout to 5 seconds myRequest.Timeout = 5000; // casts the response myResponse = (HttpWebResponse)myRequest.GetResponse(); // if we have redirection if ((int)myResponse.StatusCode == 301 || (int)myResponse.StatusCode == 302) { string uriString = myResponse.Headers["Location"]; newurl = uriString; // and keep going } else { // gets the final uri fileName = Path.GetFileName(myResponse.ResponseUri.LocalPath); // we only want CAB file if (fileName.ToLower().EndsWith(".cab")) { filePath = Path.Combine(Utils.TempPath, fileName); // gets the total lenth for progress bar long fileLength = myResponse.ContentLength; // start with zero int byteTotal = 0; // start writing file using (FileStream fileStream = File.OpenWrite(filePath)) { // gets the stream from response object using (Stream remoteStream = myResponse.GetResponseStream()) { // we make 4 MB as our buffer byte[] inBuffer = new byte[4 * 1024]; int nRead = remoteStream.Read(inBuffer, 0, inBuffer.Length); // we need to put e.Cancel as user may cancel downloading while (nRead > 0 && !e.Cancel) { if (nRead > 0) fileStream.Write(inBuffer, 0, nRead); byteTotal += nRead; // calculate the progress out of a base "100" double percentage = (double)(byteTotal) / (double)fileLength; // update the progress backgroundWorker1.ReportProgress( (int)(percentage * 100)); nRead = remoteStream.Read(inBuffer, 0, inBuffer.Length); } myResponse.Close(); myRequest.Abort(); } } // if everything is fine if (!e.Cancel) { // write the file time to be same as the original file time BCD.IO.FileEx.SetCreationTime(filePath, myResponse.LastModified); e.Result = filePath; } else { if (File.Exists(filePath)) File.Delete(filePath); } } redirecting = false; } } catch (Exception ex) { redirecting = false; Utils.WriteToLog(ex); } } } catch (Exception ex) { // if error happens on retriving map, assign the error image instead Utils.WriteToLog(ex); } finally { if (myResponse != null) myResponse.Close(); myRequest = null; myResponse = null; } }
////// This function plays the specified vibration. /// /// Must be 0 /// Must be NULL /// A Boolean value that indicates whether the song /// should be repeated. If this parameter is equal to TRUE, it will refer to dwTimeout /// to determine how long the vibration song should play. /// Must be INFINITE ////// This API is not supported by Windows Mobile 6 Professional. [DllImport("aygshell.dll", EntryPoint = "Vibrate")] private static extern int VibrateStart(int cvn, IntPtr rgvn, bool fRepeat, uint dwTimeout); ////// Stops all current vibration songs. /// ////// /// This API not supported by Windows Mobile 6 Professional. /// [DllImport("aygshell.dll")] private static extern int VibrateStop(); private const uint INFINITE = 0xffffffff; ////// Start the mobile vibration. /// ///This is not supported by Windows Mobile 6 Professional. ///public static int StartVibrate() { return VibrateStart(0, IntPtr.Zero, true, INFINITE); } /// /// Stops all current vibration. /// public static void StopVibrate() { VibrateStop(); }This is not supported by Windows Mobile 6 Professional. ///
/** * Ext.ux.grid.PageSize */ Ext.define('Ext.ux.grid.PageSize', { extend : 'Ext.form.field.ComboBox', alias : 'plugin.pagesize', beforeText : 'Show', afterText : 'rows/page', mode : 'local', displayField: 'text', valueField : 'value', allowBlank : false, triggerAction: 'all', width : 50, maskRe : /[0-9]/, /** * initialize the paging combo after the pagebar is randered */ init: function(paging) { paging.on('afterrender', this.onInitView, this); }, /** * create a local store for availabe range of pages */ store: new Ext.data.SimpleStore({ fields: ['text', 'value'], data: [['5', 5], ['10', 10], ['15', 15], ['20', 20], ['25', 25], ['50', 50], ['100', 100], ['200', 200], ['500', 500]] }), /** * assing the select and specialkey events for the combobox * after the pagebar is rendered. */ onInitView: function(paging) { this.setValue(paging.store.pageSize); paging.add('-', this.beforeText, this, this.afterText); this.on('select', this.onPageSizeChanged, paging); this.on('specialkey', function(combo, e) { if(13 === e.getKey()) { this.onPageSizeChanged.call(paging, this); } }); }, /** * refresh the page when the value is changed */ onPageSizeChanged: function(combo) { this.store.pageSize = parseInt(combo.getRawValue(), 10); this.doRefresh(); } });
/** * Ext.ux.grid.DynamicGridPanel */ Ext.define('Ext.ux.grid.DynamicGridPanel', { extend: 'Ext.grid.GridPanel', alias: 'widget.dynamicgrid', /** * initialising the components */ initComponent: function(){ /** * set the config we want */ var config = { columns:[], rowNumberer: false }; // appy to this config Ext.apply(this, config); // apply to the initialConfig Ext.apply(this.initialConfig, config); // call the arguments this.callParent(arguments); }, /** * When the store is loading then reconfigure the column model of the grid */ storeLoad: function() { /** * JSON data returned from server has the column definitions */ if(typeof(this.store.proxy.reader.jsonData.columns) === 'object') { var columns = []; /** * adding RowNumberer as we need to add them * before other columns to display first */ if(this.rowNumberer) { columns.push(Ext.create('Ext.grid.RowNumberer')); } /** * assign new columns from the json data columns */ Ext.each(this.store.proxy.reader.jsonData.columns, function(column){ columns.push(column); }); /** * reconfigure the column model of the grid */ this.reconfigure(this.store, columns); } }, /** * assign the event to itself when the object is initialising */ onRender: function(ct, position){ /** * well, old fashion way, but works well. */ Ext.ux.grid.DynamicGridPanel.superclass.onRender.call(this, ct, position); /** * hook the store load event to our function */ this.store.on('load', this.storeLoad, this); } });
// Start loading the page Ext.onReady(function(){ // we need to define the model but the field values will be parsed // automatically since we provided fields in the metaData from server Ext.define('dynamicModel', { extend: 'Ext.data.Model', //set the proxy proxy: { type: 'rest', url: 'data.php' // the sample server address } }); // create a data store var myStore = Ext.create('Ext.data.Store', { model:'dynamicModel', autoLoad:true, }); // create dynamic grid var myGrid = { title:'Dynamic Grid', xtype:'dynamicgrid', forceFit:true, region:'center', store:myStore, dockedItems: [{ xtype: 'pagingtoolbar', store: myStore, dock: 'bottom', displayInfo: true }] }; // finally, build the main layout once all the pieces are ready. Ext.create('Ext.container.Viewport', { layout:'border', items:[myGrid] }); });
$total = 100; // you can pre-define the required property parameters $output["metaData"]["idProperty"]="id"; $output["metaData"]["totalProperty"]="total"; $output["metaData"]["successProperty"]="success"; $output["metaData"]["root"]="data"; // you can parse field values via your database schema $output["metaData"]["fields"][]=array("name"=>"id","type"=>"int"); $output["metaData"]["fields"][]=array("name"=>"name","type"=>"string"); $output["metaData"]["fields"][]=array("name"=>"firstName","type"=>"string"); $output["metaData"]["fields"][]=array("name"=>"lastName","type"=>"string"); // you can parse column values via your database schema $output["columns"][]=array("dataIndex"=>"id","header"=>"ID", "width"=>10); $output["columns"][]=array("dataIndex"=>"name","header"=>"User Name","width"=>20); $output["columns"][]=array("dataIndex"=>"firstName","header"=>"First Name"); $output["columns"][]=array("dataIndex"=>"lastName","header"=>"Last Name"); // the misc properties $output["total"]=$total; $output["success"]=true; $output["message"]="success"; // parse pages $start = $_GET['start'] + 1; $max = $_GET['start'] + $_GET['limit']; // make sample data for($i = $start; $i <= $max; $i++ ){ $output["data"][]= array( "id"=>$i, "name"=>"UserName-". $i, "firstName"=>"My First Name No. ". $i, "lastName"=>"My Last Name No. ". $i); } // output the value echo json_encode($output);
[DllImport("coredll.dll", SetLastError = true)] private static extern bool SetSystemTime(ref SYSTEMTIME time);
public struct SYSTEMTIME { public short year; public short month; public short dayOfWeek; public short day; public short hour; public short minute; public short second; public short milliseconds; }
public void SetSystemDateTime(DateTime time) { SYSTEMTIME s = new SYSTEMTIME(); s.Year = (short)time.Year; s.Month = (short)time.Month; s.DayOfWeek = (short)time.DayOfWeek; s.Day = (short)time.Day; s.Hour = (short)time.Hour; s.Minute = (short)time.Minute; s.Second = (short)time.Second; s.Milliseconds = (short)time.Millisecond; SetSystemTime(ref s); }
public bool SyncDateTime(string url) { HttpWebRequest myRequest = null; HttpWebResponse myResponse = null; try { //create a HTTP request of the file and capture the response myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.Accept = "*/*"; myRequest.KeepAlive = false; // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable. myResponse = (HttpWebResponse)myRequest.GetResponse(); if (myResponse != null) { if (myResponse.Headers["Date"] != null) { DateTime dt = DateTime.Parse(myResponse.Headers["Date"], CultureInfo.CurrentCulture); // Sets the parsed time to device. SetSystemDateTime(dt.ToUniversalTime()); return true; } } } finally { // Releases the resources of the response. if (myResponse != null) myResponse.Close(); myRequest = null; myResponse = null; } return false; }
/** * Query the installation files * * @param LPTSTR xmlDoc The xml document * @param appName The application name * @return Returns true if installed */ BOOL Utils::QueryInstalledByCSP(LPTSTR xmlDoc, const TCHAR *appName) { BOOL szResult = FALSE; if(xmlDoc == NULL) return FALSE; IXMLDOMDocument *pDOM = NULL; // Load the XML DOM if(SUCCEEDED(CoInitializeEx(NULL,COINIT_MULTITHREADED))) { if(SUCCEEDED(CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IXMLDOMDocument, (LPVOID *) &pDOM))) { // Tell the "doc" that we're not going to load asynchronously. if (SUCCEEDED(pDOM->put_async(VARIANT_FALSE))) { VARIANT_BOOL vBool; pDOM->loadXML(xmlDoc,&vBool); if (vBool == VARIANT_TRUE) { IXMLDOMNode *pNode; if (SUCCEEDED(pDOM->selectSingleNode(_T("wap-provisioningdoc"), &pNode))) { IXMLDOMNodeList *pNodeList; IXMLDOMNode *pNodeChild; IXMLDOMNode *pNodeValue; IXMLDOMNamedNodeMap *pXMLNamedNodeMap; if (SUCCEEDED(pNode->selectSingleNode(_T("characteristic"), &pNode))) { if(SUCCEEDED(pNode->selectNodes(_T("characteristic"), &pNodeList))) { long length = 0; pNodeList->get_length(&length); if(length > 0) { HRESULT hr = pNodeList->nextNode(&pNodeChild); while(hr == S_OK) { if(SUCCEEDED(pNodeChild->get_attributes(&pXMLNamedNodeMap))) { if(SUCCEEDED(pXMLNamedNodeMap->getNamedItem(_T("type"), &pNodeValue))) { VARIANT varNodeValue; if(SUCCEEDED(pNodeValue->get_nodeValue(&varNodeValue))) { if(lstrcmpi(varNodeValue.bstrVal, appName) == 0) { szResult = TRUE; break; } } pNodeValue->Release(); } } hr = pNodeList->nextNode(&pNodeChild); } pXMLNamedNodeMap->Release(); } pNodeList->Release(); } } } pNode->Release(); pNode = NULL; } } pDOM->Release(); // release COM CoUninitialize(); } } return szResult; }
/** * Check the installed application name with related cab file */ BOOL Utils::CheckCabInstalled(LPTSTR xmlDoc, const TCHAR *cabName) { if(lstrcmpi(cabName, _T("NETCFv35.wm.armv4i.cab")) == 0) return QueryInstalledByCSP(xmlDoc, _T("Microsoft .NET CF 3.5")); else if(lstrcmpi(cabName, _T("NETCFv35.Messages.EN.wm.cab")) == 0) return QueryInstalledByCSP(xmlDoc, _T("Microsoft .NET CF 3.5 EN-String Resource")); else if(lstrcmpi(cabName, _T("sqlce.ppc.wce5.armv4i.CAB")) == 0) return QueryInstalledByCSP(xmlDoc, _T("SQLServerCompact 3.5 Core")); else if(lstrcmpi(cabName, _T("sqlce.repl.ppc.wce5.armv4i.CAB")) == 0) return QueryInstalledByCSP(xmlDoc, _T("SQLServerCompact 3.5 Repl")); else if(lstrcmpi(cabName, _T("sqlce.dev.ENU.ppc.wce5.armv4i.CAB")) == 0) return QueryInstalledByCSP(xmlDoc, _T("SQLServerCompact 3.5 Tools EN")); else return FALSE; }
public static Color GetColorDarker(this Color color, double factor) { // The factor value value cannot be greater than 1 or smaller than 0. // Otherwise return the original colour if (factor < 0 || factor > 1) return color; int r = (int)(factor * color.R); int g = (int)(factor * color.G); int b = (int)(factor * color.B); return Color.FromArgb(r, g, b); }
public static Color GetColorLighter(this Color color, double factor) { // The factor value value cannot be greater than 1 or smaller than 0. // Otherwise return the original colour if (factor < 0 || factor > 1) return color; int r = (int)(factor * color.R + (1 - factor) * 255); int g = (int)(factor * color.G + (1 - factor) * 255); int b = (int)(factor * color.B + (1 - factor) * 255); return Color.FromArgb(r, g, b); }
public static bool IsValidUrl(this string url) { string strRegex = "^(https?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // user@ + @"(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP- 10.0.0.1 + "|" // allows either IP or domain + @"([0-9a-z_!~*'()-]+\.)*" // tertiary domain(s)- www. + @"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]" // second level domain + @"(\.[a-z]{2,6})?)" // first level domain- .com or .museum is optional + "(:[0-9]{1,5})?" // port number- :80 + "((/?)|" // a slash isn't required if there is no file name + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; return new Regex(strRegex).IsMatch(url); }
public static string[] WrapString(this Graphics gx, Font font, string text, float maxWidth, bool wrap) { // find if actual max text width is smaller than max width or maxWidth is smaller than zero or wrap is set to false if (gx.MeasureString(text, font).Width < maxWidth || maxWidth <= 0 || !wrap) { return text.Split(new char[] { '\n' }); } int maxChars = (int)(maxWidth / (gx.MeasureString("ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789", font).Width / 37)); //text = text.BreakLongString(maxChars); text = text.Replace(Environment.NewLine, "\n"); text = text.Replace("\r", ""); text = text.Replace("\t", " "); string[] words = text.Split(new char[] { ' ' }); Listlines = new List ((int)(text.Length / maxChars)); string currentLine = ""; for (int i = 0; i < words.Length; i++) { // if the word is empty, then repace it to one space if (string.IsNullOrEmpty(words[i])) words[i] = " "; float currWidth = gx.MeasureString(currentLine + " " + words[i], font).Width; // check if the current width is greater than max length if (currWidth < maxWidth) { // if first entry, then put current line to the first word if ((lines.Count == 0) && string.IsNullOrEmpty(currentLine)) currentLine = words[i]; else { // if not, append each word to current line currentLine += " " + words[i]; // check if the currentline has \n in there. string[] newLines = currentLine.Split('\n'); // if it does, then add a new line if (newLines.Length > 1) { // do not loop to last as it will be the new currentline for (int j = 0; j < newLines.Length - 1; j++) lines.Add(newLines[j]); // the current line is the last line of the new lines currentLine = newLines[newLines.Length - 1]; } } } else { // if the currentline width is greater than max width // then add a new line to the list if (!string.IsNullOrEmpty(currentLine)) lines.Add(currentLine); // make the current line to the last word currentLine = words[i]; } } // if still has word, add it to the list if (!string.IsNullOrEmpty(currentLine)) lines.Add(currentLine); return lines.ToArray(); }