private void DataGridTridionMapping_OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { if (sender == null) { return; } DataGrid grid = sender as DataGrid; if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1) { TridionFolderInfo tridionFolder = grid.SelectedItem as TridionFolderInfo; if (tridionFolder != null) { SelectTridionTreeNodeDialogWindow dialog = new SelectTridionTreeNodeDialogWindow(); dialog.TridionSelectorMode = TridionSelectorMode.Folder; dialog.TridionFolder = tridionFolder; dialog.CurrentMapping = this.CurrentMapping; bool res = dialog.ShowDialog() == true; if (res) { CollectionViewSource.GetDefaultView(this.dataGridTridionMapping.ItemsSource).Refresh(); } } } }
public static void ProcessTridionItem(MappingInfo mapping, ItemInfo item, TridionFolderInfo folder) { //todo: nested folders? if (item == null || folder == null) return; if (!folder.ScanForItems) return; if (mapping.ProjectFolders.Any(projectFolder => projectFolder.ExistsTcmId(item.TcmId))) return; if (folder.TridionRole == TridionRole.PageLayoutContainer || folder.TridionRole == TridionRole.ComponentLayoutContainer) { TemplateBuildingBlockData tridionItem = ReadItem(mapping, item.TcmId) as TemplateBuildingBlockData; if (tridionItem == null || tridionItem.VersionInfo.RevisionDate == null) return; ShowMessage(item.Title + "..."); if (ProjectDestination_Skip) { //skip checkbox is pressed ProjectFolderInfo projectFolder = null; if (folder.TridionRole == TridionRole.PageLayoutContainer) { projectFolder = mapping.ProjectFolders.FirstOrDefault(x => x.ProjectFolderRole == ProjectFolderRole.PageLayout); } if (folder.TridionRole == TridionRole.ComponentLayoutContainer) { projectFolder = mapping.ProjectFolders.FirstOrDefault(x => x.ProjectFolderRole == ProjectFolderRole.ComponentLayout); } if (projectFolder == null) projectFolder = new ProjectFolderInfo(); if (projectFolder.ChildItems == null) projectFolder.ChildItems = new List<ProjectItemInfo>(); string path = Path.Combine(projectFolder.Path, item.Title.Replace(".cshtml", "") + ".cshtml"); ProjectFileInfo projectFile = projectFolder.ChildItems.OfType<ProjectFileInfo>().FirstOrDefault(x => x.Path == path) ?? new ProjectFileInfo(); projectFile.Parent = projectFolder; projectFile.RootPath = projectFolder.RootPath; projectFile.Path = path; projectFile.TcmId = item.TcmId; projectFile.Checked = true; projectFile.SyncTemplate = Common.IsolatedStorage.Service.GetFromIsolatedStorage(Common.IsolatedStorage.Service.GetId(mapping.Host, "ProjectDestination_SyncTemplate")) == "true"; if (projectFolder.ChildItems.OfType<ProjectFileInfo>().All(x => x.Path != path)) { projectFolder.ChildItems.Add(projectFile); } string fullPath = projectFile.FullPath; DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate; DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId); SaveVSItem(fullPath, tridionItem.Content); File.SetAttributes(fullPath, FileAttributes.Normal); File.SetLastWriteTime(fullPath, tridionLocalDate); WriteSuccessLog(fullPath + " - Saved to Visual Studio"); } else { ProjectDestinationDialogWindow dialog = new ProjectDestinationDialogWindow(); dialog.Mapping = mapping; dialog.TridionRole = folder.TridionRole; dialog.TridionTcmId = item.TcmId; dialog.TridionTitle = item.Title; dialog.TridionContent = tridionItem.Content; bool res = dialog.ShowDialog() == true; if (res) { ProjectFolderInfo projectFolder = dialog.ProjectFolder; ProjectFileInfo projectFile = dialog.ProjectFile; if (projectFolder != null && projectFile != null) { string fullPath = projectFile.FullPath; DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate; DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId); SaveVSItem(fullPath, tridionItem.Content); File.SetAttributes(fullPath, FileAttributes.Normal); File.SetLastWriteTime(fullPath, tridionLocalDate); WriteSuccessLog(fullPath + " - Saved to Visual Studio"); } } } ShowMessage(String.Empty); } if (folder.TridionRole == TridionRole.MultimediaComponentContainer) { ComponentData tridionItem = GetComponent(mapping, item.TcmId); if (tridionItem == null || tridionItem.VersionInfo.RevisionDate == null) return; ShowMessage(item.Title + "..."); if (ProjectDestination_Skip) { ProjectFolderInfo projectFolder = mapping.ProjectFolders.FirstOrDefault(x => x.ProjectFolderRole == ProjectFolderRole.Binary) ?? new ProjectFolderInfo(); if (projectFolder.ChildItems == null) projectFolder.ChildItems = new List<ProjectItemInfo>(); string path = Path.Combine(projectFolder.Path, item.Title); ProjectFileInfo projectFile = projectFolder.ChildItems.OfType<ProjectFileInfo>().FirstOrDefault(x => x.Path == path) ?? new ProjectFileInfo(); projectFile.Parent = projectFolder; projectFile.RootPath = projectFolder.RootPath; projectFile.Path = path; projectFile.TcmId = item.TcmId; projectFile.Checked = true; if (projectFolder.ChildItems.OfType<ProjectFileInfo>().All(x => x.Path != path)) { projectFolder.ChildItems.Add(projectFile); } string fullPath = projectFile.FullPath; DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate; DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId); SaveVSBinaryItem(mapping, projectFile.TcmId, fullPath); File.SetAttributes(fullPath, FileAttributes.Normal); File.SetLastWriteTime(fullPath, tridionLocalDate); WriteSuccessLog(fullPath + " - Saved to Visual Studio"); } else { ProjectBinaryDestinationDialogWindow dialog = new ProjectBinaryDestinationDialogWindow(); dialog.Mapping = mapping; dialog.TridionTcmId = item.TcmId; dialog.TridionTitle = item.Title; bool res = dialog.ShowDialog() == true; if (res) { ProjectFolderInfo projectFolder = dialog.ProjectFolder; ProjectFileInfo projectFile = dialog.ProjectFile; if (projectFolder != null && projectFile != null) { string fullPath = projectFile.FullPath; DateTime tridionDate = (DateTime)tridionItem.VersionInfo.RevisionDate; DateTime tridionLocalDate = tridionDate.GetLocalTime(mapping.TimeZoneId); SaveVSBinaryItem(mapping, projectFile.TcmId, fullPath); File.SetAttributes(fullPath, FileAttributes.Normal); File.SetLastWriteTime(fullPath, tridionLocalDate); WriteSuccessLog(fullPath + " - Saved to Visual Studio"); } } } ShowMessage(String.Empty); } }
public static void ProcessTridionFolder(MappingInfo mapping, TridionFolderInfo folder) { if (!folder.ScanForItems || String.IsNullOrEmpty(folder.TcmId) || (folder.TridionRole != TridionRole.PageLayoutContainer && folder.TridionRole != TridionRole.ComponentLayoutContainer)) return; List<ItemInfo> items = GetTbbsByParentFolder(mapping, folder.TcmId); foreach (ItemInfo item in items) { ProcessTridionItem(mapping, item, folder); } List<ItemInfo> childFolderItems = GetFoldersByParentFolder(mapping, folder.TcmId); if (childFolderItems != null && childFolderItems.Count > 0) { List<TridionFolderInfo> childFolders = childFolderItems.Select(childFolderItem => new TridionFolderInfo { TcmId = childFolderItem.TcmId, TridionRole = folder.TridionRole, ScanForItems = folder.ScanForItems, ParentFolder = folder }).ToList(); folder.ChildFolders = childFolders; foreach (TridionFolderInfo childFolder in childFolders) { ProcessTridionFolder(mapping, childFolder); } } }