private void CheckForUpdates() { NamedPipeClientStream pipeServerIn = null; try { if (File.Exists(Statics.LocalUpdateFilePath)) { try { //remove the previously downloaded update File.Delete(Statics.LocalUpdateFilePath); } catch { } } UpdateInfo.Update_InfoRow uir = Statics.ReadUpdateInfoFile(); if (uir != null) { DateTime?dtLastCheck = uir.LastUpdateCheck; if (dtLastCheck != null && DateTime.Now - dtLastCheck < TimeSpan.FromDays(1)) { return; } } //save the last time the update check was run UpdateInfo uinfo = new UpdateInfo(); uinfo.Update_Info.AddUpdate_InfoRow(DateTime.Now); Statics.SaveUpdateInfoFile(uinfo); pipeServerIn = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorIn"); if (!pipeServerIn.IsConnected) { pipeServerIn.Connect(2000); } StreamString ss = new StreamString(pipeServerIn); //verify server identity if (ss.ReadString() == "BloodSpider_Service") { //show the connected icon ChangeNotifyIcon(Icons.Enabled); //talking to the correct service so send the message ss.WriteString("CHECK_FOR_UPDATES|"); } }//try catch (Exception ex) { } finally { if (pipeServerIn != null) { pipeServerIn.Close(); } } }
private static void pipeWrite(string command, string Text1, string Text2, int icon) { //icon = (1 = Info, 2 = Warning, 3 = Error) NamedPipeClientStream pipeServerOut = null; try { pipeServerOut = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorIn"); if (!pipeServerOut.IsConnected) { pipeServerOut.Connect(2000); } StreamString ss = new StreamString(pipeServerOut); //verify server identity if (ss.ReadString() == "BloodSpider_Service") { //talking to the correct service so send the message ss.WriteString(command + "|" + Text1 + "|" + Text2 + "|" + (icon == 0 ? "" : icon.ToString())); } }//try catch (System.TimeoutException tex) { Error("003", tex); } catch (Exception ex) { Error("004", ex); } finally { pipeServerOut.Close(); } }
private void GetVersionFromService() { NamedPipeClientStream pipeServerIn = null; try { pipeServerIn = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorIn", PipeDirection.InOut, PipeOptions.None, System.Security.Principal.TokenImpersonationLevel.Anonymous, HandleInheritability.Inheritable); if (!pipeServerIn.IsConnected) { pipeServerIn.Connect(2000); } StreamString ss = new StreamString(pipeServerIn); //verify server identity if (ss.ReadString() == "BloodSpider_Service") { //show the connected icon, if not busy if (!busy) { ChangeNotifyIcon(Icons.Enabled); } //talking to the correct service so send the message ss.WriteString("VERSION|"); currentVersion = ss.ReadString(); menuItem_Version.Text = "BloodSpider " + currentVersion; settingsNotifyIcon.Text = menuItem_Version.Text; this.Text = "BloodSpider Settings v" + currentVersion; } }//try catch (System.TimeoutException) { ChangeNotifyIcon(Icons.Disabled); } finally { if (pipeServerIn != null) { pipeServerIn.Close(); } } }
private static void pipeWrite(string command, string Text1, string Text2, int icon) { //icon = (1 = Info, 2 = Warning, 3 = Error) NamedPipeClientStream pipeServerOut = null; try { pipeServerOut = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorOut"); if (!pipeServerOut.IsConnected) { pipeServerOut.Connect(2000); } StreamString ss = new StreamString(pipeServerOut); //verify server identity if (ss.ReadString() == "BloodSpider_NotifyIcon") { //talking to the correct service so send the message ss.WriteString(command + "|" + Text1 + "|" + Text2 + "|" + (icon == 0 ? "" : icon.ToString())); } }//try catch (System.TimeoutException) { Exception ex = new Exception("Notify icon app not started so no settings file could be read. Aborting read."); Errors.ServiceError(ex); Detector.ReportException("W0005", ex); } catch (Exception ex) { Errors.ServiceError(ex); Detector.ReportException("W0006", ex); } finally { pipeServerOut.Close(); } }
private void background_CommandServer_DoWork(object sender, DoWorkEventArgs e) { if (Thread.CurrentThread.Name == null) Thread.CurrentThread.Name = "CommandServer"; NamedPipeServerStream pipeServer = null; try { pipeServer = new NamedPipeServerStream("pipeBloodSpiderDetectorOut", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous); pipeServer.WaitForConnection(); StreamString ss = new StreamString(pipeServer); //verify identity ss.WriteString("BloodSpider_NotifyIcon"); //get command from client var command = ss.ReadString(); var split = command.Split(new string[] { "|" }, StringSplitOptions.None); switch (split[0].ToUpperInvariant().Trim()) { case "MSG": ToolTipIcon icon = ToolTipIcon.None; switch (split[3]) { case "1": icon = ToolTipIcon.Info; break; case "2": icon = ToolTipIcon.Warning; break; case "3": icon = ToolTipIcon.Error; break; default: break; } ShowNotificationBalloon(5000, split[1], split[2], icon); break; case "ULD": DialogResult result = MessageBox.Show(split[2], split[1], MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { pipeWrite("ULD_YES", string.Empty, string.Empty, 0); } break; case "BUSYICON": switch (split[1].ToLowerInvariant()) { case "busy": ChangeNotifyIcon(Icons.Busy); break; case "notbusy": ChangeNotifyIcon(Icons.Enabled); break; case "disabled": ChangeNotifyIcon(Icons.Disabled); break; default: break; } break; case "PATH_REQ": pipeWrite("ULD_PATH_RESP", Path.Combine(Common.Statics.BaseFilepath, "BloodSpider.sav"), string.Empty, 0); break; case "UPDATE_CHECK_FINISHED": PerformUpdate(split[1]); break; default: break; }; } catch (Exception) { } finally { if (pipeServer != null) pipeServer.Close(); } }
private static void pipeWrite(string command, string Text1, string Text2, int icon) { //icon = (1 = Info, 2 = Warning, 3 = Error) NamedPipeClientStream pipeServerOut = null; try { pipeServerOut = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorIn"); if (!pipeServerOut.IsConnected) pipeServerOut.Connect(2000); StreamString ss = new StreamString(pipeServerOut); //verify server identity if (ss.ReadString() == "BloodSpider_Service") { //talking to the correct service so send the message ss.WriteString(command + "|" + Text1 + "|" + Text2 + "|" + (icon == 0 ? "" : icon.ToString())); } }//try catch (System.TimeoutException tex) { Error("003", tex); } catch (Exception ex) { Error("004", ex); } finally { pipeServerOut.Close(); } }
private void CheckForUpdates() { NamedPipeClientStream pipeServerIn = null; try { if (File.Exists(Statics.LocalUpdateFilePath)) { try { //remove the previously downloaded update File.Delete(Statics.LocalUpdateFilePath); } catch { } } UpdateInfo.Update_InfoRow uir = Statics.ReadUpdateInfoFile(); if (uir != null) { DateTime? dtLastCheck = uir.LastUpdateCheck; if (dtLastCheck != null && DateTime.Now - dtLastCheck < TimeSpan.FromDays(1)) { return; } } //save the last time the update check was run UpdateInfo uinfo = new UpdateInfo(); uinfo.Update_Info.AddUpdate_InfoRow(DateTime.Now); Statics.SaveUpdateInfoFile(uinfo); pipeServerIn = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorIn"); if (!pipeServerIn.IsConnected) pipeServerIn.Connect(2000); StreamString ss = new StreamString(pipeServerIn); //verify server identity if (ss.ReadString() == "BloodSpider_Service") { //show the connected icon ChangeNotifyIcon(Icons.Enabled); //talking to the correct service so send the message ss.WriteString("CHECK_FOR_UPDATES|"); } }//try catch (Exception ex) { } finally { if (pipeServerIn != null) pipeServerIn.Close(); } }
private void GetVersionFromService() { NamedPipeClientStream pipeServerIn = null; try { pipeServerIn = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorIn", PipeDirection.InOut, PipeOptions.None, System.Security.Principal.TokenImpersonationLevel.Anonymous, HandleInheritability.Inheritable); if (!pipeServerIn.IsConnected) pipeServerIn.Connect(2000); StreamString ss = new StreamString(pipeServerIn); //verify server identity if (ss.ReadString() == "BloodSpider_Service") { //show the connected icon, if not busy if (!busy) ChangeNotifyIcon(Icons.Enabled); //talking to the correct service so send the message ss.WriteString("VERSION|"); currentVersion = ss.ReadString(); menuItem_Version.Text = "BloodSpider " + currentVersion; settingsNotifyIcon.Text = menuItem_Version.Text; this.Text = "BloodSpider Settings v" + currentVersion; } }//try catch (System.TimeoutException) { ChangeNotifyIcon(Icons.Disabled); } finally { if (pipeServerIn != null) pipeServerIn.Close(); } }
private void background_CommandServer_DoWork(object sender, DoWorkEventArgs e) { if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "CommandServer"; } NamedPipeServerStream pipeServer = null; try { pipeServer = new NamedPipeServerStream("pipeBloodSpiderDetectorOut", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous); pipeServer.WaitForConnection(); StreamString ss = new StreamString(pipeServer); //verify identity ss.WriteString("BloodSpider_NotifyIcon"); //get command from client var command = ss.ReadString(); var split = command.Split(new string[] { "|" }, StringSplitOptions.None); switch (split[0].ToUpperInvariant().Trim()) { case "MSG": ToolTipIcon icon = ToolTipIcon.None; switch (split[3]) { case "1": icon = ToolTipIcon.Info; break; case "2": icon = ToolTipIcon.Warning; break; case "3": icon = ToolTipIcon.Error; break; default: break; } ShowNotificationBalloon(5000, split[1], split[2], icon); break; case "ULD": DialogResult result = MessageBox.Show(split[2], split[1], MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { pipeWrite("ULD_YES", string.Empty, string.Empty, 0); } break; case "BUSYICON": switch (split[1].ToLowerInvariant()) { case "busy": ChangeNotifyIcon(Icons.Busy); break; case "notbusy": ChangeNotifyIcon(Icons.Enabled); break; case "disabled": ChangeNotifyIcon(Icons.Disabled); break; default: break; } break; case "PATH_REQ": pipeWrite("ULD_PATH_RESP", Path.Combine(Common.Statics.BaseFilepath, "BloodSpider.sav"), string.Empty, 0); break; case "UPDATE_CHECK_FINISHED": PerformUpdate(split[1]); break; default: break; } ; } catch (Exception) { } finally { if (pipeServer != null) { pipeServer.Close(); } } }
private void background_CommandServer_DoWork(object sender, DoWorkEventArgs e) { if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "CommandServer"; } NamedPipeServerStream pipeServer = null; try { PipeSecurity pipeSecurity = new PipeSecurity(); pipeSecurity.AddAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); pipeServer = new NamedPipeServerStream("pipeBloodSpiderDetectorIn", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.None, 512, 512, pipeSecurity, HandleInheritability.None); //pipeServer = new NamedPipeServerStream("pipeBloodSpiderDetectorIn", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous); pipeServer.WaitForConnection(); StreamString ss = new StreamString(pipeServer); //verify identity ss.WriteString("BloodSpider_Service"); //get command from client var command = ss.ReadString(); var split = command.Split(new string[] { "|" }, StringSplitOptions.None); switch (split[0].ToUpperInvariant().Trim()) { case "VERSION": Version ver = Assembly.GetExecutingAssembly().GetName().Version; ss.WriteString(ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString()); break; case "ULD_YES": startReaderThread(); break; case "ULD_PATH_RESP": settings = Common.Statics.ReadSettingsFile(split[1]); if (settings != null && settings.Options != null) { if (settings.Options.Rows.Count > 0 && (bool)settings.Options.Rows[0]["AutoUpload"]) { //auto upload startReaderThread(); } else { //no auto upload, require user input if (Common.Statics.deviceFound != null) { pipeWrite("ULD", "Found Meter", "Would you like to upload data from the " + Common.Statics.deviceFound.DeviceDescription + "?", 1); } } } break; case "CHECK_FOR_UPDATES": pipeWrite("UPDATE_CHECK_FINISHED", CheckForUpdates(), String.Empty, 1); break; case "REPORT_BUG": break; default: break; } ; } catch (Exception ex) { Errors.ServiceError(ex); Detector.ReportException("W0003", ex); } finally { if (pipeServer != null) { pipeServer.Close(); } } }
private static void pipeWrite(string command, string Text1, string Text2, int icon) { //icon = (1 = Info, 2 = Warning, 3 = Error) NamedPipeClientStream pipeServerOut = null; try { pipeServerOut = new NamedPipeClientStream(".", "pipeBloodSpiderDetectorOut"); if (!pipeServerOut.IsConnected) pipeServerOut.Connect(2000); StreamString ss = new StreamString(pipeServerOut); //verify server identity if (ss.ReadString() == "BloodSpider_NotifyIcon") { //talking to the correct service so send the message ss.WriteString(command + "|" + Text1 + "|" + Text2 + "|" + (icon == 0 ? "" : icon.ToString())); } }//try catch (System.TimeoutException) { Exception ex = new Exception("Notify icon app not started so no settings file could be read. Aborting read."); Errors.ServiceError(ex); Detector.ReportException("W0005", ex); } catch (Exception ex) { Errors.ServiceError(ex); Detector.ReportException("W0006", ex); } finally { pipeServerOut.Close(); } }
private void background_CommandServer_DoWork(object sender, DoWorkEventArgs e) { if (Thread.CurrentThread.Name == null) Thread.CurrentThread.Name = "CommandServer"; NamedPipeServerStream pipeServer = null; try { PipeSecurity pipeSecurity = new PipeSecurity(); pipeSecurity.AddAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); pipeServer = new NamedPipeServerStream("pipeBloodSpiderDetectorIn", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.None, 512, 512, pipeSecurity, HandleInheritability.None); //pipeServer = new NamedPipeServerStream("pipeBloodSpiderDetectorIn", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous); pipeServer.WaitForConnection(); StreamString ss = new StreamString(pipeServer); //verify identity ss.WriteString("BloodSpider_Service"); //get command from client var command = ss.ReadString(); var split = command.Split(new string[] { "|" }, StringSplitOptions.None); switch (split[0].ToUpperInvariant().Trim()) { case "VERSION": Version ver = Assembly.GetExecutingAssembly().GetName().Version; ss.WriteString(ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString()); break; case "ULD_YES": startReaderThread(); break; case "ULD_PATH_RESP": settings = Common.Statics.ReadSettingsFile(split[1]); if (settings != null && settings.Options != null) { if (settings.Options.Rows.Count > 0 && (bool)settings.Options.Rows[0]["AutoUpload"]) { //auto upload startReaderThread(); } else { //no auto upload, require user input if (Common.Statics.deviceFound != null) { pipeWrite("ULD", "Found Meter", "Would you like to upload data from the " + Common.Statics.deviceFound.DeviceDescription + "?", 1); } } } break; case "CHECK_FOR_UPDATES": pipeWrite("UPDATE_CHECK_FINISHED", CheckForUpdates(), String.Empty, 1); break; case "REPORT_BUG": break; default: break; }; } catch (Exception ex) { Errors.ServiceError(ex); Detector.ReportException("W0003", ex); } finally { if (pipeServer != null) pipeServer.Close(); } }