public void AddProperties(StringBuilderWrapper sb, MetadataType type, bool initCollections, bool includeResponseStatus) { var wasAdded = false; var defaultValue = type.IsInterface != true ? " = null" : ""; var dataMemberIndex = 1; if (type.Properties != null) { foreach (var prop in type.Properties) { if (wasAdded) { sb.AppendLine(); } var propType = Type(prop.GetTypeName(Config, allTypes), prop.GenericArgs); var fieldName = prop.Name.SafeToken().PropertyStyle(); wasAdded = AppendComments(sb, prop.Description); wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++) || wasAdded; wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded; var initProp = initCollections && !prop.GenericArgs.IsEmpty() && (ArrayTypes.Contains(prop.Type) || DictionaryTypes.Contains(prop.Type)); sb.Emit(prop, Lang.Kotlin); PrePropertyFilter?.Invoke(sb, prop, type); if (!fieldName.IsKeyWord()) { sb.AppendLine(!initProp ? $"var {fieldName}:{propType}?{defaultValue}" : $"var {fieldName}:{propType} = {propType}()"); } else { var originalName = fieldName; fieldName = char.ToUpper(fieldName[0]) + fieldName.SafeSubstring(1); sb.AppendLine(!initProp ? $"@SerializedName(\"{originalName}\") var {fieldName}:{propType}?{defaultValue}" : $"@SerializedName(\"{originalName}\") var {fieldName}:{propType} = {propType}()"); } PostPropertyFilter?.Invoke(sb, prop, type); } } if (includeResponseStatus) { if (wasAdded) { sb.AppendLine(); } AppendDataMember(sb, null, dataMemberIndex++); sb.AppendLine($"var {nameof(ResponseStatus).PropertyStyle()}:ResponseStatus?{defaultValue}"); } }
public void AddProperties(StringBuilderWrapper sb, MetadataType type, bool initCollections, bool includeResponseStatus) { var wasAdded = false; var defaultValue = type.IsInterface != true ? " = null" : ""; var dataMemberIndex = 1; if (type.Properties != null) { foreach (var prop in type.Properties) { if (wasAdded) { sb.AppendLine(); } var propType = Type(prop.Type, prop.GenericArgs); var fieldName = prop.Name.SafeToken().PropertyStyle(); wasAdded = AppendComments(sb, prop.Description); wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++) || wasAdded; wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded; var initProp = initCollections && !prop.GenericArgs.IsEmpty() && (ArrayTypes.Contains(prop.Type) || DictionaryTypes.Contains(prop.Type)); if (!fieldName.IsKeyWord()) { sb.AppendLine(!initProp ? "var {0}:{1}?{2}".Fmt(fieldName, propType, defaultValue) : "var {0}:{1} = {1}()".Fmt(fieldName, propType, defaultValue)); } else { var originalName = fieldName; fieldName = char.ToUpper(fieldName[0]) + fieldName.SafeSubstring(1); sb.AppendLine(!initProp ? "@SerializedName(\"{0}\") var {1}:{2}?{3}".Fmt(originalName, fieldName, propType, defaultValue) : "@SerializedName(\"{0}\") var {1}:{2} = {2}()".Fmt(originalName, fieldName, propType)); } } } if (includeResponseStatus) { if (wasAdded) { sb.AppendLine(); } AppendDataMember(sb, null, dataMemberIndex++); sb.AppendLine("var {0}:ResponseStatus?{1}".Fmt(typeof(ResponseStatus).Name.PropertyStyle(), defaultValue)); } }
private void dg_delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int ItemID = int.Parse(e.Item.Cells[0].Text); DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), iDictionaryType.ToString()); Dictionaries.DeleteItem(ItemID, dic); dgDic.EditItemIndex = -1; BindDG(); }
/// <summary> /// ItemId, ItemName, Weight, StateId, CanDelete (int) /// </summary> public static DataTable GetList(DictionaryTypes dict) { DataTable dt = null; switch (dict) { case DictionaryTypes.Categories: dt = DBCommon.GetListCategoriesForDictionaries(); break; case DictionaryTypes.IncidentSeverities: dt = DBIncident.GetListIncidentSeverityForDictionaries(); break; case DictionaryTypes.IncidentTypes: dt = DBIncident.GetListIncidentTypesForDictionaries(); break; case DictionaryTypes.ProjectTypes: dt = DBProject.GetListProjectTypesForDictionaries(); break; case DictionaryTypes.ProjectCategories: dt = DBProject.GetListProjectCategoriesForDictionaries(); break; case DictionaryTypes.IncidentCategories: dt = DBIncident.GetListIncidentCategoriesForDictionaries(); break; case DictionaryTypes.Currency: dt = DBCommon.GetListCurrencyForDictionaries(); break; case DictionaryTypes.DocumentStatus: dt = DBDocument.GetListDocumentStatusForDictionaries(Security.CurrentUser.LanguageId); break; case DictionaryTypes.ProjectPhases: dt = DBProject.GetListProjectPhasesForDictionaries(); break; case DictionaryTypes.RiskLevels: dt = DBProject.GetListRiskLevelsForDictionaries(); break; } if (dict != DictionaryTypes.ProjectPhases && dict != DictionaryTypes.RiskLevels && dt != null) { dt.Columns.Add("Weight", typeof(int)); } return(dt); }
public static void AddItem(string ItemName, int Param, DictionaryTypes dict) { if (!Company.CheckDiskSpace()) { throw new MaxDiskSpaceException(); } switch (dict) { case DictionaryTypes.Categories: DBCommon.AddCategory(ItemName); break; case DictionaryTypes.IncidentSeverities: DBIncident.AddIncidentSeverity(ItemName); break; case DictionaryTypes.IncidentTypes: DBIncident.AddIncidentType(ItemName); break; case DictionaryTypes.ProjectTypes: AddProjectType(ItemName); break; case DictionaryTypes.ProjectCategories: DBProject.AddProjectCategory(ItemName); break; case DictionaryTypes.IncidentCategories: DBIncident.AddIncidentCategory(ItemName); break; case DictionaryTypes.Currency: DBCommon.AddCurrency(ItemName); break; case DictionaryTypes.DocumentStatus: DBDocument.AddDocumentStatus(ItemName, Param); break; case DictionaryTypes.ProjectPhases: DBProject.AddProjectPhase(ItemName, Param); break; case DictionaryTypes.RiskLevels: DBProject.AddRiskLevel(ItemName, Param); break; } }
public static void UpdateItem(int ItemId, string ItemName, int Param, DictionaryTypes dict) { switch (dict) { case DictionaryTypes.Categories: DBCommon.UpdateCategory(ItemId, ItemName); break; case DictionaryTypes.IncidentSeverities: DBIncident.UpdateIncidentSeverity(ItemId, ItemName); break; case DictionaryTypes.IncidentTypes: DBIncident.UpdateIncidentType(ItemId, ItemName); break; case DictionaryTypes.ProjectTypes: UpdateProjectType(ItemId, ItemName); break; // case DictionaryTypes.Clients: // DBProject.UpdateClient(ItemId, ItemName); // break; case DictionaryTypes.ProjectCategories: DBProject.UpdateProjectCategory(ItemId, ItemName); break; case DictionaryTypes.IncidentCategories: DBIncident.UpdateIncidentCategory(ItemId, ItemName); break; case DictionaryTypes.Currency: DBCommon.UpdateCurrency(ItemId, ItemName); break; case DictionaryTypes.DocumentStatus: DBDocument.UpdateDocumentStatus(ItemId, ItemName, Param); break; case DictionaryTypes.ProjectPhases: DBProject.UpdateProjectPhase(ItemId, ItemName, Param); break; case DictionaryTypes.RiskLevels: DBProject.UpdateRiskLevel(ItemId, ItemName, Param); break; } }
public static void DeleteItem(int ItemId, DictionaryTypes dict) { switch (dict) { case DictionaryTypes.Categories: DBCommon.DeleteCategory(ItemId); break; case DictionaryTypes.IncidentSeverities: DBIncident.DeleteIncidentSeverity(ItemId); break; case DictionaryTypes.IncidentTypes: DBIncident.DeleteIncidentType(ItemId); break; case DictionaryTypes.ProjectTypes: DeleteProjectType(ItemId); break; // case DictionaryTypes.Clients: // DBProject.DeleteClient(ItemId); // break; case DictionaryTypes.ProjectCategories: DBProject.DeleteProjectCategory(ItemId); break; case DictionaryTypes.IncidentCategories: DBIncident.DeleteIncidentCategory(ItemId); break; case DictionaryTypes.Currency: DBCommon.DeleteCurrency(ItemId); break; case DictionaryTypes.DocumentStatus: DBDocument.DeleteDocumentStatus(ItemId); break; case DictionaryTypes.ProjectPhases: DBProject.DeleteProjectPhase(ItemId); break; case DictionaryTypes.RiskLevels: DBProject.DeleteRiskLevel(ItemId); break; } }
public static void DeleteItem(int ItemId, DictionaryTypes dict) { switch(dict) { case DictionaryTypes.Categories: DBCommon.DeleteCategory(ItemId); break; case DictionaryTypes.IncidentSeverities: DBIncident.DeleteIncidentSeverity(ItemId); break; case DictionaryTypes.IncidentTypes: DBIncident.DeleteIncidentType(ItemId); break; case DictionaryTypes.ProjectTypes: DeleteProjectType(ItemId); break; // case DictionaryTypes.Clients: // DBProject.DeleteClient(ItemId); // break; case DictionaryTypes.ProjectCategories: DBProject.DeleteProjectCategory(ItemId); break; case DictionaryTypes.IncidentCategories: DBIncident.DeleteIncidentCategory(ItemId); break; case DictionaryTypes.Currency: DBCommon.DeleteCurrency(ItemId); break; case DictionaryTypes.DocumentStatus: DBDocument.DeleteDocumentStatus(ItemId); break; case DictionaryTypes.ProjectPhases: DBProject.DeleteProjectPhase(ItemId); break; case DictionaryTypes.RiskLevels: DBProject.DeleteRiskLevel(ItemId); break; } }
public static void AddItem(string ItemName, int Param, DictionaryTypes dict) { if (!Company.CheckDiskSpace()) throw new MaxDiskSpaceException(); switch(dict) { case DictionaryTypes.Categories: DBCommon.AddCategory(ItemName); break; case DictionaryTypes.IncidentSeverities: DBIncident.AddIncidentSeverity(ItemName); break; case DictionaryTypes.IncidentTypes: DBIncident.AddIncidentType(ItemName); break; case DictionaryTypes.ProjectTypes: AddProjectType(ItemName); break; case DictionaryTypes.ProjectCategories: DBProject.AddProjectCategory(ItemName); break; case DictionaryTypes.IncidentCategories: DBIncident.AddIncidentCategory(ItemName); break; case DictionaryTypes.Currency: DBCommon.AddCurrency(ItemName); break; case DictionaryTypes.DocumentStatus: DBDocument.AddDocumentStatus(ItemName, Param); break; case DictionaryTypes.ProjectPhases: DBProject.AddProjectPhase(ItemName, Param); break; case DictionaryTypes.RiskLevels: DBProject.AddRiskLevel(ItemName, Param); break; } }
private void dg_delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string dictionaryName = ddDictionaries.SelectedItem.Value; if (dictionaryName == ListManager.ListTypeEnumName) { MetaFieldType mft = Mediachase.Ibn.Core.MetaDataWrapper.GetEnumByName(dictionaryName); if (mft != null) { MetaEnum.RemoveItem(mft, int.Parse(e.CommandArgument.ToString())); } dgEnum.EditItemIndex = -1; } else { int ItemID = int.Parse(e.Item.Cells[0].Text); DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), dictionaryName); Dictionaries.DeleteItem(ItemID, dic); dgDic.EditItemIndex = -1; } BindDG(); }
private void BindDG() { dgDic.Columns[1].HeaderText = LocRM.GetString("Name"); dgDic.Columns[2].HeaderText = LocRM.GetString("tWeight"); dgDic.Columns[3].HeaderText = LocRM.GetString("Options"); DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), iDictionaryType.ToString()); DataView dv = Dictionaries.GetList(dic).DefaultView; if ((DictionaryTypes)iDictionaryType != DictionaryTypes.ProjectPhases) { dv.Sort = "ItemName"; } else { dv.Sort = "Weight"; } dgDic.DataSource = dv; dgDic.DataBind(); foreach (DataGridItem dgi in dgDic.Items) { ImageButton ib = (ImageButton)dgi.FindControl("ibDelete"); if (ib != null) { ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("Warning") + "')"); } RequiredFieldValidator rf = (RequiredFieldValidator)dgi.FindControl("rfName"); if (rf != null) { rf.ErrorMessage = LocRM.GetString("Required"); } } }
public static void AddItem(string ItemName, DictionaryTypes dict) { AddItem(ItemName, 0, dict); }
protected void btnAddNewItem_Click(object sender, System.EventArgs e) { if (ddDictionaries.SelectedValue == "0") { DataTable dt = GetTable(BusinessScore.List()); DataRow dr = dt.NewRow(); dr["BusinessScoreId"] = -1; dr["Key"] = ""; dr["Name"] = ""; dt.Rows.Add(dr); dgScore.EditItemIndex = dt.Rows.Count - 1; dgScore.DataSource = dt.DefaultView; dgScore.DataBind(); } else if (ddDictionaries.SelectedValue == "-1") { DataTable dt = GetTableSlot(BasePlanSlot.List()); DataRow dr = dt.NewRow(); dr["BasePlanSlotId"] = -1; dr["Name"] = ""; dr["IsDefault"] = false; dt.Rows.Add(dr); dgPlanSlot.EditItemIndex = dt.Rows.Count - 1; dgPlanSlot.DataSource = dt.DefaultView; dgPlanSlot.DataBind(); } else if (ddDictionaries.SelectedValue == ListManager.ListTypeEnumName) //List Types { DataTable dt = GetListTable(); DataRow dr = dt.NewRow(); dr["Id"] = -1; dr["OrderId"] = dt.Rows.Count + 1; dr["Name"] = ""; dt.Rows.Add(dr); dgEnum.EditItemIndex = dt.Rows.Count - 1; dgEnum.DataSource = dt.DefaultView; dgEnum.DataBind(); DropDownList ddl = (DropDownList)dgEnum.Items[dgEnum.EditItemIndex].FindControl("ddlOrder"); if (ddl != null) { for (int i = 1; i <= dgEnum.Items.Count; i++) { ddl.Items.Add(i.ToString()); } ddl.SelectedIndex = dgEnum.EditItemIndex; } } else { DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), ddDictionaries.SelectedItem.Value); DataTable dt = Dictionaries.GetList(dic); DataRow dr = dt.NewRow(); dr["ItemId"] = -1; dr["ItemName"] = ""; dr["Weight"] = 0; dr["CanDelete"] = 0; dt.Rows.Add(dr); dgDic.EditItemIndex = dt.Rows.Count - 1; dgDic.DataSource = dt.DefaultView; dgDic.DataBind(); } }
private void BindDG() { if (ddDictionaries.SelectedValue == "0") //Business Score { dgScore.Visible = true; dgPlanSlot.Visible = false; dgDic.Visible = false; dgEnum.Visible = false; dgScore.Columns[1].HeaderText = LocRM.GetString("tKey"); dgScore.Columns[2].HeaderText = LocRM.GetString("Name"); dgScore.DataSource = GetTable(BusinessScore.List()).DefaultView; dgScore.DataBind(); foreach (DataGridItem dgi in dgScore.Items) { ImageButton ib = (ImageButton)dgi.FindControl("ibDelete2"); if (ib != null) { ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("Warning") + "')"); } RequiredFieldValidator rf = (RequiredFieldValidator)dgi.FindControl("rfKey"); if (rf != null) { rf.ErrorMessage = LocRM.GetString("Required"); } RequiredFieldValidator rf2 = (RequiredFieldValidator)dgi.FindControl("rfName2"); if (rf2 != null) { rf2.ErrorMessage = LocRM.GetString("Required"); } } } else if (ddDictionaries.SelectedValue == "-1") //Base Plan Slot { dgScore.Visible = false; dgDic.Visible = false; dgPlanSlot.Visible = true; dgEnum.Visible = false; dgPlanSlot.Columns[1].HeaderText = LocRM.GetString("Name"); dgPlanSlot.Columns[2].HeaderText = LocRM.GetString("tIsDefault"); dgPlanSlot.DataSource = GetTableSlot(BasePlanSlot.List()).DefaultView; dgPlanSlot.DataBind(); foreach (DataGridItem dgi in dgPlanSlot.Items) { ImageButton ib = (ImageButton)dgi.FindControl("ibDelete3"); if (ib != null) { ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("Warning") + "')"); } RequiredFieldValidator rf3 = (RequiredFieldValidator)dgi.FindControl("rfName3"); if (rf3 != null) { rf3.ErrorMessage = LocRM.GetString("Required"); } } } else if (ddDictionaries.SelectedValue == ListManager.ListTypeEnumName) //List Types { dgScore.Visible = false; dgPlanSlot.Visible = false; dgDic.Visible = false; dgEnum.Visible = true; dgEnum.DataSource = GetListTable().DefaultView; dgEnum.DataBind(); foreach (DataGridItem row in dgEnum.Items) { ImageButton ib = (ImageButton)row.FindControl("ibDelete"); if (ib != null) { ib.Attributes.Add("onclick", "return confirm('" + GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Delete").ToString() + "?')"); } TextBox tb = (TextBox)row.FindControl("txtName"); HtmlImage im = (HtmlImage)row.FindControl("imResourceTemplate"); RequiredFieldValidator rfv = (RequiredFieldValidator)row.FindControl("rfName"); if (im != null && tb != null && rfv != null) { im.Attributes.Add("onclick", "SetText('" + tb.ClientID + "','{ResourceName:ResourceKey}','" + rfv.ClientID + "')"); } } if (dgEnum.EditItemIndex >= 0) { DropDownList ddl = (DropDownList)dgEnum.Items[dgEnum.EditItemIndex].FindControl("ddlOrder"); if (ddl != null) { for (int i = 1; i <= dgEnum.Items.Count; i++) { ddl.Items.Add(i.ToString()); } ddl.SelectedIndex = dgEnum.EditItemIndex; } } } else { dgScore.Visible = false; dgPlanSlot.Visible = false; dgDic.Visible = true; dgEnum.Visible = false; dgDic.Columns[1].HeaderText = LocRM.GetString("Name"); dgDic.Columns[2].HeaderText = LocRM.GetString("tWeight"); //dgDic.Columns[3].HeaderText = LocRM.GetString("Options"); DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), ddDictionaries.SelectedItem.Value); DataView dv = Dictionaries.GetList(dic).DefaultView; // dv.Sort = "ItemName"; dgDic.DataSource = dv; dgDic.DataBind(); foreach (DataGridItem dgi in dgDic.Items) { ImageButton ib = (ImageButton)dgi.FindControl("ibDelete"); if (ib != null) { ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("Warning") + "')"); } RequiredFieldValidator rf = (RequiredFieldValidator)dgi.FindControl("rfName"); if (rf != null) { rf.ErrorMessage = LocRM.GetString("Required"); } } } }
/// <summary> /// Check if the type is a dictionary. /// </summary> public static bool IsDictionary(Type type) { return(DictionaryTypes.Contains(type)); }
public static void UpdateItem(int ItemId, string ItemName, DictionaryTypes dict) { UpdateItem(ItemId, ItemName, 0, dict); }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { var typeName = Type(type.Name, type.GenericArgs); var typeNameOnly = typeName.SplitOnFirst('<')[0]; sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); //func typeConfig() sbExt.AppendLine("public class func typeConfig() -> JsConfigType<{0}>".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine( "return JsConfig.typeConfig() ?? JsConfig.configure(JsConfigType<{0}>(".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("writers: ["); sbExt = sbExt.Indent(); foreach (var prop in type.Properties.Safe()) { var isOptional = !(initCollections && (prop.IsArray() || (!prop.GenericArgs.IsEmpty() && (ArrayTypes.Contains(prop.Type) || DictionaryTypes.Contains(prop.Type))) )); var fn = isOptional ? "setOptionalValue" : "setValue"; sbExt.AppendLine("(\"{1}\", {{ (x:{0}, map:NSDictionary) in {2}(&x.{1}, map, \"{1}\") }}),".Fmt( typeName, prop.Name.SafeToken().PropertyStyle(), fn)); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("],"); sbExt.AppendLine("readers: ["); sbExt = sbExt.Indent(); foreach (var prop in type.Properties.Safe()) { sbExt.AppendLine("(\"{1}\", {{ (x:{0}) in x.{1} as Any }}),".Fmt( typeName, prop.Name.SafeToken().PropertyStyle())); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("]"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("))"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toJson() sbExt.AppendLine(); sbExt.AppendLine("public func toJson() -> String"); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return serializeToJson(self, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromDictionary() sbExt.AppendLine(); sbExt.AppendLine("public class func fromDictionary(map:NSDictionary) -> {0}".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return populate({0}(), map, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromJson() sbExt.AppendLine(); sbExt.AppendLine("public class func fromJson(json:String) -> {0}".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return populate({0}(), json, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { //Swift doesn't support extensions on same protocol used by Base and Sub types if (Config.FlattenAbstractTypes && type.IsAbstract()) { return; } var typeProperties = type.Properties.Safe().ToList(); if (Config.FlattenAbstractTypes) { var baseType = FindType(type.Inherits); if (baseType != null && baseType.IsAbstract()) { typeProperties.InsertRange(0, baseType.Properties.Safe()); } } var typeName = Type(type.Name, type.GenericArgs); var typeNameOnly = typeName.SplitOnFirst('<')[0]; sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); //func typeConfig() sbExt.AppendLine("public class func typeConfig() -> JsConfigType<{0}>".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine( "return JsConfig.typeConfig() ?? JsConfig.configure(JsConfigType<{0}>(".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("writers: ["); sbExt = sbExt.Indent(); foreach (var prop in typeProperties) { var isOptional = !(initCollections && (prop.IsArray() || (!prop.GenericArgs.IsEmpty() && (ArrayTypes.Contains(prop.Type) || DictionaryTypes.Contains(prop.Type))) )); var fn = isOptional ? "setOptionalValue" : "setValue"; sbExt.AppendLine("(\"{1}\", {{ (x:{0}, map:NSDictionary) in {2}(&x.{1}, map, \"{1}\") }}),".Fmt( typeName, prop.Name.SafeToken().PropertyStyle(), fn)); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("],"); sbExt.AppendLine("readers: ["); sbExt = sbExt.Indent(); foreach (var prop in typeProperties) { sbExt.AppendLine("(\"{1}\", Type<{0}>.value {{ $0.{1} }}),".Fmt( typeName, prop.Name.SafeToken().PropertyStyle())); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("]"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("))"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toJson() sbExt.AppendLine(); sbExt.AppendLine("public func toJson() -> String"); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return serializeToJson(self, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromDictionary() sbExt.AppendLine(); sbExt.AppendLine("public class func fromDictionary(map:NSDictionary) -> {0}".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return populate({0}(), map, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromJson() sbExt.AppendLine(); sbExt.AppendLine("public class func fromJson(json:String) -> {0}".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return populate({0}(), json, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
private void dg_update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string dictionaryName = ddDictionaries.SelectedItem.Value; if (dictionaryName == ListManager.ListTypeEnumName) { MetaFieldType mft = Mediachase.Ibn.Core.MetaDataWrapper.GetEnumByName(dictionaryName); int ItemId = int.Parse(e.CommandArgument.ToString()); TextBox tb = (TextBox)e.Item.FindControl("txtName"); DropDownList ddl = (DropDownList)e.Item.FindControl("ddlOrder"); int OrderId = int.Parse(ddl.SelectedValue); if (tb != null && tb.Text.Trim() != String.Empty) { if (ItemId > 0) { MetaEnum.UpdateItem(mft, ItemId, tb.Text.Trim(), OrderId); } else { MetaEnum.AddItem(mft, tb.Text.Trim(), OrderId); } } dgEnum.EditItemIndex = -1; } else { int ItemID = int.Parse(e.Item.Cells[0].Text); DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), ddDictionaries.SelectedItem.Value); TextBox tb = (TextBox)e.Item.FindControl("tbName"); int _weight = 0; TextBox tbW = (TextBox)e.Item.FindControl("tbWeight"); if (tbW != null && tbW.Text.Length > 0) { _weight = int.Parse(tbW.Text); } if (tb != null) { try { if (ItemID > 0) { Dictionaries.UpdateItem(ItemID, tb.Text, _weight, dic); } else { Dictionaries.AddItem(tb.Text, _weight, dic); } } catch (SqlException ex) { if (ex.Number == 2627) // Violation of UNIQUE KEY { lblError.Visible = true; lblError.Text = "<br><br>" + LocRM.GetString("Duplication"); } } } dgDic.EditItemIndex = -1; } BindDG(); }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { //Swift doesn't support extensions on same protocol used by Base and Sub types if (type.IsAbstract()) { return; } var typeName = Type(type.Name, type.GenericArgs); var typeNameOnly = typeName.SplitOnFirst('<')[0]; sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("public static var typeName:String {{ return \"{0}\" }}".Fmt(typeName)); //func typeConfig() var isGenericType = !type.GenericArgs.IsEmpty(); if (!isGenericType) { sbExt.AppendLine("public static var metadata = Metadata.create(["); sbExt = sbExt.Indent(); } else { //Swift 2.0 doesn't allow stored static properties on generic types yet sbExt.AppendLine("public static var metadata:Metadata {"); sbExt = sbExt.Indent(); sbExt.AppendLine("return Metadata.create(["); } sbExt = sbExt.Indent(); foreach (var prop in GetPropertes(type)) { var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs); if (propType.IsInterface() || IgnorePropertyTypeNames.Contains(prop.Type) || IgnorePropertyNames.Contains(prop.Name)) { continue; } var fnName = "property"; if (prop.IsArray() || ArrayTypes.Contains(prop.Type)) { fnName = initCollections ? "arrayProperty" : "optionalArrayProperty"; } else if (DictionaryTypes.Contains(prop.Type)) { fnName = initCollections ? "objectProperty" : "optionalObjectProperty"; } else { if (propType != null && !propType.IsEnum.GetValueOrDefault()) { fnName = "optionalObjectProperty"; } else { fnName = "optionalProperty"; } } sbExt.AppendLine("Type<{0}>.{1}(\"{2}\", get: {{ $0.{2} }}, set: {{ $0.{2} = $1 }}),".Fmt( typeName, fnName, prop.Name.SafeToken().PropertyStyle())); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("])"); sbExt = sbExt.UnIndent(); if (isGenericType) { sbExt.AppendLine("}"); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
public static void UpdateItem(int ItemId, string ItemName, int Param, DictionaryTypes dict) { switch(dict) { case DictionaryTypes.Categories: DBCommon.UpdateCategory(ItemId, ItemName); break; case DictionaryTypes.IncidentSeverities: DBIncident.UpdateIncidentSeverity(ItemId, ItemName); break; case DictionaryTypes.IncidentTypes: DBIncident.UpdateIncidentType(ItemId, ItemName); break; case DictionaryTypes.ProjectTypes: UpdateProjectType(ItemId, ItemName); break; // case DictionaryTypes.Clients: // DBProject.UpdateClient(ItemId, ItemName); // break; case DictionaryTypes.ProjectCategories: DBProject.UpdateProjectCategory(ItemId, ItemName); break; case DictionaryTypes.IncidentCategories: DBIncident.UpdateIncidentCategory(ItemId, ItemName); break; case DictionaryTypes.Currency: DBCommon.UpdateCurrency(ItemId, ItemName); break; case DictionaryTypes.DocumentStatus: DBDocument.UpdateDocumentStatus(ItemId, ItemName, Param); break; case DictionaryTypes.ProjectPhases: DBProject.UpdateProjectPhase(ItemId, ItemName, Param); break; case DictionaryTypes.RiskLevels: DBProject.UpdateRiskLevel(ItemId, ItemName, Param); break; } }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { //Swift doesn't support extensions on same protocol used by Base and Sub types if (type.IsAbstract()) { return; } var typeName = Type(type.Name, type.GenericArgs); var typeNameOnly = typeName.SplitOnFirst('<')[0]; sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("public class var typeName:String {{ return \"{0}\" }}".Fmt(typeName)); //func typeConfig() sbExt.AppendLine("public class func reflect() -> Type<{0}> {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine( "return TypeConfig.config() ?? TypeConfig.configure(Type<{0}>(".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("properties: [".Fmt(typeName)); sbExt = sbExt.Indent(); foreach (var prop in GetPropertes(type)) { var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs); if (propType.IsInterface() || IgnorePropertyTypeNames.Contains(prop.Type) || IgnorePropertyNames.Contains(prop.Name)) { continue; } var fnName = "property"; if (prop.IsArray() || ArrayTypes.Contains(prop.Type)) { fnName = initCollections ? "arrayProperty" : "optionalArrayProperty"; } else if (DictionaryTypes.Contains(prop.Type)) { fnName = initCollections ? "objectProperty" : "optionalObjectProperty"; } else { if (propType != null && !propType.IsEnum.GetValueOrDefault()) { fnName = "optionalObjectProperty"; } else { fnName = "optionalProperty"; } } sbExt.AppendLine("Type<{0}>.{1}(\"{2}\", get: {{ $0.{2} }}, set: {{ $0.{2} = $1 }}),".Fmt( typeName, fnName, prop.Name.SafeToken().PropertyStyle())); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("]))"); sbExt = sbExt.UnIndent(); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toJson() sbExt.AppendLine("public func toJson() -> String {"); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().toJson(self)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromJson() sbExt.AppendLine("public class func fromJson(json:String) -> {0}? {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().fromJson({0}(), json: json)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromObject() sbExt.AppendLine("public class func fromObject(any:AnyObject) -> {0}? {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().fromObject({0}(), any:any)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toString() sbExt.AppendLine("public func toString() -> String {"); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().toString(self)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromString() sbExt.AppendLine("public class func fromString(string:String) -> {0}? {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().fromString({0}(), string: string)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
public void AddProperties(StringBuilderWrapper sb, MetadataType type, bool initCollections) { var wasAdded = false; var dataMemberIndex = 1; if (type.Properties != null) { foreach (var prop in type.Properties) { if (wasAdded) { sb.AppendLine(); } var propType = Type(prop.Type, prop.GenericArgs); var optional = ""; var defaultValue = ""; if (propType.EndsWith("?")) { propType = propType.Substring(0, propType.Length - 1); optional = "?"; } if (Config.MakePropertiesOptional) { optional = "?"; } if (prop.Attributes.Safe().FirstOrDefault(x => x.Name == "Required") != null) { optional = "?"; //always use optional } if (prop.IsArray()) { optional = ""; defaultValue = " = []"; } else if (initCollections && !prop.GenericArgs.IsEmpty()) { if (ArrayTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = []"; } if (DictionaryTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = [:]"; } } wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++); wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded; if (type.IsInterface()) { sb.AppendLine("var {0}:{1}{2} {{ get set }}".Fmt( prop.Name.SafeToken().PropertyStyle(), propType, optional)); } else { sb.AppendLine("public var {0}:{1}{2}{3}".Fmt( prop.Name.SafeToken().PropertyStyle(), propType, optional, defaultValue)); } } } if (Config.AddResponseStatus && (type.Properties == null || type.Properties.All(x => x.Name != "ResponseStatus"))) { if (wasAdded) { sb.AppendLine(); } AppendDataMember(sb, null, dataMemberIndex++); sb.AppendLine("public var {0}:ResponseStatus".Fmt("ResponseStatus".PropertyStyle())); } }
/// <summary> /// ItemId, ItemName, Weight, StateId, CanDelete (int) /// </summary> public static DataTable GetList(DictionaryTypes dict) { DataTable dt = null; switch(dict) { case DictionaryTypes.Categories: dt = DBCommon.GetListCategoriesForDictionaries(); break; case DictionaryTypes.IncidentSeverities: dt = DBIncident.GetListIncidentSeverityForDictionaries(); break; case DictionaryTypes.IncidentTypes: dt = DBIncident.GetListIncidentTypesForDictionaries(); break; case DictionaryTypes.ProjectTypes: dt = DBProject.GetListProjectTypesForDictionaries(); break; case DictionaryTypes.ProjectCategories: dt = DBProject.GetListProjectCategoriesForDictionaries(); break; case DictionaryTypes.IncidentCategories: dt = DBIncident.GetListIncidentCategoriesForDictionaries(); break; case DictionaryTypes.Currency: dt = DBCommon.GetListCurrencyForDictionaries(); break; case DictionaryTypes.DocumentStatus: dt = DBDocument.GetListDocumentStatusForDictionaries(Security.CurrentUser.LanguageId); break; case DictionaryTypes.ProjectPhases: dt = DBProject.GetListProjectPhasesForDictionaries(); break; case DictionaryTypes.RiskLevels: dt = DBProject.GetListRiskLevelsForDictionaries(); break; } if (dict != DictionaryTypes.ProjectPhases && dict != DictionaryTypes.RiskLevels && dt != null) dt.Columns.Add("Weight", typeof(int)); return dt; }
public void AddProperties(StringBuilderWrapper sb, MetadataType type, bool initCollections, bool includeResponseStatus) { var wasAdded = false; var dataMemberIndex = 1; foreach (var prop in type.Properties.Safe()) { if (wasAdded) { sb.AppendLine(); } var propTypeName = Type(prop.Type, prop.GenericArgs); var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs); var optional = ""; var defaultValue = ""; if (propTypeName.EndsWith("?")) { propTypeName = propTypeName.Substring(0, propTypeName.Length - 1); optional = "?"; } if (Config.MakePropertiesOptional) { optional = "?"; } if (prop.Attributes.Safe().FirstOrDefault(x => x.Name == "Required") != null) { optional = "?"; //always use optional } if (prop.IsArray()) { optional = ""; defaultValue = " = []"; } else if (initCollections && !prop.GenericArgs.IsEmpty()) { if (ArrayTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = []"; } if (DictionaryTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = [:]"; } } if (propType.IsInterface() || IgnorePropertyNames.Contains(prop.Name)) { sb.AppendLine("//{0}:{1} ignored. Swift doesn't support interface properties" .Fmt(prop.Name.SafeToken().PropertyStyle(), propTypeName)); continue; } else if (IgnorePropertyTypeNames.Contains(propTypeName)) { sb.AppendLine("//{0}:{1} ignored. Type could not be extended in Swift" .Fmt(prop.Name.SafeToken().PropertyStyle(), propTypeName)); continue; } wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++); wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded; if (type.IsInterface()) { sb.AppendLine("var {0}:{1}{2} {{ get set }}".Fmt( prop.Name.SafeToken().PropertyStyle(), propTypeName, optional)); } else { sb.AppendLine("public var {0}:{1}{2}{3}".Fmt( prop.Name.SafeToken().PropertyStyle(), propTypeName, optional, defaultValue)); } } if (includeResponseStatus) { if (wasAdded) { sb.AppendLine(); } AppendDataMember(sb, null, dataMemberIndex++); sb.AppendLine("public var {0}:ResponseStatus?".Fmt(typeof(ResponseStatus).Name.PropertyStyle())); } }
public DeleteDictionaryItem(DictionaryTypes dictionaryType, long id) { DictionaryType = dictionaryType; Id = id; }