Beispiel #1
0
        /// <summary>
        /// 注入
        /// </summary>
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //Config
            var localConfig = FileUtil.LoadFromJsonFile <GlobalConfig>(Service.Models.ResourcesMap.LocationDic[Location.GlobalConfigFile]);

            //Version
            var version = ResourceAssembly.GetName().Version;
            var appData = new AppData
            {
                Version = $"{version.Major}.{version.Minor}.{version.Build}",
                Config  = localConfig ?? new GlobalConfig()
            };

            Logger.Instance.Main.Info($"[ Version ] v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}");

            //Settings
            containerRegistry.RegisterInstance(appData.Config);
            containerRegistry.RegisterInstance(appData);

            //Dialog
            containerRegistry.RegisterDialogWindow <DialogWindow>();
            containerRegistry.RegisterDialog <MessageDialog, MessageDialogViewModel>();

            RegisterTypesByServiceCollection(containerRegistry);
        }
Beispiel #2
0
 public static void AllowMultipleApplication(bool flag = false)
 {
     if (flag)
     {
         Process.Start(ResourceAssembly.Location);
         Process.GetCurrentProcess().Kill();
     }
     else
     {
         int     openedAppId  = 0;
         string  assemblyName = ResourceAssembly.GetName().Name;
         Process process      = Process.GetProcessesByName(assemblyName).FirstOrDefault();
         if (process != null)
         {
             openedAppId = process.Id;
         }
         if (((IEnumerable <Process>)Process.GetProcesses()).Count(e => e.ProcessName.Equals(assemblyName)) <= 1)
         {
             return;
         }
         int num = (int)MessageBox.Show("Uygulama zaten çalışıyor...", assemblyName, MessageBoxButton.OK,
                                        MessageBoxImage.Asterisk);
         Process.GetCurrentProcess().Kill();
         Task.Delay(4000);
         if (openedAppId.Equals(0))
         {
             return;
         }
         ((IEnumerable <Process>)Process.GetProcessesByName(assemblyName)).Where(e => e.Id != openedAppId)
         .ToList().ForEach(p => p.Kill());
     }
 }
Beispiel #3
0
        private static Uri ResourceUri(string path)
        {
            var sb = new StringBuilder();

            sb.Append(@"pack://application:,,,/");
            sb.Append(ResourceAssembly.GetName().Name);
            sb.Append(";component/Resources/");
            sb.Append(path);
            return(new Uri(sb.ToString(), UriKind.Absolute));
        }
Beispiel #4
0
 public static void Abort(string message)
 {
     MessageBox.Show(
         message,
         ResourceAssembly.GetName().Name,
         MessageBoxButton.OK,
         MessageBoxImage.Error
         );
     Current.Shutdown();
 }
Beispiel #5
0
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //Dialog
            containerRegistry.RegisterDialogWindow <DialogWindow>();
            containerRegistry.RegisterDialog <MessageDialog, MessageDialogViewModel>();

            //Command
            containerRegistry.RegisterSingleton <IApplicationCommands, ApplicationCommands>();

            //Work Area
            containerRegistry.Register <WorkControl>();

            //Code Completion
            containerRegistry.RegisterInstance(new XsdParser());

            //Config
            var localConfig = FileHelper.LoadFromJsonFile <XamlConfig>(ResourcesMap.LocationDic[Location.GlobalConfigFile]);

            if (localConfig != null)
            {
                //check history file
                if (localConfig.Files == null)
                {
                    localConfig.Files = new List <string>();
                }
                else
                {
                    localConfig.Files.RemoveAll(f => !FileHelper.Exists(f) || Path.GetExtension(f).ToLower() != ".xaml");
                }

                //check reference file
                if (localConfig.References == null)
                {
                    localConfig.References = new List <string>();
                }
                else
                {
                    localConfig.References.RemoveAll(f => !FileHelper.Exists(AppDomain.CurrentDomain.BaseDirectory + f) || Path.GetExtension(f).ToLower() != ".dll");
                }
            }

            //version
            var version = ResourceAssembly.GetName().Version;
            var appData = new AppData {
                Config = localConfig ?? new XamlConfig(), Version = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build)
            };

            if (_xamlFiles != null && _xamlFiles.Length > 0)
            {
                appData.Config.Files.RemoveAll(f => _xamlFiles.Any(xf => Path.GetFullPath(xf).ToLower() == Path.GetFullPath(f).ToLower()));
                appData.Config.Files.InsertRange(0, _xamlFiles);
            }

            containerRegistry.RegisterInstance(appData);
        }
Beispiel #6
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
#if DEBUG
            InstallUtils.RegisterApp();
#else
            SquirrelAwareApp.HandleEvents(
                onAppUpdate: v => InstallUtils.ReregisterApp(),
                onInitialInstall: v => InstallUtils.RegisterApp(),
                onAppUninstall: v => {
                InstallUtils.KillOtherInstances();
                InstallUtils.UnregisterApp();
                Current.Shutdown();
            }
                );
