Ejemplo n.º 1
0
        public static TTo ConvertTo <TFrom, TTo>(this TFrom t, DefaultMapConfig defaultMapConfig = null)
        {
            var mapper =
                ObjectMapperManager.DefaultInstance.GetMapper <TFrom, TTo>(defaultMapConfig ?? new DefaultMapConfig());

            return(mapper.Map(t));
        }
Ejemplo n.º 2
0
        public static Horse Map(HorseModel horse)
        {
            var config = new DefaultMapConfig();
            var result = config.ConvertUsing((HorseModel source) =>
                                             new Horse()
            {
                HorseName   = source.HorseName,
                Weight      = source.Weight,
                Age         = source.Age,
                WinsCount   = source.WinsCount,
                LossesCount = source.LossesCount
            });

            var horse1 = ObjectMapperManager
                         .DefaultInstance
                         .GetMapper <HorseModel, Horse>(result)
                         .Map(new HorseModel()
            {
                HorseName   = horse.HorseName,
                Weight      = horse.Weight,
                Age         = horse.Age,
                WinsCount   = horse.WinsCount,
                LossesCount = horse.LossesCount
            });

            return(horse1);
        }
Ejemplo n.º 3
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox1.Text) ||
                !IsFileNameValid(textBox1.Text))
            {
                MessageBox.Show("不合法的名称!");
                return;
            }
            DefaultMapConfig config = null;

            if (this.comboBox1.SelectedIndex == 0)
            {
                config = new KeyBoardConfig();
            }
            else if (this.comboBox1.SelectedIndex == 1)
            {
                config = new XInputConfig();
            }
            else
            {
                config = new MixModeConfig();
            }
            config.Name = textBox1.Text;
            this.OnSuccess(config);
            this.Close();
        }
