Example #1
0
 private void StartStop_Click(object sender, EventArgs e)
 {
     if (!isAllowed())
     {
         StartStop.Checked = UiApiClient.GetServiceStatus() == ServiceControllerStatus.Running;
         return;
     }
     UiApiClient.StartStopService(StartStop.Checked);
     StartStop.Checked = UiApiClient.GetServiceStatus() == ServiceControllerStatus.Running;
 }
        void save(object sender, EventArgs e)
        {
            try
            {
                ushort v;

                //if (!ushort.TryParse(ServerDefaultPort.Text, out v))
                //    throw new Exception("Server port must be an integer between 0 and " + ushort.MaxValue);
                //general.TcpClientDefaultPort = v;

                if (string.IsNullOrWhiteSpace(ServerDefaultIp.Text))
                {
                    throw new Exception("Default server ip is not specified.");
                }
                IPAddress ia;
                if (!IPAddress.TryParse(ServerDefaultIp.Text, out ia))
                {
                    throw new Exception("Default server ip is not a valid value.");
                }
                general.TcpClientDefaultIp = ia.ToString();

                if (!ushort.TryParse(ClientPort.Text, out v))
                {
                    throw new Exception("Client port must be an between 0 and " + ushort.MaxValue);
                }
                general.TcpServerPort = v;

                if (string.IsNullOrWhiteSpace(ServiceDomain.Text))
                {
                    throw new Exception("Service domian is not specified.");
                }
                general.ServiceDomain = ServiceDomain.Text.Trim();

                if (string.IsNullOrWhiteSpace(ServiceType.Text))
                {
                    throw new Exception("Service type is not specified.");
                }
                general.ServiceType = ServiceType.Text.Trim();

                if (Monitors.SelectedIndex < 0)
                {
                    throw new Exception("Captured Video Source is not specified.");
                }
                general.CapturedMonitorDeviceName = (string)Monitors.SelectedValue;

                general.ShowMpegWindow = ShowMpegWindow.IsChecked ?? false;

                general.WriteMpegOutput2Log = WriteMpegOutput2Log.IsChecked ?? false;

                //general.CapturedMonitorRectangle = MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName);
                //if (general.CapturedMonitorRectangle == null)
                //    throw new Exception("Could not get rectangle for monitor '" + general.CapturedMonitorDeviceName + "'");
                general.CapturedMonitorRectangle = null;

                general.DeleteLogsOlderDays = int.Parse(DeleteLogsOlderDays.Text);

                UiApiClient.SaveServiceSettings(general);

                if (Settings.View.DeleteLogsOlderDays != general.DeleteLogsOlderDays)
                {
                    Settings.View.DeleteLogsOlderDays = general.DeleteLogsOlderDays;
                    Settings.View.Save();
                }

                System.ServiceProcess.ServiceControllerStatus?status = UiApiClient.GetServiceStatus();
                if (status != null && status != System.ServiceProcess.ServiceControllerStatus.Stopped &&
                    (ProcessRoutines.ProcessIsSystem() ||/*used for configuration during installing*/
                     Message.YesNo("The changes have been saved and will be engaged after service restart. Would you like to restart the service (all the present connections if any, will be terminated)?")
                    )
                    )
                {
                    MessageForm mf = null;
                    ThreadRoutines.StartTry(() =>
                    {
                        mf = new MessageForm(System.Windows.Forms.Application.ProductName, System.Drawing.SystemIcons.Information, "Resetting the service. Please wait...", null, 0, null);
                        mf.ShowDialog();
                    });

                    UiApiClient.StartStopService(false);
                    UiApiClient.StartStopService(true);

                    if (null == SleepRoutines.WaitForObject(() => { return(mf); }, 1000))
                    {
                        throw new Exception("Could not get MessageForm");
                    }
                    mf.Invoke(() => { mf.Close(); });
                }

                Close();
            }
            catch (Exception ex)
            {
                Message.Exclaim(ex.Message);
            }
        }