private void ListBox1_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { ProjectFolderInfo folder = this.ProjectFolders[this.lstDestination.SelectedIndex]; if (folder == null) { return; } ProjectFolderRole role = folder.ProjectFolderRole; this.chkSyncTemplate.IsEnabled = role == ProjectFolderRole.PageLayout || role == ProjectFolderRole.ComponentLayout; this.chkSyncTemplate.IsChecked = Common.IsolatedStorage.Service.GetFromIsolatedStorage(Common.IsolatedStorage.Service.GetId(Mapping.Host.GetDomainName(), Mapping.Host.GetPort(), "ProjectDestination_SyncTemplate")) == "true"; }
private void SetVisibility(ProjectFolderRole role) { if (role == ProjectFolderRole.PageLayout) { this.txtTemplateFormat.IsEnabled = true; this.txtSchemaNames.IsEnabled = false; this.txtSchemaNames.Text = null; this._TridionRole = TridionRole.PageLayoutContainer; } if (role == ProjectFolderRole.ComponentLayout) { this.txtTemplateFormat.IsEnabled = true; this.txtSchemaNames.IsEnabled = true; this._TridionRole = TridionRole.ComponentLayoutContainer; } if (role == ProjectFolderRole.Binary) { this.txtTemplateFormat.IsEnabled = false; this.txtSchemaNames.IsEnabled = false; this.txtTemplateFormat.Text = null; this.txtSchemaNames.Text = null; this._TridionRole = TridionRole.MultimediaComponentContainer; } if (role == ProjectFolderRole.Other) { this.txtTemplateFormat.IsEnabled = false; this.txtSchemaNames.IsEnabled = false; this.txtTemplateFormat.Text = null; this.txtSchemaNames.Text = null; this._TridionRole = TridionRole.Other; } List <TridionFolderInfo> items = this.TridionFolders.Where(x => x.TridionRole == this._TridionRole).ToList(); this.lstTridionFolders.ItemsSource = items; this.lstTridionFolders.DisplayMemberPath = "NamedPathCut2"; this.lstTridionFolders.SelectedIndex = 0; this.lstTridionFolders.IsEnabled = items.Count > 1; }
private void cbRoles_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.cbRoles.SelectedValue == null) { return; } ProjectFolderRole role = (ProjectFolderRole)this.cbRoles.SelectedValue; if (this._ProjectItem.IsFolder) { ProjectFolderInfo folder = (ProjectFolderInfo)this._ProjectItem; folder.ProjectFolderRole = role; this.SetChildProperties(folder); } this.SetVisibility(role); }
private void SetVisibility(ProjectFolderRole role) { if (role == ProjectFolderRole.PageLayout) { this.txtTemplateFormat.IsEnabled = true; this.txtSchemaNames.IsEnabled = false; this.txtSchemaNames.Text = null; this._TridionRole = TridionRole.PageLayoutContainer; } if (role == ProjectFolderRole.ComponentLayout) { this.txtTemplateFormat.IsEnabled = true; this.txtSchemaNames.IsEnabled = true; this._TridionRole = TridionRole.ComponentLayoutContainer; } if (role == ProjectFolderRole.Binary) { this.txtTemplateFormat.IsEnabled = false; this.txtSchemaNames.IsEnabled = false; this.txtTemplateFormat.Text = null; this.txtSchemaNames.Text = null; this._TridionRole = TridionRole.MultimediaComponentContainer; } if (role == ProjectFolderRole.Other) { this.txtTemplateFormat.IsEnabled = false; this.txtSchemaNames.IsEnabled = false; this.txtTemplateFormat.Text = null; this.txtSchemaNames.Text = null; this._TridionRole = TridionRole.Other; } List<TridionFolderInfo> items = this.TridionFolders.Where(x => x.TridionRole == this._TridionRole).ToList(); this.lstTridionFolders.ItemsSource = items; this.lstTridionFolders.DisplayMemberPath = "NamedPathCut2"; this.lstTridionFolders.SelectedIndex = 0; this.lstTridionFolders.IsEnabled = items.Count > 1; }
public static void SyncRazorLayoutTbb(MappingInfo mapping, string tcmContainer, ProjectFileInfo file, ProjectFolderRole role, string serverTimeZoneId) { string path = file.FullPath; if (String.IsNullOrEmpty(path)) return; if (!File.Exists(path)) { //remove non-existing file from mapping foreach (ProjectFolderInfo folder in mapping.ProjectFolders) { Service.DeleteFileFromMapping(folder, path); } return; } IncludeProjectItem(path); string title; if (String.IsNullOrEmpty(file.Title)) { title = Path.GetFileNameWithoutExtension(path); file.Title = title; } else { title = file.Title; } string id; if (String.IsNullOrEmpty(file.TcmId)) { id = GetItemTcmId(mapping, tcmContainer, title); file.TcmId = id; } else { id = file.TcmId; } string fileContent = TransformRazor2Mediator(File.ReadAllText(path)); bool updated = false; if (String.IsNullOrEmpty(id)) { TridionDestinationDialogWindow dialog = new TridionDestinationDialogWindow(); dialog.Mapping = mapping; dialog.FilterItemTcmId = tcmContainer; dialog.PublicationTcmId = GetPublicationTcmId(tcmContainer); dialog.LayoutTitle = title; dialog.TemplateTitle = String.IsNullOrEmpty(file.TemplateTitle) ? title : file.TemplateTitle; bool res = dialog.ShowDialog() == true; if (res) { file.Title = dialog.LayoutTitle; file.TemplateTitle = dialog.TemplateTitle; tcmContainer = GetBluePrintItemTcmId(tcmContainer, dialog.PublicationTcmId); string stackTraceMessage; updated = SaveRazorLayoutTbb(mapping, file.Title, fileContent, tcmContainer, out stackTraceMessage); if (updated) { id = GetItemTcmId(mapping, tcmContainer, file.Title); if (String.IsNullOrEmpty(id)) { WriteErrorLog(file.Path + " - Item is broken after updating"); return; } file.TcmId = id; } else { WriteErrorLog(file.Path + " - Creating failed", stackTraceMessage); return; } } } TemplateBuildingBlockData item = ReadItem(mapping, id) as TemplateBuildingBlockData; if (item == null || item.VersionInfo.RevisionDate == null) { WriteErrorLog(String.Format("Item {0} does not exist", id)); return; } FileInfo fi = new FileInfo(path); DateTime fileDate = fi.LastWriteTime; DateTime tridionDate = (DateTime) item.VersionInfo.RevisionDate; DateTime tridionLocalDate = tridionDate.GetLocalTime(serverTimeZoneId); if (updated) { File.SetAttributes(path, FileAttributes.Normal); File.SetLastWriteTime(path, tridionLocalDate); WriteSuccessLog(file.Path + " - Saved to Tridion CM successfully"); return; } if (fileDate == tridionLocalDate) return; string tridionContent = item.Content; file.Title = item.Title; if (Equals(fileContent, tridionContent)) { File.SetAttributes(path, FileAttributes.Normal); File.SetLastWriteTime(path, tridionLocalDate); WriteSuccessLog(file.Path + " - Date of project item is updated to " + tridionLocalDate); } else { string user = item.VersionInfo is FullVersionInfo && ((FullVersionInfo)item.VersionInfo).Revisor != null ? ((FullVersionInfo)item.VersionInfo).Revisor.Title : "Unknown"; DiffDialogWindow dialog = new DiffDialogWindow(); if (fileDate > tridionLocalDate) { dialog.StartItemInfo = String.Format("Tridion Item: {0} ({1}), {2}, {3}", item.Title, item.Id, tridionLocalDate, user); dialog.EndItemInfo = String.Format("VS File: {0}, {1}", Path.GetFileName(path), fileDate); dialog.StartItemText = tridionContent; dialog.EndItemText = fileContent; dialog.SyncState = SyncState.VS2Tridion; dialog.Tridion2VSEnabled = true; dialog.VS2TridionEnabled = !IsCheckedOut(mapping, item.Id); } else { dialog.StartItemInfo = String.Format("VS File: {0}, {1}", Path.GetFileName(path), fileDate); dialog.EndItemInfo = String.Format("Tridion Item: {0} ({1}), {2}, {3}", item.Title, item.Id, tridionLocalDate, user); dialog.StartItemText = fileContent; dialog.EndItemText = tridionContent; dialog.SyncState = SyncState.Tridion2VS; dialog.Tridion2VSEnabled = true; dialog.VS2TridionEnabled = true; } bool res = dialog.ShowDialog() == true; if (res) { if (dialog.SyncState == SyncState.VS2Tridion) { string stackTraceMessage; updated = SaveRazorLayoutTbb(mapping, id, fileContent, out stackTraceMessage); if (updated) { item = ReadItem(mapping, id) as TemplateBuildingBlockData; if (item == null || item.VersionInfo.RevisionDate == null) { WriteErrorLog(String.Format("Item {0} does not exist", id)); } else { tridionDate = (DateTime)item.VersionInfo.RevisionDate; tridionLocalDate = tridionDate.GetLocalTime(serverTimeZoneId); File.SetAttributes(path, FileAttributes.Normal); File.SetLastWriteTime(path, tridionLocalDate); WriteSuccessLog(file.Path + " - Saved to Tridion CM successfully"); } } else { WriteErrorLog(file.Path + " - Updating failed", stackTraceMessage); } } else if (dialog.SyncState == SyncState.Tridion2VS) { SaveVSItem(path, tridionContent); File.SetAttributes(path, FileAttributes.Normal); File.SetLastWriteTime(path, tridionLocalDate); WriteSuccessLog(file.Path + " - Saved to Visual Studio successfully"); } } } }
private void SetForm() { ProjectFolderRole role = this._TopFolder.ProjectFolderRole; this.cbRoles.IsEnabled = this._ProjectItem.IsFolder; this.chkSyncTemplate.IsEnabled = this._ProjectItem.IsFile && (role == ProjectFolderRole.ComponentLayout || role == ProjectFolderRole.PageLayout); if (role == ProjectFolderRole.ComponentLayout || role == ProjectFolderRole.PageLayout) { this.chkSyncTemplate.IsChecked = this._ProjectItem.IsSyncTemplate(); } else { this.chkSyncTemplate.IsChecked = false; } this.btnDebug.IsEnabled = this._ProjectItem.IsFile && (role == ProjectFolderRole.ComponentLayout || role == ProjectFolderRole.PageLayout); if (this.btnDebug.IsEnabled) { ProjectFileInfo projectFile = (ProjectFileInfo)this._ProjectItem; this.btnDebug.Foreground = new SolidColorBrush(!string.IsNullOrEmpty(projectFile.TestItemTcmId) && !string.IsNullOrEmpty(projectFile.TestTemplateTcmId) ? Colors.Green : Colors.Red); } else { this.btnDebug.Foreground = new SolidColorBrush(Colors.Gray); } this.cbRoles.SelectedValue = role; if (role == ProjectFolderRole.Other) { return; } if (role == ProjectFolderRole.Binary) { this.txtTemplateFormat.Text = String.Empty; this.txtTemplateFormat.IsEnabled = false; this.txtSchemaNames.Text = String.Empty; this.txtSchemaNames.IsEnabled = false; if (this._ProjectItem.IsFolder) { this.txtTitle.Text = null; this.txtTitle.IsEnabled = false; } else { ProjectFileInfo file = (ProjectFileInfo)this._ProjectItem; this.txtTitle.Text = String.IsNullOrEmpty(file.Title) ? Path.GetFileNameWithoutExtension(file.Path) : file.Title; file.Title = String.IsNullOrEmpty(this.txtTitle.Text) ? null : this.txtTitle.Text; this.txtTitle.IsEnabled = true; } this.txtTemplateTitle.Text = null; this.txtTemplateTitle.IsEnabled = false; } else { if (this._ProjectItem.IsFolder) { if (this._ProjectItem.Path == this._TopFolder.Path) { this.txtTemplateFormat.Text = this._TopFolder.TemplateFormat.PrettyXml(); this.txtTemplateFormat.IsEnabled = true; } else { this.txtTemplateFormat.Text = String.Empty; this.txtTemplateFormat.IsEnabled = false; } this.txtSchemaNames.Text = String.Empty; this.txtSchemaNames.IsEnabled = false; this.txtTitle.Text = null; this.txtTitle.IsEnabled = false; this.txtTemplateTitle.Text = null; this.txtTemplateTitle.IsEnabled = false; } else { ProjectFileInfo file = (ProjectFileInfo)this._ProjectItem; this.txtTemplateFormat.Text = this._TopFolder.TemplateFormat.PrettyXml(); this.txtTemplateFormat.IsEnabled = false; this.txtSchemaNames.Text = file.SchemaNames == null ? String.Empty : string.Join("\n", file.SchemaNames); this.txtSchemaNames.IsEnabled = true; string title = Path.GetFileNameWithoutExtension(file.Path); this.txtTitle.Text = String.IsNullOrEmpty(file.Title) ? (string.IsNullOrEmpty(title) ? null : title.Replace(" Layout", "") + " Layout") : file.Title; file.Title = String.IsNullOrEmpty(this.txtTitle.Text) ? null : this.txtTitle.Text; this.txtTitle.IsEnabled = true; this.txtTemplateTitle.Text = String.IsNullOrEmpty(file.TemplateTitle) ? (string.IsNullOrEmpty(title) ? null : title.Replace(" Layout", "")) : file.TemplateTitle; file.TemplateTitle = String.IsNullOrEmpty(this.txtTemplateTitle.Text) ? null : this.txtTemplateTitle.Text; this.txtTemplateTitle.IsEnabled = this.chkSyncTemplate.IsChecked == true; } } List <TridionFolderInfo> tridionFolders = this.TridionFolders.Where(x => x.TridionRole == this._TridionRole).ToList(); this.lstTridionFolders.SelectedIndex = tridionFolders.Any(x => x.TcmId == this._TopFolder.TcmId) ? tridionFolders.FindIndex(x => x.TcmId == this._TopFolder.TcmId) : 0; }
public static void AddChildItems(ProjectFolderInfo projectFolder, string rootPath) { if (projectFolder == null) { return; } if (String.IsNullOrEmpty(projectFolder.FullPath)) { return; } if (!Directory.Exists(projectFolder.FullPath)) { Directory.CreateDirectory(projectFolder.FullPath); } ProjectFolderInfo topFolder = projectFolder.GetTopFolder(); ProjectFolderRole role = topFolder.ProjectFolderRole; string[] extensions = role == Misc.ProjectFolderRole.Binary ? Const.Extensions.Keys.ToArray() : new[] { "*.cshtml" }; string[] directories = Directory.GetDirectories(projectFolder.FullPath); string[] files = IO.Service.GetFiles(projectFolder.FullPath, extensions); if (directories.Length == 0 && files.Length == 0) { projectFolder.ChildItems = null; return; } List <ProjectItemInfo> newChildItems = new List <ProjectItemInfo>(); foreach (string dir in directories) { ProjectFolderInfo childFolder = null; if (projectFolder.ChildItems != null) { childFolder = projectFolder.ChildItems.FirstOrDefault(x => x.IsFolder && x.FullPath == dir) as ProjectFolderInfo; } if (childFolder == null) { childFolder = new ProjectFolderInfo { RootPath = rootPath, Path = dir.Replace(rootPath, "").Trim('\\'), Checked = false }; } childFolder.Parent = projectFolder; AddChildItems(childFolder, rootPath); newChildItems.Add(childFolder); } foreach (string file in files) { ProjectFileInfo childFile = null; if (projectFolder.ChildItems != null) { childFile = projectFolder.ChildItems.FirstOrDefault(x => x.IsFile && x.FullPath == file) as ProjectFileInfo; } if (childFile == null) { childFile = new ProjectFileInfo { RootPath = rootPath, Path = file.Replace(rootPath, "").Trim('\\'), Checked = false }; } childFile.Parent = projectFolder; newChildItems.Add(childFile); } projectFolder.ChildItems = newChildItems.Count > 0 ? newChildItems : null; }