Пример #1
0
		private void buttonItemSettingsLibraries_Click(object sender, EventArgs e)
		{
			ProcessChanges();
			using (var form = new FormPaths())
			{
				form.BackupPath = MainController.Instance.Settings.BackupPath;
				form.LocalSyncPath = MainController.Instance.Settings.NetworkPath;
				form.WebSyncPath = MainController.Instance.Settings.WebPath;
				if (form.ShowDialog(MainController.Instance.MainForm) != DialogResult.OK) return;
				var backupChanged = !String.Equals(
					MainController.Instance.Settings.BackupPath,
					form.BackupPath,
					StringComparison.InvariantCultureIgnoreCase);

				if (backupChanged)
				{
					DatabaseConnectionHelper.Disconnect(MainController.Instance.Settings.BackupPath);

					var connectionState = DatabaseConnectionHelper.GetConnectionState(form.BackupPath);
					if (connectionState.Type == ConnectionStateType.Busy)
					{
						MainController.Instance.PopupMessages.ShowWarning(
							String.Format(
								"{0} is currently updating the site.{1}Please try back again later, or ask the user to hurry up and finish…",
								connectionState.User,
								Environment.NewLine));
						return;
					}
				}
				MainController.Instance.Settings.BackupPath = form.BackupPath;
				MainController.Instance.Settings.NetworkPath = form.LocalSyncPath;
				MainController.Instance.Settings.WebPath = form.WebSyncPath;
				MainController.Instance.Settings.Save();
				if (!backupChanged) return;
				NeedToUpdate = true;
				MainController.Instance.ReloadData();
			}
		}
Пример #2
0
		public void RunApplication()
		{
			var stopRun = false;

			LicenseHelper.Register();

			AppProfileManager.Instance.InitApplication(AppTypeEnum.FileManager);

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

			FileStorageManager.Instance.Authorizing += (o, e) =>
			{
				var authManager = new AuthManager();
				authManager.Init();
				authManager.Auth(e);
			};

			ProcessManager.RunStartProcess(
				"Connecting to adSALEScloud…",
				cancellationToken => AsyncHelper.RunSync(FileStorageManager.Instance.Init));

			if (stopRun) return;

			var appReady = FileStorageManager.Instance.Activated;

			if (appReady)
			{
				ProcessManager.RunStartProcess(
					"Connecting adSALEScloud...",
					cancellationToken => AsyncHelper.RunSync(async () =>
					{
						await AppProfileManager.Instance.LoadProfile();
						await Configuration.RemoteResourceManager.Instance.LoadLocal();
						Settings.LoadLocal();
					}));

				if (!String.IsNullOrEmpty(Settings.BackupPath) && Directory.Exists(Settings.BackupPath))
				{
					var connectionState = DatabaseConnectionHelper.GetConnectionState(Settings.BackupPath);
					if (connectionState.Type == ConnectionStateType.Busy)
					{
						PopupMessages.ShowWarning(
							String.Format(
								"{0} is currently updating the site.{1}Please try back again later, or ask the user to hurry up and finish…",
								connectionState.User,
								Environment.NewLine));
						return;
					}
				}

				ProcessManager.RunStartProcess(
						"Connecting adSALEScloud...",
						cancellationToken => AsyncHelper.RunSync(async () =>
						{
							await AppProfileManager.Instance.LoadProfile();
							await Configuration.RemoteResourceManager.Instance.LoadLocal();
							Settings.LoadLocal();
						}));

				var progressTitle = String.Empty;
				switch (FileStorageManager.Instance.DataState)
				{
					case DataActualityState.NotExisted:
						progressTitle = "Syncing adSALEScloud for the 1st time…";
						break;
					case DataActualityState.Outdated:
						progressTitle = "Refreshing data from adSALEScloud…";
						break;
					default:
						progressTitle = "Loading data...";
						break;
				}

				ProcessManager.RunStartProcess(
					progressTitle,
					cancellationToken => AsyncHelper.RunSync(async () =>
					{
						await Configuration.RemoteResourceManager.Instance.LoadRemote();
						Settings.LoadRemote();
						InitBusinessObjects();
						await FileStorageManager.Instance.FixDataState();
					}));

				MainForm.Shown += (o, e) =>
				{
					if (String.IsNullOrEmpty(Settings.BackupPath) || !Directory.Exists(Settings.BackupPath))
					{
						using (var form = new FormPaths())
						{
							var mainForm = (Form)o;
							if (form.ShowDialog(mainForm) == DialogResult.OK)
							{
								Settings.BackupPath = form.BackupPath;
								Settings.NetworkPath = form.LocalSyncPath;
								Settings.WebPath = form.WebSyncPath;
								Settings.Save();
							}
							else
								mainForm.Close();
						}
					}
					MainForm.InitForm();
					LoadControllers();
					LoadData();
					ProcessInactiveLinks();
					ProcessManager.RunInQueue("Loading Wallbin...",
						() => MainForm.Invoke(new MethodInvoker(() => WallbinViews.Load())),
						() => MainForm.Invoke(new MethodInvoker(() => ShowTab(TabPageEnum.Home))));
				};
				Application.Run(MainForm);
			}

			if (!appReady)
				PopupMessages.ShowWarning("This app is not activated. Contact adSALESapps Support ([email protected])");
		}