//get device id public static string getDeviceId() { string strDeviceUniqueID = ""; try { byte[] byteArray = DeviceExtendedProperties.GetValue("DeviceUniqueId") as byte[]; string strTemp = ""; foreach (byte b in byteArray) { strTemp = b.ToString(); if (1 == strTemp.Length) { strTemp = "00" + strTemp; } else if (2 == strTemp.Length) { strTemp = "0" + strTemp; } strDeviceUniqueID += strTemp; } } catch (Exception e) { DebugTool.Log(e); } return(strDeviceUniqueID); }
private void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; System.IO.Stream postStream = request.EndGetRequestStream(asynchronousResult); string parametersString = "content=" + this.message; // DebugTool.Log("post data:" + message); byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(parametersString); // Write to the request stream. postStream.Write(byteArray, 0, parametersString.Length); postStream.Close(); // Start the asynchronous operation to get the response try { request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); } catch (Exception e) { DebugTool.Log(e.InnerException.Message); } }
//TODO: is it good to use async void here? public static async void saveFile(int type, object obj) { try { Windows.Storage.ApplicationDataContainer settings = Windows.Storage.ApplicationData.Current.LocalSettings; switch (type) { case (int)UMSApi.DataType.CLIENTDATA: // client data ClientData c = (ClientData)obj; List <ClientData> list_clientdata = await ApplicationSettings.GetSettingFromXmlFileAsync <List <ClientData> >(SettingKeys.CLIENT_DATA, new List <ClientData>()); list_clientdata.Add(c); await ApplicationSettings.SetSettingToXmlFileAsync <List <ClientData> >(SettingKeys.CLIENT_DATA, list_clientdata); // DebugTool.Log("client data list size:" + list_clientdata.Count); break; case (int)UMSApi.DataType.EVENTDATA: //event data Event e = (Event)obj; List <Event> list_event = await ApplicationSettings.GetSettingFromXmlFileAsync <List <Event> >(SettingKeys.EVENT_DATA, new List <Event>()); list_event.Add(e); await ApplicationSettings.SetSettingToXmlFileAsync <List <Event> >(SettingKeys.EVENT_DATA, list_event); DebugTool.Log("event list size:" + list_event.Count); break; case (int)UMSApi.DataType.ERRORDATA: //error data break; case (int)UMSApi.DataType.PAGEINFODATA: //page info data PageInfo pageinfo = (PageInfo)obj; List <PageInfo> list_pageinfo = await ApplicationSettings.GetSettingFromXmlFileAsync <List <PageInfo> >(SettingKeys.PAGE_INFO, new List <PageInfo>()); list_pageinfo.Add(pageinfo); await ApplicationSettings.SetSettingToXmlFileAsync <List <PageInfo> >(SettingKeys.PAGE_INFO, list_pageinfo); DebugTool.Log("pageinfo list size:" + list_pageinfo.Count); break; default: break; } ApplicationSettings.SetSetting <string>(SettingKeys.HAS_DATA_TO_SEND, "1"); } catch (Exception ex)//UnauthorizedAccessException { Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); } }
//all data private string allData2jsonstr() { AllInfo allinfo = new AllInfo(); allinfo.appkey = UmsManager.appkey; string ret = ""; IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; if (settings.Contains("clientdata")) { List <ClientData> list_client_data = (List <ClientData>)settings["clientdata"]; allinfo.clientData = list_client_data; } if (settings.Contains("tagdata")) { List <Tag> list_tag_data = (List <Tag>)settings["tagdata"]; allinfo.tagListInfo = list_tag_data; } if (settings.Contains("eventdata")) { List <Event> list_event_data = (List <Event>)settings["eventdata"]; allinfo.eventInfo = list_event_data; } try { string err_str = CrashListener.CheckForPreviousException(); ErrorInfo error = UmsJson.Deserialize <ErrorInfo>(err_str); if (error != null) { List <ErrorInfo> err_list = new List <ErrorInfo>(); err_list.Add(error); allinfo.errorInfo = err_list; } } catch (Exception e) { DebugTool.Log(e.Message); } if (settings.Contains("pageinfo")) { List <PageInfo> list_pageinfo_data = (List <PageInfo>)settings["pageinfo"]; allinfo.activityInfo = list_pageinfo_data; } ret = UmsJson.Serialize(allinfo); return(ret); }
public async void sendData(string url) { /* * var request = HttpWebRequest.Create(url); * var result = (IAsyncResult)request.BeginGetResponse(ResponseCallback, request); */ //HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); //myRequest.Method = "POST"; //myRequest.ContentType = "application/x-www-form-urlencoded"; //myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest); HttpClient client = new GZipHttpClient(); //must call getPostInfo() to initialize the message first await getPostInfo(); HttpContent httpContent = new StringContent("content=" + this.message);//TODO convert to UTF8 httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); HttpResponseMessage response = null; try { response = await client.PostAsync(url, httpContent); DebugTool.Log("post response:" + response); } catch (HttpRequestException ex) { //do nothing response = null; } if (response == null || response.StatusCode != HttpStatusCode.OK) { CommonRet errorRet = new CommonRet(); errorRet.flag = "-100"; errorRet.msg = "server error "; if (response != null) { errorRet.msg += response.StatusCode; } ret = UmsJson.Serialize(errorRet); DebugTool.Log(ret); stateChanged(type, ret, obj); } else { ret = await response.Content.ReadAsStringAsync(); stateChanged(type, ret, obj); } }
//get device resolution public static string getResolution() { try { double w = System.Windows.Application.Current.Host.Content.ActualWidth; double h = System.Windows.Application.Current.Host.Content.ActualHeight; return(w.ToString() + "*" + h.ToString()); } catch (Exception e) { DebugTool.Log(e.Message.ToString()); } return(""); }
//get device name public static string getDeviceName() { string devicename = ""; try { devicename = DeviceExtendedProperties.GetValue("DeviceName").ToString(); } catch (Exception e) { DebugTool.Log(e); } return(devicename); }
//get current app version public static string getApplicationVersion() { string version = ""; try { version = XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value; } catch (Exception e) { DebugTool.Log(e); } return(version); }
//get os version public static string getOsVersion() { //OperatingSystem os = Environment.OSVersion; //return os.Platform + os.Version.ToString(); string version = ""; try { version = System.Environment.OSVersion.Version.ToString(); } catch (Exception e) { DebugTool.Log(e); } return("windows phone " + version); }
//get device resolution public static string getResolution() { try { var bounds = Window.Current.Bounds; double h = bounds.Height; double w = bounds.Width; return(w.ToString() + "*" + h.ToString()); } catch (Exception e) { DebugTool.Log(e.Message.ToString()); } return(""); }
private void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = null; try { response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); } catch (Exception e) { DebugTool.Log(e.InnerException.Message); } if (response == null) { CommonRet errorRet = new CommonRet(); errorRet.flag = "-100"; errorRet.msg = "server is not founded."; ret = UmsJson.Serialize(errorRet); DebugTool.Log(ret); stateChanged(type, ret, obj); return; } Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseString = streamRead.ReadToEnd(); // Close the stream object streamResponse.Close(); streamRead.Close(); ret = responseString; stateChanged(type, ret, obj); }
//get current app version public static string getApplicationVersion() { string versionStr = ""; try { Package package = Package.Current; PackageId packageId = package.Id; PackageVersion version = packageId.Version; versionStr = string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision); //version = XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value; } catch (Exception e) { DebugTool.Log(e); } return(versionStr); }
//check is exist crash log public static bool isExistCrashLog() { try { string err_str = CrashListener.CheckForPreviousException(); ErrorInfo o = UmsJson.Deserialize <ErrorInfo>(err_str); if (o != null) { return(true); } } catch (Exception e) { DebugTool.Log(e.Message); return(false); } return(false); }
//get lati and longi public static double[] GetLocationProperty() { double[] latLong = new double[2]; try { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(); watcher.TryStart(false, TimeSpan.FromMilliseconds(1000)); GeoCoordinate coord = watcher.Position.Location; if (coord.IsUnknown != true) { latLong[0] = coord.Latitude; latLong[1] = coord.Longitude; } } catch (Exception e) { DebugTool.Log(e); } return(latLong); }
//all data private async Task <string> allData2jsonstr() { AllInfo allinfo = new AllInfo(); allinfo.appkey = UmsManager.appkey; string ret = ""; Windows.Storage.ApplicationDataContainer settings = Windows.Storage.ApplicationData.Current.LocalSettings; allinfo.clientData = await ApplicationSettings.GetSettingFromXmlFileAsync <List <ClientData> >(SettingKeys.CLIENT_DATA, null); allinfo.eventInfo = await ApplicationSettings.GetSettingFromXmlFileAsync <List <Event> >(SettingKeys.EVENT_DATA, null); allinfo.activityInfo = await ApplicationSettings.GetSettingFromXmlFileAsync <List <PageInfo> >(SettingKeys.PAGE_INFO, null); //patch: we nolonger use in storage settings anymore, just remove it for old versions ApplicationSettings.RemoveSetting(SettingKeys.CLIENT_DATA); ApplicationSettings.RemoveSetting(SettingKeys.EVENT_DATA); ApplicationSettings.RemoveSetting(SettingKeys.PAGE_INFO); try { string err_str = CrashListener.CheckForPreviousException(); ErrorInfo error = UmsJson.Deserialize <ErrorInfo>(err_str); if (error != null) { List <ErrorInfo> err_list = new List <ErrorInfo>(); err_list.Add(error); allinfo.errorInfo = err_list; } } catch (Exception e) { DebugTool.Log(e.Message); } ret = UmsJson.Serialize(allinfo); return(ret); }
public static void saveFile(int type, object obj) { IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; switch (type) { case (int)UMSApi.DataType.CLIENTDATA: // client data List <ClientData> list_clientdata = new List <ClientData>(); ClientData c = (ClientData)obj; if (settings.Contains("clientdata")) { list_clientdata = (List <ClientData>)settings["clientdata"]; list_clientdata.Add(c); settings["clientdata"] = list_clientdata; } else { list_clientdata.Add(c); settings.Add("clientdata", list_clientdata); } settings.Save(); // DebugTool.Log("client data list size:" + list_clientdata.Count); break; case (int)UMSApi.DataType.EVENTDATA: //event data List <Event> list_event = new List <Event>(); Event e = (Event)obj; if (settings.Contains("eventdata")) { list_event = (List <Event>)settings["eventdata"]; list_event.Add(e); settings["eventdata"] = list_event; } else { list_event.Add(e); settings.Add("eventdata", list_event); } settings.Save(); DebugTool.Log("event list size:" + list_event.Count); break; case (int)UMSApi.DataType.ERRORDATA: //error data break; case (int)UMSApi.DataType.PAGEINFODATA: //page info data PageInfo pageinfo = (PageInfo)obj; List <PageInfo> list_pageinfo = new List <PageInfo>(); if (settings.Contains("pageinfo")) { list_pageinfo = (List <PageInfo>)settings["pageinfo"]; list_pageinfo.Add(pageinfo); settings["pageinfo"] = list_pageinfo; } else { list_pageinfo.Add(pageinfo); settings.Add("pageinfo", list_pageinfo); } settings.Save(); DebugTool.Log("pageinfo list size:" + list_pageinfo.Count); break; default: break; } if (settings.Contains("hasDateToSend")) { settings["hasDateToSend"] = "1"; } else { settings.Add("hasDateToSend", "1"); } }