コード例 #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;
 }
コード例 #2
0
        static UiApiClient()
        {
            try
            {
                instanceContext = new InstanceContext(new UiApiCallback());

                System.ServiceProcess.ServiceControllerStatus?status = UiApiClient.GetServiceStatus();
                if (status != null && status != System.ServiceProcess.ServiceControllerStatus.Stopped)
                {
                    _this = new CisteraScreenCaptureService.UiApiClient(instanceContext);
                }

                beginMonitorServiceStartStop();
            }
            catch (Exception e)
            {
                LogMessage.Error(e);
            }
        }
コード例 #3
0
        SysTray()
        {
            InitializeComponent();

            CreateHandle();

            Load += delegate
            {
                Icon = AssemblyRoutines.GetAppIcon();

                ServiceStateChanged(UiApiClient.GetServiceStatus());
                silentlyToolStripMenuItem.Checked = !Settings.View.DisplayNotifications;

                //string __file;
                //Cliver.CisteraScreenCaptureService.Settings.GeneralSettings general = UiApiClient.GetServiceSettings(out __file);
                //if(general.CapturedMonitorRectangle == null)
                //{
                //    if(string.IsNullOrWhiteSpace( general.CapturedMonitorDeviceName))
                //        general.CapturedMonitorDeviceName = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetDefaultMonitorName();
                //    if (string.IsNullOrWhiteSpace(general.CapturedMonitorDeviceName))
                //        LogMessage.Error("Could not detect default monitor.");
                //    else
                //    {
                //        WinApi.User32.RECT? a = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName);
                //        if (a == null)
                //        {
                //            string defaultMonitorName = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetDefaultMonitorName();
                //            LogMessage.Warning("Monitor '" + general.CapturedMonitorDeviceName + "' was not found. Using default one '" + defaultMonitorName + "'");
                //            general.CapturedMonitorDeviceName = defaultMonitorName;
                //            a = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName);
                //            if (a == null)
                //                LogMessage.Error("Monitor '" + general.CapturedMonitorDeviceName + "' was not found.");
                //        }
                //        general.CapturedMonitorRectangle = a;
                //    }
                //    general.Save(__file);
                //}
            };
        }
コード例 #4
0
        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);
            }
        }