예제 #1
0
        public MainWindowViewModel(AppConnector appConnector)
        {
            this.appConnector = appConnector;
            M = new MainWindowModel(this.appConnector);

            DialogViewModel                  = new DialogViewModel(M.DialogModel);
            ResultControlViewModel           = new ResultControlViewModel(M.ResultControlModel);
            FullScreenResultControlViewModel = new ResultControlViewModel(M.FullScreenResultControlModel);

            ViewModels = new Dictionary <Screen, IViewModel>()
            {
                { Screen.MainMenu, new MainMenuViewModel() },
                { Screen.GroupMenu, new GroupMenuViewModel() },
                { Screen.OneTouchMenu, new OneTouchMenuViewModel() },
            };
            foreach (KeyValuePair <Screen, IViewModel> p in ViewModels)
            {
                IViewModel vm = p.Value;
                vm.Model = M.Models[p.Key];
            }

            StepColors = new ObservableCollection <SolidColorBrush>()
            {
                Brushes.White,
                Brushes.White,
                Brushes.White,
                Brushes.White,
            };

            ShowVersionDialog = new DelegateCommand(() =>
            {
                M.DialogModel.ShowDialog($"TRS係員操作端末 MS-12\n\n\nVersion {ProductVersion}\n\n{Copyright}\n\n\n\nバージョン及び著作権の詳細は、取扱説明書をご覧下さい。", "バージョン情報");
            });

            List <ITicketPlugin> ticketPlugins = M.Plugins.TicketPlugins.ConvertAll(p => p.Plugin);

            TicketInputControls = ticketPlugins.ConvertAll(t => t.InputControl);
            TicketKeyControls   = ticketPlugins.ConvertAll(t => t.KeyControl);

            FClicked = M.FunctionKeyCommands;

            foreach (KeyValuePair <FunctionKeys, bool> item in FIsChecked)
            {
                M.FunctionKeyToggleButtonsIsChecked.Add(item);
            }


            M.PropertyChanged += new PropertyChangedEventHandler((sender, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(M.CurrentScreen):
                    Screen showedControl = Screen.None;
                    try
                    {
                        showedControl = ViewModels.First(p => p.Value.Visibility == Visibility.Visible).Key;
                        ViewModels[(Screen)showedControl].Visibility = Visibility.Hidden;
                    }
                    catch { }

                    if (M.CurrentScreen == Screen.Tickets)
                    {
                    }
                    else if (M.CurrentScreen != Screen.None)
                    {
                        IModel model = ViewModels[M.CurrentScreen].Model;
                        ViewModels[M.CurrentScreen].Visibility = Visibility.Visible;
                    }

                    if (M.CurrentScreen == Screen.None)
                    {
                        MainGridIsEnabled = false;
                        DoEvents();
                    }
                    else if (showedControl == Screen.None)
                    {
                        MainGridIsEnabled = true;
                    }
                    break;

                case nameof(M.IsTicketSending):
                    MainGridIsEnabled2 = !M.IsTicketSending;
                    DoEvents();
                    break;

                case nameof(M.SendType):
                    foreach (SendTypes type in Enum.GetValues(typeof(SendTypes)))
                    {
                        SendTypeButtonsIsChecked[type] = M.SendType == type;
                    }
                    break;

                case nameof(M.IsOneTimeMode):
                    LogBox4 = M.IsOneTimeMode ? "一件操作中" : "";
                    break;
                }
            });

            M.ResultControlModel.PropertyChanged += new PropertyChangedEventHandler((sender, e) =>
            {
                if (e.PropertyName == nameof(M.ResultControlModel.SendResult))
                {
                    if (M.ResultControlModel.IsVisible)
                    {
                        KeyControlVisibility  = Visibility.Hidden;
                        InputControlIsEnabled = false;
                        KeyControlIsEnabled   = false;
                    }
                    else
                    {
                        KeyControlVisibility  = Visibility.Visible;
                        InputControlIsEnabled = true;
                        KeyControlIsEnabled   = true;
                    }
                    DoEvents();
                }
            });

            M.FullScreenResultControlModel.PropertyChanged += new PropertyChangedEventHandler((sender, e) =>
            {
                if (e.PropertyName == nameof(M.FullScreenResultControlModel.SendResult))
                {
                    if (M.FullScreenResultControlModel.IsVisible)
                    {
                        InputControlVisibility = Visibility.Hidden;
                        KeyControlVisibility   = Visibility.Hidden;
                        InputControlIsEnabled  = false;
                        KeyControlIsEnabled    = false;
                    }
                    else
                    {
                        InputControlVisibility = Visibility.Visible;
                        KeyControlVisibility   = Visibility.Visible;
                        InputControlIsEnabled  = true;
                        KeyControlIsEnabled    = true;
                    }
                    DoEvents();
                }
            });

            M.FunctionKeyToggleButtonsIsChecked.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    FunctionKeys key = M.FunctionKeyToggleButtonsIsChecked.First(c => c.Value != FIsChecked[c.Key]).Key;
                    FIsChecked[key]  = M.FunctionKeyToggleButtonsIsChecked[key];
                }
                catch { }
            });

            FIsChecked.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    FunctionKeys key = FIsChecked.First(c => c.Value != M.FunctionKeyToggleButtonsIsChecked[c.Key]).Key;

                    M.FunctionKeyToggleButtonsIsChecked[key] = FIsChecked[key];
                }
                catch { }
            });

            SendTypeButtonsIsChecked.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                SendTypes?currentType = null;
                try
                {
                    currentType = SendTypeButtonsIsChecked.First(b => b.Value).Key;
                }
                catch { }
                M.SendType = currentType;
            });
        }
