/// <summary> /// gets settings setup for cog item data usage. we are making assumption there will only ever be one /// </summary> /// <param name="dataTypeDefinitions"></param> /// <returns></returns> private static List<Setting<string, string>> GetDataTypeSettingsForItemDataUsage(IEnumerable<DataTypeDefinition> dataTypeDefinitions) { DataTypeDefinition dataTypeDef = dataTypeDefinitions.First(); // load the settings DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); List<Setting<string, string>> s = ss.GetSettings(dataTypeDef.Id); ss.Dispose(); return s; }
protected override void OnInit(EventArgs e) { base.OnInit (e); Control oControl = new System.Web.UI.UserControl().LoadControl(_usercontrolPath); if (HasSettings(oControl.GetType())) { DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); List<Setting<string, string>> s = ss.GetSettings(((umbraco.cms.businesslogic.datatype.DefaultData)_data).DataTypeDefinitionId); ss.Dispose(); foreach (Setting<string, string> setting in s) { try { if(!string.IsNullOrEmpty(setting.Key)) { oControl.GetType().InvokeMember(setting.Key, System.Reflection.BindingFlags.SetProperty, null, oControl, new object[] { setting.Value }); } } catch (MissingMethodException) { } } } // Add property data to the usercontrol if it supports it // TODO: Find the best way to test for an interface! IUsercontrolPropertyData propertyData = oControl as IUsercontrolPropertyData; if (propertyData != null) { propertyData.PropertyObject = new Property(((usercontrolData)_data).PropertyId); } this.Controls.Add(oControl); if (!Page.IsPostBack) ((IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor).value = _data.Value; }
private bool CompareProperties(Type dataType, DataTypeDefinition existingDataType) { var dataTypeAttr = DataTypeManager.GetDataTypeAttribute(dataType); if (existingDataType.Text != dataTypeAttr.Name) { return false; } if (existingDataType.DataType == null || existingDataType.DataType.Id != new Guid(dataTypeAttr.RenderControlGuid)) { return false; } var instance = Activator.CreateInstance(dataType, null) as DataTypeBase; var prevalues = instance.Prevalues; var settingsStorage = new DataEditorSettingsStorage(); var existingSettings = settingsStorage.GetSettings(existingDataType.Id); if (existingSettings.Count != prevalues.Count()) { return false; } int counter = 0; foreach (var setting in existingSettings) { if (setting.Key != prevalues[counter].Alias || setting.Value != prevalues[counter].Value) { return false; } counter++; } return true; }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (this.datatype.HasSettings()) { var ss = new DataEditorSettingsStorage(); var s = ss.GetSettings(this.datatype.DataTypeDefinitionId); ss.Dispose(); this.datatype.LoadSettings(s); } this.Controls.Add(this.Control); }
private void SynchronizeDataTypes() { var factory = new umbraco.cms.businesslogic.datatype.controls.Factory(); foreach (Type typeDataType in Util.GetFirstLevelSubTypes(typeof(DataTypeBase))) { var dataTypeAttr = GetDataTypeAttribute(typeDataType); try { this.AddToSynchronized(null, dataTypeAttr.Name, typeDataType); } catch (ArgumentException exc) { throw new Exception( string.Format( "DataType with name '{0}' already exists! Please use unique DataType names. DataType causing the problem: '{1}' (assembly: '{2}'). Error message: {3}", dataTypeAttr.Name, typeDataType.FullName, typeDataType.Assembly.FullName, exc.Message)); } var dtd = DataTypeDefinition.GetAll().FirstOrDefault(d => d.Text == dataTypeAttr.Name || (!string.IsNullOrEmpty(dataTypeAttr.UniqueId) && d.UniqueId == new Guid(dataTypeAttr.UniqueId))); // If there are no datatypes with name already we can go ahead and create one if (dtd == null) { if (!string.IsNullOrEmpty(dataTypeAttr.UniqueId)) { dtd = DataTypeDefinition.MakeNew(User.GetUser(0), dataTypeAttr.Name, new Guid(dataTypeAttr.UniqueId)); } else { dtd = DataTypeDefinition.MakeNew(User.GetUser(0), dataTypeAttr.Name); } } dtd.DataType = factory.DataType(new Guid(dataTypeAttr.RenderControlGuid)); dtd.Text = dataTypeAttr.Name; System.Web.HttpRuntime.Cache.Remove(string.Format("UmbracoDataTypeDefinition{0}", dtd.UniqueId)); dtd.Save(); var instance = Activator.CreateInstance(typeDataType, null) as DataTypeBase; DataTypePrevalue[] prevalues = instance.Prevalues; if (prevalues.Any()) { var settingsStorage = new DataEditorSettingsStorage(); // Check if there are settings already defined for data type. If there are, skip this step. List<Setting<string, string>> availableSettings = settingsStorage.GetSettings(dtd.Id); if (availableSettings == null || availableSettings.Count == 0) { // updating all settings to those defined in datatype class // If you've exported, all settings will be defined here anyway? settingsStorage.InsertSettings(dtd.Id, prevalues.Select(pre => new Setting<string, string> { Key = pre.Alias, Value = pre.Value }).ToList()); } } } }
public void Save() { bool hasErrors = false; foreach (KeyValuePair <string, DataEditorSettingType> k in dtSettings) { var result = k.Value.Validate(); Label lbl = FindControlRecursive <Label>(_phSettings, "lbl" + k.Key); if (result == null && lbl != null) { if (lbl != null) { lbl.Text = string.Empty; } } else { if (hasErrors == false) { hasErrors = true; } if (lbl != null) { lbl.Text = " " + result.ErrorMessage; } } } if (!hasErrors) { _datatype.DBType = (umbraco.cms.businesslogic.datatype.DBTypes) Enum.Parse(typeof(umbraco.cms.businesslogic.datatype.DBTypes), _dropdownlist.SelectedValue, true); // Generate data-string string data = _dropdownlistUserControl.SelectedValue; // If the add new prevalue textbox is filled out - add the value to the collection. IParameter[] SqlParams = new IParameter[] { SqlHelper.CreateParameter("@value", data), SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId) }; SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", SqlParams); // we need to populate the parameters again due to an issue with SQL CE SqlParams = new IParameter[] { SqlHelper.CreateParameter("@value", data), SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId) }; SqlHelper.ExecuteNonQuery( "insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", SqlParams); //settings DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); //ss.ClearSettings(_datatype.DataTypeDefinitionId); int i = 0; foreach (KeyValuePair <string, DataEditorSettingType> k in dtSettings) { ss.InsertSetting(_datatype.DataTypeDefinitionId, k.Key, k.Value.Value, i); i++; } ss.Dispose(); if (dtSettings.Count == 0) { if (!string.IsNullOrEmpty(Configuration)) { LoadSetttings(Configuration); } } } }
public void Save() { _datatype.DBType = (umbraco.cms.businesslogic.datatype.DBTypes)Enum.Parse(typeof(umbraco.cms.businesslogic.datatype.DBTypes), _dropdownlist.SelectedValue, true); // Generate data-string string data = _dropdownlistUserControl.SelectedValue; // If the add new prevalue textbox is filled out - add the value to the collection. IParameter[] SqlParams = new IParameter[] { SqlHelper.CreateParameter("@value",data), SqlHelper.CreateParameter("@dtdefid",_datatype.DataTypeDefinitionId)}; SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", SqlParams); // we need to populate the parameters again due to an issue with SQL CE SqlParams = new IParameter[] { SqlHelper.CreateParameter("@value",data), SqlHelper.CreateParameter("@dtdefid",_datatype.DataTypeDefinitionId)}; SqlHelper.ExecuteNonQuery("insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", SqlParams); //settings DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); //ss.ClearSettings(_datatype.DataTypeDefinitionId); int i = 0; foreach (KeyValuePair<string, DataEditorSettingType> k in dtSettings) { ss.InsertSetting(_datatype.DataTypeDefinitionId, k.Key, k.Value.Value, i); i++; } ss.Dispose(); if (dtSettings.Count == 0) { if (!string.IsNullOrEmpty(Configuration)) LoadSetttings(Configuration); } }
private void LoadSetttings(string fileName) { if (System.IO.File.Exists(IOHelper.MapPath("~/" + fileName))) { UserControl oControl = (UserControl)this.Page.LoadControl(@"~/" + fileName); Type type = oControl.GetType(); Dictionary<string, DataEditorSetting> settings = GetSettings(type); foreach (KeyValuePair<string, DataEditorSetting> kv in settings) { DataEditorSettingType dst = kv.Value.GetDataEditorSettingType(); dtSettings.Add(kv.Key, dst); DataEditorPropertyPanel panel = new DataEditorPropertyPanel(); panel.Text = kv.Value.GetName(); panel.Text += "<br/><small>" + kv.Value.description + "</small>"; if (HasSettings(type)) { DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); List<Setting<string, string>> s = ss.GetSettings(_datatype.DataTypeDefinitionId); ss.Dispose(); if (s.Find(set => set.Key == kv.Key).Value != null) dst.Value = s.Find(set => set.Key == kv.Key).Value; } panel.Controls.Add(dst.RenderControl(kv.Value)); _phSettings.Controls.Add(panel); } } }