public async Task LoadLocal()
		{
			await Common.Helpers.RemoteResourceManager.Instance.LoadLocal();

			MetaDataCacheFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppNameSet,
				"Cache"
			});
			if (!await MetaDataCacheFolder.Exists())
				await StorageDirectory.CreateSubFolder(new object[]
				{
					FileStorageManager.LocalFilesFolderName,
					AppProfileManager.Instance.AppNameSet
				}, "Cache");

			LocalLibraryCacheFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppNameSet,
				"Library"
			});
			if (!await LocalLibraryCacheFolder.Exists())
				await StorageDirectory.CreateSubFolder(new object[]
				{
					FileStorageManager.LocalFilesFolderName,
					AppProfileManager.Instance.AppNameSet
				}, "Library");
		}
		private void LoadApprovedThemes(StorageDirectory root)
		{
			var contentFile = new StorageFile(root.GetParentFolder().RelativePathParts.Merge("ApprovedThemes.xml"));

			if (!contentFile.ExistsLocal()) return;

			var document = new XmlDocument();
			document.Load(contentFile.LocalPath);

			foreach (var slideNode in document.SelectNodes(@"//Root/Slide").OfType<XmlNode>())
			{
				var slideAttribute = slideNode.Attributes["Name"];
				if (slideAttribute == null) continue;
				var slideType = SlideType.None;
				switch (slideAttribute.Value)
				{
					case "SalesLibrary":
						slideType = SlideType.SalesDepot;
						break;
				}
				if (slideType == SlideType.None) continue;
				foreach (var themeNode in slideNode.SelectNodes("Theme").OfType<XmlNode>())
				{
					if (!ApprovedThemes.ContainsKey(slideType))
						ApprovedThemes.Add(slideType, new List<string>());
					ApprovedThemes[slideType].Add(themeNode.InnerText);
				}
			}
		}
		public void UpdatePageLogo()
		{
			MainController.Instance.MainForm.ribbonBarHomeWallbin.SuspendLayout();

			var pageLogoFolder = new StorageDirectory(RemoteResourceManager.Instance.ArtworkFolder.RelativePathParts.Merge(new[]
			{
				Constants.LibraryLogoFolder,
				"libraries",
				PageContainer.Page.Library.Name,
			}));

			var libraryContainerVisibility = MainController.Instance.MainForm.itemContainerHomeWallbinLibrary.Visible;
			MainController.Instance.MainForm.itemContainerHomeWallbinLibrary.Visible = false;
			var pageLogoPath = Path.Combine(pageLogoFolder.LocalPath, String.Format("page{0}.png", PageContainer.Page.Order + 1));
			if (!File.Exists(pageLogoPath))
				pageLogoPath = Path.Combine(pageLogoFolder.LocalPath, "no_logo.png");
			if (File.Exists(pageLogoPath))
				MainController.Instance.MainForm.labelItemHomeWallbinLogo.Image = Image.FromFile(pageLogoPath);
			else
				MainController.Instance.MainForm.labelItemHomeWallbinLogo.Image = Properties.Resources.SettingsLogo;
			MainController.Instance.MainForm.itemContainerHomeWallbinLibrary.Visible = libraryContainerVisibility;
			MainController.Instance.MainForm.ribbonBarHomeWallbin.RecalcLayout();
			MainController.Instance.MainForm.ribbonPanelHome.PerformLayout();

			MainController.Instance.MainForm.ribbonBarHomeWallbin.ResumeLayout();
		}
		private FormStateHelper(Form targetForm, StorageDirectory storagePath, string filePrefix, bool showMaximized, bool saveSate)
		{
			_form = targetForm;
			_formKey = filePrefix;
			_stateStorageFile = new StorageFile(storagePath.RelativePathParts.Merge(String.Format("{0}-{1}", filePrefix, StorageName)));
			_showMaximized = showMaximized;
			_saveSate = saveSate;
			_form.WindowState = FormWindowState.Normal;
			_form.Load += (o, e) => LoadState();
			_form.FormClosed += (o, e) => SaveState();
		}
		public async Task LoadProfile()
		{
			_localAppIdFile = String.IsNullOrEmpty(LibraryAlias) ?
				new StorageFile(new[] { String.Format("{0}_app_id.xml", AppName) }) :
				new StorageFile(new[] { String.Format("{0}_{1}_app_id.xml", AppName, LibraryAlias) });

			_appID = Guid.Empty;
			if (File.Exists(_localAppIdFile.LocalPath))
			{
				var document = new XmlDocument();
				document.Load(_localAppIdFile.LocalPath);

				var node = document.SelectSingleNode(@"/AppID");
				if (!String.IsNullOrEmpty(node?.InnerText))
					_appID = new Guid(node.InnerText);
			}

			if (_appID.Equals(Guid.Empty))
				CreateProfile();

			ProfilesRootFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.OutgoingFolderName,
				AppNameSet
			});
			if (!await ProfilesRootFolder.Exists(true))
				if (AppNameSet.Length > 1)
				{
					await StorageDirectory.CreateSubFolder(new[]
					{
						FileStorageManager.OutgoingFolderName
					}, AppName, true);
					await StorageDirectory.CreateSubFolder(new[]
					{
						FileStorageManager.OutgoingFolderName
					}, AppNameSet, true);
				}
				else
				{
					await StorageDirectory.CreateSubFolder(new[]
					{
						FileStorageManager.OutgoingFolderName
					}, AppNameSet, true);
				}

			ProfileFolder = new StorageDirectory(ProfilesRootFolder.RelativePathParts.Merge(ProfileName));
			if (!await ProfileFolder.Exists(true))
				await StorageDirectory.CreateSubFolder(ProfilesRootFolder.RelativePathParts, ProfileName, true);

			UserDataFolder = new StorageDirectory(ProfileFolder.RelativePathParts.Merge(new[] { UserDataFolderName }));
			if (!await UserDataFolder.Exists(true))
				await StorageDirectory.CreateSubFolder(ProfileFolder.RelativePathParts, UserDataFolderName, true);
		}
		public void Load()
		{
			MainFolder = new StorageDirectory(RemoteResourceManager.Instance.ArtworkFolder.RelativePathParts.Merge("Banners"));
			AdditionalFolder = new StorageDirectory(RemoteResourceManager.Instance.ArtworkFolder.RelativePathParts.Merge("Banners_2"));
			FavsFolder = new StorageDirectory(RemoteResourceManager.Instance.AppSharedSettingsFolder.RelativePathParts.Merge("Favorite_Banners"));

			Items.Clear();

			SourceFolderImageGroup sourceFolderImageGroup = new RegularImageGroup(this);
			sourceFolderImageGroup.Name = "Gallery";
			sourceFolderImageGroup.Order = -3;
			if (MainFolder.ExistsLocal())
				sourceFolderImageGroup.LoadImages<Banner>(MainFolder.LocalPath);
			Items.Add(sourceFolderImageGroup);

			var searchResultsimageGroup = new SearchResultsImageGroup(this);
			searchResultsimageGroup.Name = "Search Results";
			searchResultsimageGroup.Order = -2;
			Items.Add(searchResultsimageGroup);

			sourceFolderImageGroup = new FavoriteImageGroup(this);
			sourceFolderImageGroup.Name = "My Favorites";
			sourceFolderImageGroup.Order = -1;
			if (FavsFolder.ExistsLocal())
				sourceFolderImageGroup.LoadImages<Banner>(FavsFolder.LocalPath);
			Items.Add(sourceFolderImageGroup);

			if (AdditionalFolder.ExistsLocal())
			{
				var contentDescriptionPath = Path.Combine(AdditionalFolder.LocalPath, "order.txt");
				if (File.Exists(contentDescriptionPath))
				{
					var groupNames = File.ReadAllLines(contentDescriptionPath);
					var groupIndex = 0;
					foreach (var groupName in groupNames)
					{
						if (String.IsNullOrEmpty(groupName)) continue;
						var groupFolderPath = Path.Combine(AdditionalFolder.LocalPath, groupName);
						if (!Directory.Exists(groupFolderPath)) continue;
						sourceFolderImageGroup = new RegularImageGroup(this);
						sourceFolderImageGroup.Name = groupName;
						sourceFolderImageGroup.Order = groupIndex;
						sourceFolderImageGroup.LoadImages<Banner>(groupFolderPath);
						Items.Add(sourceFolderImageGroup);
						groupIndex++;
					}
				}
			}
			Items.Sort((x, y) => x.Order.CompareTo(y.Order));
		}
		public void Load()
		{
			_themes.Clear();
			var storageDirectory = new StorageDirectory(RemoteResourceManager.Instance.ThemesFolder.RelativePathParts.Merge(PowerPointManager.Instance.SlideSettings.SlideMasterFolder));
			if (!storageDirectory.ExistsLocal()) return;

			LoadApprovedThemes(storageDirectory);

			foreach (var themeFolder in storageDirectory.GetLocalFolders())
			{
				var theme = new Theme(themeFolder);
				theme.Load();
				foreach (var approvedTheme in ApprovedThemes.Where(approvedTheme => approvedTheme.Value.Any(t => t.Equals(theme.Name))))
					theme.ApprovedSlides.Add(approvedTheme.Key);
				_themes.Add(theme);
			}
			_themes.Sort((x, y) => x.Order.CompareTo(y.Order));

			ThemesChanged?.Invoke(this, EventArgs.Empty);
		}
		public async Task LoadLocal()
		{
			await Common.Helpers.RemoteResourceManager.Instance.LoadLocal();

			MetaDataCacheFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppNameSet,
				"Cache"
			});
			if (!await MetaDataCacheFolder.Exists())
				await StorageDirectory.CreateSubFolder(new object[]
				{
					FileStorageManager.LocalFilesFolderName,
					AppProfileManager.Instance.AppNameSet
				}, "Cache");

			ArchiveFolder = new StorageDirectory(AppProfileManager.Instance.ProfileFolder.RelativePathParts.Merge("Sync Archive"));
			if (!await ArchiveFolder.Exists(true))
				await StorageDirectory.CreateSubFolder(AppProfileManager.Instance.ProfileFolder.RelativePathParts, "Sync Archive", true);
		}
		public async Task LoadRemote()
		{
			await Common.Helpers.RemoteResourceManager.Instance.LoadRemote();

			#region Remote
			var appOutgoingFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.IncomingFolderName,
				AppProfileManager.Instance.AppNameSet,
				"AppSettings"
			});

			SiteFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"Site.txt"
				));
			await SiteFile.Download();

			CategoryRequestSettingsFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"CategoryRequest.xml"
				));
			await CategoryRequestSettingsFile.Download();

			ErrorEmailSettingsFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"ErrorEmail.xml"
				));
			await ErrorEmailSettingsFile.Download();

			TabSettingsFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"RibbonTabs.xml"
				));
			await TabSettingsFile.Download();

			SyncLockSettingsFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"SyncLock.xml"
				));
			await SyncLockSettingsFile.Download();
			#endregion
		}
		public async Task LoadLocal()
		{
			TempFolder = new StorageDirectory(new[]
			{
				"Temp"
			});
			if (TempFolder.ExistsLocal())
				Utils.CleanFolder(TempFolder.LocalPath);
			if (!TempFolder.ExistsLocal())
				await StorageDirectory.CreateSubFolder(new string[] { }, "Temp");

			AppSharedSettingsFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppName,
				"shared"
			});
			if (!await AppSharedSettingsFolder.Exists())
				await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, new[] { AppProfileManager.Instance.AppName, "shared" });

			AppAliasSettingsFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppNameSet,
			});
			if (!await AppAliasSettingsFolder.Exists())
				await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, AppProfileManager.Instance.AppNameSet);

			AppSettingsFile = new StorageFile(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppNameSet,
				"Settings.xml"
			});
			AppSettingsFile.AllocateParentFolder();
		}
		public void Load()
		{
			MainFolder = new StorageDirectory(RemoteResourceManager.Instance.ArtworkFolder.RelativePathParts.Merge("link_bundle_icons"));
			AdditionalFolder = new StorageDirectory(RemoteResourceManager.Instance.ArtworkFolder.RelativePathParts.Merge("link_bundle_icons_2"));
			FavsFolder = new StorageDirectory(RemoteResourceManager.Instance.AppAliasSettingsFolder.RelativePathParts.Merge("Favorite Link Bundle Icons"));

			DefaultPowerPointLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_pptx.png"));
			DefaultWordLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_docx.png"));
			DefaultExcelLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_xlsx.png"));
			DefaultPdfLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_pdf.png"));
			DefaultVideoLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_mp4.png"));
			DefaultImageLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_image.png"));

			DefaultInfoLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_info.png"));
			DefaultRevenueLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_revenue.png"));
			DefaultStrategyLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_sales_strategy.png"));
			DefaultUrlLogo = new StorageFile(MainFolder.RelativePathParts.Merge("default_url.png"));

			Items.Clear();

			SourceFolderImageGroup sourceFolderImageGroup = new RegularImageGroup(this);
			sourceFolderImageGroup.Name = "Gallery";
			sourceFolderImageGroup.Order = -2;
			if (MainFolder.ExistsLocal())
				sourceFolderImageGroup.LoadImages<Widget>(MainFolder.LocalPath);
			Items.Add(sourceFolderImageGroup);

			sourceFolderImageGroup = new FavoriteImageGroup(this);
			sourceFolderImageGroup.Name = "My Favorites";
			sourceFolderImageGroup.Order = -1;
			if (FavsFolder.ExistsLocal())
				sourceFolderImageGroup.LoadImages<Widget>(FavsFolder.LocalPath);
			Items.Add(sourceFolderImageGroup);

			Items.Sort((x, y) => x.Order.CompareTo(y.Order));
		}
