private void btnStart_Click(object sender, RoutedEventArgs e) { string sourceTable = this.cbSourceTable.SelectedValue as string; string sourceDatabase = this.cbSourceDatabase.SelectedValue as string; ItemInfo targetSchema = this.cbTargetSchema.SelectedValue as ItemInfo; if (sourceDatabase == null || sourceTable == null || targetSchema == null) return; this.SetCustomImporters(); this.SetCustomNameTransformers(); if (this.HistoryMapping == null) { this.HistoryMapping = Functions.GetHistoryMapping(Functions.GetId(this.txtHost.Text, sourceDatabase, sourceTable, targetSchema.TcmId)); } if (this.HistoryMapping == null && (this.CustomComponentImporter == null || this.CustomMetadataImporter == null)) { MessageBox.Show("Neither field mapping nor custom importers is set. Please set mapping or select custom importer and try again.", "Field Mapping", MessageBoxButton.OK, MessageBoxImage.Information); return; } //inform that custom transfromation is selected if (this.CustomComponentImporter != null || this.CustomMetadataImporter != null) { string messsage = ""; if (this.CustomComponentImporter != null && this.CustomMetadataImporter != null) { messsage = String.Format("Custom imports {0} and {1} are used.\n\nContinue?", this.CustomComponentImporter.Title, this.CustomMetadataImporter.Title); } else if (this.CustomComponentImporter != null) { messsage = String.Format("Custom component import {0} is used.\n\nContinue?", this.CustomComponentImporter.Title); } else if (this.CustomMetadataImporter != null) { messsage = String.Format("Custom metadata import {0} is used.\n\nContinue?", this.CustomMetadataImporter.Title); } if (MessageBox.Show(messsage, "Custom import", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) return; } if (this.HistoryMapping != null) { foreach (HistoryItemMappingInfo historyMapping in this.HistoryMapping) { foreach (FieldMappingInfo mapping in historyMapping.Mapping) { mapping.SourceFields = this._SourceSchemaFields; mapping.TargetFields = this._TargetSchemaFields; } } Functions.SetHistoryMappingTree(this.HistoryMapping); } List<ResultInfo> results = new List<ResultInfo>(); bool localize = this.chkLocalize.IsChecked == true; Functions.SaveToIsolatedStorage(Functions.GetId(this.txtDbHost.Text, sourceDatabase, sourceTable, "Localize"), localize.ToString()); // Import components from database Functions.ImportComponents(this.txtDbHost.Text, this.txtDbUsername.Text, this.txtDbPassword.Password, sourceDatabase, sourceTable, this.Sql, this.TargetTridionFolder.TcmId, targetSchema.TcmId, this._FormatString, this._Replacements, localize, this.HistoryMapping, this.CustomComponentImporter, this.CustomMetadataImporter, results); if (results.Any(x => x.Status == Status.Success)) { ResultInfo resultFinish = new ResultInfo(); resultFinish.Status = Status.Info; resultFinish.Message = "Finished"; results.Add(resultFinish); } else { ResultInfo resultFinish = new ResultInfo(); resultFinish.Status = Status.Info; resultFinish.Message = "No Actions Made"; results.Add(resultFinish); } //show results ResultsWindow dialog = new ResultsWindow(); dialog.Host = this.txtHost.Text; dialog.ListBoxReport.ItemsSource = results.Where(x => x != null && x.Status != Status.None); dialog.ListBoxReport.MouseDoubleClick += lbReport_OnMouseDoubleClick; dialog.Show(); //reload target tree this._Publications = Functions.GetPublications(); this.treeTargetTridionFolder.ItemsSource = this._Publications.Expand(this.TargetTridionSelectorMode, this.TargetTridionFolder.TcmIdPath, this.TargetTridionFolder.TcmId).MakeExpandable(); }
private List<ResultInfo> CheckResults(List<ResultInfo> results) { if (results != null && results.Any()) return results; List<ResultInfo> newResults = new List<ResultInfo>(); ResultInfo resultFinish = new ResultInfo(); resultFinish.Status = Status.Info; resultFinish.Message = "No Actions Made"; newResults.Add(resultFinish); return newResults; }
private void btnStart_Click(object sender, RoutedEventArgs e) { ItemInfo sourceSchema = this.cbSourceSchema.SelectedValue as ItemInfo; ItemInfo targetSchema = this.cbTargetSchema.SelectedValue as ItemInfo; if (sourceSchema == null || targetSchema == null) return; this.SetCustomTransformers(); this.SetCustomNameTransformers(); if (this.HistoryMapping == null) { this.HistoryMapping = Functions.GetHistoryMapping(Functions.GetId(this.txtHost.Text, sourceSchema.TcmId, targetSchema.TcmId)); } if (this.HistoryMapping == null && (this.CustomComponentTransformer == null || this.CustomMetadataTransformer == null)) { MessageBox.Show("Neither field mapping nor custom transformers is set. Please set mapping or select custom transformer and try again.", "Field Mapping", MessageBoxButton.OK, MessageBoxImage.Information); return; } //inform that custom transfromation is selected if (this.CustomComponentTransformer != null || this.CustomMetadataTransformer != null) { string messsage = ""; if (this.CustomComponentTransformer != null && this.CustomMetadataTransformer != null) { messsage = String.Format("Custom transformations {0} and {1} are used.\n\nContinue?", this.CustomComponentTransformer.Title, this.CustomMetadataTransformer.Title); } else if (this.CustomComponentTransformer != null) { messsage = String.Format("Custom component transformation {0} is used.\n\nContinue?", this.CustomComponentTransformer.Title); } else if (this.CustomMetadataTransformer != null) { messsage = String.Format("Custom metadata transformation {0} is used.\n\nContinue?", this.CustomMetadataTransformer.Title); } if (MessageBox.Show(messsage, "Custom Transformations", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) return; } if (this.HistoryMapping != null) { foreach (HistoryItemMappingInfo historyMapping in this.HistoryMapping) { string sourceSchemaVersionTcmId = historyMapping.TcmId; if (historyMapping.Current && sourceSchemaVersionTcmId.Contains("-v")) { sourceSchemaVersionTcmId = sourceSchemaVersionTcmId.Replace("-" + sourceSchemaVersionTcmId.Split('-')[3], ""); } List<ItemFieldDefinitionData> sourceComponentFields = Functions.GetSchemaFields(sourceSchemaVersionTcmId); List<ItemFieldDefinitionData> sourceMetadataFields = Functions.GetSchemaMetadataFields(sourceSchemaVersionTcmId); List<FieldInfo> sourceSchemaFields = Functions.GetAllFields(sourceComponentFields, sourceMetadataFields, true, false); foreach (FieldMappingInfo mapping in historyMapping.Mapping) { mapping.SourceFields = sourceSchemaFields; mapping.TargetFields = this._TargetSchemaFields; } } Functions.SetHistoryMappingTree(this.HistoryMapping); } List<ResultInfo> results = new List<ResultInfo>(); ItemType sourceItemType = Functions.GetItemType(this.SourceTridionObject.TcmId); string sourceSchemaTcmId = sourceSchema.TcmId; string targetFolderUri = this.chkSameFolder.IsChecked == true ? this.SourceTridionObject.TcmId : this.TargetTridionFolder.TcmId; bool sameFolder = this.chkSameFolder.IsChecked == true || this.SourceTridionObject.TcmId == this.TargetTridionFolder.TcmId; bool localize = this.chkLocalize.IsChecked == true; Functions.SaveToIsolatedStorage(Functions.GetId(this.txtHost.Text.GetDomainName(), sourceSchema.TcmId, "Localize"), localize.ToString()); // same folder selected: schema change and component fix functionality if (sameFolder) { // single component if (sourceItemType == ItemType.Component) { if (sourceSchema.TcmId.GetId() == targetSchema.TcmId.GetId()) { // fix single component Functions.FixComponent(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } else { // change schema for single component Functions.ChangeSchemaForComponent(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetSchema.TcmId, targetFolderUri, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } } // folder if (sourceItemType == ItemType.Folder) { if (sourceSchema.TcmId.GetId() == targetSchema.TcmId.GetId()) { // fix all componnets in folder Functions.FixComponentsInFolder(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, this._Criterias, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } else { // change schema for all components in folder Functions.ChangeSchemasForComponentsInFolder(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, targetSchema.TcmId, this._Criterias, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } } // single page if (sourceItemType == ItemType.Page) { if (sourceSchema.TcmId.GetId() == targetSchema.TcmId.GetId()) { // fix single page metadata Functions.FixTridionObjectMetadata(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, localize, this.HistoryMapping, this.CustomMetadataTransformer, results); } else { // change metadata schema for single page Functions.ChangeMetadataSchemaForTridionObject(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, targetSchema.TcmId, localize, this.HistoryMapping, this.CustomMetadataTransformer, results); } } // structure group if (sourceItemType == ItemType.StructureGroup) { if (sourceSchema.TcmId.GetId() == targetSchema.TcmId.GetId()) { // fix metadata for all pages in structure group Functions.FixMetadataForTridionObjectsInContainer(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, localize, this.HistoryMapping, this.CustomMetadataTransformer, results); } else { // change metadata schema for all pages in structure group Functions.ChangeMetadataSchemasForTridionObjectsInContainer(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetFolderUri, targetSchema.TcmId, localize, this.HistoryMapping, this.CustomMetadataTransformer, results); } } } // transform and copy to destination else { string targetTridionObjectContainerUri = this.chkSameFolder.IsChecked == true ? this.SourceTridionObject.TcmId : this.TargetTridionFolder.TcmId; // single component if (sourceItemType == ItemType.Component) { // copy / transform component Functions.TransformComponent(this.SourceTridionObject.TcmId, string.Empty, sourceSchemaTcmId, targetTridionObjectContainerUri, targetSchema.TcmId, this._FormatString, this._Replacements, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } // folder if (sourceItemType == ItemType.Folder) { // copy / transform all components in folder Functions.TransformComponentsInFolder(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetTridionObjectContainerUri, targetSchema.TcmId, this._Criterias, this._FormatString, this._Replacements, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } // single page if (sourceItemType == ItemType.Page) { // copy / transform metadata Functions.TransformTridionObjectMetadata(this.SourceTridionObject.TcmId, string.Empty, sourceSchemaTcmId, targetTridionObjectContainerUri, targetSchema.TcmId, this._FormatString, this._Replacements, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } // structure group if (sourceItemType == ItemType.StructureGroup) { // copy / transform all pages in structure group Functions.TransformMetadataForTridionObjectsInContainer(this.SourceTridionObject.TcmId, sourceSchemaTcmId, targetTridionObjectContainerUri, targetSchema.TcmId, this._FormatString, this._Replacements, localize, this.HistoryMapping, this.CustomComponentTransformer, this.CustomMetadataTransformer, results); } } if (results.Any(x => x.Status == Status.Success)) { ResultInfo resultFinish = new ResultInfo(); resultFinish.Status = Status.Info; resultFinish.Message = "Finished"; results.Add(resultFinish); } else { ResultInfo resultFinish = new ResultInfo(); resultFinish.Status = Status.Info; resultFinish.Message = "No Actions Made"; results.Add(resultFinish); } //show results ResultsWindow dialog = new ResultsWindow(); dialog.Host = this.txtHost.Text; dialog.ListBoxReport.ItemsSource = results.Where(x => x != null && x.Status != Status.None); dialog.ListBoxReport.MouseDoubleClick += lbReport_OnMouseDoubleClick; dialog.Show(); //reload source and target tree this._Publications1 = Functions.GetPublications(); this.treeSourceTridionObject.ItemsSource = this._Publications1.Expand(this.SourceTridionSelectorMode, this.SourceTridionObject.TcmIdPath, this.SourceTridionObject.TcmId).MakeExpandable(); this._Publications2 = Functions.GetPublications(); this.treeTargetTridionFolder.ItemsSource = this._Publications2.Expand(this.TargetTridionSelectorMode, this.TargetTridionFolder.TcmIdPath, this.TargetTridionFolder.TcmId).MakeExpandable(); }