/// <summary> /// 调用设备改变事件 /// </summary> /// <param name="sDev"></param> public static void InvokeSyncDeviceChanged(SyncDevice sDev) { if (SyncDeviceChanged != null) //调用端口移除委托 { SyncDeviceChanged(sDev); } }
void gridViewMain_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { if (e.Column.Name == "gc_operate") { SyncDevice sDev = (SyncDevice)gridViewMain.GetRow(e.RowHandle); if (sDev.syncState == SyncDeviceSyncState.UnSync && sDev.state == SyncDeviceState.Ready) { //满足同步条件 if (!CheckLogin()) { if (LoginMethod != null) { LoginMethod(); } } if (CheckLogin()) { UCSyncData sync = new UCSyncData(sDev); DialogResult dr = sync.ShowPanel(); DealSyncResult(dr, sDev); //sDev.syncState = SyncDeviceSyncState.SyncFailed; //sDev.state = SyncDeviceState.Ready; //SyncDeviceTool.InvokeSyncDeviceChanged(sDev); } } } }
/// <summary> /// HID设备连接事件 /// </summary> /// <param name="hidDev"></param> static void hid_OnConnected(UsbHidDevice hidDev) { if (GetSyncDeviceByHidPath(hidDev.DevicePath) != null) { hid_OnDisConnected(hidDev); } SyncDevice sDev = new SyncDevice(hidDev); }
/// <summary> /// HID设备移除事件 /// </summary> /// <param name="hidDev"></param> static void hid_OnDisConnected(UsbHidDevice hidDev) { SyncDevice sDev = GetSyncDeviceByHidPath(hidDev.DevicePath); if (sDev != null) { sDev.Close(); } }
static bool SyncDeviceTool_SubmitDataMethod(SyncDevice sDev, object submitData) { string submitStr = submitData as string; if (sDev.deviceType == SyncDeviceType.ALKBP || sDev.deviceType == SyncDeviceType.ALKBG || sDev.deviceType == SyncDeviceType.JBQ) { return(TmoServiceClient.InvokeServerMethodT <bool>(funCode.AddMonitorData, submitStr)); } return(false); }
static bool SyncDeviceTool_SubmitDataMethod(SyncDevice sDev, object submitData) { string submitStr = submitData as string; WebServiceDLL.MonitorService service = new WebServiceDLL.MonitorService(); if (sDev.deviceType == SyncDeviceType.ALKBP || sDev.deviceType == SyncDeviceType.ALKBG || sDev.deviceType == SyncDeviceType.JBQ) { return(service.AddMonitorData(submitStr)); } return(false); }
/// <summary> /// 提交数据事件 /// </summary> /// <param name="sDev"></param> /// <param name="submitData"></param> /// <returns></returns> public static bool InvokeSubmitDataMethod(SyncDevice sDev, object submitData) { if (sDev.state == SyncDeviceState.Ready) { if (errPortName.ContainsKey(sDev.portName)) { errPortName.Remove(sDev.portName); } } if (SubmitDataMethod != null) { return(SubmitDataMethod(sDev, submitData)); } return(false); }
private void SyncData() { try { for (int i = 0; i < devList.Count; i++) { SyncDevice sDev = devList[i]; syncingPortName = sDev.portName; this.CrossThreadCalls(() => { //pressTotal.EditValue = i + 1; lblSyncName.Text = string.Format(format0, sDev.deviceName); pressItem.Properties.Maximum = 4; }); if (sDev.state == SyncDeviceState.Ready && sDev.syncState == SyncDeviceSyncState.UnSync) { //满足同步条件 switch (sDev.deviceType) { case SyncDeviceType.ALKBP: case SyncDeviceType.ALKBG: case SyncDeviceType.JBQ: try { sDev.SyncData(); } catch (Exception ex) { returnDR = DialogResult.Ignore; } break; } } } } catch { returnDR = DialogResult.Cancel; } if (devList.Count != 1) { returnDR = returnDR == DialogResult.OK ? DialogResult.OK : returnDR; } else { returnDR = returnDR == DialogResult.OK ? DialogResult.OK : DialogResult.Cancel; } }
void ParentForm_FormClosed(object sender, FormClosedEventArgs e) { if (th_syncData != null && th_syncData.ThreadState != ThreadState.Stopped) //终止线程 { th_syncData.Abort(); } for (int i = 0; i < devList.Count; i++) { SyncDevice sDev = devList[i]; if (sDev.syncState != SyncDeviceSyncState.Synced) { sDev.syncState = SyncDeviceSyncState.UnSync; SyncDeviceTool.InvokeSyncDeviceChanged(sDev); } } }
void SyncDeviceTool_SyncDeviceChanged(SyncDevice sDev) { if (sDev.portName == syncingPortName) { this.CrossThreadCalls(() => { lblOperatorName.Text = sDev.syncStateText; switch (sDev.syncState) { case SyncDeviceSyncState.UnSync: pressItem.EditValue = 0; break; case SyncDeviceSyncState.Synced: pressItem.EditValue = 4; break; case SyncDeviceSyncState.ReadData: pressItem.EditValue = 1; break; case SyncDeviceSyncState.DealData: pressItem.EditValue = 2; break; case SyncDeviceSyncState.OptData: pressItem.EditValue = 3; break; case SyncDeviceSyncState.SyncData: pressItem.EditValue = 3; break; case SyncDeviceSyncState.SyncFailed: pressItem.EditValue = 4; break; } if (sDev.state == SyncDeviceState.Removed) { if (this.ParentForm != null) { this.ParentForm.Close(); } } }); } }
private void DealSyncResult(DialogResult dr, SyncDevice sDev = null) { if (dr == System.Windows.Forms.DialogResult.OK) { string msg = (sDev == null ? "" : "【" + sDev.deviceName + "】") + "数据同步成功!"; DXMessageBox.Show(msg, true); } else if (dr == System.Windows.Forms.DialogResult.Ignore) { DXMessageBox.Show("部分设备同步未成功!", true); } else if (dr == System.Windows.Forms.DialogResult.Cancel) { string msg = (sDev == null ? "" : "【" + sDev.deviceName + "】") + "数据同步失败!\n请尝试重新插拔设备并重试"; DXMessageBox.ShowError(msg); } else if (dr == System.Windows.Forms.DialogResult.Abort) { DXMessageBox.Show("没有可同步设备,已取消同步!", true); } }
void SyncDeviceTool_SyncDeviceChanged(SyncDevice sDev) { this.CrossThreadCalls(() => { switch (sDev.state) { case SyncDeviceState.Scaned: deviceList.Add(sDev); break; case SyncDeviceState.Removed: deviceList.Remove(sDev); break; default: if (!deviceList.Contains(sDev)) { deviceList.Add(sDev); } break; } gc_DevList.RefreshDataSource(); }); }
public void RefreshDevice(SyncDevice device) { Dispatcher.BeginInvoke(() => { lblTitle.Text = device.Name; }); }
protected override void CreateSyncDownloadViewInternal(Action<IBaseView> onViewReady, SyncDevice device, IEnumerable<AudioFile> audioFiles) { _onSyncDownloadViewReady = onViewReady; var frame = Application.Current.RootVisual as PhoneApplicationFrame; frame.Navigate(new Uri("/Classes/Pages/SyncDownloadPage.xaml", UriKind.Relative)); }
public void SyncDevice(SyncDevice device) { }
// private bool IsAuthenticated(HttpListenerContext context) // { // var authenticationCodeCookie = context.Request.Cookies["authenticationCode"]; // if(authenticationCodeCookie != null) // { // string authenticationCode = authenticationCodeCookie.Value; // if(AuthenticationCode.ToUpper() == authenticationCode.ToUpper()) // return true; // else // return false; // } // return false; // } // private void WriteRedirect(HttpListenerContext context, string url) // { // byte[] responseBytes = System.Text.Encoding.UTF8.GetBytes("redirect"); // context.Response.RedirectLocation = url; // context.Response.StatusCode = 302; // context.Response.ContentType = "text/html"; // context.Response.ContentLength64 = responseBytes.Length; // context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length); // context.Response.OutputStream.Close(); // } // private void WriteHTMLResponse(HttpListenerContext context, string response) // { // WriteHTMLResponse(context, response, HttpStatusCode.OK); // } // private void WriteHTMLResponse(HttpListenerContext context, string response, HttpStatusCode statusCode) // { // WriteResponse(context, response, statusCode, "text/html"); // } // private void WriteXMLResponse(HttpListenerContext context, string response) // { // WriteResponse(context, response, HttpStatusCode.OK, "text/html"); // } // private void WriteJSONResponse(HttpListenerContext context, string response) // { // WriteResponse(context, response, HttpStatusCode.OK, "text/html"); // } // private void WriteResponse(HttpListenerContext context, string response, HttpStatusCode statusCode, string contentType) // { // byte[] responseBytes = System.Text.Encoding.UTF8.GetBytes(response); // context.Response.ContentType = contentType; // context.Response.StatusCode = (int)statusCode; // context.Response.ContentLength64 = responseBytes.Length; // context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length); // context.Response.OutputStream.Close(); // } // private void WriteFileResponse(HttpListenerContext context, string filePath, bool isAttachment) // { // var response = context.Response; // using (FileStream fs = File.OpenRead(filePath)) // { // response.ContentLength64 = fs.Length; // response.SendChunked = false; // response.ContentType = System.Net.Mime.MediaTypeNames.Application.Octet; // if(isAttachment) // response.AddHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filePath)); // byte[] buffer = new byte[64 * 1024]; // int read; // using (BinaryWriter bw = new BinaryWriter(response.OutputStream)) // { // while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) // { // bw.Write(buffer, 0, read); // bw.Flush(); // } // bw.Close(); // } // response.StatusCode = (int)HttpStatusCode.OK; // response.StatusDescription = "OK"; // response.OutputStream.Close(); // } // } // private void WriteFileResponse(HttpListenerContext context, Stream stream, string fileName) // { // Console.WriteLine("SyncListenerService - WriteFileResponse - fileName: {0}", fileName); // var response = context.Response; //// string extension = Path.GetExtension(fileName); //// if (extension.ToUpper().Contains("CSS")) //// response.ContentType = "text/css"; //// else if (extension.ToUpper().Contains("HTML")) //// response.ContentType = "text/html"; //// else if (extension.ToUpper().Contains("JS")) //// response.ContentType = "text/plain"; // response.ContentLength64 = stream.Length; // response.SendChunked = false; // byte[] buffer = new byte[64 * 1024]; // int read; // using (BinaryWriter bw = new BinaryWriter(response.OutputStream)) // { // while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) // { // bw.Write(buffer, 0, read); // bw.Flush(); // } // bw.Close(); // } // response.StatusCode = (int)HttpStatusCode.OK; // response.StatusDescription = "OK"; // response.OutputStream.Close(); // } // private void ReadFileTextResponse(HttpListenerContext context) // { // var request = context.Request; // if (!request.HasEntityBody) // { // Console.WriteLine("No client data was sent with the request."); // return; // } // if (request.ContentType != null) // Console.WriteLine("Client data content type {0}", request.ContentType); // Stream stream = request.InputStream; // StreamReader reader = new StreamReader(stream, request.ContentEncoding); // Console.WriteLine("Client data content length {0}", request.ContentLength64); // Console.WriteLine("[Start of client data]"); // string s = reader.ReadToEnd(); // Console.WriteLine(s); // Console.WriteLine("[End of client data]"); // stream.Close(); // reader.Close(); // } // private void ReadFileBinaryResponse(HttpListenerContext context) // { // string fileName = "/Users/ycastonguay/Desktop/hello.mp3"; // var request = context.Request; // Console.WriteLine("SyncListenerService - ReadFileBinaryResponse fileName: {0}", fileName); // if (!request.HasEntityBody) // { // Console.WriteLine("No client data was sent with the request."); // return; // } // if (request.ContentType != null) // Console.WriteLine("Client data content type {0}", request.ContentType); // Stream stream = request.InputStream; // BinaryReader reader = new BinaryReader(stream); // using (FileStream writeStream = File.OpenWrite(fileName)) // { // byte[] buffer = new byte[1024]; // int bytesRead; // while ((bytesRead = stream.Read(buffer, 0, 1024)) > 0) // { // writeStream.Write(buffer, 0, bytesRead); // } // } // stream.Close(); // reader.Close(); // } //private String GetBoundary(String ctype) //{ // return "--" + ctype.Split(';')[1].Split('=')[1]; //} //private void ReadFileMultiPartFormData(Encoding enc, String boundary, Stream input) //{ // // http://stackoverflow.com/questions/8466703/httplistener-and-file-upload // string fileName = "/Users/ycastonguay/Desktop/test.txt"; // Console.WriteLine("SyncListenerService - ReadFileMultiPartFormData fileName: {0}", fileName); // // TODO: Add multiple files... // Byte[] boundaryBytes = enc.GetBytes(boundary); // Int32 boundaryLen = boundaryBytes.Length; // using (FileStream output = new FileStream(fileName, FileMode.Create, FileAccess.Write)) // { // Byte[] buffer = new Byte[1024]; // Int32 len = input.Read(buffer, 0, 1024); // Int32 startPos = -1; // // Find start boundary // while (true) // { // if (len == 0) // { // throw new Exception("Start Boundaray Not Found"); // } // startPos = IndexOf(buffer, len, boundaryBytes); // if (startPos >= 0) // { // break; // } // else // { // Array.Copy(buffer, len - boundaryLen, buffer, 0, boundaryLen); // len = input.Read(buffer, boundaryLen, 1024 - boundaryLen); // } // } // // Skip four lines (Boundary, Content-Disposition, Content-Type, and a blank) // for (Int32 i = 0; i < 4; i++) // { // while (true) // { // if (len == 0) // { // throw new Exception("Preamble not Found."); // } // startPos = Array.IndexOf(buffer, enc.GetBytes("\n")[0], startPos); // Console.WriteLine("Multipart - skip 4 lines - startPos: {0}", startPos); // if (startPos >= 0) // { // startPos++; // break; // } // else // { // len = input.Read(buffer, 0, 1024); // } // } // } // Array.Copy(buffer, startPos, buffer, 0, len - startPos); // len = len - startPos; // while (true) // { // Int32 endPos = IndexOf(buffer, len, boundaryBytes); // if (endPos >= 0) // { // if (endPos > 0) output.Write(buffer, 0, endPos); // break; // } // else if (len <= boundaryLen) // { // throw new Exception("End Boundaray Not Found"); // } // else // { // output.Write(buffer, 0, len - boundaryLen); // Array.Copy(buffer, len - boundaryLen, buffer, 0, boundaryLen); // len = input.Read(buffer, boundaryLen, 1024 - boundaryLen) + boundaryLen; // } // } // } // input.Close(); //} //private Int32 IndexOf(Byte[] buffer, Int32 len, Byte[] boundaryBytes) //{ // for (Int32 i = 0; i <= len - boundaryBytes.Length; i++) // { // Boolean match = true; // for (Int32 j = 0; j < boundaryBytes.Length && match; j++) // { // match = buffer[i + j] == boundaryBytes[j]; // } // if (match) // { // return i; // } // } // return -1; //} // Alternative that doesnt work under MonoTouch though! // public static IPAddress GetIPAddressForDesktop() // { // if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) // return null; // // IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); // return host.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork); // } //public static string GetLocalIPAddress() //{ // string address = "Not Connected"; // try // { // //Console.WriteLine("GetIPAddress - Detecting IP address..."); // foreach (var ni in NetworkInterface.GetAllNetworkInterfaces()) // { // //Console.WriteLine("GetIPAddress - NetworkInterface: {0} {1}", ni.Name, ni.NetworkInterfaceType.ToString()); // if(ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || // ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) // { // IPAddress ip = null; // foreach (var a in ni.GetIPProperties().UnicastAddresses) // { // //Console.WriteLine("GetIPAddress - Address: {0} {1}", a.Address, a.Address.AddressFamily.ToString()); // if(a.Address.AddressFamily == AddressFamily.InterNetwork) // { // //Console.WriteLine("GetIPAddress - Address **FOUND**: {0} {1}", a.Address, a.Address.AddressFamily.ToString()); // ip = a.Address; // break; // } // } // if(ip != null) // { // address = ip.ToString(); // break; // } // } // } // } // catch (Exception ex) // { // Console.WriteLine("GetIPAddress - Exception: {0}", ex); // } // return address; //} public SyncDevice GetInternalSyncDevice() { var device = new SyncDevice(); device.SyncVersionId = SyncVersionId; device.Name = _syncDeviceSpecifications.GetDeviceName(); device.DeviceType = _syncDeviceSpecifications.GetDeviceType(); return device; }
protected override void CreateSyncMenuViewInternal(Action<IBaseView> onViewReady, SyncDevice device) { _onSyncMenuViewReady = onViewReady; var frame = Window.Current.Content as Frame; frame.Navigate(typeof(SyncMenuPage)); }
protected override void CreateSyncDownloadViewInternal(Action<IBaseView> onViewReady, SyncDevice device, IEnumerable<AudioFile> audioFiles) { _onSyncDownloadViewReady = onViewReady; var frame = Window.Current.Content as Frame; frame.Navigate(typeof(SyncDownloadPage)); }
public void RefreshDevice(SyncDevice device) { }
protected override void CreateSyncMenuViewInternal(Action<IBaseView> onViewReady, SyncDevice device) { _onSyncMenuViewReady = onViewReady; var frame = Application.Current.RootVisual as PhoneApplicationFrame; frame.Navigate(new Uri("/Classes/Pages/SyncMenuPage.xaml", UriKind.Relative)); }