Ejemplo n.º 1
0
        private void OnLoadAtStartupCheckedChanged(object sender, CheckBoxChangeEventArgs e)
        {
            if (checkBoxItemLoadAtStartup.Checked)
            {
                LoadAtStartupHelper.SetLoadAtStartup();
            }
            else
            {
                LoadAtStartupHelper.UnsetLoadAtStartup();
            }

            AppManager.Instance.Settings.UserSettings.LoadAtStartup = checkBoxItemLoadAtStartup.Checked;
            AppManager.Instance.Settings.UserSettings.Save();
        }
Ejemplo n.º 2
0
        private void InitLoadAtStartupSettings()
        {
            if (AppManager.Instance.Settings.UserSettings.LoadAtStartup &&
                !LoadAtStartupHelper.IsLoadAtStartupEnabled())
            {
                LoadAtStartupHelper.SetLoadAtStartup();
            }

            if (!AppManager.Instance.Settings.UserSettings.LoadAtStartup &&
                LoadAtStartupHelper.IsLoadAtStartupEnabled())
            {
                LoadAtStartupHelper.UnsetLoadAtStartup();
            }

            checkBoxItemLoadAtStartup.Checked         = LoadAtStartupHelper.IsLoadAtStartupEnabled();
            checkBoxItemLoadAtStartup.CheckedChanged += OnLoadAtStartupCheckedChanged;
        }
Ejemplo n.º 3
0
        public void RunApplication(bool forceUpdateMode)
        {
            bool stopRun = false;

            AppProfileManager.Instance.InitApplication(AppTypeEnum.AdBar);
            PopupMessageHelper.Instance.Title = "adsalesapps";

            FileStorageManager.Instance.UsingLocalMode += (o, e) =>
            {
                if (FileStorageManager.Instance.UseLocalMode)
                {
                    return;
                }
                FormStart.CloseProgress();
                if (FileStorageManager.Instance.DataState != DataActualityState.Updated)
                {
                    PopupMessageHelper.Instance.ShowWarning("Server is not available. Application will be closed");
                    stopRun = true;
                }
                else if (PopupMessageHelper.Instance.ShowWarningQuestion("Server is not available. Do you want to continue to work in local mode?") != DialogResult.Yes)
                {
                    stopRun = true;
                }
                if (stopRun)
                {
                    FormStart.Destroy();
                }
            };

            FileStorageManager.Instance.Authorizing += (o, e) =>
            {
                var authManager = new AdBarAuthManager();
                Settings.GrayConnectConfig.Load();
                FormStart.SetTitle("Checking credentials...");
                authManager.Auth(e);
                if (!e.Authorized)
                {
                    LoadAtStartupHelper.UnsetLoadAtStartup();
                }
            };

            FormStart.ShowProgress();
            FormStart.SetTitle("Connecting to adSALEScloud…");
            var thread = new Thread(() =>
            {
                AsyncHelper.RunSync(() => FileStorageManager.Instance.InitStorage());
                if (FileStorageManager.Instance.Activated)
                {
                    AsyncHelper.RunSync(() => FileStorageManager.Instance.CheckDataSate(forceUpdateMode));
                }
            });

            thread.Start();
            while (thread.IsAlive)
            {
                Application.DoEvents();
            }

            if (stopRun)
            {
                return;
            }

            FileStorageManager.Instance.Downloading += OnFileDownloading;
            FileStorageManager.Instance.Extracting  += OnFileExtracting;

            if (FileStorageManager.Instance.Activated)
            {
                if (FileStorageManager.Instance.DataState == DataActualityState.NotExisted)
                {
                    FormStart.SetTitle("Syncing adSALEScloud for the 1st time…");
                }
                else if (FileStorageManager.Instance.DataState == DataActualityState.Outdated)
                {
                    FormStart.SetTitle("Refreshing data from adSALEScloud…");
                }
                else
                {
                    FormStart.SetTitle("Loading application data...");
                }

                thread = new Thread(() =>
                {
                    AsyncHelper.RunSync(LoadBusinessObjects);
                    AsyncHelper.RunSync(FileStorageManager.Instance.FixCommonDataState);
                });
                thread.Start();
                while (thread.IsAlive)
                {
                    Application.DoEvents();
                }
            }

            FileStorageManager.Instance.Downloading -= OnFileDownloading;
            FileStorageManager.Instance.Extracting  -= OnFileExtracting;
            FormStart.CloseProgress();
            FormStart.Destroy();

            if (FileStorageManager.Instance.Activated)
            {
                if (Settings.PatchUpdaterConfig.RunUpdater && (!Settings.UserSettings.LastPatchUpdate.HasValue || Settings.UserSettings.LastPatchUpdate.Value < Settings.PatchUpdaterConfig.PatchDate))
                {
                    var confirm = true;
                    if (Settings.PatchUpdaterConfig.ShowUpdaterInfo && !String.IsNullOrEmpty(Settings.PatchUpdaterConfig.UpdaterText))
                    {
                        confirm = PopupMessageHelper.Instance.ShowWarningQuestion(
                            String.Format("{0}. Do you want to apply?", Settings.PatchUpdaterConfig.UpdaterText)) == DialogResult.Yes;
                    }
                    if (confirm)
                    {
                        Settings.UserSettings.LastPatchUpdate = Settings.PatchUpdaterConfig.PatchDate;
                        Settings.UserSettings.Save();

                        var updaterExecutablePath = Path.Combine(ResourceManager.Instance.AppRootFolderPath, "PatchUpdater.exe");
                        var pathRootFolder        = new StorageDirectory(ResourceManager.Instance.SpecialAppsFolder.RelativePathParts.Merge(new[] { "special_apps", "sfx_updater" }));
                        if (File.Exists(updaterExecutablePath))
                        {
                            try
                            {
                                var process = new Process();
                                process.StartInfo.FileName  = updaterExecutablePath;
                                process.StartInfo.Arguments = String.Format("\"{0}\"", pathRootFolder.LocalPath);
                                process.Start();
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                else if (Settings.MaintenanceConfig.MaintenanceEnabled)
                {
                    if (Settings.MaintenanceConfig.ShowInfo)
                    {
                        Application.Run(new FormMaintenance());
                    }
                }
                else
                {
                    Application.Run(new FormMain());
                }
            }
            else
            {
                PopupMessageHelper.Instance.ShowWarning("This app is not activated. Contact adSALESapps Support ([email protected])");
            }
        }