Exemple #12
0
		public Theme(StorageDirectory root)
		{
			_root = root;
		}
		public ArchiveDirectory(object[] relativePathParts) : base(relativePathParts)
		{
			_parentFoder = GetParentFolder();
		}
		public static async Task<bool> Exists(string[] relativePathParts, bool checkRemoteToo = false)
		{
			var storageItem = new StorageDirectory(relativePathParts);
			return await storageItem.Exists(checkRemoteToo);
		}
		public async Task<IEnumerable<StorageDirectory>> GetRemoteFolders(Func<string, bool> filter)
		{
			var items = await GetRemoteItems(item => item.IsCollection);
			return items
				.Where(item => filter(item.GetName()))
				.Select(item =>
				{
					var directory = new StorageDirectory(RelativePathParts.Merge(item.GetName()));
					if (!Directory.Exists(directory.LocalPath))
						Directory.CreateDirectory(directory.LocalPath);
					return directory;
				})
				.ToList();
		}
		public static FormStateHelper Init(Form targetForm, StorageDirectory storagePath, string filePrefix, bool showMaximized, bool saveSate)
		{
			return new FormStateHelper(targetForm, storagePath, filePrefix, showMaximized, saveSate);
		}
		public static async Task CreateSubFolder(object[] relativePathParts, string[] nameSet, bool remoteToo = false)
		{
			var storageItem = new StorageDirectory(relativePathParts);
			await storageItem.CreateSubFolder(nameSet, remoteToo);
		}
		public IEnumerable<StorageFile> GetLocalFiles(Func<string, bool> filter = null, bool recursive = false)
		{
			if (filter == null)
				filter = item => true;

			var items = new List<StorageFile>();
			if (recursive)
			{
				foreach (var directoryPath in Directory.GetDirectories(LocalPath))
				{
					var subDirectory = new StorageDirectory(RelativePathParts.Merge(Path.GetFileName(directoryPath)));
					items.AddRange(subDirectory.GetLocalFiles(filter, true));
				}
			}
			items.AddRange(Directory.GetFiles(LocalPath)
					.Where(filePath => filter(Path.GetFileName(filePath)))
					.Select(filePath => new StorageFile(RelativePathParts.Merge(Path.GetFileName(filePath)))));
			return items;
		}
		public async Task Load()
		{
			await Common.Helpers.RemoteResourceManager.Instance.LoadLocal();
			await Common.Helpers.RemoteResourceManager.Instance.LoadRemote();

			#region Local
			LocalLibraryFolder = new StorageDirectory(new[]
			{
				FileStorageManager.LocalFilesFolderName,
				"Libraries"
			});
			if (!await LocalLibraryFolder.Exists())
				await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, "Libraries");

			EmailBinFile = new StorageFile(new object[]
			{
				FileStorageManager.LocalFilesFolderName,
				AppProfileManager.Instance.AppNameSet,
				"EmailBin.xml"
			});
			EmailBinFile.AllocateParentFolder();
			#endregion

			#region Remote
			var appOutgoingFolder = new StorageDirectory(new object[]
			{
				FileStorageManager.IncomingFolderName,
				AppProfileManager.Instance.AppNameSet,
				"AppSettings"
			});

			NetworkPathFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"NetworkPath.txt"
				));
			await NetworkPathFile.Download();

			DefaultViewFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"DefaultView.xml"
				));
			await DefaultViewFile.Download();

			ViewButtonsFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"ViewButtons.xml"
				));
			await ViewButtonsFile.Download();

			TabSettingsFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"SDTabNames.xml"
				));
			await TabSettingsFile.Download();

			CalendarDisclaimerFile = new StorageFile(new object[]
			{
				FileStorageManager.IncomingFolderName,
				AppProfileManager.Instance.AppNameSet,
				"Nielsen Permissible Use.pdf"
			});
			await CalendarDisclaimerFile.Download();

			Gallery1ConfigFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"Gallery1.xml"
				));
			await Gallery1ConfigFile.Download();

			Gallery2ConfigFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"Gallery2.xml"
				));
			await Gallery2ConfigFile.Download();

			CalendarRibbonLogoFile = new StorageFile(appOutgoingFolder.RelativePathParts.Merge(
				"oc_logo.png"
				));
			await CalendarRibbonLogoFile.Download();

			SDSearchFile = new StorageFile(new object[]
			{
				FileStorageManager.IncomingFolderName,
				AppProfileManager.Instance.AppNameSet,
				"Data",
				"SDSearch.xml"
			});
			await SDSearchFile.Download();
			#endregion
		}
		public async Task<IEnumerable<StorageFile>> GetRemoteFiles(Func<string, bool> filter = null, bool recursive = false)
		{
			if (filter == null)
				filter = item => true;

			var items = new List<StorageFile>();
			var subItems = (await GetRemoteItems()).ToList();

			if (recursive)
			{
				foreach (var subItem in subItems.Where(subItem => subItem.IsCollection))
				{
					var subDirectory = new StorageDirectory(RelativePathParts.Merge(subItem.GetName()));
					items.AddRange(await subDirectory.GetRemoteFiles(filter, true));
				}
			}

			items.AddRange(subItems
					.Where(item => !item.IsCollection && filter(item.GetName()))
					.Select(item => new StorageFile(RelativePathParts, item)));

			return items;
		}