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) { } } } this.Controls.Add(oControl); if (!Page.IsPostBack) { ((IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor).value = _data.Value; } }
/// <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; }
/// <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); }
private void LoadSetttings(string fileName) { // due to legacy, some user controls may not have the tilde start if (fileName.StartsWith("~/")) { fileName = fileName.Substring(2); } 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)); Label invalid = new Label(); invalid.Attributes.Add("style", "color:#8A1F11"); invalid.ID = "lbl" + kv.Key; panel.Controls.Add(invalid); _phSettings.Controls.Add(panel); } } }
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 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); } } }
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); }
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> /// Adds an alias the prevalue settings that are stored in the database. /// </summary> private void FixPrevalueSettings() { var dataTypeId = new Guid(Constants.SingleLocationDataTypeId); var definitions = DataTypeDefinition.GetAll().Where(x => x.DataType.Id == dataTypeId); if (definitions != null) { var dataEditorSettings = this.Settings(); var storage = new DataEditorSettingsStorage(); foreach (var definition in definitions) { var settings = storage.GetSettings(definition.Id); var keys = settings.Select(s => s.Key); if (keys.Contains(null) && settings.Count == dataEditorSettings.Count) { var updatedSettings = new List <Setting <string, string> >(); var enumerator = dataEditorSettings.GetEnumerator(); foreach (var setting in settings) { enumerator.MoveNext(); updatedSettings.Add(new Setting <string, string>() { Key = enumerator.Current.Key, Value = setting.Value }); } storage.UpdateSettings(definition.Id, updatedSettings); } } } }
/// <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()); } } } }
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); } } }