public static ExtendedField GetExtendedField(MaxLabs.bbsMax.PassportServerInterface.ExtendedFieldProxy proxy) { if (proxy == null) { return(null); } ExtendedField field = new ExtendedField(); field.Description = proxy.Description; field.DisplayType = (ExtendedFieldDisplayType)proxy.DisplayType; field.FieldTypeName = proxy.FieldTypeName; field.IsRequired = proxy.IsRequired; field.Key = proxy.Key; field.Name = proxy.Name; field.Searchable = proxy.Searchable; field.Settings = new StringTable(); foreach (MaxLabs.bbsMax.PassportServerInterface.StringKeyValueProxy keyValue in proxy.Settings) { field.Settings.Add(keyValue.Key, keyValue.Value); } field.IsPassport = true; field.SortOrder = proxy.SortOrder; return(field); }
public ExtendedFieldTest() { this.Width = DefaultWidth; this.Height = DefaultHeight; var f = new ExtendedField(6, 12, DefaultWidth, DefaultHeight); f.Container.AttachTo(this); var feeder = new SimplePipeFeeder(6, Colors.Yellow); feeder.Container.MoveTo(Tile.ShadowBorder, Tile.ShadowBorder + Tile.Size).AttachTo(this); f.Overlay.AttachTo(this); f.PipeToBeBuilt = feeder.Current; f.PipeToBeBuiltUsed += delegate { feeder.MoveNext(); f.PipeToBeBuilt = feeder.Current; }; var Randomized = f.Field.Tiles.TileList.Randomize().GetEnumerator(); Randomized.Take().Drain.Show(); Randomized.Take().Drain.Show(); Randomized.Take().Drain.Show(); }
private bool CreateExtendField(ExtendedFieldType fieldType) { MessageDisplay msgDisplay = CreateMessageDisplay(); ExtendedField extendFiled = GetExtendFieldInfo(fieldType); extendFiled.Key = Guid.NewGuid().ToString(); ExtendedFieldSettings settings = SettingManager.CloneSetttings <ExtendedFieldSettings>(AllSettings.Current.ExtendedFieldSettings); settings.Version = Guid.NewGuid().ToString(); foreach (ExtendedField field in AllSettings.Current.ExtendedFieldSettings.Fields) { if (string.Compare(extendFiled.Name, field.Name, true) == 0) { msgDisplay.AddError("已经存在同名的扩展字段\"" + field.Name + "\",请更换名称"); break; } } if (msgDisplay.HasAnyError()) { return(false); } settings.Fields.Add(extendFiled); SettingManager.SaveSettings(settings); return(true); }
public static ExtendedFieldSearchInfo Parse(StringTable values) { ExtendedFieldSearchInfo result = new ExtendedFieldSearchInfo(); ExtendedField[] fileds = AllSettings.Current.ExtendedFieldSettings.FieldsWithPassport.ToArray(); foreach (DictionaryEntry item in values) { if (item.Value == null || (string)item.Value == string.Empty) { continue; } ExtendedField field = Array.Find <ExtendedField>(fileds, match => match.Key == (string)item.Key); if (field != null) { ExtendedFieldType type = UserBO.Instance.GetExtendedFieldType(field.FieldTypeName); if (type != null) { if (result.Items == null) { result.Items = new List <ExtendedFieldSearchInfoItem>(); } result.Items.Add(new ExtendedFieldSearchInfoItem((string)item.Key, (string)item.Value, type.NeedExactMatch)); } } } return(result); }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = StringUtil.HtmlEncode(HttpContext.Current.Request.Form[fieldInfo.Key]); if (string.IsNullOrEmpty(value)) { return(value); } int maxLength = 0; int.TryParse(fieldInfo.Settings["maxlength"], out maxLength); int minLength = 0; int.TryParse(fieldInfo.Settings["minlength"], out minLength); if (maxLength > 0 && StringUtil.GetByteCount(value) > maxLength) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能大于" + maxLength + "个字节(一个汉字等于两个字节)")); return(null); } else if (StringUtil.GetByteCount(value) < minLength) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能小于" + minLength + "个字节(一个汉字等于两个字节)")); return(null); } return(value); }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = StringUtil.HtmlEncode(HttpContext.Current.Request.Form[fieldInfo.Key]); if (string.IsNullOrEmpty(value)) { return(value); } if (StringUtil.IsIntegerFormat(value) == false) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "号码必须由数字组成")); return(null); } if (value.Length > 12) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能大于12个数字")); return(null); } else if (value.Length < 11) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能小于11个数字")); return(null); } return(value); }
/// <summary> /// Get the value of a field on an object /// </summary> /// <param name="obj"></param> /// <param name="field"></param> public static T GetFieldValue <T>(this object obj, ExtendedField field) { try { return((T)field.FieldInfo.GetValue(obj)); } catch (Exception) { throw; } }
protected void Page_Load(object sender, EventArgs e) { if (AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.Action.Setting_ExtendedField) == false) { ShowError("没有权限删除扩展字段"); } if (_Request.IsClick("delete")) { string key = Request.QueryString["key"]; if (key != null) { if (Field.IsPassport) { ShowError("您试图删除的是passport服务器端的扩展字段,这是不允许的"); } //ExtendedField[] fields = AllSettings.Current.ExtendedFieldSettings.Fields.ToArray(); ExtendedFieldSettings settings = SettingManager.CloneSetttings <ExtendedFieldSettings>(AllSettings.Current.ExtendedFieldSettings); ExtendedFieldCollection fields = new ExtendedFieldCollection(); ExtendedField deletedField = null; foreach (ExtendedField field in settings.Fields) { if (field.Key != key) { fields.Add(field); } else { deletedField = field; } } settings.Fields = fields; SettingManager.SaveSettings(settings); if (deletedField != null) { UserBO.Instance.DeleteUserExtendFields(deletedField.Key); UserBO.Instance.Server_UpdatePassportUserExtendFieldCache(fields); } Return("id", key); } } }
private bool UpdateExtendField(ExtendedFieldType fieldType, string key) { MsgDisplayForSaveSettings = CreateMessageDisplay(); ExtendedField extendFiled = GetExtendFieldInfo(fieldType); extendFiled.Key = key; ExtendedFieldSettings settings = SettingManager.CloneSetttings <ExtendedFieldSettings>(AllSettings.Current.ExtendedFieldSettings); settings.Version = Guid.NewGuid().ToString(); ExtendedFieldCollection fields = new ExtendedFieldCollection(); ExtendedFieldDisplayType?oldDisplayType = null; foreach (ExtendedField field in settings.Fields) { if (field.Key == extendFiled.Key) { fields.Add(extendFiled); oldDisplayType = field.DisplayType; } else { if (string.Compare(extendFiled.Name, field.Name, true) == 0) { MsgDisplayForSaveSettings.AddError("已经存在同名的扩展字段\"" + field.Name + "\",请更换名称"); break; } else { fields.Add(field); } } } if (MsgDisplayForSaveSettings.HasAnyError()) { return(false); } if (oldDisplayType != null && extendFiled.DisplayType != oldDisplayType.Value) { UserBO.Instance.UpdateUserExtendFieldPrivacy(extendFiled.Key, extendFiled.DisplayType); } settings.Fields = fields; SettingManager.SaveSettings(settings); return(true); }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = HttpContext.Current.Request.Form[fieldInfo.Key]; if (string.IsNullOrEmpty(value)) { return(value); } long maxValue = 0; long.TryParse(fieldInfo.Settings["maxvalue"], out maxValue); long minValue = 0; long.TryParse(fieldInfo.Settings["minvalue"], out minValue); value = value.Trim(); if (string.IsNullOrEmpty(value) == false) { long number; if (long.TryParse(value, out number)) { if (number < minValue) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须大等于" + minValue)); } else if (maxValue > 0 && number > maxValue) { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须小等于" + maxValue)); } else { return(number.ToString()); } } else { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须填写数字")); } } else { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须填写数字")); } return(null); }
private ExtendedField GetExtendFieldInfo(ExtendedFieldType fieldType) { ExtendedField extendFiled = new ExtendedField(); extendFiled.FieldTypeName = fieldType.TypeName; extendFiled.Name = _Request.Get("Name", Method.Post); extendFiled.Description = _Request.Get("Description", Method.Post); extendFiled.IsRequired = _Request.Get("IsRequired", Method.Post) == "True"; extendFiled.IsHidden = _Request.Get("IsHidden", Method.Post) == "True"; extendFiled.Searchable = _Request.Get("Searchable", Method.Post) == "True"; extendFiled.DisplayType = _Request.Get <ExtendedFieldDisplayType>("DisplayType", Method.Post, ExtendedFieldDisplayType.AllVisible); extendFiled.SortOrder = _Request.Get <int>("SortOrder", Method.Post, 0); extendFiled.Settings = fieldType.LoadSettingsFromRequest(); return(extendFiled); }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string url = base.LoadValueFromRequest(fieldInfo); if (string.IsNullOrEmpty(url) == false) { if (s_UrlRegex.IsMatch(url)) { return(url); } else { MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.UrlFormatError>(new MaxLabs.bbsMax.Errors.UrlFormatError(fieldInfo.Key, url)); } } return(null); }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = HttpContext.Current.Request.Form[fieldInfo.Key] + ""; value = HttpUtility.HtmlDecode(value); Match match = s_SelectionValueRegex.Match(value); if (match.Success) { string[] data = fieldInfo.Settings["data"].Replace("\r", "").Split('\n'); string text1 = match.Groups[1].Value; if (CheckValue(text1, data) == false) { goto ERROR; } for (int i = 0; i < match.Groups[2].Captures.Count; i++) { string text = match.Groups[2].Captures[i].Value; for (int l = 0; l < i + 1; l++) { text = '-' + text; } if (CheckValue(text, data) == false) { goto ERROR; } } return(StringUtil.HtmlEncode(value)); } ERROR: MaxLabs.WebEngine.Context.ThrowError <MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, fieldInfo.Name + "数据格式不正确")); return(null); }
//public static ChatSessionFilterProxy GetChatSessionFilterProxy(ChatSessionFilter filter) //{ // if (filter == null) // return null; // ChatSessionFilterProxy proxy = new ChatSessionFilterProxy(); // proxy.BeginDate = filter.BeginDate; // proxy.Contains = filter.Contains; // proxy.EndDate = filter.EndDate; // proxy.IsDesc = filter.IsDesc; // proxy.PageSize = filter.PageSize; // proxy.ShowAll = filter.ShowAll; // proxy.UserID = filter.UserID; // proxy.Username = filter.Username; // return proxy; //} public static ExtendedFieldProxy GetExtendedFieldProxy(ExtendedField field) { if (field == null) { return(null); } ExtendedFieldProxy proxy = new ExtendedFieldProxy(); proxy.Description = field.Description; proxy.DisplayType = (int)field.DisplayType; proxy.FieldTypeName = field.FieldTypeName; proxy.IsRequired = field.IsRequired; proxy.Key = field.Key; proxy.Name = field.Name; proxy.Searchable = field.Searchable; proxy.Settings = new List <StringKeyValueProxy>(); foreach (DictionaryEntry item in field.Settings) { string value; if (item.Value == null) { value = string.Empty; } else { value = item.Value.ToString(); } StringKeyValueProxy temp = new StringKeyValueProxy(item.Key.ToString(), value); proxy.Settings.Add(temp); } proxy.SortOrder = field.SortOrder; return(proxy); }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = StringUtil.HtmlEncode(HttpContext.Current.Request.Form[fieldInfo.Key]); if (string.IsNullOrEmpty(value)) return value; int maxLength = 0; int.TryParse(fieldInfo.Settings["maxlength"], out maxLength); int minLength = 0; int.TryParse(fieldInfo.Settings["minlength"], out minLength); if (maxLength > 0 && StringUtil.GetByteCount(value) > maxLength) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能大于" + maxLength + "个字节(一个汉字等于两个字节)")); return null; } else if (StringUtil.GetByteCount(value) < minLength) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能小于" + minLength + "个字节(一个汉字等于两个字节)")); return null; } return value; }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = HttpContext.Current.Request.Form[fieldInfo.Key]+""; value = HttpUtility.HtmlDecode(value); Match match = s_SelectionValueRegex.Match(value); if (match.Success) { string[] data = fieldInfo.Settings["data"].Replace("\r", "").Split('\n'); string text1 = match.Groups[1].Value; if (CheckValue(text1, data) == false) goto ERROR; for (int i = 0; i < match.Groups[2].Captures.Count; i++) { string text = match.Groups[2].Captures[i].Value; for (int l = 0; l < i + 1; l++) { text = '-' + text; } if (CheckValue(text, data) == false) goto ERROR; } return StringUtil.HtmlEncode(value); } ERROR: MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, fieldInfo.Name + "数据格式不正确")); return null; }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = HttpContext.Current.Request.Form[fieldInfo.Key]; if (string.IsNullOrEmpty(value)) { return value; } long maxValue = 0; long.TryParse(fieldInfo.Settings["maxvalue"], out maxValue); long minValue = 0; long.TryParse(fieldInfo.Settings["minvalue"], out minValue); value = value.Trim(); if (string.IsNullOrEmpty(value) == false) { long number; if (long.TryParse(value, out number)) { if (number < minValue) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须大等于" + minValue)); } else if (maxValue > 0 && number > maxValue) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须小等于" + maxValue)); } else return number.ToString(); } else { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须填写数字")); } } else { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "必须填写数字")); } return null; }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string url = base.LoadValueFromRequest(fieldInfo); if (string.IsNullOrEmpty(url) == false) { if (s_UrlRegex.IsMatch(url)) return url; else { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.UrlFormatError>(new MaxLabs.bbsMax.Errors.UrlFormatError(fieldInfo.Key, url)); } } return null; }
public override string LoadValueFromRequest(ExtendedField fieldInfo) { string value = StringUtil.HtmlEncode(HttpContext.Current.Request.Form[fieldInfo.Key]); if (string.IsNullOrEmpty(value)) return value; if (StringUtil.IsIntegerFormat(value) == false) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "号码必须由数字组成")); return null; } if (value.Length > 12) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能大于12个数字")); return null; } else if (value.Length < 11) { MaxLabs.WebEngine.Context.ThrowError<MaxLabs.bbsMax.Errors.CustomError>(new MaxLabs.bbsMax.Errors.CustomError(fieldInfo.Key, "长度不能小于11个数字")); return null; } return value; }
private ExtendedField GetExtendFieldInfo(ExtendedFieldType fieldType) { ExtendedField extendFiled = new ExtendedField(); extendFiled.FieldTypeName = fieldType.TypeName; extendFiled.Name = _Request.Get("Name", Method.Post); extendFiled.Description = _Request.Get("Description", Method.Post); extendFiled.IsRequired = _Request.Get("IsRequired", Method.Post) == "True"; extendFiled.IsHidden = _Request.Get("IsHidden", Method.Post) == "True"; extendFiled.Searchable = _Request.Get("Searchable", Method.Post) == "True"; extendFiled.DisplayType = _Request.Get<ExtendedFieldDisplayType>("DisplayType", Method.Post, ExtendedFieldDisplayType.AllVisible); extendFiled.SortOrder = _Request.Get<int>("SortOrder", Method.Post, 0); extendFiled.Settings = fieldType.LoadSettingsFromRequest(); return extendFiled; }
/// <summary> /// /// </summary> /// <param name="fieldInfo"></param> /// <returns></returns> public abstract string LoadValueFromRequest(ExtendedField fieldInfo);
public SpaceInvaderTest() { this.Width = DefaultWidth; this.Height = DefaultHeight; // SpaceInvaderTest // http://www.glassgiant.com/ascii/ // http://text-image.com/convert/ // these maps could be inside a zip file var map = new ASCIIImage(@" MMMMMMM...MMMMMMMMMMMMMMMMMMM...MMMMMMMM MMMMMMM...MMMMMMMMMMMMMMMMMMM...MMMMMMMM MMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMM MMMMMMM MMMMMMMM MMMMMMM MMMMMMMM MMM MMMM MMMM MMMM MMM MMMM MMMM MMMM MMM MMMM MMMM MMMM ... ... ... ... ...MMMM MMMMMMMMMMMMMMMMMMM MMMM ...MMMM MMMMMMMMMMMMMMMMMMM MMMM MMMMMMMMMM MMM. MMMMMMMMMMM MMMMMMMMMM MMM. MMMMMMMMMMM MMMMMMMMMM MMM. MMMMMMMMMMM ".Trim()); var f = new ExtendedField(map.Width, map.Height, DefaultWidth, DefaultHeight); f.Field.Tiles.TileList.ForEach( value => { if (map[value.IndexX, value.IndexY] == "M") f.Field.Tiles[value.IndexX, value.IndexY].Hide(); } ); f.Field.DefaultPipeColor = Colors.Yellow; f.Field.Tiles.Color = Colors.Cyan; f.Container.AttachTo(this); #region feeder var feeder = new SimplePipeFeeder(6, Colors.Brown); feeder.Container.AttachTo(this); var feeder_autohide = new SimplePipeFeeder.AutoHide(feeder, f.Overlay, DefaultWidth, DefaultHeight); f.Overlay.AttachTo(this); f.PipeToBeBuilt = feeder.Current; f.PipeToBeBuiltUsed += delegate { feeder.MoveNext(); f.PipeToBeBuilt = feeder.Current; }; #endregion #region setting up some stuff on the field var Randomized = f.Field.Tiles.TileList.Where(k => k.IsVisible).Randomize().GetEnumerator(); Enumerable.Range(0, 4).ForEach( Index => { var Target = Randomized.Take(); Target.Drain.Show(); if (Index % 2 == 0) f.Field[Target] = new SimplePipe.LeftToDrain(); else f.Field[Target] = new SimplePipe.RightToDrain(); } ); var PumpTimeout = new Random(); Enumerable.Range(0, 4).ForEach( Index => { var Target = Randomized.Take(); var pump = default(SimplePipe); if (Index % 2 == 0) pump = new SimplePipe.PumpToLeft(); else pump = new SimplePipe.PumpToRight(); pump.AddTimer(PumpTimeout.Next(20, 150), pump.Input.Pump); f.Field[Target] = pump; } ); Enumerable.Range(0, 6).ForEach( Index => { var Target = Randomized.Take(); f.Field[Target] = new SimplePipe.BonusPickup(); } ); #endregion }
//public static ChatSessionFilterProxy GetChatSessionFilterProxy(ChatSessionFilter filter) //{ // if (filter == null) // return null; // ChatSessionFilterProxy proxy = new ChatSessionFilterProxy(); // proxy.BeginDate = filter.BeginDate; // proxy.Contains = filter.Contains; // proxy.EndDate = filter.EndDate; // proxy.IsDesc = filter.IsDesc; // proxy.PageSize = filter.PageSize; // proxy.ShowAll = filter.ShowAll; // proxy.UserID = filter.UserID; // proxy.Username = filter.Username; // return proxy; //} public static ExtendedFieldProxy GetExtendedFieldProxy(ExtendedField field) { if (field == null) return null; ExtendedFieldProxy proxy = new ExtendedFieldProxy(); proxy.Description = field.Description; proxy.DisplayType = (int)field.DisplayType; proxy.FieldTypeName = field.FieldTypeName; proxy.IsRequired = field.IsRequired; proxy.Key = field.Key; proxy.Name = field.Name; proxy.Searchable = field.Searchable; proxy.Settings = new List<StringKeyValueProxy>(); foreach (DictionaryEntry item in field.Settings) { string value; if (item.Value == null) value = string.Empty; else value = item.Value.ToString(); StringKeyValueProxy temp = new StringKeyValueProxy(item.Key.ToString(), value); proxy.Settings.Add(temp); } proxy.SortOrder = field.SortOrder; return proxy; }
public ColoredFieldTest() { this.Width = DefaultWidth; this.Height = DefaultHeight; var f = new ExtendedField(16, 6, DefaultWidth, DefaultHeight); f.Field.DefaultPipeColor = Colors.Green; f.Field.Tiles.Color = Colors.Pink; f.Container.AttachTo(this); #region feeder var feeder = new SimplePipeFeeder(6, Colors.Yellow); feeder.Container.AttachTo(this); var feeder_autohide = new SimplePipeFeeder.AutoHide(feeder, f.Overlay, DefaultWidth, DefaultHeight); f.Overlay.AttachTo(this); f.PipeToBeBuilt = feeder.Current; f.PipeToBeBuiltUsed += delegate { feeder.MoveNext(); f.PipeToBeBuilt = feeder.Current; }; #endregion #region setting up some stuff on the field var Randomized = f.Field.Tiles.TileList.Randomize().GetEnumerator(); Enumerable.Range(0, 4).ForEach( Index => { var Target = Randomized.Take(); Target.Drain.Show(); if (Index % 2 == 0) f.Field[Target] = new SimplePipe.LeftToDrain(); else f.Field[Target] = new SimplePipe.RightToDrain(); } ); var PumpTimeout = new Random(); Enumerable.Range(0, 4).ForEach( Index => { var Target = Randomized.Take(); var pump = default(SimplePipe); if (Index % 2 == 0) pump = new SimplePipe.PumpToLeft(); else pump = new SimplePipe.PumpToRight(); pump.AddTimer(PumpTimeout.Next(20, 150), pump.Input.Pump); f.Field[Target] = pump; } ); #endregion }
private object MapField <TSource, TDest>(object newObject, object sourceObject, ObjectMap objectMapper, ExtendedField field, int currentDepth, int maxDepth, MappingOptions options, IDictionary <ObjectHashcode, object> objectTree, string path, ICollection <string> ignorePropertiesOrPaths = null) { var sourceFieldName = field.Name; var sourceFieldBackedPropertyName = field.BackedPropertyName; var sourceFieldType = field.Type; var sourceField = new Field(sourceFieldBackedPropertyName ?? sourceFieldName, sourceFieldType, field.ReflectedType); var sourceFieldValue = sourceObject.GetFieldValue(field); var destinationFieldName = field.Name; var destinationFieldBackedPropertyName = field.BackedPropertyName; var destinationFieldType = sourceFieldType; var destinationField = new Field(destinationFieldBackedPropertyName, destinationFieldType, field.ReflectedType); // determine from the registry what we are mapping this to var fieldMapper = objectMapper?.Mappings .Where(x => x.Source.DeclaringType == sourceFieldType && x.Source.Name == field.Name || (field.IsBackingField && x.Source.Name == field.BackedPropertyName)) .FirstOrDefault(); if (fieldMapper != null) { destinationFieldName = fieldMapper.Destination.Name; destinationFieldType = fieldMapper.Destination.Type; destinationFieldBackedPropertyName = fieldMapper.Destination.Name; destinationField = new Field(destinationFieldName, destinationFieldType, fieldMapper.Destination.DeclaringType); } FieldInfo destinationFieldInfo = null; PropertyInfo destinationPropertyInfo = null; destinationFieldInfo = newObject.GetField(destinationFieldName, sourceFieldType.Type); if (destinationFieldInfo == null) { if (sourceFieldType.IsNullable) { // support nullable => non-nullable destinationFieldInfo = newObject.GetField(destinationFieldName, sourceFieldType.NullableBaseType); if (destinationFieldInfo != null) { destinationFieldType = sourceFieldType.NullableBaseType.GetExtendedType(); } } } if (destinationFieldInfo == null) { // doesn't exist on the other side, try getting its property // todo: reduce the code duplication here if (field.IsBackingField) { destinationPropertyInfo = newObject.GetProperty(destinationFieldBackedPropertyName, sourceFieldType.Type); if (destinationPropertyInfo == null) { // support non-nullable => nullable destinationPropertyInfo = newObject.GetProperty(destinationFieldBackedPropertyName, GetNullableType(sourceFieldType.Type)); if (destinationPropertyInfo != null) { destinationFieldType = GetNullableType(sourceFieldType.Type).GetExtendedType(); } } } else { destinationPropertyInfo = newObject.GetProperty(destinationFieldName, sourceFieldType.Type); if (destinationPropertyInfo == null) { // support non-nullable => nullable destinationPropertyInfo = newObject.GetProperty(destinationFieldName, GetNullableType(sourceFieldType.Type)); if (destinationPropertyInfo != null) { destinationFieldType = GetNullableType(sourceFieldType.Type).GetExtendedType(); } } } } if (destinationFieldInfo != null || destinationPropertyInfo != null) { var sourceBaseType = sourceFieldType.IsNullable ? sourceFieldType.NullableBaseType : sourceFieldType.Type; var destinationBaseType = destinationFieldType.IsNullable ? destinationFieldType.NullableBaseType : destinationFieldType.Type; if (sourceBaseType != destinationBaseType) { throw new MappingException(sourceField, destinationField); } if (sourceFieldType.IsValueType || sourceFieldType.IsImmutable) { if (destinationFieldInfo != null) { newObject.SetFieldValue(destinationFieldName, destinationFieldType.Type, sourceFieldValue); } else { if (field.IsBackingField) { newObject.SetPropertyValue(destinationFieldBackedPropertyName, destinationFieldType.Type, sourceFieldValue); } else { newObject.SetPropertyValue(destinationFieldName, destinationFieldType.Type, sourceFieldValue); } } } else if (sourceFieldValue != null) { var clonedFieldValue = InspectAndMap <TSource, TDest>(sourceFieldValue, null, sourceFieldType, currentDepth, maxDepth, options, objectTree, path, ignorePropertiesOrPaths); if (destinationFieldInfo != null) { newObject.SetFieldValue(destinationFieldName, destinationFieldType.Type, clonedFieldValue); } else { if (field.IsBackingField) { newObject.SetPropertyValue(destinationFieldBackedPropertyName, destinationFieldType.Type, clonedFieldValue); } else { newObject.SetPropertyValue(destinationFieldName, destinationFieldType.Type, clonedFieldValue); } } } } else { // destination field does not exist or is not mapped // throw new MappingException($"There is no mapping configured for the property {MappingException.FormatField(sourceField)}"); } return(newObject); }
public static ExtendedField GetExtendedField(MaxLabs.bbsMax.PassportServerInterface.ExtendedFieldProxy proxy) { if (proxy == null) return null; ExtendedField field = new ExtendedField(); field.Description = proxy.Description; field.DisplayType = (ExtendedFieldDisplayType)proxy.DisplayType; field.FieldTypeName = proxy.FieldTypeName; field.IsRequired = proxy.IsRequired; field.Key = proxy.Key; field.Name = proxy.Name; field.Searchable = proxy.Searchable; field.Settings = new StringTable(); foreach (MaxLabs.bbsMax.PassportServerInterface.StringKeyValueProxy keyValue in proxy.Settings) { field.Settings.Add(keyValue.Key, keyValue.Value); } field.IsPassport = true; field.SortOrder = proxy.SortOrder; return field; }
void ReplaceEntry(CoolPicker newPicker) { var originalEntry = Control as UITextField; var customEntry = new ExtendedField { Space = 0 }; customEntry.EditingDidBegin += OnStarted; customEntry.EditingChanged += OnEditing; customEntry.EditingDidEnd += OnEnded; customEntry.InputAccessoryView = originalEntry.InputAccessoryView; var toolBar = (UIToolbar)customEntry.InputAccessoryView; if (newPicker.PickerBarColor != Color.Default) { toolBar.BackgroundColor = newPicker.PickerBarColor.ToUIColor(); } var toolBarItems = toolBar.Items; toolBarItems[1] = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => { var picker = (UIPickerView)Control.InputView; if (selectedIndex == -1 && Element.Items != null && Element.Items.Count > 0) { UpdatePickerSelectedIndex(0); } else if (selectedIndex >= 0 && Element.Items.Count > 0) { UpdateTextColor(); Control.Text = Element.Items[selectedIndex]; } else if (selectedIndex >= 0) { selectedIndex = -1; } ElementController.SetValueFromRenderer(Picker.SelectedIndexProperty, selectedIndex); customEntry.ResignFirstResponder(); } ); if (newPicker.PickerBarTextColor != Color.Default) { toolBarItems[1].TintColor = newPicker.PickerBarTextColor.ToUIColor(); } toolBar.SetItems(toolBarItems, false); var pickerView = new UIPickerView(); customEntry.InputView = pickerView; var model = new CoolModel(this); pickerView.Model = model; pickerView.WeakDelegate = model; if (newPicker.PickerColor != Color.Default) { pickerView.BackgroundColor = newPicker.PickerColor.ToUIColor(); } originalEntry.RemoveFromSuperview(); originalEntry.Dispose(); SetNativeControl(customEntry); }