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"); } } } }
public static void SyncMultimedia(MappingInfo mapping, ProjectFileInfo file, string tcmContainer, string serverTimeZoneId) { string path = file.FullPath; 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); if (String.IsNullOrEmpty(id)) id = GetItemTcmId(mapping, tcmContainer, Path.GetFileNameWithoutExtension(path)); if (String.IsNullOrEmpty(id)) id = GetItemTcmId(mapping, tcmContainer, Path.GetFileName(path)); file.TcmId = id; } else { id = file.TcmId; } if (!File.Exists(path) && String.IsNullOrEmpty(id)) return; bool updated = false; if (File.Exists(path) && String.IsNullOrEmpty(id)) { TridionDestinationDialogWindow dialog = new TridionDestinationDialogWindow(); dialog.Mapping = mapping; dialog.FilterItemTcmId = tcmContainer; dialog.PublicationTcmId = GetPublicationTcmId(tcmContainer); dialog.LayoutTitle = title; bool res = dialog.ShowDialog() == true; if (res) { file.Title = dialog.LayoutTitle; tcmContainer = GetBluePrintItemTcmId(tcmContainer, dialog.PublicationTcmId); string stackTraceMessage; updated = SaveMultimediaComponentFromBinary(mapping, path, file.Title, tcmContainer, out stackTraceMessage); if (updated) { id = GetItemTcmId(mapping, tcmContainer, Path.GetFileName(path)); if (String.IsNullOrEmpty(id)) id = GetItemTcmId(mapping, tcmContainer, Path.GetFileNameWithoutExtension(path)); if (String.IsNullOrEmpty(id)) { WriteErrorLog(file.Path + " - Item is broken after updating"); return; } file.TcmId = id; } else { WriteErrorLog(path + " - Creating failed", stackTraceMessage); return; } } } ComponentData item = ReadItem(mapping, id) as ComponentData; 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(path + " - Saved to Tridion CM successfully"); return; } if (fileDate == tridionLocalDate) { return; } file.Title = item.Title; if (fi.Length == item.BinaryContent.FileSize) { File.SetAttributes(path, FileAttributes.Normal); File.SetLastWriteTime(path, tridionLocalDate); WriteSuccessLog(path + " - Saved to Tridion CM successfully"); } else { BinaryDiffDialogWindow dialog = new BinaryDiffDialogWindow(); if (fileDate > tridionLocalDate) { dialog.StartItemInfo = String.Format("Tridion Item: {0} ({1}), {2}", item.Title, item.Id, tridionLocalDate); dialog.EndItemInfo = String.Format("VS File: {0}, {1}", Path.GetFileName(path), fileDate); 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}", item.Title, item.Id, tridionLocalDate); 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 = SaveMultimediaComponentFromBinary(mapping, id, path, out stackTraceMessage); if (updated) { item = ReadItem(mapping, id) as ComponentData; 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(path + " - Saved to Tridion CM successfully"); } } else { WriteErrorLog(path + " - Updating failed", stackTraceMessage); } } else if (dialog.SyncState == SyncState.Tridion2VS) { SaveVSBinaryItem(mapping, id, path); File.SetAttributes(path, FileAttributes.Normal); File.SetLastWriteTime(path, tridionLocalDate); WriteSuccessLog(path + " - Saved to Visual Studio successfully"); } } } }