Ejemplo n.º 4
0
 public ScriptJoyMap(DefaultMapConfig _config) : base(_config)
 {
     KeyBoardConfig = new KeyBoardConfig();
     XinputConfig   = new XInputConfig();
     Scripts        = new Dictionary <int, string>();
     config         = _config;
 }
        /// <summary>
        /// 將來源物件所有屬性值填入指定目的物件中
        /// </summary>
        /// <typeparam name="TSource">來源物件類別</typeparam>
        /// <typeparam name="TTarget">目的物件類別</typeparam>
        /// <param name="source">來源物件</param>
        /// <param name="sourcePrefix">來源屬性前綴字</param>
        /// <param name="targetPrefix">目的屬性前綴字</param>
        /// <param name="target">目的物件</param>
        /// <param name="ignoreNames">略過填入目的物件屬性名列表</param>
        public static void Inject <TSource, TTarget>(this TSource source, string sourcePrefix, string targetPrefix,
                                                     TTarget target,
                                                     params string[] ignoreNames)
        {
            var model = target as EntityObject;

            if (model != null && ignoreNames.Length == 0)
            {
                ignoreNames = model.EntityKey.EntityKeyValues.Select(v => v.Key).ToArray();
            }
            var mapConfig = new DefaultMapConfig();

            if (ignoreNames.Length > 0)
            {
                mapConfig.IgnoreMembers <TSource, TTarget>(ignoreNames);
            }
            if (sourcePrefix != null || targetPrefix != null)
            {
                if (sourcePrefix == null)
                {
                    sourcePrefix = "";
                }
                if (targetPrefix == null)
                {
                    targetPrefix = "";
                }
                mapConfig.MatchMembers((m1, m2) => targetPrefix + m1 == sourcePrefix + m2);
            }
            var mapper = ObjectMapperManager.DefaultInstance.GetMapper <TSource, TTarget>(mapConfig);

            mapper.Map(source, target);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 将TFrom模型属性映射到TTo模型,未映射字段属性不变
        /// </summary>
        public static TTo Mapper <TFrom, TTo>(TFrom from, TTo tto) where TFrom : class
        {
            var mapConfig = new DefaultMapConfig();
            var ignores   = new List <string>();

            //初始化忽略映射的属性
            typeof(TFrom).GetProperties().ForEach(p =>
            {
                if (p.GetCustomAttributes(typeof(IgnoreMapperAttribute), false).Length > 0)
                {
                    ignores.Add(p.Name);
                }
            });
            typeof(TTo).GetProperties().ForEach(p =>
            {
                if (p.GetCustomAttributes(typeof(IgnoreMapperAttribute), false).Length > 0)
                {
                    ignores.Add(p.Name);
                }
            });

            mapConfig.IgnoreMembers <TFrom, TTo>(ignores.ToArray());
            ObjectsMapper <TFrom, TTo> mapper = ObjectMapperManager.DefaultInstance.GetMapper <TFrom, TTo>(mapConfig);

            return(mapper.Map(from, tto));
        }
Ejemplo n.º 7
0
        private void InitializeConfigs()
        {
            csw = Container.Resolve<ICountryService>();
            lsw = Container.Resolve<ILocalService>();
            ssw = Container.Resolve<ISubdivisionService>();

            ConfigUser = new DefaultMapConfig();
                ConfigUserFullInfo = new DefaultMapConfig();
                ConfigUser.ConvertUsing((UserFullInfo usr) =>
                    new User
                    {
                        Id = usr.Id,
                        FirstName = usr.FirstName,
                        SecondName = usr.SecondName,
                        CountryId = usr.Country.Id,
                        LocationId = usr.Location.Id,
                        SubdivisionId = usr.Subdivision.Id
                    });

                ConfigUserFullInfo.ConvertUsing((User usr) =>
                    new UserFullInfo
                    {
                        Id = usr.Id,
                        FirstName = usr.FirstName,
                        SecondName = usr.SecondName,
                        Country = csw.GetCountryById(usr.CountryId),
                        Subdivision = usr.SubdivisionId != null ? ssw.GetSubdivisionById((int)usr.SubdivisionId) : null,
                        Location = usr.LocationId != null ? lsw.GetLocationById((int)usr.LocationId) : null

                    });
        }
Ejemplo n.º 8
0
        private void BindMixMode(DefaultMapConfig config)
        {
            cbA.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.A]);
            cbB.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.B]);
            cbX.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.X]);
            cbY.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.Y]);

            cbBack.SelectedIndex  = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.BACK]);
            cbStart.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.START]);

            cbBackL.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LBACK]);
            cbBackR.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RBACK]);

            cbHelp.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.HELP]);
            cbHome.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.HOME]);

            cbLB.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LB]);
            cbRB.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RB]);

            cbUp.SelectedIndex    = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.UP]);
            cbDown.SelectedIndex  = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.DOWN]);
            cbLeft.SelectedIndex  = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LEFT]);
            cbRight.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RIGHT]);

            cbLT.SelectedIndex  = this.allXinputAxesEnum.IndexOf((Xbox360Axes)(config.LTrigger - 65535));
            cbRT.SelectedIndex  = this.allXinputAxesEnum.IndexOf((Xbox360Axes)(config.RTrigger - 65535));
            cbLSX.SelectedIndex = this.allXinputAxesEnum.IndexOf((Xbox360Axes)(config.LeftRemoteX - 65535));
            cbLSY.SelectedIndex = this.allXinputAxesEnum.IndexOf((Xbox360Axes)(config.LeftRemoteY - 65535));
            cbRSX.SelectedIndex = this.allXinputAxesEnum.IndexOf((Xbox360Axes)(config.RightRemoteX - 65535));
            cbRSY.SelectedIndex = this.allXinputAxesEnum.IndexOf((Xbox360Axes)(config.RightRemoteY - 65535));

            cbLSB.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LSBUTTON]);
            cbRSB.SelectedIndex = this.allMixBt.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RSBUTTON]);
        }
