/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (string.IsNullOrEmpty(txtLastName.Text)) { ShowError(GetString("om.contact.enterlastname")); return(false); } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!ValidationHelper.IsIdentifier(txtTableName.Text)) { ShowError(GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")); return(false); } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!ValidationHelper.IsFileName(txtFileName.Text)) { ShowError(GetString("general.invalidfilename")); return false; } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!ValidationHelper.IsIdentifier(txtTableName.Text)) { ShowError(GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")); return false; } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (string.IsNullOrEmpty(txtLastName.Text)) { ShowError(GetString("om.contact.enterlastname")); return false; } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!ValidationHelper.IsFileName(txtFileName.Text)) { ShowError(GetString("general.invalidfilename")); return(false); } return(true); }
/// <summary> /// Returns if input value is valid email address. /// </summary> public override bool IsValid(CloneSettings settings) { if (String.IsNullOrWhiteSpace(txtEmail.Text) || !txtEmail.IsValid()) { ShowError(GetString("om.contact.enteremail")); return(false); } return(true); }
/// <summary> /// Returns if input value is valid email address. /// </summary> public override bool IsValid(CloneSettings settings) { string value = txtEmail.Text; if (String.IsNullOrWhiteSpace(value) || !ValidationHelper.IsEmail(value)) { ShowError(GetString("om.contact.enteremail")); return false; } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> /// <returns></returns> public override bool IsValid(CloneSettings settings) { TableManager tm = new TableManager(null); if (tm.TableExists(txtTableName.Text)) { ShowError(GetString("sysdev.class_edit_gen.tablenameunique")); return(false); } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { DataSet ds = CountryInfoProvider.GetCountries().WhereEquals("CountryTwoLetterCode", txtTwoLetterCode.Text).Or().WhereEquals("CountryThreeLetterCode", txtThreeLetterCode.Text); if (!DataHelper.DataSourceIsEmpty(ds)) { ShowError(GetString("clonning.settings.country.uniquecodes")); return false; } return true; }
/// <summary> /// Returns if input value is valid email address. /// </summary> public override bool IsValid(CloneSettings settings) { string value = txtEmail.Text; if (String.IsNullOrWhiteSpace(value) || !ValidationHelper.IsEmail(value)) { ShowError(GetString("om.contact.enteremail")); return(false); } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!chkGeneratePassword.Checked) { if (!txtPassword.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(CMSContext.CurrentSiteName)); return false; } } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!chkGeneratePassword.Checked) { if (!txtPassword.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(CMSContext.CurrentSiteName)); return(false); } } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { DataSet ds = CountryInfo.Provider.Get().WhereEquals("CountryTwoLetterCode", txtTwoLetterCode.Text).Or().WhereEquals("CountryThreeLetterCode", txtThreeLetterCode.Text); if (!DataHelper.DataSourceIsEmpty(ds)) { ShowError(GetString("clonning.settings.country.uniquecodes")); return(false); } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { // Check the uniqueness of 2-letter and 3-letter codes string where = "CountryTwoLetterCode = '" + SqlHelperClass.GetSafeQueryString(txtTwoLetterCode.Text) + "' OR CountryThreeLetterCode = '" + SqlHelperClass.GetSafeQueryString(txtThreeLetterCode.Text) + "'"; DataSet ds = CountryInfoProvider.GetCountries(where, null); if (!DataHelper.DataSourceIsEmpty(ds)) { ShowError(GetString("clonning.settings.country.uniquecodes")); return false; } return true; }
/// <summary> /// Returns initialized clone settings based on filled controls. /// </summary> private CloneSettings InitializeCloneSettings() { var settings = new CloneSettings { KeepFieldsTranslated = chkKeepFieldsTranslated.Checked, CloneBase = InfoToClone, CodeName = txtCodeName.Text, DisplayName = txtDisplayName.Text, IncludeBindings = chkBindings.Checked, IncludeOtherBindings = chkBindings.Checked, IncludeChildren = chkChildren.Checked, IncludeMetafiles = chkMetafiles.Checked, IncludeSiteBindings = chkSiteBindings.Checked, MaxRelativeLevel = ValidationHelper.GetInteger(drpMaxRelativeLevel.SelectedValue, -1), CloneToSiteID = (plcCloneUnderSite.Visible && siteElem.Visible) ? siteElem.SiteID : InfoToClone.Generalized.ObjectSiteID }; if (plcAssignToCurrentSite.Visible) { settings.AssignToSiteID = (chkAssignToCurrentSite.Checked ? SiteContext.CurrentSiteID : 0); } if (customProperties != null) { if (customProperties.IsValid(settings)) { var customParameters = customProperties.CustomParameters; if (customParameters != null) { settings.CustomParameters = customParameters; } settings.ExcludedChildTypes.AddRange(excludedChildren); settings.ExcludedBindingTypes.AddRange(excludedBindings); settings.ExcludedOtherBindingTypes.AddRange(excludedOtherBindings); } else { return(null); } } if (InfoToClone.Parent != null) { settings.ParentID = InfoToClone.Parent.Generalized.ObjectID; } return(settings); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (InfoToClone.GetBooleanValue("IssueIsABTest", false)) { if (!settings.IncludeChildren || (settings.MaxRelativeLevel == 0)) { // It is not possible to clone ABTest issue without its children, because children are variants of the AB Tests and it makes no sense to clone without variants ShowError(GetString("newsletters.cannotcloneabtestissuewithoutchildren")); return false; } } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (InfoToClone.GetBooleanValue("IssueIsABTest", false)) { if (!settings.IncludeChildren || (settings.MaxRelativeLevel == 0)) { // It is not possible to clone ABTest issue without its children, because children are variants of the AB Tests and it makes no sense to clone without variants ShowError(GetString("newsletters.cannotcloneabtestissuewithoutchildren")); return(false); } } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { // Check the uniqueness of 2-letter and 3-letter codes string where = "CountryTwoLetterCode = '" + SqlHelper.GetSafeQueryString(txtTwoLetterCode.Text) + "' OR CountryThreeLetterCode = '" + SqlHelper.GetSafeQueryString(txtThreeLetterCode.Text) + "'"; DataSet ds = CountryInfoProvider.GetCountries(where, null); if (!DataHelper.DataSourceIsEmpty(ds)) { ShowError(GetString("clonning.settings.country.uniquecodes")); return(false); } return(true); }
public DocumentClient GetSampleDocumentDbClient() { try { var SourceCosmosDBSettings = CloneSettings.GetConfigurationSection("SampleCosmosDBSettings"); string SourceEndpointUrl = SourceCosmosDBSettings["EndpointUrl"]; string SourceAccessKey = SourceCosmosDBSettings["AccessKey"]; var sourceDocumentClient = new DocumentClient(new Uri(SourceEndpointUrl), SourceAccessKey, ConnectionPolicy); return(sourceDocumentClient); } catch (Exception ex) { logger.LogError(ex); throw; } }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!ValidationHelper.IsIdentifier(txtTableName.Text)) { ShowError(GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")); return(false); } TableManager tm = new TableManager(null); if (tm.TableExists(txtTableName.Text)) { ShowError(GetString("sysdev.class_edit_gen.tablenameunique")); return(false); } return(true); }
public override bool IsValid(CloneSettings settings) { // It is not possible to clone ABTest issue without its children, // because children are variants of the AB Tests and it makes no sense to clone without variants if (IssueToClone.IssueIsABTest) { if (!settings.IncludeChildren || (settings.MaxRelativeLevel == 0)) { ShowError(GetString("newsletters.cannotcloneabtestissuewithoutchildren")); return(false); } } var targetFeed = TargetFeed; if (targetFeed == null || targetFeed.NewsletterSiteID != SiteContext.CurrentSiteID) { ShowError(GetString("newsletters.invalidtargetemailfeed")); return(false); } if (IssueToClone.IssueTemplateID > 0) { // Check if the email template of the cloned issue is supported in the target parent newsletter feed var templateIsSupported = EmailTemplateNewsletterInfo.Provider.Get() .WhereEquals("TemplateID", IssueToClone.IssueTemplateID) .And() .WhereEquals("NewsletterID", ValidationHelper.GetInteger(drpNewsletters.Value, 0)) .TopN(1) .Any(); if (!templateIsSupported) { ShowError(string.Format(GetString("newsletters.cannotcloneissuetofeedwithrestrictedtemplate"), IssueToClone.IssueDisplayName, targetFeed.NewsletterDisplayName)); return(false); } } return(true); }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (dtValidFrom.SelectedDateTime > dtValidTo.SelectedDateTime) { ShowError(GetString("general.dateoverlaps")); return false; } if (!dtValidFrom.IsValidRange()) { ShowError(GetString("general.errorinvaliddatetimerange")); return false; } if (!dtValidTo.IsValidRange()) { ShowError(GetString("general.errorinvaliddatetimerange")); return false; } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (dtValidFrom.SelectedDateTime > dtValidTo.SelectedDateTime) { ShowError(GetString("general.dateoverlaps")); return(false); } if (!dtValidFrom.IsValidRange()) { ShowError(GetString("general.errorinvaliddatetimerange")); return(false); } if (!dtValidTo.IsValidRange()) { ShowError(GetString("general.errorinvaliddatetimerange")); return(false); } return(true); }
//private EntitySummary summary; #endregion public CodeMigrator() { //initialize settings and other utilities var SourceCosmosDBSettings = CloneSettings.GetConfigurationSection("SourceCosmosDBSettings"); SourceEndpointUrl = CloneSettings.SourceSettings.EndpointUrl;; SourceAccessKey = CloneSettings.SourceSettings.AccessKey; sourceDatabaseName = CloneSettings.SourceSettings.DatabaseName; sourceCollectionName = CloneSettings.SourceSettings.CollectionName; //var TargetCosmosDBSettings = CloneSettings.GetConfigurationSection("TargetCosmosDBSettings"); TargetEndpointUrl = CloneSettings.TargetSettings.EndpointUrl; TargetAccessKey = CloneSettings.TargetSettings.AccessKey; TargetDatabaseName = CloneSettings.TargetSettings.DatabaseName; TargetCollectionName = CloneSettings.TargetSettings.CollectionName; cosmosHelper = new CosmosDBHelper(); cosmosBulkImporter = new CosmosBulkImporter(); //summary = new EntitySummary(); //summary.EntityType = "DBCode"; }
public async Task <DocumentCollection> CreateSampleDocumentCollection(DocumentClient sampleClient, bool IsFixedCollection = false) { try { var sampleCosmosDBSettings = CloneSettings.GetConfigurationSection("SampleCosmosDBSettings"); string sampleDatabaseName = sampleCosmosDBSettings["DatabaseName"];; string sampleCollectionName = sampleCosmosDBSettings["CollectionName"]; int offerThroughput = 1000; int.TryParse(sampleCosmosDBSettings["OfferThroughputRUs"], out offerThroughput); await sampleClient.CreateDatabaseIfNotExistsAsync(new Database { Id = sampleDatabaseName }); DocumentCollection newDocumentCollection; if (!IsFixedCollection) { var partitionKeyDefinition = new PartitionKeyDefinition(); partitionKeyDefinition.Paths.Add("/CompositeName"); newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync (UriFactory.CreateDatabaseUri(sampleDatabaseName), new DocumentCollection { Id = sampleCollectionName, PartitionKey = partitionKeyDefinition }, new RequestOptions { OfferThroughput = offerThroughput }); } else { //no partition key if it is a fixed collection newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync (UriFactory.CreateDatabaseUri(sampleDatabaseName), new DocumentCollection { Id = sampleCollectionName }, new RequestOptions { OfferThroughput = offerThroughput }); } return(newDocumentCollection); } catch (Exception ex) { logger.LogError(ex); throw; } }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!chkGeneratePassword.Checked) { if (!txtPassword.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(SiteContext.CurrentSiteName)); return false; } } // Get sites of original user var user = (UserInfo)InfoToClone; DataTable siteTable = UserInfoProvider.GetUserSites(user.UserID, null, null, 0, "SiteName"); var sites = siteTable.AsEnumerable().Select(s => s["SiteName"].ToString()); // Check that e-mail is unique if (!UserInfoProvider.IsEmailUnique(txtEmail.Text.Trim(), sites, 0)) { throw new Exception(GetString("cloneUser.uniqueEmailRequired")); } return true; }
/// <summary> /// Returns true if custom settings are valid against given clone setting. /// </summary> /// <param name="settings">Clone settings</param> public override bool IsValid(CloneSettings settings) { if (!chkGeneratePassword.Checked) { if (!txtPassword.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(SiteContext.CurrentSiteName)); return(false); } } // Get sites of original user var user = (UserInfo)InfoToClone; DataTable siteTable = UserInfoProvider.GetUserSites(user.UserID, null, null, 0, "SiteName"); var sites = siteTable.AsEnumerable().Select(s => s["SiteName"].ToString()); // Check that e-mail is unique if (!UserInfoProvider.IsEmailUnique(txtEmail.Text.Trim(), sites, 0)) { throw new Exception(GetString("cloneUser.uniqueEmailRequired")); } return(true); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); CloneSettings.LoadSettings(); CosmosHelper = new CosmosDBHelper(); }
/// <summary> /// Clones the object to the DB according to provided settings. /// </summary> public CloneResult CloneObject() { if (InfoToClone != null) { TransferExcludedTypes(); // Check code name if (plcCodeName.Visible) { bool checkCodeName = true; if (customProperties != null) { checkCodeName = customProperties.ValidateCodeName; } if (checkCodeName && !ValidationHelper.IsCodeName(txtCodeName.Text)) { ShowError(GetString("general.invalidcodename")); return(null); } } // Check permissions string targetSiteName = SiteContext.CurrentSiteName; if (plcCloneUnderSite.Visible && siteElem.Visible) { int targetSiteId = siteElem.SiteID; if (targetSiteId > 0) { targetSiteName = SiteInfoProvider.GetSiteName(targetSiteId); } } // Check object permissions (Create & Modify) try { InfoToClone.CheckPermissions(PermissionsEnum.Create, targetSiteName, CurrentUser, true); InfoToClone.CheckPermissions(PermissionsEnum.Modify, targetSiteName, CurrentUser, true); } catch (PermissionCheckException ex) { RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed); } CloneSettings settings = new CloneSettings(); settings.KeepFieldsTranslated = chkKeepFieldsTranslated.Checked; settings.CloneBase = InfoToClone; settings.CodeName = txtCodeName.Text; settings.DisplayName = txtDisplayName.Text; settings.IncludeBindings = chkBindings.Checked; settings.IncludeOtherBindings = chkBindings.Checked; settings.IncludeChildren = chkChildren.Checked; settings.IncludeMetafiles = chkMetafiles.Checked; settings.IncludeSiteBindings = chkSiteBindings.Checked; if (plcAssignToCurrentSite.Visible) { settings.AssignToSiteID = (chkAssignToCurrentSite.Checked ? SiteContext.CurrentSiteID : 0); } settings.MaxRelativeLevel = ValidationHelper.GetInteger(drpMaxRelativeLevel.SelectedValue, -1); if (plcCloneUnderSite.Visible && siteElem.Visible) { settings.CloneToSiteID = siteElem.SiteID; } else { settings.CloneToSiteID = InfoToClone.Generalized.ObjectSiteID; } if (customProperties != null) { if (customProperties.IsValid(settings)) { Hashtable p = customProperties.CustomParameters; if (p != null) { settings.CustomParameters = p; } settings.ExcludedChildTypes.AddRange(excludedChildren); settings.ExcludedBindingTypes.AddRange(excludedBindings); settings.ExcludedOtherBindingTypes.AddRange(excludedOtherBindings); } else { return(null); } } if (InfoToClone.Parent != null) { settings.ParentID = InfoToClone.Parent.Generalized.ObjectID; } CloneResult result = new CloneResult(); BaseInfo clone = null; if (chkUseTransaction.Checked) { using (var transaction = new CMSTransactionScope()) { clone = InfoToClone.Generalized.InsertAsClone(settings, result); transaction.Commit(); } } else { clone = InfoToClone.Generalized.InsertAsClone(settings, result); } if (customProperties != null) { string script = customProperties.CloseScript; if (!string.IsNullOrEmpty(script)) { mCloseScript = script.Replace("{0}", clone.Generalized.ObjectID.ToString()); } } return(result); } return(null); }
private bool PerformAction(Page currentPage) { if (GetPageNumber(currentPage) == 0) { var result = ((SourcePage)currentPage).TestSourceConnection(); if (result) { CloneSettings.SaveSettings(); } return(result); } else if (GetPageNumber(currentPage) == 1) { var result = ((DestinationPage)currentPage).TestDestinationConnection(); if (result) { CloneSettings.SaveSettings(); } return(result); } else if (GetPageNumber(currentPage) == 2) { var page = ((CloneOptionsPage)currentPage); var valid = page.TestCloneOptions(); if (valid) { CloneSettings.SaveSettings(); } return(valid); } else if (GetPageNumber(currentPage) == 3) { btn_finish.IsEnabled = false; scrubRules = ((DataAnonymizationPage)currentPage).getScrubRules(); bool isValidationSuccess = ((DataAnonymizationPage)currentPage).validateInput(); if (!isValidationSuccess) { return(false); } BackgroundWorker worker = new BackgroundWorker { WorkerReportsProgress = true }; worker.DoWork += Worker_DoWork; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; worker.RunWorkerAsync(1000); BackgroundWorker worker2 = new BackgroundWorker { WorkerReportsProgress = true }; worker2.DoWork += Worker_DoWork2; worker2.ProgressChanged += Worker_ProgressChanged2; worker2.RunWorkerCompleted += Worker_RunWorkerCompleted2; worker2.RunWorkerAsync(1000); var nextPage = GetNextPage(currentPage); ((CopyCollectionPage)nextPage).setRequiredprogressBars(scrubRules); return(true); } else if (GetPageNumber(currentPage) == 4) { btn_finish.IsEnabled = false; ((CopyCollectionPage)currentPage).setRequiredprogressBars(scrubRules); return(true); } else { return(true); } }
/// <summary> /// Clones the object to the DB according to provided settings. /// </summary> /// public CloneResult CloneObject() { if (InfoToClone == null) { return(null); } TransferExcludedTypes(); // Check code name if (plcCodeName.Visible) { bool checkCodeName = customProperties?.ValidateCodeName ?? true; if (checkCodeName && !ValidationHelper.IsCodeName(txtCodeName.Text)) { ShowError(GetString("general.invalidcodename")); return(null); } } // Check display name length if (plcDisplayName.Visible && (txtDisplayName.Text.Length > mDisplayNameMaxLength)) { ShowError(string.Format(GetString("cloning.displayname.maxlengthexceed"), mDisplayNameMaxLength)); return(null); } // Check permissions string targetSiteName = SiteContext.CurrentSiteName; if (plcCloneUnderSite.Visible && siteElem.Visible && (siteElem.SiteID > 0)) { targetSiteName = SiteInfoProvider.GetSiteName(siteElem.SiteID); } // Check object permissions (Create & Modify) try { InfoToClone.CheckPermissions(PermissionsEnum.Create, targetSiteName, CurrentUser, true); InfoToClone.CheckPermissions(PermissionsEnum.Modify, targetSiteName, CurrentUser, true); } catch (PermissionCheckException ex) { RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed); } CloneSettings settings = InitializeCloneSettings(); if (settings == null) { return(null); } var result = new CloneResult(); BaseInfo clone; if (chkUseTransaction.Checked) { using (var transaction = new CMSTransactionScope()) { clone = InfoToClone.Generalized.InsertAsClone(settings, result); transaction.Commit(); } } else { clone = InfoToClone.Generalized.InsertAsClone(settings, result); } string script = customProperties?.CloseScript; if (!string.IsNullOrEmpty(script)) { mCloseScript = script.Replace("{0}", clone.Generalized.ObjectID.ToString()); } return(result); }
public void CloneAsNew() { var aml = @"<Item type='PCO'> <Relationships> <Item type='PCO Task' typeId='34D0942644C04D6D975C871961559FAA' id='A68D766FBB974F03925D9AA468F5E61C'> <copied_from is_null='1' /> <id keyed_name='A68D766FBB974F03925D9AA468F5E61C' type='PCO Task'>A68D766FBB974F03925D9AA468F5E61C</id> <related_id keyed_name='Confirm material handling and storage requirements' type='Task'> <Item type='Task' typeId='3B76D2C3A38142BBAA09995160D485A4' id='13E475EB99D44AC29C94A6F63DCBBD7C'> <config_id keyed_name='Confirm material handling and storage requirements' type='Task'>13E475EB99D44AC29C94A6F63DCBBD7C</config_id> <created_by_id keyed_name='Eric Domke' type='User'>2D246C5838644C1C8FD34F8D2796E327</created_by_id> <created_on>2018-04-06T08:32:35</created_on> <current_state name='Planning' keyed_name='Planning' type='Life Cycle State'>ED755CB822BD4D50A91E1219CD3599AC</current_state> <date_due_target>2018-04-06T08:32:35</date_due_target> <generation>1</generation> <id keyed_name='Confirm material handling and storage requirements' type='Task'>13E475EB99D44AC29C94A6F63DCBBD7C</id> <indent>0</indent> <is_complete>0</is_complete> <is_current>1</is_current> <is_released>0</is_released> <keyed_name>Confirm material handling and storage requirements</keyed_name> <modified_by_id keyed_name='Eric Domke' type='User'>2D246C5838644C1C8FD34F8D2796E327</modified_by_id> <modified_on>2018-04-06T08:32:35</modified_on> <new_version>0</new_version> <not_lockable>0</not_lockable> <owned_by_id keyed_name='* Owner' type='Identity'> <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='538B300BB2A347F396C436E9EEE1976C'> <id keyed_name='* Owner' type='Identity'>538B300BB2A347F396C436E9EEE1976C</id> <is_alias>0</is_alias> <itemtype>E582AB17663F4EF28460015B2BE9E094</itemtype> </Item> </owned_by_id> <parent_project keyed_name='PCO-16549' type='Simple Project'>B0D545C34B9C449088394C164D846FAB</parent_project> <permission_id keyed_name='Task - Planning' type='Permission'>FA094E3BE840483895602050EBFC62CB</permission_id> <state>Planning</state> <state_image>../images/customer/images/Project_Planning22.png</state_image> <team_id keyed_name='B0D545C34B9C449088394C164D846FAB' type='Team'>B69BCA6C8B354CFBB9BB4CBBE6D51C56</team_id> <name>Confirm material handling and storage requirements</name> <itemtype>3B76D2C3A38142BBAA09995160D485A4</itemtype> </Item> </related_id> <source_id keyed_name='PCO-16549' type='Process Change Order'>B0D545C34B9C449088394C164D846FAB</source_id> </Item> </Relationships> </Item>"; var item = ElementFactory.Local.FromXml(aml).AssertItem(); var settings = new CloneSettings() { DoCloneItem = (path, i) => !path.EndsWith("/Identity", StringComparison.OrdinalIgnoreCase) }; var pco = item.CloneAsNew(settings); Assert.IsFalse(pco.Elements().OfType <IReadOnlyProperty>().Any()); Assert.AreNotEqual(item.Id(), pco.Id()); var pcoTask = pco.Relationships().Single(); Assert.AreNotEqual(item.Relationships().Single().Id(), pcoTask.Id()); Assert.AreEqual(1, pcoTask.Elements().OfType <IReadOnlyProperty>().Count()); var task = pcoTask.RelatedItem(); var origTask = item.Relationships().Single().RelatedItem(); Assert.AreNotEqual(origTask.Id(), task.Id()); var clonedProps = new string[] { "date_due_target", "indent", "is_complete", "name", "owned_by_id", "parent_project", "state_image", "team_id", }; CollectionAssert.AreEqual(clonedProps, task.Elements().OfType <IReadOnlyProperty>().Select(p => p.Name).OrderBy(n => n).ToArray()); Assert.AreEqual(origTask.OwnedById().Value, task.OwnedById().Value); }
/// <summary> /// Clones the object to the DB according to provided settings. /// </summary> public CloneResult CloneObject() { if (InfoToClone != null) { // Check code name if (plcCodeName.Visible) { if (!ValidationHelper.IsCodeName(txtCodeName.Text)) { ShowError(GetString("general.invalidcodename")); return null; } } // Check permissions string targetSiteName = CMSContext.CurrentSiteName; int targetSiteId = 0; if (plcCloneUnderSite.Visible && siteElem.Visible) { targetSiteId = siteElem.SiteID; if (targetSiteId > 0) { targetSiteName = SiteInfoProvider.GetSiteName(targetSiteId); } } // Check object permissions (Create & Modify) try { CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Create, InfoToClone, targetSiteName, true); CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Modify, InfoToClone, targetSiteName, true); } catch (PermissionCheckException ex) { RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed); } CloneSettings settings = new CloneSettings(); settings.KeepFieldsTranslated = chkKeepFieldsTranslated.Checked; settings.CloneBase = InfoToClone; settings.CodeName = txtCodeName.Text; settings.DisplayName = txtDisplayName.Text; settings.IncludeBindings = chkBindings.Checked; settings.IncludeOtherBindings = chkBindings.Checked; settings.IncludeChildren = chkChildren.Checked; settings.IncludeMetafiles = chkMetafiles.Checked; settings.IncludeSiteBindings = chkSiteBindings.Checked; if (plcAssignToCurrentSite.Visible) { settings.AssignToSiteID = (chkAssignToCurrentSite.Checked ? CMSContext.CurrentSiteID : 0); } settings.MaxRelativeLevel = ValidationHelper.GetInteger(drpMaxRelativeLevel.SelectedValue, -1); if (plcCloneUnderSite.Visible && siteElem.Visible) { settings.CloneToSiteID = siteElem.SiteID; } else { settings.CloneToSiteID = InfoToClone.Generalized.ObjectSiteID; } if (customProperties != null) { if (customProperties.IsValid(settings)) { Hashtable p = customProperties.CustomParameters; if (p != null) { settings.CustomParameters = p; } settings.ExcludedChildTypes.AddRange(excludedChildren); settings.ExcludedBindingTypes.AddRange(excludedBindings); settings.ExcludedOtherBindingTypes.AddRange(excludedOtherBindings); } else { return null; } } if (InfoToClone.Parent != null) { settings.ParentID = InfoToClone.Parent.Generalized.ObjectID; } CloneResult result = new CloneResult(); BaseInfo clone = null; if (chkUseTransaction.Checked) { using (CMSTransactionScope transaction = new CMSTransactionScope()) { clone = InfoToClone.Generalized.InsertAsClone(settings, result); transaction.Commit(); } } else { clone = InfoToClone.Generalized.InsertAsClone(settings, result); } if (customProperties != null) { string script = customProperties.CloseScript; if (!string.IsNullOrEmpty(script)) { mCloseScript = script.Replace("{0}", clone.Generalized.ObjectID.ToString()); } } return result; } return null; }