예제 #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            SplashScreen splash     = null;
            MainWindow   mainWindow = null;

            var splashVM = new SplashScreenViewModel()
            {
                Stop   = new DelegateCommand(() => Shutdown()),
                Ignore = new DelegateCommand(() => Start()),
            };

            splash          = new SplashScreen(splashVM);
            this.MainWindow = splash;
            splash.Show();

            AppConnector appConnector = null;
            bool         canStart     = true;

            try
            {
                XElement appSettings = XDocument.Load(@"Settings\App.xml").Element("ApplicationSettings");

                if ((bool)appSettings.Element("CatchUnobservedExceptions").Attribute("Enabled"))
                {
                    DispatcherUnhandledException += AppDispatcherUnhandledException;
                }

                XElement menuLayoutSources = XDocument.Load(@"Settings\MenuLayoutSources.xml").Element("MenuLayoutSources");

                appConnector = new AppConnector(splashVM)
                {
                    PrinterClass = (string)appSettings.Element("Printer").Attribute("Class"),
                    PrinterName  = (string)appSettings.Element("Printer").Attribute("Name"),

                    MainMenuLayoutSourcePath        = Path.GetFullPath(Path.Combine(AppDirectory, "Settings", (string)menuLayoutSources.Element("MainMenu").Attribute("Source") ?? "")),
                    OneTouchMenuLayoutSourcePath    = Path.GetFullPath(Path.Combine(AppDirectory, "Settings", (string)menuLayoutSources.Element("OneTouchMenu").Attribute("Source") ?? "")),
                    MaintenanceMenuLayoutSourcePath = Path.GetFullPath(Path.Combine(AppDirectory, "Settings", (string)menuLayoutSources.Element("MaintenanceMenu").Attribute("Source") ?? "")),
                };
            }
            catch
            {
                splashVM.Errors.Add("基本設定を正常に読み込めませんでした。設定内容に誤りが無いか確認し、解消されない場合は再インストールを検討して下さい。");
                splashVM.IsErrorIgnorable = false;
                splashVM.IsErrorShown     = true;
                canStart = false;
            }

            if (canStart)
            {
                MainWindowVM = new MainWindowViewModel(appConnector);
                mainWindow   = new MainWindow(MainWindowVM);
                MainWindowVM.M.Loaded();

                if (splashVM.Errors.Count > 0)
                {
                    splashVM.Stop = new DelegateCommand(() =>
                    {
                        MainWindowVM.M.CurrentPrinter.Dispose();
                        Shutdown();
                    });

                    splashVM.IsErrorIgnorable = !splashVM.Errors.Any(err => err.StartsWith("(エラー ) "));
                    splashVM.IsErrorShown     = true;
                }
                else
                {
                    Start();
                }
            }


            async void Start()
            {
                MainWindowVM.M.DialogModel.ShowInformationDialog("ソフトウェアのバージョンを確認しています...", false);

                this.MainWindow = mainWindow;
                mainWindow.Show();
                splash.Close();

                try
                {
                    using (HttpClient client = new HttpClient())
                    {
                        string latestVersion = await client.GetStringAsync("https://script.google.com/macros/s/AKfycbxXOLf46ZjE9WDUC4xQYn2itPOrKA5Qr3_uPWqcpWU9AFJr7QGgkF-KQQAYlu0kRvGX/exec");

                        if (latestVersion == ProductVersion)
                        {
                            MainWindowVM.M.DialogModel.ShowInformationDialog($"ご利用のバージョンは最新です。\n\nご利用のバージョン: Version {ProductVersion}\n最新のバージョン : Version {latestVersion}");
                        }
                        else
                        {
                            MainWindowVM.M.DialogModel.ShowInformationDialog($"新しいバージョンがリリースされています。\n\nご利用のバージョン: Version {ProductVersion}\n最新のバージョン : Version {latestVersion}");
                        }
                    }
                }
                catch
                {
                    MainWindowVM.M.DialogModel.ShowInformationDialog($"ご利用のバージョンが最新であるか確認出来ませんでした。\n\nご利用のバージョン: Version {ProductVersion}\n最新のバージョン : 不明");
                }
            }
        }