Ejemplo n.º 9
0
        private void CbConfigList_SelectedIndexChanged(object sender, EventArgs e)
        {
            DefaultMapConfig config = (DefaultMapConfig)this.cbConfigList.SelectedItem;

            if (config != null)
            {
                if (config.MapType == MapType.XINPUT)
                {
                    SetXinputDefault();
                    BindXinput(config);
                }
                else if (config.MapType == MapType.KEYBOARD)
                {
                    SetKeyboardDefault();
                    BindKeyBoard(config);
                }
                else if (config.MapType == MapType.MIX)
                {
                    SetMixModeDefault();
                    BindMixMode(config);
                }
                else if (config.MapType == MapType.SCRIPT)
                {
                    SetScriptDefault();
                    BindScriptMode(config);
                }
            }
        }
        /// <summary>
        /// 將來源集合中的物件所有屬性值填入目的物件中,傳回一新目的物件集合
        /// </summary>
        /// <typeparam name="TSource">來源物件類別</typeparam>
        /// <typeparam name="TTarget">目的物件類別</typeparam>
        /// <param name="sources">來源物件集合</param>
        /// <param name="ignoreNames">略過填入目的物件屬性名列表</param>
        /// <returns></returns>
        public static IEnumerable <TTarget> Inject <TSource, TTarget>(this IEnumerable <TSource> sources,
                                                                      params string[] ignoreNames)
            where TTarget : new()
        {
            var mapConfig = new DefaultMapConfig().ShallowMap().IgnoreMembers <TSource, TTarget>(ignoreNames);
            var mapper    = ObjectMapperManager.DefaultInstance.GetMapper <TSource, TTarget>(mapConfig);

            return(sources.Select(mapper.Map));
        }
