Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            try
            {
                //Wpf.Message.ResourceDictionaryPath = "assembly=" + System.Reflection.Assembly.GetEntryAssembly().EscapedCodeBase + ";resources/style.xaml";

                //Uri u = new System.Uri("/" + PathRoutines.GetFileNameFromPath(System.Reflection.Assembly.GetEntryAssembly().EscapedCodeBase) + ";component/resources/style.xaml", System.UriKind.Relative);
                //System.Windows.ResourceDictionary rd = new System.Windows.ResourceDictionary();
                //System.Windows.Application.LoadComponent(rd, u);
                //Wpf.Message.ResourceDictionary = rd;
                //System.Windows.Resources.StreamResourceInfo info = System.Windows.Application.GetContentStream(u);
                //System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
                //Wpf.Message.ResourceDictionary = (System.Windows.ResourceDictionary)reader.LoadAsync(info.Stream);

                Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion());
                string user = ProcessRoutines.GetProcessUserName();
                string m    = "User: "******" (as administrator)";
                }
                Log.Main.Inform(m);

                ProcessRoutines.RunSingleProcessOnly();

                if (ProgramRoutines.IsParameterSet <CommandLineParameters>(CommandLineParameters.INITIAL_CONFIGURATION))
                {
                    Message.Inform("Please configure service in the next window.");
                    SettingsWindow.OpenDialog();
                    return;
                }

#if !test
                Application.Run(SysTray.This);
#else
                UiApiClient.testCreateInstanceContext();
                SettingsWindow.Open();
                Application.Run(SysTray.This);
                //UiApiClient.testSubscribe();
                //UiApiClient.testSubscribe();
                //Thread.Sleep(1000);
                //UiApiClient.testCloseInstanceContext();
                //UiApiClient.testCreateInstanceContext();
                //UiApiClient.testSubscribe();
                //UiApiClient.testSubscribe();
                //for (; ; )
                //{
                //    System.Threading.Thread.Sleep(10000);
                //}
#endif
            }
            catch (Exception e)
            {
                LogMessage.Error(e);
            }
            finally
            {
                Exit();
            }
        }
        //class ValidationException:Exception
        //{

        //}

        void reset_settings(object sender, RoutedEventArgs e)
        {
            //if (!Message.YesNo("Settings will be reset to their initial state. Proceed?"))
            //    return;
            //general.Reset();
            //general = Cliver.CisteraScreenCaptureService.Settings.General.GetResetInstance<Cliver.CisteraScreenCaptureService.Settings.GeneralSettings>();
            general = UiApiClient.GetServiceSettings(true);
            set();
        }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 private void serviceToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         string d = UiApiClient.GetServiceLogDir();
         if (d == null)
         {
             Message.Error("The service is unavailable.");
         }
         else
         {
             Process.Start(d);
         }
     }
     catch (Exception ex)
     {
         LogMessage.Error(ex);
     }
 }
        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);
            }
        }
        SettingsWindow()
        {
            InitializeComponent();
            System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this);

            Icon = AssemblyRoutines.GetAppIconImageSource();

            ContentRendered += delegate
            {
                //this.MinHeight = this.ActualHeight;
                //this.MaxHeight = this.ActualHeight;
                //this.MinWidth = this.ActualWidth;
            };

            WpfRoutines.AddFadeEffect(this, 300);

            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            //WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //DefaultServerIp.ValueDataType = typeof(IPAddress);

            general = UiApiClient.GetServiceSettings();
            if (general == null)
            {
                ok.IsEnabled    = false;
                reset.IsEnabled = false;
                Message.Error("The service is unavailable.");
                return;
            }
            set();

            if (!ProcessRoutines.ProcessHasElevatedPrivileges() && !ProcessRoutines.ProcessIsSystem() /*used for configuration during installing*/)
            {
                ok.IsEnabled    = false;
                reset.IsEnabled = false;
                if (Message.YesNo("Settings modification requires elevated privileges. Would you like to restart this application 'As Administrator'?"))
                {
                    ProcessRoutines.Restart(true);
                }
            }
        }
Exemplo n.º 7
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);
                //}
            };
        }
        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);
            }
        }
Exemplo n.º 9
0
 static internal void Exit()
 {
     Log.Main.Inform("Exiting...\r\n" + Log.GetStackString(0, 10));
     UiApiClient.Unsubscribe();
     Environment.Exit(0);
 }