Ejemplo n.º 1
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])");
		}
Ejemplo n.º 2
0
		public void RunApplication()
		{
			var stopRun = false;

			LicenseHelper.Register();

			AppProfileManager.Instance.InitApplication(AppTypeEnum.SalesDepot);

			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)
			{
				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(InitBusinessObjects));

				ProcessManager.RunStartProcess(
					FileStorageManager.Instance.DataState == DataActualityState.NotExisted ?
						"Syncing Libraries for the 1st time…" :
						"Syncing Sales Libraries…",
					cancellationToken =>
					{
						LibrariesSyncHelper.Sync(
							File.ReadAllLines(Configuration.RemoteResourceManager.Instance.NetworkPathFile.LocalPath),
							Configuration.RemoteResourceManager.Instance.LocalLibraryFolder.LocalPath
							);
						Wallbin.LoadLibraries(Configuration.RemoteResourceManager.Instance.LocalLibraryFolder.LocalPath);
						EmailBin.Load();
					});

				appReady &= Wallbin.Libraries.Any();
				if (appReady)
				{
					if (Settings.RunPowerPointWhenNeeded.HasValue && Settings.RunPowerPointWhenNeeded.Value)
						PowerPointManager.Instance.RunPowerPointLoader();

					ActivityManager.AddUserActivity("Application started");

					LoadControllers();

					MainForm.InitForm();

					Application.Run(MainForm);

				}
			}
			if (!appReady)
				PopupMessages.ShowWarning("This app is not activated. Contact adSALESapps Support ([email protected])");
		}
Ejemplo n.º 3
0
		public void RunConsole()
		{
			var stopRun = false;

			LicenseHelper.Register();

			AppProfileManager.Instance.InitApplication(AppTypeEnum.FileManager);

			FileStorageManager.Instance.UsingLocalMode += (o, e) =>
			{
				if (FileStorageManager.Instance.UseLocalMode) return;
				if (FileStorageManager.Instance.DataState == DataActualityState.Updated) return;
				stopRun = true;
			};

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

			AsyncHelper.RunSync(FileStorageManager.Instance.Init);

			if (stopRun) return;

			if (!FileStorageManager.Instance.Activated) return;

			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;
				}
			}

			AsyncHelper.RunSync(async () =>
			{
				await Configuration.RemoteResourceManager.Instance.LoadRemote();
				Settings.LoadRemote();
				InitBusinessObjects();
				await FileStorageManager.Instance.FixDataState();
			});
			Wallbin.LoadLibrary(Settings.BackupPath);
			SyncManager.SyncSilent();
		}