protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["EntityToken"] == null) { RelationshipGraphHolder.Controls.Add(new LiteralControl("No entity token.... nothing to do....")); return; } string serializedEntityToken = Request.QueryString["EntityToken"]; EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); //Composite.Core.WebClient.ElementInformation elementInformation = ElementInformationSerializer.Deserialize(serializedEntityToken); RelationshipGraph graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both); foreach (RelationshipGraphLevel level in graph.Levels) { if (level.AllEntities.Count() != 0) { RelationshipGraphHolder.Controls.Add(new LiteralControl(new XElement("h2", string.Format("Level {0}", level.Level)).ToString())); } foreach (EntityToken token in level.Entities) { PrettyPrintEntityToken(token, "red"); } foreach (EntityToken token in level.HookedEntities) { PrettyPrintEntityToken(token, "green"); } } }
private static void LoadLockingInformation() { List <ILockingInformation> lockingInformations = DataFacade.GetData <ILockingInformation>().ToList(); List <Guid> lockingInformationsToDelete = new List <Guid>(); foreach (ILockingInformation lockingInformation in lockingInformations) { object ownerId = DeserializeOwnerId(lockingInformation.SerializedOwnerId); LockingInformation li = new LockingInformation { OwnerId = ownerId, Username = lockingInformation.Username }; try { EntityToken entityToken = EntityTokenSerializer.Deserialize(lockingInformation.SerializedEntityToken); _lockingInformations.Add(entityToken, li); } catch (Exception) { // Removing broken locking information (Ex. dead data source ids) /MRJ lockingInformationsToDelete.Add(lockingInformation.Id); } } foreach (Guid id in lockingInformationsToDelete) { DataFacade.Delete <ILockingInformation>(f => f.Id == id); } }
public static ActionToken Deserialize(string serialiedWorkflowActionToken) { var data = (DataEntityToken)EntityTokenSerializer.Deserialize(serialiedWorkflowActionToken); var page = (IPage)data.Data; return(new GetPageLinkActionToken(page)); }
public static ActionToken Deserialize(string serialiedWorkflowActionToken) { var data = (DataEntityToken)EntityTokenSerializer.Deserialize(serialiedWorkflowActionToken); var file = (IMediaFile)data.Data; return(new GetMediaLinkActionToken(file)); }
public void RemoveUserPermissionDefinition(UserToken userToken, string serializedEntityToken) { string username = userToken.Username; var entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope()) { IList <IUserPermissionDefinition> toDelete; if (entityToken.IsValid()) { toDelete = DataFacade.GetData <IUserPermissionDefinition>() .Where(upd => upd.Username == username) .ToList() .Where(d => entityToken.EqualsWithVersionIgnore(DeserializeSilent(d.SerializedEntityToken))) .ToList(); } else { toDelete = DataFacade.GetData <IUserPermissionDefinition>() .Where(upd => upd.Username == username && upd.SerializedEntityToken == serializedEntityToken) .ToList(); } if (toDelete.Count > 0) { DataFacade.Delete <IUserPermissionDefinition>(toDelete); } transactionScope.Complete(); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["PiggyBagId"] == null) { ElementInformationPlaceHolder.Controls.Add(new LiteralControl("No entity token.... nothing to do.... ")); return; } Guid piggybagId = new Guid(Request.QueryString["PiggyBagId"]); string filename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.TempDirectory), string.Format("{0}.showinfo", piggybagId)); string[] showinfo = C1File.ReadAllLines(filename); string serializedEntityToken = showinfo[0]; string serializedPiggyBag = showinfo[1]; EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedPiggyBag); Dictionary <string, string> piggybag = new Dictionary <string, string>(); foreach (var kvp in dic) { piggybag.Add(kvp.Key, StringConversionServices.DeserializeValueString(kvp.Value)); } string entityTokenHtml = entityToken.GetPrettyHtml(piggybag); ElementInformationPlaceHolder.Controls.Add(new LiteralControl(entityTokenHtml)); }
public void RemoveUserGroupPermissionDefinition(Guid userGroupId, string serializedEntityToken) { var entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); using (var transactionScope = TransactionsFacade.CreateNewScope()) { IList <IUserGroupPermissionDefinition> toDelete; if (entityToken.IsValid()) { toDelete = DataFacade.GetData <IUserGroupPermissionDefinition>() .Where(ugpd => ugpd.UserGroupId == userGroupId) .ToList() .Where(d => entityToken.Equals(DeserializeSilent(d.SerializedEntityToken))) .ToList(); } else { toDelete = DataFacade.GetData <IUserGroupPermissionDefinition>() .Where(ugpd => ugpd.UserGroupId == userGroupId && ugpd.SerializedEntityToken == serializedEntityToken).ToList(); } if (toDelete.Any()) { DataFacade.Delete <IUserGroupPermissionDefinition>(toDelete); } transactionScope.Complete(); } }
/// <exclude /> public object Deserialize(string serializedObject) { RefreshTreeMessageQueueItem result = new RefreshTreeMessageQueueItem(); result.EntityToken = EntityTokenSerializer.Deserialize(serializedObject); return(result); }
public void HandleConsoleCommand(string consoleId, string commandPayload) { var serializedEntityToken = commandPayload.Replace("%5C", "\\"); var entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); ConsoleCommandHelper.SelectConsoleElement(consoleId, entityToken); }
private void AcquireLockIfNeeded(Type workflowType, Guid instanceId, string serializedEntityToken) { if (HasEntityTokenLockAttribute(workflowType)) { EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); AcquireLock(instanceId, entityToken); } }
/// <exclude /> public static List <RefreshChildrenInfo> FindEntityToken(string serializedAncestorEntityToken, string serializedEntityToken, List <RefreshChildrenParams> openedNodes) { Verify.ArgumentNotNullOrEmpty(serializedAncestorEntityToken, "serializedAncestorEntityToken"); Verify.ArgumentNotNullOrEmpty(serializedEntityToken, "serializedEntityToken"); EntityToken ancestorEntityToken = EntityTokenSerializer.Deserialize(serializedAncestorEntityToken); EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); return(FindEntityToken(ancestorEntityToken, entityToken, openedNodes)); }
internal static List <RefreshChildrenInfo> FindEntityToken(EntityToken ancestorEntityToken, EntityToken entityToken, List <RefreshChildrenParams> nodesToRefresh) { var openedNodes = nodesToRefresh.Select(node => new { EntityToken = EntityTokenSerializer.Deserialize(node.EntityToken), ElementData = node }).ToList(); foreach (List <EntityToken> ancestorChain in GetAncestorChains(ancestorEntityToken, entityToken)) { if (ancestorChain == null || ancestorChain.Count == 0) { continue; } List <EntityToken> ancestorEntityTokens = ancestorChain.ToList(); int lastAlreadyOpenedNodeIndex = 0; while (lastAlreadyOpenedNodeIndex + 1 < ancestorChain.Count && openedNodes.Any(node => node.EntityToken.Equals(ancestorEntityTokens[lastAlreadyOpenedNodeIndex + 1]))) { lastAlreadyOpenedNodeIndex++; } var openNode = openedNodes.FirstOrDefault(node => node.EntityToken.Equals(ancestorEntityTokens[lastAlreadyOpenedNodeIndex])); if (openNode == null) { return(null); } // Expanding all the nodes under the root var nodesToBeExpanded = new List <EntityToken>(); nodesToBeExpanded.AddRange(ancestorEntityTokens.Skip(lastAlreadyOpenedNodeIndex)); nodesToBeExpanded.RemoveAt(nodesToBeExpanded.Count - 1); // Last node is a target one, so doesn't have to be expanded nodesToBeExpanded.AddRange(openedNodes.Select(node => node.EntityToken)); var result = new List <RefreshChildrenInfo>(); // Expanding all the nodes, and checking if all of the nodes in the ancestor chain is marked // as seen in TreeLockBehaviour bool success = ExpandNodesRec(openNode.ElementData.EntityToken, openNode.ElementData.ProviderName, openNode.ElementData.Piggybag, nodesToBeExpanded, result, ancestorEntityTokens); if (success) { return(result); } } return(null); }
/// <exclude /> public FlowToken Execute(string serializedEntityToken, string serializedActionToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer) { DataEntityToken dataEntityToken = (DataEntityToken)EntityTokenSerializer.Deserialize(serializedEntityToken); IData data = dataEntityToken.Data; Verify.IsNotNull(data, "Failed to get the data from an entity token"); var action = DataActionTokenResolverFacade.Resolve(data, ((ProxyDataActionToken)actionToken).ActionIdentifier); return(ActionExecutorFacade.Execute(dataEntityToken, action, flowControllerServicesContainer)); }
/// <exclude /> public FlowToken Execute(string serializedEntityToken, string serializedActionToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer) { PageAddActionToken pageAddActionToken = (PageAddActionToken)actionToken; var newPage = DataFacade.BuildNew <IPage>(); newPage.PageTypeId = pageAddActionToken.PageTypeId; var action = DataActionTokenResolverFacade.Resolve(newPage, ((PageAddActionToken)actionToken).ActionIdentifier); return(ActionExecutorFacade.Execute(EntityTokenSerializer.Deserialize(serializedEntityToken), action, flowControllerServicesContainer)); }
private EntityToken DeserializeSilent(string serializedEntityToken) { try { return(EntityTokenSerializer.Deserialize(serializedEntityToken)); } catch (Exception) { // Silent return(null); } }
/// <summary> /// Expands nodes recurcively. /// </summary> /// <param name="entityToken"></param> /// <param name="elementProviderName"></param> /// <param name="piggybag"></param> /// <param name="entityTokensToBeExpanded"></param> /// <param name="resultList"></param> /// <param name="keyNodes"></param> /// <returns>Returns false, if there's a key node, that has [element.TreeLockBehavior == None]</returns> private static bool ExpandNodesRec(string entityToken, string elementProviderName, string piggybag, List <EntityToken> entityTokensToBeExpanded, List <RefreshChildrenInfo> resultList, List <EntityToken> keyNodes) { if (resultList.Count > 1000) // Preventing an infinite loop { return(true); } List <ClientElement> children = GetChildren(elementProviderName, entityToken, piggybag, null); var refreshChildrenInfo = new RefreshChildrenInfo { ElementKey = GetElementKey(elementProviderName, entityToken, piggybag), ClientElements = children }; resultList.Add(refreshChildrenInfo); foreach (ClientElement child in children) { var childEntityToken = EntityTokenSerializer.Deserialize(child.EntityToken); if (!child.TreeLockEnabled && keyNodes.Contains(childEntityToken)) { return(false); } if (entityTokensToBeExpanded.Contains(childEntityToken)) { if (ExpandNodesRec(child.EntityToken, child.ProviderName, child.Piggybag, entityTokensToBeExpanded, resultList, keyNodes)) { return(true); } } else { if (keyNodes.Contains(childEntityToken)) { return(true); } } } return(false); }
/// <exclude /> public static List <RefreshChildrenInfo> GetMultipleChildren(List <RefreshChildrenParams> nodesToBeRefreshed) { int t1 = Environment.TickCount; var result = new List <RefreshChildrenInfo>(); foreach (RefreshChildrenParams node in nodesToBeRefreshed) { EntityToken entityToken; try { entityToken = EntityTokenSerializer.Deserialize(node.EntityToken); } catch (EntityTokenSerializerException) { continue; } var elementHandle = new ElementHandle(node.ProviderName, entityToken, node.Piggybag); SearchToken searchToken = null; if (!string.IsNullOrEmpty(node.SearchToken)) { searchToken = SearchToken.Deserialize(node.SearchToken); } List <Element> childElements; if (UserSettings.ForeignLocaleCultureInfo == null || UserSettings.ForeignLocaleCultureInfo.Equals(UserSettings.ActiveLocaleCultureInfo)) { childElements = ElementFacade.GetChildren(elementHandle, searchToken).ToList(); } else { childElements = ElementFacade.GetForeignChildren(elementHandle, searchToken).ToList(); } result.Add(new RefreshChildrenInfo { ElementKey = GetElementKey(node.ProviderName, node.EntityToken, node.Piggybag), ClientElements = childElements.ToClientElementList() }); } int t2 = Environment.TickCount; //LoggingService.LogVerbose("TreeServiceFacade", string.Format("GetMultipleChildren: {0} ms", t2 - t1)); return(result); }
/// <exclude /> public static bool TryGetPiggybaggedEntityToken(this Dictionary <string, string> piggybag, int generation, out EntityToken entityToken) { string key = $"{ParentEntityTokenPiggybagString}{generation}"; string serializedEntityToken; if (!piggybag.TryGetValue(key, out serializedEntityToken)) { entityToken = null; return(false); } entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); return(true); }
/// <exclude /> public static bool TryGetPiggybaggedEntityToken(this Dictionary <string, string> piggybag, int generation, out EntityToken entityToken) { string key = string.Format("{0}{1}", ParentEntityTokenPiggybagString, generation); string serializedEntityToken; if (piggybag.TryGetValue(key, out serializedEntityToken) == false) { entityToken = null; return(false); } entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); return(true); }
/// <exclude /> public static bool ExecuteElementDraggedAndDropped(string draggedElementProviderName, string draggedElementSerializedEntityToken, string draggedElementPiggybag, string newParentElementProviderName, string newParentElementSerializedEntityToken, string newParentElementPiggybag, int dropIndex, string consoleId, bool isCopy) { if (draggedElementProviderName != newParentElementProviderName) { throw new InvalidOperationException("Only drag'n'drop internal in element providers are allowed"); } EntityToken draggedElementEntityToken = EntityTokenSerializer.Deserialize(draggedElementSerializedEntityToken); ElementHandle draggedElementHandle = new ElementHandle(draggedElementProviderName, draggedElementEntityToken, draggedElementPiggybag); EntityToken newParentElementEntityToken = EntityTokenSerializer.Deserialize(newParentElementSerializedEntityToken); ElementHandle newParentdElementHandle = new ElementHandle(newParentElementProviderName, newParentElementEntityToken, newParentElementPiggybag); return(ActionExecutionMediator.ExecuteElementDraggedAndDropped(draggedElementHandle, newParentdElementHandle, dropIndex, consoleId, isCopy)); }
/// <exclude /> public static List <ClientLabeledProperty> GetLabeledProperties(string providerName, string serializedEntityToken, string piggybag) { var elementEntityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); var elementHandle = new ElementHandle(providerName, elementEntityToken, piggybag); bool showForeign = UserSettings.ForeignLocaleCultureInfo != null && UserSettings.ForeignLocaleCultureInfo.Equals(UserSettings.ActiveLocaleCultureInfo); var labeledProperties = showForeign ? ElementFacade.GetForeignLabeledProperties(elementHandle) : ElementFacade.GetLabeledProperties(elementHandle); return ((from property in labeledProperties select new ClientLabeledProperty(property)).ToList()); }
/// <exclude /> public static List <ClientElement> GetChildren(string providerName, string serializedEntityToken, string piggybag, string serializedSearchToken) { //LoggingService.LogVerbose("RGB(255, 0, 255)TreeServiceFacade", "----- Start -----------------------------------------------"); int t1 = Environment.TickCount; EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); ElementHandle elementHandle = new ElementHandle(providerName, entityToken, piggybag); //int t2 = Environment.TickCount; SearchToken searchToken = null; if (!string.IsNullOrEmpty(serializedSearchToken)) { searchToken = SearchToken.Deserialize(serializedSearchToken); } List <Element> childElements; if (UserSettings.ForeignLocaleCultureInfo == null || UserSettings.ForeignLocaleCultureInfo.Equals(UserSettings.ActiveLocaleCultureInfo)) { childElements = ElementFacade.GetChildren(elementHandle, searchToken).ToList(); } else { childElements = ElementFacade.GetForeignChildren(elementHandle, searchToken).ToList(); } //int t3 = Environment.TickCount; List <ClientElement> resultList = childElements.ToClientElementList(); int t4 = Environment.TickCount; //LoggingService.LogVerbose("RGB(255, 0, 255)TreeServiceFacade", string.Format("ElementHandle: {0} ms", t2 - t1)); //LoggingService.LogVerbose("RGB(255, 0, 255)TreeServiceFacade", string.Format("GetChildren: {0} ms", t3 - t2)); //LoggingService.LogVerbose("RGB(255, 0, 255)TreeServiceFacade", string.Format("ToClientElementList: {0} ms", t4 - t3)); //LoggingService.LogVerbose("RGB(255, 0, 255)TreeServiceFacade", string.Format("Total: {0} ms", t4 - t1)); //LoggingService.LogVerbose("RGB(255, 0, 255)TreeServiceFacade", "----- End -------------------------------------------------"); //LoggingService.LogVerbose("TreeServiceFacade", string.Format("GetChildren: {0} ms", t4 - t1)); return(resultList); }
/// <exclude /> public static IEnumerable <EntityToken> GetParentEntityTokens(this Dictionary <string, string> piggybag, EntityToken entityTokenToInclude = null) { if (entityTokenToInclude != null) { yield return(entityTokenToInclude); } int generation = 1; string seriazliedEntityToken; while (piggybag.TryGetValue(string.Format("{0}{1}", ParentEntityTokenPiggybagString, generation), out seriazliedEntityToken)) { yield return(EntityTokenSerializer.Deserialize(seriazliedEntityToken)); generation++; } }
/// <exclude /> public static void ExecuteElementAction(string providerName, string serializedEntityToken, string piggybag, string serializedActionToken, string consoleId) { using (DebugLoggingScope.MethodInfoScope) { EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); if (!entityToken.IsValid()) { ShowInvalidEntityMessage(consoleId); return; } var elementHandle = new ElementHandle(providerName, entityToken, piggybag); ActionToken actionToken = ActionTokenSerializer.Deserialize(serializedActionToken, true); ActionHandle actionHandle = new ActionHandle(actionToken); ActionExecutionMediator.ExecuteElementAction(elementHandle, actionHandle, consoleId); } }
/// <exclude /> public static List <ClientLabeledProperty> GetLabeledProperties(string providerName, string serializedEntityToken, string piggybag) { EntityToken elementEntityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); ElementHandle elementHandle = new ElementHandle(providerName, elementEntityToken, piggybag); IEnumerable <LabeledProperty> labeledProperties; if (UserSettings.ForeignLocaleCultureInfo == null || UserSettings.ForeignLocaleCultureInfo.Equals(UserSettings.ActiveLocaleCultureInfo)) { labeledProperties = ElementFacade.GetLabeledProperties(elementHandle); } else { labeledProperties = ElementFacade.GetForeignLabeledProperties(elementHandle); } return ((from property in labeledProperties select new ClientLabeledProperty(property)).ToList()); }
protected static void UpdateParents(string seralizedEntityToken, string consoleId) { var entityToken = EntityTokenSerializer.Deserialize(seralizedEntityToken); var graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both); if (graph.Levels.Count() <= 1) { return; } var level = graph.Levels.ElementAt(1); foreach (var token in level.AllEntities) { var consoleMessageQueueItem = new RefreshTreeMessageQueueItem { EntityToken = token }; ConsoleMessageQueueFacade.Enqueue(consoleMessageQueueItem, consoleId); } }
protected void Page_Load(object sender, EventArgs e) { EntityToken entityToken = EntityTokenSerializer.Deserialize(Request["entityToken"]); var result = XElement.Load(entityToken.Id); var table = new XElement("table"); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", Path.GetFileNameWithoutExtension(entityToken.Id))); var attributes = result.Elements().Attributes() .Where(a => !a.IsNamespaceDeclaration) .Select(a => a.Name).Distinct(); table.Add( new XElement("tr", attributes.Select( a => new XElement("th", a.LocalName ) ) ) ); table.Add( result.Elements().Select( row => new XElement("tr", attributes.Select( a => new XElement("td", (row.Attribute(a) != null) ? row.Attribute(a).Value : string.Empty ) ) ) ) ); TableLiteral.Text = table.ToString(); }
/// <exclude /> public FlowToken Execute(string serializedEntityToken, string serializedActionToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer) { var dataEntityToken = (DataEntityToken)EntityTokenSerializer.Deserialize(serializedEntityToken); var data = dataEntityToken.Data; Verify.IsNotNull(data, "Failed to get the data from an entity token"); using (new DataScope(DataScopeIdentifier.Administrated)) { var treeRefresher = new AddNewTreeRefresher(dataEntityToken, flowControllerServicesContainer); var newData = (IData)StaticReflection.GetGenericMethodInfo(() => CloneData((IData)null)) .MakeGenericMethod(data.DataSourceId.InterfaceType).Invoke(this, new object[] { data }); var consoleId = flowControllerServicesContainer.GetService <IManagementConsoleMessageService>().CurrentConsoleId; ConsoleCommandHelper.SelectConsoleElementWithoutPerspectiveChange(consoleId, newData.GetDataEntityToken()); treeRefresher.PostRefreshMessages(dataEntityToken); } return(null); }
private static void UpgradeStoredData() { const string _ET = "EntityToken"; const string _DSI = "DataSourceId"; List <string> magicPropertyNames = new List <string> { _ET, _DSI }; Func <DataFieldDescriptor, bool> isSerializedFieldFunc = g => magicPropertyNames.Any(s => g.Name.Contains(s)); var descriptors = DataMetaDataFacade.AllDataTypeDescriptors.Where(f => f.Fields.Any(isSerializedFieldFunc)); foreach (var descriptor in descriptors) { Type dataType = descriptor.GetInterfaceType(); if (dataType == null) { continue; } var propertiesToUpdate = new List <PropertyInfo>(); foreach (var tokenField in descriptor.Fields.Where(isSerializedFieldFunc)) { var tokenProperty = dataType.GetProperty(tokenField.Name); propertiesToUpdate.Add(tokenProperty); } using (var dc = new DataConnection(PublicationScope.Unpublished)) { var allRows = DataFacade.GetData(dataType).ToDataList(); foreach (var rowItem in allRows) { bool rowChange = false; foreach (var tokenProperty in propertiesToUpdate) { string token = tokenProperty.GetValue(rowItem) as string; if (tokenProperty.Name.Contains(_ET)) { try { var entityToken = EntityTokenSerializer.Deserialize(token); var tokenReserialized = EntityTokenSerializer.Serialize(entityToken); if (tokenReserialized != token) { tokenProperty.SetValue(rowItem, tokenReserialized); rowChange = true; } } catch (Exception ex) { _log.LogError(nameof(LegacySerializedEntityTokenUpgrader), "Failed to upgrade old token {0} from data type {1} as EntityToken.\n{2}", token, dataType.FullName, ex); } } if (tokenProperty.Name.Contains(_DSI)) { try { token = EnsureValidDataSourceId(token); var dataSourceId = DataSourceId.Deserialize(token); var dataSourceIdReserialized = dataSourceId.Serialize(); if (dataSourceIdReserialized != token) { tokenProperty.SetValue(rowItem, dataSourceIdReserialized); rowChange = true; } } catch (Exception ex) { _log.LogError(nameof(LegacySerializedEntityTokenUpgrader), "Failed to upgrade old token {0} from data type {1} as DataSourceId.\n{2}", token, dataType.FullName, ex); } } if (rowChange) { DataFacade.Update(rowItem); } } } } } }
private static void UpgradeStoredData() { const string _ET = "EntityToken"; const string _DSI = "DataSourceId"; List <string> magicPropertyNames = new List <string> { _ET, _DSI }; Func <DataFieldDescriptor, bool> isSerializedFieldFunc = g => magicPropertyNames.Any(s => g.Name.Contains(s)); var descriptors = DataMetaDataFacade.AllDataTypeDescriptors.Where(f => f.Fields.Any(isSerializedFieldFunc)); foreach (var descriptor in descriptors) { Type dataType = descriptor.GetInterfaceType(); if (dataType == null) { continue; } var propertiesToUpdate = new List <PropertyInfo>(); foreach (var tokenField in descriptor.Fields.Where(isSerializedFieldFunc)) { var tokenProperty = dataType.GetProperty(tokenField.Name); propertiesToUpdate.Add(tokenProperty); } using (new DataConnection(PublicationScope.Unpublished)) { var allRows = DataFacade.GetData(dataType).ToDataList(); var toUpdate = new List <IData>(); int errors = 0, updated = 0; foreach (var rowItem in allRows) { bool rowChange = false; foreach (var tokenProperty in propertiesToUpdate) { string token = tokenProperty.GetValue(rowItem) as string; try { string tokenReserialized; if (tokenProperty.Name.Contains(_ET)) { var entityToken = EntityTokenSerializer.Deserialize(token); tokenReserialized = EntityTokenSerializer.Serialize(entityToken); } else if (tokenProperty.Name.Contains(_DSI)) { token = EnsureValidDataSourceId(token); var dataSourceId = DataSourceId.Deserialize(token); tokenReserialized = dataSourceId.Serialize(); } else { throw new InvalidOperationException("This line should not be reachable"); } if (tokenReserialized != token) { tokenProperty.SetValue(rowItem, tokenReserialized); rowChange = true; } } catch (Exception ex) { errors++; if (errors <= MaxErrorMessagesPerType) { _log.LogError(LogTitle, $"Failed to upgrade old token '{token}' from data type '{dataType.FullName}' as EntityToken.\n{ex}"); } } } if (rowChange) { updated++; toUpdate.Add(rowItem); if (toUpdate.Count >= 1000) { DataFacade.Update(toUpdate, true, false, false); toUpdate.Clear(); } } } if (toUpdate.Count > 0) { DataFacade.Update(toUpdate, true, false, false); toUpdate.Clear(); } _log.LogInformation(LogTitle, $"Finished updating serialized tokens for data type '{dataType.FullName}'. Rows: {allRows.Count}, Updated: {updated}, Errors: {errors}"); } } }