Ejemplo n.º 11
0
        public MapBuilder <TSource> PostProcess <T>(ValuesPostProcessor <T> postProcessor)
        {
            //var vpp = new ValuesPostProcessor<T>((t1, t2) =>
            //{
            //    return postProcessor(t1);
            //});

            _config = _config.PostProcess(postProcessor);
            return(this);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 一对一的指定对应关系
        /// </summary>
        /// <typeparam name="TFrom"></typeparam>
        /// <typeparam name="TTo"></typeparam>
        /// <param name="mapconfig"></param>
        /// <param name="destinationMember"></param>
        /// <param name="sourceMember"></param>
        /// <returns></returns>
        public static FlatteringConfig ForMember <TFrom, TTo>(this DefaultMapConfig mapconfig, Expression <Func <TTo, object> > destinationMember, Func <TFrom, object> sourceMember)
        {
            FlatteringConfig flattering = mapconfig as FlatteringConfig;

            if (flattering == null)
            {
                throw new NotSupportedException("当前对象不支持 ForMember 方法");
            }
            return(flattering.ForMember <TFrom, TTo>(destinationMember, sourceMember));
        }
Ejemplo n.º 13
0
        public static void Mapper <TIN, TOUT>(TIN modelIN, TOUT modelOUT)
        {
            var config = new DefaultMapConfig();

            config.MatchMembers((s1, s2) => s1.Equals(s2, StringComparison.InvariantCultureIgnoreCase));
            var outout = global::EmitMapper.ObjectMapperManager
                         .DefaultInstance.GetMapper <TIN, TOUT>(config);

            outout.Map(modelIN, modelOUT);
        }
Ejemplo n.º 14
0
        ///// <summary>
        ///// 虚拟手柄的BYTE信号缓冲区
        ///// </summary>
        //byte[] XinputKeyBuffer { get; set; } = new byte[4];
        //byte[] XinputLTriggerBuffer { get; set; } = new byte[1];
        //byte[] XinputRTriggerBuffer { get; set; } = new byte[1];
        //byte[] XinputLRemoteXBuffer { get; set; } = new byte[1];
        //byte[] XinputLRemoteYBuffer { get; set; } = new byte[1];
        //byte[] XinputRRemoteXBuffer { get; set; } = new byte[1];
        //byte[] XinputRRemoteYBuffer { get; set; } = new byte[1];
        ///// <summary>
        ///// 键盘的BYTE信号缓冲区
        ///// </summary>
        //byte[] KeyBoardKeyBuffer { get; set; } = new byte[4];
        //byte[] KeyBoardLTriggerBuffer { get; set; } = new byte[1];
        //byte[] KeyBoardRTriggerBuffer { get; set; } = new byte[1];
        //byte[] KeyBoardLRemoteXBuffer { get; set; } = new byte[1];
        //byte[] KeyBoardLRemoteYBuffer { get; set; } = new byte[1];
        //byte[] KeyBoardRRemoteXBuffer { get; set; } = new byte[1];
        //byte[] KeyBoardRRemoteYBuffer { get; set; } = new byte[1];
        public MixModeJoyMap(DefaultMapConfig _config) : base(_config)
        {
            if (_config == null)
            {
                _config = new XInputConfig();
            }

            KeyBoardConfig = new DefaultMapConfig();
            XinputConfig   = new DefaultMapConfig();
            config         = _config;
        }
 public ActionResult FieldEpsilonSave(VFieldEpsilon m)
 {
     ShortTitle = "epsilon";
     SolverData sd = GetSolverData();
     string[] fieldsToIgnore = { "BottomType", "TopType", "WestType", "EastType", "NorthType", "SouthType" };
     var config = new DefaultMapConfig().IgnoreMembers<VFieldEpsilon, FieldEpsilon>(fieldsToIgnore);
     ObjectMapperManager.DefaultInstance.GetMapper<VFieldEpsilon, FieldEpsilon>(config).Map(m, sd.FieldEpsilon);
     SetSolverData(sd);
     if (Request.IsAjaxRequest()) return Json("OK");
     return View(m);
 }
Ejemplo n.º 16
0
 public ScriptJoyMap(DefaultMapConfig _config) : base(_config)
 {
     //TODO 创建脚本数据库 读取所有脚本
     if (!Directory.Exists("joyScripts"))
     {
         Directory.CreateDirectory("joyScripts");
     }
     foreach (var item in Directory.GetFiles("joyScripts"))
     {
     }
 }
Ejemplo n.º 17
0
        private static ObjectsMapper <TFrom, TTo> GetMapper <TFrom, TTo>()
        {
            var config = new DefaultMapConfig();

            config.NullSubstitution <int?, int>((o) => 0);
            config.NullSubstitution <bool?, bool>((o) => false);
            var mapper = ObjectMapperManager.DefaultInstance
                         .GetMapper <TFrom, TTo>(config);

            return(mapper);
        }
Ejemplo n.º 18
0
        public TTo Map <TForm, TTo>(TForm source, DefaultMapConfig conf = null) where TForm : class where TTo : class
        {
            TTo toObj = null;

            if (conf == null)
            {
                return(_mapper.GetMapper <TForm, TTo>().Map(source));
            }

            toObj = _mapper.GetMapper <TForm, TTo>(conf).Map(source);

            return(toObj);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 模型转换
        /// </summary>
        /// <typeparam name="TFrom">来源模型</typeparam>
        /// <typeparam name="TTo">目标模型</typeparam>
        /// <param name="model">源对象</param>
        /// <param name="tmodel">目标对象</param>
        /// <param name="ignoreMembers">被忽略的不被赋值的属性</param>
        /// <returns>目标对象</returns>
        protected TTo MappingIgnore <TFrom, TTo>(TFrom model, TTo tmodel, params string[] ignoreMembers)
        {
            var config = new DefaultMapConfig();

            if (ignoreMembers != null)
            {
                config.IgnoreMembers <TFrom, TTo>(ignoreMembers);
            }

            var mapper = ObjectMapperManager.DefaultInstance.GetMapper <TFrom, TTo>(config);

            mapper.Map(model, tmodel);
            return(tmodel);
        }
Ejemplo n.º 20
0
        public static TDestination MapTo <TDestination>(this object source)
            where TDestination : class
        {
            var config = new DefaultMapConfig();

            if (typeof(TDestination).IsAssignableFrom(typeof(IEnumerable <>)))
            {
                config = config.ConvertGeneric(typeof(IEnumerable <>), typeof(IEnumerable <>), new DefaultCustomConverterProvider(typeof(TDestination)));
            }

            var item = ObjectMapperManager.DefaultInstance.GetMapperImpl(source.GetType(), typeof(TDestination), config).Map(source);

            return(item.As <TDestination>());
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 模型转换
        /// </summary>
        /// <typeparam name="TFrom">来源模型</typeparam>
        /// <typeparam name="TTo">目标模型</typeparam>
        /// <param name="model">源对象</param>
        /// <param name="tmodel">目标对象</param>
        /// <param name="propertySelector">指定属性赋值设置</param>
        /// <returns>目标对象</returns>
        protected TTo Mapping <TFrom, TTo>(TFrom model, TTo tmodel, Func <string, string, bool> propertySelector = null)
        {
            var config = new DefaultMapConfig();

            if (propertySelector != null)
            {
                config.MatchMembers(propertySelector);
            }

            var mapper = ObjectMapperManager.DefaultInstance.GetMapper <TFrom, TTo>(config);

            mapper.Map(model, tmodel);
            return(tmodel);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 将TFrom模型属性映射到TTo模型
        /// </summary>
        public static TTo Mapper <TFrom, TTo>(TFrom from, TTo tto, string[] fields, string[] ignores) where TFrom : class
        {
            var mapConfig = new DefaultMapConfig();

            if (fields != null)
            {
                mapConfig.MatchMembers((f, t) => fields.Contains(f));
            }
            if (ignores != null)
            {
                mapConfig.IgnoreMembers <TFrom, TTo>(ignores.ToArray());
            }

            return(Mapper(from, tto, mapConfig));
        }
        public ActionResult FieldEpsilonSave(VFieldEpsilon m)
        {
            ShortTitle = "epsilon";
            SolverData sd = GetSolverData();

            string[] fieldsToIgnore = { "BottomType", "TopType", "WestType", "EastType", "NorthType", "SouthType" };
            var      config         = new DefaultMapConfig().IgnoreMembers <VFieldEpsilon, FieldEpsilon>(fieldsToIgnore);

            ObjectMapperManager.DefaultInstance.GetMapper <VFieldEpsilon, FieldEpsilon>(config).Map(m, sd.FieldEpsilon);
            SetSolverData(sd);
            if (Request.IsAjaxRequest())
            {
                return(Json("OK"));
            }
            return(View(m));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 将源对象映射到目标对象
        /// </summary>
        /// <typeparam name="TSource">源类型</typeparam>
        /// <typeparam name="TDestination">目标类型</typeparam>
        /// <param name="source">源对象</param>
        /// <param name="destination">目标对象</param>
        /// <param name="config">配置</param>
        public static TDestination EmitMapTo <TSource, TDestination>(this TSource source, TDestination destination, DefaultMapConfig config = null)
        {
            if (config == null)
            {
                config = new DefaultMapConfig().NullSubstitution <DateTime?, DateTime>(t => DateTime.Now)
                         .NullSubstitution <bool?, bool>(t => false)
                         .NullSubstitution <Guid?, Guid>(t => Uuid.Next())
                         .NullSubstitution <int?, int>(t => - 1)
                         .NullSubstitution <decimal?, decimal>(t => - 1)
                         .NullSubstitution <float?, float>(t => - 1)
                         .NullSubstitution <double?, double>(t => - 1);
            }
            var map = ObjectMapperManager.DefaultInstance.GetMapper <TSource, TDestination>(config);

            return(map.Map(source, destination));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 模型转换
        /// </summary>
        /// <typeparam name="TFrom">来源模型</typeparam>
        /// <typeparam name="TTo">目标模型</typeparam>
        /// <param name="model">源对象</param>
        /// <param name="tmodel">目标对象</param>
        /// <returns>目标对象</returns>
        protected TTo MappingIgnoreDefault <TFrom, TTo>(TFrom model, TTo tmodel)
        {
            //var config = new DefaultMapConfig();
            //if (ignoreMembers != null)
            //    config.IgnoreMembers<TFrom, TTo>(ignoreMembers);

            var config = new DefaultMapConfig();
            // 不更新ID 和 Data_CreateTime
            var ignoreMembers = new string[] { "ID", "Data_CreateTime", "CreateUser" };

            config.IgnoreMembers <TFrom, TTo>(ignoreMembers);

            var mapper = ObjectMapperManager.DefaultInstance.GetMapper <TFrom, TTo>(config);

            mapper.Map(model, tmodel);
            return(tmodel);
        }
Ejemplo n.º 26
0
        public static User Map(UserModel user)
        {
            var config = new DefaultMapConfig();
            var result = config.ConvertUsing((UserModel source) =>
                                             new User
            {
                Email = source.Email
            });

            var user1 = ObjectMapperManager
                        .DefaultInstance
                        .GetMapper <UserModel, User>(result)
                        .Map(new UserModel {
                Email = user.Email
            });

            return(user1);
        }
Ejemplo n.º 27
0
        public static TTO Map <TFrom, TTO>(TFrom from, TTO to, string[] ignoreNames = null)
        {
            Type             tFrom = typeof(TFrom), tTo = typeof(TTO);
            DefaultMapConfig config;

            if (!ignoreNames.IsNullOrEmpty())
            {
                config = new DefaultMapConfig().IgnoreMembers(tFrom, tTo, ignoreNames);
            }
            else
            {
                string key = GetKey(tFrom, tTo);
                config = GetMapConfig(key);
            }
            var mapper = ObjectMapperManager.DefaultInstance.GetMapperImpl(tFrom, tTo, config);

            return((TTO)mapper.Map(from, to, from));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 反向绑定当前设置到Config
        /// </summary>
        /// <param name="config"></param>
        private void BindToConfig(DefaultMapConfig config)
        {
            config.Keymap[(byte)TimeBoxButton.A]     = GetKeyValue(cbA.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.B]     = GetKeyValue(cbB.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.X]     = GetKeyValue(cbX.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.Y]     = GetKeyValue(cbY.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.BACK]  = GetKeyValue(cbBack.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.START] = GetKeyValue(cbStart.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.LBACK] = GetKeyValue(cbBackL.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.RBACK] = GetKeyValue(cbBackR.SelectedItem);

            config.Keymap[(byte)TimeBoxButton.HELP] = GetKeyValue(cbHelp.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.HOME] = GetKeyValue(cbHome.SelectedItem);

            config.Keymap[(byte)TimeBoxButton.LB] = GetKeyValue(cbLB.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.RB] = GetKeyValue(cbRB.SelectedItem);

            config.Keymap[(byte)TimeBoxButton.UP]    = GetKeyValue(cbUp.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.DOWN]  = GetKeyValue(cbDown.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.LEFT]  = GetKeyValue(cbLeft.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.RIGHT] = GetKeyValue(cbRight.SelectedItem);

            config.Keymap[(byte)TimeBoxButton.LSBUTTON] = GetKeyValue(cbLSB.SelectedItem);
            config.Keymap[(byte)TimeBoxButton.RSBUTTON] = GetKeyValue(cbRSB.SelectedItem);

            config.LeftRemoteX  = cbLSX.SelectedIndex == -1?-1: GetKeyValue(cbLSX.SelectedItem);
            config.LeftRemoteY  = cbLSY.SelectedIndex == -1 ? -1 : GetKeyValue(cbLSY.SelectedItem);
            config.RightRemoteX = cbRSX.SelectedIndex == -1 ? -1 : GetKeyValue(cbRSX.SelectedItem);
            config.RightRemoteY = cbRSY.SelectedIndex == -1 ? -1 : GetKeyValue(cbRSY.SelectedItem);
            config.LTrigger     = cbLT.SelectedIndex == -1 ? -1 : GetKeyValue(cbLT.SelectedItem);
            config.RTrigger     = cbRT.SelectedIndex == -1 ? -1 : GetKeyValue(cbRT.SelectedItem);

            config.LeftRemoteUp    = GetKeyValue(cbLSUp.SelectedItem);
            config.LeftRemoteDown  = GetKeyValue(cbLSDown.SelectedItem);
            config.LeftRemoteLeft  = GetKeyValue(cbLSLeft.SelectedItem);
            config.LeftRemoteRight = GetKeyValue(cbLSRight.SelectedItem);

            config.RightRemoteUp    = GetKeyValue(cbRSUp.SelectedItem);
            config.RightRemoteDown  = GetKeyValue(cbRSDown.SelectedItem);
            config.RightRemoteLeft  = GetKeyValue(cbRSLeft.SelectedItem);
            config.RightRemoteRight = GetKeyValue(cbRSRight.SelectedItem);
        }
Ejemplo n.º 29
0
        public static Bet Map(BetModel bet)
        {
            var config = new DefaultMapConfig();
            var result = config.ConvertUsing((BetModel source) =>
                                             new Bet {
                Coefficient = source.Coefficient,
                BetItemType = source.BetType
            });

            var bet1 = ObjectMapperManager
                       .DefaultInstance
                       .GetMapper <BetModel, Bet>(result)
                       .Map(new BetModel()
            {
                Coefficient = bet.Coefficient,
                BetType     = bet.BetType
            });

            return(bet1);
        }
Ejemplo n.º 30
0
        private void Button1_Click(object sender, EventArgs e)
        {
            DefaultMapConfig config = (DefaultMapConfig)this.cbConfigList.SelectedItem;

            if (config != null)
            {
                this.BindToConfig(config);
                if (!Directory.Exists("maps"))
                {
                    Directory.CreateDirectory("maps");
                }
                FileHelper fh        = new FileHelper();
                string     configStr = JsonConvert.SerializeObject(config);
                fh.SaveFile(Path.Combine("maps", config.Name + ".config"), configStr);

                this.device.SetJoyMap(this.manager, config);

                MessageBox.Show("配置切换成功!");
            }
            this.Close();
        }
Ejemplo n.º 31
0
        private void BindKeyBoard(DefaultMapConfig config)
        {
            cbA.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.A]);
            cbB.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.B]);
            cbX.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.X]);
            cbY.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.Y]);

            cbBack.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.BACK]);
            cbStart.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.START]);

            cbBackL.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.LBACK]);
            cbBackR.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.RBACK]);

            cbHelp.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.HELP]);
            cbHome.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.HOME]);

            cbLB.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.LB]);
            cbRB.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.RB]);

            cbUp.SelectedIndex    = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.UP]);
            cbDown.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.DOWN]);
            cbLeft.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.LEFT]);
            cbRight.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.RIGHT]);

            cbLT.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.LTrigger);
            cbRT.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.RTrigger);

            cbLSUp.SelectedIndex    = this.allKeysEnum.IndexOf((Keys)config.LeftRemoteUp);
            cbLSDown.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.LeftRemoteDown);
            cbLSLeft.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.LeftRemoteLeft);
            cbLSRight.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.LeftRemoteRight);

            cbRSUp.SelectedIndex    = this.allKeysEnum.IndexOf((Keys)config.RightRemoteUp);
            cbRSDown.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.RightRemoteDown);
            cbRSLeft.SelectedIndex  = this.allKeysEnum.IndexOf((Keys)config.RightRemoteLeft);
            cbRSRight.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.RightRemoteRight);

            cbLSB.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.LSBUTTON]);
            cbRSB.SelectedIndex = this.allKeysEnum.IndexOf((Keys)config.Keymap[(byte)TimeBoxButton.RSBUTTON]);
        }
