//protected VideoPage TabVideo { get; private set; }
		#endregion

		private MainController()
		{
			Settings = new SettingsManager();
			Lists = new ListManager();
			AuthManager = new AuthManager();
			SoapServiceConnection = new SoapServiceConnection();
			RestServiceConnection = new RestServiceConnection();
			Wallbin = new CloudWallbinManager(RestServiceConnection);
			HelpManager = new HelpManager();
			WallbinViews = new ViewManager();
			MainForm = new FormMain();
			ProcessManager = new BackgroundProcessManager(MainForm, "Site Admin");
			PopupMessages = new PopupMessageHelper("Site Admin");
		}
		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])");
		}
		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])");
		}
		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();
		}