public RepositoryItemBase CreateCopy(bool setNewGUID = true) { // Create a copy by serailized and load from the text, it will not copy all atrs only the one which are saved to XML string s = RepositorySerializer.SerializeToString(this); // TODO: fixme not good practice and not safe, add param to handle in function or another solution... RepositoryItemBase duplicatedItem = (RepositoryItemBase)RepositorySerializer.DeserializeFromText(this.GetType(), s, filePath: this.FilePath); //change the GUID of duplicated item if (setNewGUID && duplicatedItem != null) { duplicatedItem.ParentGuid = Guid.Empty; duplicatedItem.ExternalID = string.Empty; duplicatedItem.Guid = Guid.NewGuid(); List <GuidMapper> guidMappingList = new List <GuidMapper>(); //set new GUID also to child items UpdateRepoItemGuids(duplicatedItem, guidMappingList); duplicatedItem = duplicatedItem.GetUpdatedRepoItem(guidMappingList); } return(duplicatedItem); }
private RepositoryItemBase GetUpdatedRepoItem(List <GuidMapper> list) { string s = RepositorySerializer.SerializeToString(this); foreach (GuidMapper mapper in list) { s = s.Replace(mapper.Original.ToString(), mapper.newGuid.ToString()); } return((RepositoryItemBase)RepositorySerializer.DeserializeFromText(this.GetType(), s, filePath: this.FilePath)); }
/// <summary> /// Update flow control and other places with new guid of entities. /// If FC is GoTo action and action got a new guid this method update flow control value with new guid /// </summary> /// <param name="list">mapping of old and new guids</param> /// <returns></returns> private RepositoryItemBase ReplaceOldGuidUsages(List <GuidMapper> list) { string s = RepositorySerializer.SerializeToString(this); foreach (GuidMapper mapper in list) { s = s.Replace(mapper.Original.ToString(), mapper.newGuid.ToString()); s = s.Replace("ParentGuid=" + "\"" + mapper.newGuid.ToString() + "\"", "ParentGuid=" + "\"" + mapper.Original.ToString() + "\""); } return((RepositoryItemBase)RepositorySerializer.DeserializeFromText(this.GetType(), s, filePath: string.Empty)); }