Ejemplo n.º 32
0
        private void BindScriptMode(DefaultMapConfig config)
        {
            cbA.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.A]);
            cbB.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.B]);
            cbX.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.X]);
            cbY.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.Y]);

            cbBack.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.BACK]);
            cbStart.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.START]);

            cbBackL.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LBACK]);
            cbBackR.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RBACK]);

            cbHelp.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.HELP]);
            cbHome.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.HOME]);

            cbLB.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LB]);
            cbRB.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RB]);

            cbUp.SelectedIndex    = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.UP]);
            cbDown.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.DOWN]);
            cbLeft.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LEFT]);
            cbRight.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RIGHT]);

            cbLT.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.LTrigger);
            cbRT.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.RTrigger);

            cbLSUp.SelectedIndex    = allScripts.FindIndex(i => i.ToInt() == config.LeftRemoteUp);
            cbLSDown.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.LeftRemoteDown);
            cbLSLeft.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.LeftRemoteLeft);
            cbLSRight.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.LeftRemoteRight);

            cbRSUp.SelectedIndex    = allScripts.FindIndex(i => i.ToInt() == config.RightRemoteUp);
            cbRSDown.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.RightRemoteDown);
            cbRSLeft.SelectedIndex  = allScripts.FindIndex(i => i.ToInt() == config.RightRemoteLeft);
            cbRSRight.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.RightRemoteRight);

            cbLSB.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.LSBUTTON]);
            cbRSB.SelectedIndex = allScripts.FindIndex(i => i.ToInt() == config.Keymap[(byte)TimeBoxButton.RSBUTTON]);
        }
Ejemplo n.º 33
0
        public void EntityToEntityVariantsMappingTest()
        {
            var entity = new Entity
            {
                Id = Guid.NewGuid(),
                Name = "Entity Name",
                Number = 134567,
                Price = 100.500m,
                UserName = null,
            };

            var mapConfig = new DefaultMapConfig().PostProcess<object>((value, state) =>
            {
                Console.WriteLine("Post processing: " + value.ToString());
                return value;
            });

            Mapper.DataMapper.AddConfiguration<Entity, Entity2>(mapConfig);

            Entity2 entity2 = Mapper.Map<Entity, Entity2>(entity);

            Assert.AreEqual(entity.Id, entity2.Id);
            Assert.AreEqual(entity.Name, entity2.Name);
            Assert.AreEqual(entity.Number, entity2.Number);
            Assert.AreEqual(entity.UserName, entity2.UserName);
        }