public ProcessingItem( PerServerSettings.PerServerView view, VCRNETControl context ) { // Remember m_Context = context; View = view; // Attach to settings PerServerSettings settings = view.Settings; // Create a snap shot ServerName = settings.ServerName; ServerPort = settings.ServerPort; // Report View.StartProcessing(); }
public ProcessingItem(PerServerSettings.PerServerView view, VCRNETControl context) { // Remember m_Context = context; View = view; // Attach to settings PerServerSettings settings = view.Settings; // Create a snap shot ServerName = settings.ServerName; ServerPort = settings.ServerPort; // Report View.StartProcessing(); }
/// <summary> /// Führt eine Anfrage aus. /// </summary> /// <typeparam name="TResult">Die Art des erwarteten Ergebnisses.</typeparam> /// <param name="uri">Die aufzurufende Adresse.</param> /// <param name="method">Die Methode zum Aufruf.</param> /// <returns>Das Ergebnis des Aufrufs.</returns> private static TResult CallServer <TResult>(string uri, string method = "GET") { // Be safe try { // Create request var request = WebRequest.Create(uri); // Configure request.UseDefaultCredentials = true; request.ContentLength = 0; request.Timeout = 10000; request.Method = method; // Load the response var response = request.GetResponse(); try { // Process using (var status = response.GetResponseStream()) using (var reader = new StreamReader(status)) return((TResult)s_Deserializer.Deserialize(reader, typeof(TResult))); } finally { // Done response.Close(); } } catch (Exception e) { // See if this is a timeout var webException = e as WebException; if (webException != null) { if (webException.Status == WebExceptionStatus.Timeout) { VCRNETControl.Log("Timeout calling {1} ({0})", method, uri); } } // Forward throw; } }
static void Main(string[] args) { // Check settings var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); if (!version.Equals( Properties.Settings.Default.Version )) { // Upgrade Properties.Settings.Default.Upgrade(); Properties.Settings.Default.Version = version; Properties.Settings.Default.Save(); } // Initial delay if (Properties.Settings.Default.StartupDelay > 0) Thread.Sleep(Properties.Settings.Default.StartupDelay * 1000); // Be fully safe try { // Get a token for this process IntPtr hToken; if (OpenProcessToken(Process.GetCurrentProcess().Handle, 0x28, out hToken)) { // Helper TokenPrivileges pPriv = new TokenPrivileges(); // Lookup the privilege value if (LookupPrivilegeValue(null, "SeShutdownPrivilege", out pPriv.Luid)) { // Finish pPriv.PrivilegeCount = 1; pPriv.Attributes = 2; // Update AdjustTokenPrivileges(hToken, false, ref pPriv, 0, IntPtr.Zero, IntPtr.Zero); } // Release CloseHandle(hToken); } // Load language string language = Properties.Settings.Default.Language; if (!string.IsNullOrEmpty(language)) try { // Choose it Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language); } catch { // Ignore any error } // Initialize Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Create using (VCRNETControl main = new VCRNETControl(args)) if ((1 == args.Length) && args[0].Equals("/install")) { // Run Application.Run(main); } else { // Run Application.Run(); } } catch (Exception e) { // Report and terminate MessageBox.Show(e.ToString()); } }
/// <summary> /// Wird periodisch aufgerufen und frage den aktuellen Zustand des Dienstes auf einem Rechner ab. /// </summary> /// <param name="state">Wird ignoriert.</param> public void CheckServer(object state) { // Create a processing clone var settings = new VCRNETRestProxy.ServiceInformation(); var serverInfo = View.ServerInfo; // Safe process try { // Report VCRNETControl.Log("Checking {0}:{1}", ServerName, ServerPort); // Try to resolve MAC View.Settings.DetectMAC(); // Read the server settings settings = VCRNETRestProxy.GetInformation(EndPoint); // Load version once if (string.IsNullOrEmpty(serverInfo.Version)) { serverInfo.Version = settings.version; } // Check mode bool hasNext = false, near = false; // Find all activities var activities = VCRNETRestProxy.GetActivities(EndPoint); // All profiles foreach (var profile in settings.profileNames) { // Report VCRNETControl.Log("Processing Profile {2} for {0}:{1}", ServerName, ServerPort, profile); // Attach to the profile var info = serverInfo[profile]; var profileActivities = activities.Where(activity => StringComparer.InvariantCultureIgnoreCase.Equals(activity.device, profile)).ToArray(); var profileCurrent = profileActivities.Where(activity => activity.IsActive).ToArray(); // Check for a current recording if (profileCurrent.Length > 0) { // Remember info.CurrentRecordings = profileCurrent; // Done continue; } // Find the next recording var next = profileActivities.FirstOrDefault(); if (next == null) { continue; } if (!next.start.HasValue) { continue; } if (next.start.Value == DateTime.MinValue) { continue; } // At least there are recordings hasNext = true; // Check delta var delta = next.start.Value - DateTime.UtcNow; if (delta.TotalMinutes < Math.Max(5, settings.sleepMinimum)) { near = true; } } // Check mode if (serverInfo.State == TrayColors.Red) { if (near) { serverInfo.State = TrayColors.Yellow; } else if (hasNext) { serverInfo.State = TrayColors.Green; } else { serverInfo.State = TrayColors.Standard; } } } catch { } // Update View.ServerInfo = serverInfo; // Report if (!m_Context.ProcessStateAndCheckHibernation(this, serverInfo.State, settings.hibernationPending, View.Settings.IsLocal && settings.extensionsRunning)) { return; } // Safe tell the server that we take over hibernation control. try { // Process VCRNETRestProxy.ResetPendingHibernation(EndPoint); } catch { } }
static void Main(string[] args) { // Check settings var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); if (!version.Equals(Properties.Settings.Default.Version)) { // Upgrade Properties.Settings.Default.Upgrade(); Properties.Settings.Default.Version = version; Properties.Settings.Default.Save(); } // Initial delay if (Properties.Settings.Default.StartupDelay > 0) { Thread.Sleep(Properties.Settings.Default.StartupDelay * 1000); } // Be fully safe try { // Get a token for this process IntPtr hToken; if (OpenProcessToken(Process.GetCurrentProcess().Handle, 0x28, out hToken)) { // Helper TokenPrivileges pPriv = new TokenPrivileges(); // Lookup the privilege value if (LookupPrivilegeValue(null, "SeShutdownPrivilege", out pPriv.Luid)) { // Finish pPriv.PrivilegeCount = 1; pPriv.Attributes = 2; // Update AdjustTokenPrivileges(hToken, false, ref pPriv, 0, IntPtr.Zero, IntPtr.Zero); } // Release CloseHandle(hToken); } // Load language string language = Properties.Settings.Default.Language; if (!string.IsNullOrEmpty(language)) { try { // Choose it Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language); } catch { // Ignore any error } } // Initialize Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Create using (VCRNETControl main = new VCRNETControl(args)) if ((1 == args.Length) && args[0].Equals("/install")) { // Run Application.Run(main); } else { // Run Application.Run(); } } catch (Exception e) { // Report and terminate MessageBox.Show(e.ToString()); } }