private void AddToPanelPickerAllowedEditors() { var panelPickerDataType = _dataTypeService.GetDataTypeDefinitionByName(PanelsInstallationConstants.DataTypeNames.PanelPicker); var preValuesDictionary = _dataTypeService.GetPreValuesCollectionByDataTypeId(panelPickerDataType.Id).PreValuesAsDictionary; AddAllowedEditor(preValuesDictionary, TableEditor); _dataTypeService.SavePreValues(panelPickerDataType, preValuesDictionary); }
private void SetDataTypePreValues(IEntity dataType, DataType model) { if (!model.PreValues.Any()) { _dataTypeService.SavePreValues(dataType.Id, new Dictionary <string, PreValue>()); return; } var preValues = model.PreValues.ToDictionary(preValue => preValue.Key, v => new PreValue(v.Value)); _dataTypeService.SavePreValues(dataType.Id, preValues); }
private void Synchronize(IDataTypeDefinition[] dataTypes, DataType model) { var dataType = _dataTypeFinder.Find(model, dataTypes).SingleOrDefault(); if (dataType == null) { // Create new data type. dataType = CreateDataType(model); _dataTypeService.SaveDataTypeAndPreValues(dataType, GetPreValues(model)); } else { // Update the data type and its pre-values. _dataTypeService.Save(UpdateDataTypeDefinition(dataType, model)); var existingPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).FormatAsDictionary(); var preValuesToSave = existingPreValues.Any() ? GetUpdatedPreValues(existingPreValues, model.PreValues) : GetPreValues(model); _dataTypeService.SavePreValues(dataType.Id, preValuesToSave); } // We get the data type once more to refresh it after saving it. dataType = _dataTypeService.GetDataTypeDefinitionByName(dataType.Name); // Set/update tracking. SetDataTypeId(model, dataType); }
private async Task UnpackDataTypes(IEnumerable <XElement> elements) { foreach (var element in elements) { var name = (string)element.Attribute("Name"); await Out.WriteLineFormattedAsync("Importing DataType '{0}'", name); packagingService.ImportDataTypeDefinitions(new XElement("DataTypes", element)); var preValues = element.Element("PreValues"); if (preValues != null) { var pv = preValues.Elements("PreValue"); var dataType = dataTypeService.GetDataTypeDefinitionById(Guid.Parse(element.Attribute("Definition").Value)); dataTypeService.SavePreValues( dataType, pv.Select(xml => new { Alias = xml.Attribute("Alias").Value, xml.Attribute("Value").Value }) .ToDictionary(x => x.Alias, x => new PreValue(x.Value)) ); } } }
private void SavePrevaluesFromXml(List <IDataTypeDefinition> dataTypes, IEnumerable <XElement> dataTypeElements) { foreach (var dataTypeElement in dataTypeElements) { var prevaluesElement = dataTypeElement.Element("PreValues"); if (prevaluesElement == null) { continue; } var dataTypeDefinitionName = dataTypeElement.Attribute("Name").Value; var dataTypeDefinition = dataTypes.First(x => x.Name == dataTypeDefinitionName); var values = prevaluesElement.Elements("PreValue").Select(prevalue => prevalue.Attribute("Value").Value).ToList(); _dataTypeService.SavePreValues(dataTypeDefinition.Id, values); } }
public IDataTypeDefinition Create(string name, string propertyEditorAlias, int parentId, DataTypeDatabaseType databaseType, IDictionary <string, string> preValues) { if (Exists(name)) { return(null); } var dataType = new DataTypeDefinition(propertyEditorAlias) { Name = name, DatabaseType = databaseType, }; if (parentId > 0) { dataType.ParentId = parentId; } _dataTypeService.Save(dataType); var itemPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id) .FormatAsDictionary(); foreach (var preValue in preValues) { LogHelper.Info <DataTypeBuilder>("PreValue: {0} [{1}]", () => preValue.Key, () => preValue.Value); if (itemPreValues.ContainsKey(preValue.Key)) { LogHelper.Info <DataTypeBuilder>("Update"); itemPreValues[preValue.Key].Value = preValue.Value; } else { LogHelper.Info <DataTypeBuilder>("Add"); itemPreValues.Add(preValue.Key, new PreValue(preValue.Value)); } } _dataTypeService.SavePreValues(dataType, itemPreValues); _dataTypeService.Save(dataType); return(dataType); }
private void RemoveFromPreValues(IEnumerable <string> editorsToRemove) { const string itemsKey = "items"; var defaultGridDataType = _dataTypeService.GetDataTypeDefinitionByName(CoreInstallationConstants.DataTypeNames.DefaultGrid); var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(defaultGridDataType.Id); var preValuesDictionary = preValues.FormatAsDictionary(); var items = preValuesDictionary[itemsKey].Value.Pipe(Json.Decode); var availableEditors = items.layouts[0].areas[0].allowed; var availableEditorsList = new List <string>(); foreach (var editor in availableEditors) { availableEditorsList.Add((string)editor); } var actualEditors = availableEditorsList.Except(editorsToRemove); items.layouts[0].areas[0].allowed = JArray.FromObject(actualEditors).ToDynamic(); preValuesDictionary[itemsKey].Value = JsonConvert.SerializeObject(items); _dataTypeService.SavePreValues(1057, preValuesDictionary); }
private void DeserializeUpdatePreValues(IDataTypeDefinition item, XElement node) { LogHelper.Debug <DataTypeSerializer>("Deserializing DataType PreValues: {0}", () => item.Name); var preValueRootNode = node.Element("PreValues"); if (preValueRootNode != null) { var itemPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(item.Id) .FormatAsDictionary(); List <string> preValsToRemove = new List <string>(); foreach (var preValue in itemPreValues) { var preValNode = preValueRootNode.Elements("PreValue") .Where(x => x.Attribute("Alias") != null && ((string)x.Attribute("Alias").Value == preValue.Key)) .FirstOrDefault(); if (preValNode != null) { // if the xml still has MapGuid on it, then the mapping didn't work // so we just don't set this value, its a value that the site does have // but its possible the content or whatever is set diffrently on this install // if (preValNode.Attribute("MapGuid") == null) { // set the value of preValue value to the value of the value attribute :) preValue.Value.Value = preValNode.Attribute("Value").Value; } } else { preValsToRemove.Add(preValue.Key); } } // remove things that we didn't find foreach (var key in preValsToRemove) { itemPreValues.Remove(key); } // now add any new prevalues from the xml /* * var valuesWithKeys = preValueRootNode.Elements("PreValue") * .Where(x => (string.IsNullOrWhiteSpace((string)x.Attribute("Alias")) == false)) * .ToDictionary(key => (string)key.Attribute("Alias"), val => (string)val.Attribute("Value")); */ foreach (var nodeValue in preValueRootNode.Elements("PreValue")) { var alias = nodeValue.Attribute("Alias").ValueOrDefault(string.Empty); var value = nodeValue.Attribute("Value").ValueOrDefault(string.Empty); if (!string.IsNullOrEmpty(alias)) { if (!itemPreValues.ContainsKey(alias)) { LogHelper.Debug <DataTypeSerializer>("Adding PreValue {0} for {1}", () => alias, () => item.Name); itemPreValues.Add(alias, new PreValue(value)); } } } _dataTypeService.SavePreValues(item, itemPreValues); /* * var valuesSansKeys = preValueRootNode.Elements("PreValue") * .Where(x => ((string)x.Attribute("Alias")).IsNullOrWhiteSpace() == false) * .Select(x => x.Attribute("Value").Value); * * /// this is marked as obsolete? but don't some prevalues still have no keys? * if (valuesSansKeys.Any()) * { * _dataTypeService.SavePreValues(item.Id, valuesSansKeys); * } */ } }