예제 #3
0
        public static PluginList Load(AppConnector appConnector)
        {
            List <LoadedPlugin <IPlugin> >        plugins        = new List <LoadedPlugin <IPlugin> >();
            List <LoadedPlugin <ITicketPlugin> >  ticketPlugins  = new List <LoadedPlugin <ITicketPlugin> >();
            List <LoadedPlugin <IPrinterPlugin> > printerPlugins = new List <LoadedPlugin <IPrinterPlugin> >();

            string iPrinterPluginName = typeof(IPrinterPlugin).FullName;
            string iTicketPluginName  = typeof(ITicketPlugin).FullName;
            string iPluginName        = typeof(IPlugin).FullName;

            string pluginDirectory = Path.Combine(AppDirectory, "Plugins");

            if (!Directory.Exists(pluginDirectory))
            {
                appConnector.OnError($"フォルダ \"{pluginDirectory}\" が見つかりませんでした。", "プラグイン読込エラー", ErrorType.Error);
                return(new PluginList(plugins, ticketPlugins, printerPlugins));
            }

            List <string> pluginPaths = LoadPluginLists(pluginDirectory);

            string[] pluginDlls = Directory.GetFiles(pluginDirectory, "*.dll", SearchOption.AllDirectories);
            foreach (string dll in pluginDlls)
            {
                try
                {
                    Assembly           assembly = Assembly.LoadFrom(dll);
                    IEnumerable <Type> types    = assembly.GetTypes();

                    ticketPlugins.AddRange(types.Where(t =>
                    {
                        return(t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface(iTicketPluginName) != null);
                    }).Select(t =>
                    {
                        return(new LoadedPlugin <ITicketPlugin>((ITicketPlugin)assembly.CreateInstance(t.FullName), dll.Replace(AppDirectory + @"\", "")));
                    }));

                    plugins.AddRange(types.Where(t =>
                    {
                        return(t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface(iPluginName) != null && t.GetInterface(iTicketPluginName) == null);
                    }).Select(t =>
                    {
                        return(new LoadedPlugin <IPlugin>((IPlugin)assembly.CreateInstance(t.FullName), dll.Replace(AppDirectory + @"\", "")));
                    }));
                }
                catch (ReflectionTypeLoadException ex)
                {
                    Exception[] loaderExceptions = ex.LoaderExceptions;
                }
                catch (FileLoadException ex)
                {
                    if (ex.InnerException is NotSupportedException && pluginPaths.Contains(dll))
                    {
                        appConnector.OnError($"プラグインDLL \"{dll}\" はブロックされているため、読み込めませんでした。ファイルのプロパティからブロックを解除して下さい。", "プラグイン読込エラー", ErrorType.Warning);
                    }
                }
                catch { }
            }

            string printerDirectory = Path.Combine(AppDirectory, "Printers");

            if (!Directory.Exists(printerDirectory))
            {
                appConnector.OnError($"フォルダ \"{printerDirectory}\" が見つかりませんでした。", "プラグイン読込エラー", ErrorType.Error);
                return(new PluginList(plugins, ticketPlugins, printerPlugins));
            }

            List <string> printerPaths = LoadPluginLists(printerDirectory);

            string[] printerDlls = Directory.GetFiles(printerDirectory, "*.dll", SearchOption.AllDirectories);
            foreach (string dll in printerDlls)
            {
                try
                {
                    Assembly           assembly = Assembly.LoadFrom(dll);
                    IEnumerable <Type> types    = assembly.GetTypes();

                    var a = types.Where(t =>
                    {
                        return(t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface(iPrinterPluginName) != null);
                    });
                    printerPlugins.AddRange(a.Select(t =>
                    {
                        return(new LoadedPlugin <IPrinterPlugin>((IPrinterPlugin)assembly.CreateInstance(t.FullName), dll.Replace(AppDirectory + @"\", "")));
                    }));
                }
                catch (FileLoadException ex)
                {
                    if (ex.InnerException is NotSupportedException && printerPaths.Contains(dll))
                    {
                        appConnector.OnError($"プリンタープラグインDLL {dll} はブロックされているため、読み込めませんでした。ファイルのプロパティからブロックを解除して下さい。", "プラグイン読込エラー", ErrorType.Warning);
                    }
                }
                catch
                { }
            }

            return(new PluginList(plugins, ticketPlugins, printerPlugins));
        }