Esempio n. 1
0
        private void ThreadProc(object args)
        {
            try
            {
                SynchronizationContext.SetSynchronizationContext(this.syncContext);
                using (var container = Program.InitializeContainer(this.syncContext, false))
                {
                    this.log = container.GetInstance <ILogger>();

                    ICarpetProcessor carpetProcessor = container.GetInstance <ICarpetProcessor>();
                    carpetProcessor.Start();
                    this.syncContext.RunOnCurrentThread();
                    container.GetInstance <IProgramState>().Save();
                    carpetProcessor.Stop();
                }
            }
            catch (Exception ex)
            {
                this.log.Error("Service thread error." + Environment.NewLine + ex.ToString());
            }
        }
Esempio n. 2
0
        public MainForm(ICarpetProcessor carpetProcessor, ICutRollList cutRollList, IInspectionAreaList inspectionAreaList, IMahloIpcClient mahloClient, IServiceSettings serviceSettings)
        {
            this.InitializeComponent();
            this.carpetProcessor          = carpetProcessor;
            this.cutRollList              = cutRollList;
            this.inspectionAreaList       = inspectionAreaList;
            this.mahloClient              = mahloClient;
            this.serviceSettings          = serviceSettings;
            this.statusBar1.StatusBarInfo = (IStatusBarInfo)this.carpetProcessor.PatternRepeatLogic;
            this.defaultCellColor         = new CellColor
            {
                ForeColor = this.grdGreigeRoll.DefaultCellStyle.ForeColor,
                BackColor = this.grdGreigeRoll.DefaultCellStyle.BackColor
            };

            this.disposables.Add(
                Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                    h => ((INotifyPropertyChanged)this.carpetProcessor.MahloLogic).PropertyChanged += h,
                    h => ((INotifyPropertyChanged)this.carpetProcessor.MahloLogic).PropertyChanged -= h)
                .Where(args => args.EventArgs.PropertyName == nameof(this.carpetProcessor.MahloLogic.CurrentRoll))
                .Subscribe(args =>
            {
                this.mahloRollSrc.DataSource = this.carpetProcessor.MahloLogic.CurrentRoll;
                this.DoAutoScroll();
                this.grdGreigeRoll.Invalidate();
            }));

            this.disposables.Add(
                Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                    h => ((INotifyPropertyChanged)this.carpetProcessor.BowAndSkewLogic).PropertyChanged += h,
                    h => ((INotifyPropertyChanged)this.carpetProcessor.BowAndSkewLogic).PropertyChanged -= h)
                .Where(args => args.EventArgs.PropertyName == nameof(this.carpetProcessor.BowAndSkewLogic.CurrentRoll))
                .Subscribe(args =>
            {
                this.bowAndSkewRollSrc.DataSource = this.carpetProcessor.BowAndSkewLogic.CurrentRoll;
                this.DoAutoScroll();
                this.grdGreigeRoll.Invalidate();
            }));

            this.disposables.Add(
                Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                    h => ((INotifyPropertyChanged)this.carpetProcessor.PatternRepeatLogic).PropertyChanged += h,
                    h => ((INotifyPropertyChanged)this.carpetProcessor.PatternRepeatLogic).PropertyChanged -= h)
                .Where(args => args.EventArgs.PropertyName == nameof(this.carpetProcessor.PatternRepeatLogic.CurrentRoll))
                .Subscribe(args =>
            {
                this.patternRepeatRollSrc.DataSource = this.carpetProcessor.PatternRepeatLogic.CurrentRoll;
                this.DoAutoScroll();
                this.grdGreigeRoll.Invalidate();
            }));

            // Make column heading alignment match column data alignment
            foreach (DataGridViewColumn column in this.grdGreigeRoll.Columns)
            {
                column.HeaderCell.Style.Alignment = column.DefaultCellStyle.Alignment;
            }

            foreach (DataGridViewColumn column in this.grdCutRoll.Columns)
            {
                column.HeaderCell.Style.Alignment = column.DefaultCellStyle.Alignment;
            }

            foreach (DataGridViewColumn column in this.grdInspectionArea.Columns)
            {
                column.HeaderCell.Style.Alignment = column.DefaultCellStyle.Alignment;
            }

            this.colMalFeet.Tag         =
                this.colBasFeet.Tag     =
                    this.colPrsFeet.Tag = new CellFormattingAction(this.SetFeetColor);

            this.colBow.Tag        = new CellFormattingAction(this.SetBowColor);
            this.colSkew.Tag       = new CellFormattingAction(this.SetSkewColor);
            this.colElongation.Tag = new CellFormattingAction(this.SetElongationColor);

            this.colCutBow.Tag        = new CellFormattingAction(this.SetCutBowColor);
            this.colCutSkew.Tag       = new CellFormattingAction(this.SetCutSkewColor);
            this.colCutElongation.Tag = new CellFormattingAction(this.SetCutEPEColor);
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            try
            {
                string instanceName = @"Local\{7A97254E-AFC8-4C0C-A6DB-C6DA0BFB463F}";
                using (new SingleInstance(instanceName))
                {
                    Log.Logger = new LoggerConfiguration()
                                 .ReadFrom.AppSettings()
                                 .CreateLogger();

                    if (Environment.UserInteractive)
                    {
                        if (args.Contains("--migrate"))
                        {
                            var runner = new MahloService.DbMigrations.Runner(new DbLocal(new DbConnectionFactory.Factory()));
                            runner.MigrateToLatest();
                            Environment.Exit(0);
                        }

                        if (args.Contains("--install"))
                        {
                            var runner = new MahloService.DbMigrations.Runner(new DbLocal(new DbConnectionFactory.Factory()));
                            runner.MigrateToLatest();
                            ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                            new ServiceController(StrMahloMapper).Start();
                            Environment.Exit(0);
                        }

                        if (args.Contains("--uninstall"))
                        {
                            ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                            Environment.Exit(0);
                        }

                        bool shouldSimulate = args.Contains("--simulate");
                        if (shouldSimulate)
                        {
                            Application.EnableVisualStyles();
                            Application.SetCompatibleTextRenderingDefault(false);
                            using (new Control()) { }
                            using (var container = InitializeContainer(WindowsFormsSynchronizationContext.Current, shouldSimulate))
                            {
                                ICarpetProcessor carpetProcessor = container.GetInstance <ICarpetProcessor>();
                                carpetProcessor.Start();
                                Application.Run(container.GetInstance <FormSim>());
                                container.GetInstance <IProgramState>().Save();
                                carpetProcessor.Stop();
                            }
                        }
                        else
                        {
                            ApplicationContext appContext = new ApplicationContext();
                            WindowsFormsSynchronizationContext.AutoInstall = false;

                            WindowsFormsSynchronizationContext syncContext = new WindowsFormsSynchronizationContext();
                            SynchronizationContext.SetSynchronizationContext(syncContext);

                            using (var consoleCtrl = new ConsoleCtrl())
                                using (var container = InitializeContainer(syncContext, shouldSimulate))
                                {
                                    consoleCtrl.ControlEvent += (sender, e) =>
                                    {
                                        Application.Exit();
                                        e.Result = true;
                                    };

                                    Log.Logger.Information("Application started");
                                    ICarpetProcessor carpetProcessor = container.GetInstance <ICarpetProcessor>();
                                    carpetProcessor.Start();
                                    Application.Run(appContext);
                                    container.GetInstance <IProgramState>().Save();
                                    carpetProcessor.Stop();
                                    Log.Logger.Information("Application stopped");
                                }
                        }
                    }
                    else
                    {
                        service = new Service();
                        ServiceBase.Run(service);
                    }
                }
            }
            catch (SingleInstanceException)
            {
                Environment.Exit(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), Application.ProductName);
                Environment.Exit(1);
            }
        }