#endif
            websocket    = new WebsocketUtils();
            notification = new NotificationUtils();
            pushHistory  = new List <JObject>();

            contextMenu = new System.Windows.Forms.ContextMenu()
            {
                MenuItems =
                {
                    new System.Windows.Forms.MenuItem("&Settings", (a, b) => {
                        SettingsWindow settings = new SettingsWindow();
                        settings.Logout        += OnLogout;
                        settings.Show();
                    }),
                    new System.Windows.Forms.MenuItem("-"),
                    new System.Windows.Forms.MenuItem("&Exit",     (a, b) => {
                        Current.Shutdown();
                    })
                }
            };

            icon = new System.Windows.Forms.NotifyIcon()
            {
                Visible     = true,
                Text        = ResourceAssembly.GetName().Name,
                Icon        = Notiwin.Properties.Resources.Tray,
                ContextMenu = contextMenu
            };

            websocket.LoginError += OnLoginError;
            websocket.Data       += OnData;

            NotificationActivator.Action += OnAction;
            NotificationActivator.Initialize();

            NetworkUtils.ConnectionChanged += OnNetworkChange;

            OpenLoginWindow(openHidden: true);
            Init();
        }
Beispiel #7
0
        public static string BuildVersion()
        {
            StringBuilder Version = new StringBuilder();

            Version
            .Append(ResourceAssembly.GetName().Version.Major).Append(".")
            .Append(ResourceAssembly.GetName().Version.Minor).Append(".")
            .Append(ResourceAssembly.GetName().Version.Build);
#if DEBUG
            Version.Append(" (调试版)");
#endif
            return(Version.ToString());
        }
Beispiel #8
0
        /// <summary>
        /// Check if end of application session should be canceled or not
        /// (we may have gotten here through unhandled exceptions - so we
        /// display it and attempt CONTINUE so user can save his data.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
        {
            base.OnSessionEnding(e);

            try
            {
                try
                {
                    Logger.Error(string.Format(CultureInfo.InvariantCulture,
                                               "The {0} application received request to shutdown: {1}.",
                                               ResourceAssembly.GetName(), e.ReasonSessionEnding.ToString()));
                }
                catch
                {
                }

                var mainWin = GetMainWindow();
                var appVM   = GetWorkSpace();

                if (mainWin != null && appVM != null)
                {
                    if (mainWin.DataContext != null && appVM.Files != null)
                    {
                        // Close all open files and check whether application is ready to close
                        if (appVM.Exit_CheckConditions(mainWin) == true)
                        {
                            e.Cancel = false;
                        }
                        else
                        {
                            e.Cancel = appVM.ShutDownInProgressCancel = true;
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Logger.Error(exp);
            }

            try
            {
                _Container.Dispose();
                _Container = null;
            }
            catch (Exception exp)
            {
                Logger.Error(exp);
            }
        }
Beispiel #9
0
    protected override void OnStartup(StartupEventArgs e)
    {
        AppMainMutex = new Mutex(true, ResourceAssembly.GetName().Name, out var createdNew);

        if (createdNew)
        {
            RegisterEvents();

            base.OnStartup(e);
        }
        else
        {
            MessageBox.Show("请不要重复打开,程序已经运行\n如果一直提示,请到\"任务管理器-详细信息(win7为进程)\"里结束本程序",
                            "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
            Current.Shutdown();
        }
    }
        public InlineScriptActionFromFileInAssembly(string resourceName, Assembly resourceAssembly = null)
        {
            ResourceAssembly = resourceAssembly ?? Assembly.GetEntryAssembly();
            var candidates = ResourceAssembly.GetManifestResourceNames().Where(name => name.EndsWith(resourceName)).ToArray();

            if (!candidates.Any())
            {
                throw new ArgumentException($"There is no embedded resource in {ResourceAssembly.GetName().Name} like {resourceName}. Available resources are:{Environment.NewLine}{string.Join(Environment.NewLine, ResourceAssembly.GetManifestResourceNames().OrderBy(x => x))}");
            }

            if (candidates.Length > 1)
            {
                throw new ArgumentException($"There are {candidates.Length} embedded resources in {ResourceAssembly.GetName().Name} like {resourceName}, which one do you want?{Environment.NewLine}{string.Join(Environment.NewLine, candidates.OrderBy(x => x))}");
            }

            ResourceName = candidates.Single();
        }
Beispiel #11
0
        protected override void OnStartup(StartupEventArgs e)
        {
            mutex = new Mutex(true, ResourceAssembly.GetName().Name, out createNew);

            if (createNew)
            {
                base.OnStartup(e);

                // UI线程未捕获异常处理事件(UI主线程)
                DispatcherUnhandledException += App_DispatcherUnhandledException;
                // 非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                // Task线程内未捕获异常处理事件
                TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
            }
            else
            {
                MessageBox.Show("请不要重复打开,程序已经运行\n如果一直提示,请到\"任务管理器-详细信息(win7为进程)\"里结束本程序",
                                " 警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                Current.Shutdown();
            }
        }