コード例 #1
0
ファイル: CSVInputAdapter.cs プロジェクト: hahanonym/nesper
        private IDictionary <string, object> CreateMapFromRow(string[] row)
        {
            var map = new Dictionary <string, object>();

            var count = 0;

            try
            {
                foreach (var property in _propertyOrder)
                {
                    // Skip properties that are in the title row but not
                    // part of the map to send
                    if ((_propertyTypes != null) &&
                        (!_propertyTypes.ContainsKey(property)) &&
                        (!property.Equals(_adapterSpec.TimestampColumn)))
                    {
                        count++;
                        continue;
                    }

                    var value = Coercer.Coerce(property, row[count++]);
                    map.Put(property, value);
                }
            }
            catch (Exception e)
            {
                throw new EPException(e);
            }

            return(map);
        }
コード例 #2
0
        /// <summary>
        /// Watches for a response to the a user profile request
        /// </summary>
        /// <param name="Bot">The bot instance to attach to</param>
        /// <param name="uid">The user id to look for</param>
        /// <param name="resp">The action to do upon finishing</param>
        /// <returns>This instance of the packet (for string-able-ness)</returns>
        public Packet Watch(PalBot Bot, UserId uid, Action <User> resp)
        {
            if (resp == null)
            {
                return(this);
            }

            Bot.Callbacks.Watch("SUB PROFILE QUERY RESULT", resp, (packet) =>
            {
                var bytes = Static.PalringoEncoding.GetBytes(packet.Payload);
                var map   = new DataMap(bytes);

                if (map.ContainsKey("sub-id"))
                {
                    int id = map.GetValueInt("sub-id");

                    if (!Bot.Information.UserCache.ContainsKey(id))
                    {
                        Bot.Information.UserCache.Add(id, new User());
                    }

                    foreach (var m in map.EnumerateMaps())
                    {
                        Bot.Information.UserCache[id].Parse(Bot, m);
                    }

                    return(Bot.Information.UserCache[id]);
                }
                return(null);
            }, (t) => t.Id == uid);
            return(this);
        }
コード例 #3
0
            void UpdateUiForConfigDataMap(DataMap config)
            {
                bool uiUpdated = false;

                foreach (var configKey in config.KeySet())
                {
                    if (!config.ContainsKey(configKey))
                    {
                        continue;
                    }
                    int color = config.GetInt(configKey);
                    if (Log.IsLoggable(Tag, LogPriority.Debug))
                    {
                        Log.Debug(Tag, "Found watch face config key: " + configKey + " -> "
                                  + Integer.ToHexString(color));
                    }
                    if (UpdateUiForKey(configKey, color))
                    {
                        uiUpdated = true;
                    }
                }
                if (uiUpdated)
                {
                    Invalidate();
                }
            }
コード例 #4
0
 void addIntKeyIfMissing(DataMap config, string key, int color)
 {
     if (!config.ContainsKey(key))
     {
         config.PutInt(key, color);
     }
 }
コード例 #5
0
        public override Dictionary <string, Rect> ParseData(string name, string data)
        {
            if (DataMap.ContainsKey(name))
            {
                return(DataMap[name]);
            }

            DataMap.Add(name, new Dictionary <string, Rect>());
            var jsonData = JsonConvert.DeserializeObject <TPUnityJsonData>(data);

            if (jsonData == null)
            {
                return(DataMap[name]);
            }

            var textureSize = jsonData.Metadata.ImageSize;

            foreach (var(frameName, frameData) in jsonData.Frames)
            {
                // Calculate mapping.
                var scale  = new Vector2(frameData.Frame.Width / textureSize.Width, frameData.Frame.Height / textureSize.Height);
                var offset = new Vector2(frameData.Frame.X / textureSize.Width, (textureSize.Height - frameData.Frame.Y - frameData.SourceSize.Height) / textureSize.Height);
                var rect   = new Rect(offset.x, offset.y, scale.x, scale.y);
                DataMap[name].Add(frameName, rect);
            }

            return(DataMap[name]);
        }
コード例 #6
0
        public void GroupUpdateHandler(GroupUpdate update, IPalBot bot)
        {
            var map = update.Payload;

            broadcast.BroadcastGroupUpdate(bot, update);

            if (!((PalBot)bot).SubProfiling.Users.ContainsKey(update.UserId))
            {
                ((PalBot)bot).SubProfiling.Users.Add(update.UserId, new User(update.UserId));
            }

            if (!((PalBot)bot).SubProfiling.Groups.ContainsKey(update.GroupId))
            {
                return;
            }

            if (update.Type == GroupUpdateType.Leave &&
                ((PalBot)bot).SubProfiling.Groups[update.GroupId].Members.ContainsKey(update.UserId))
            {
                ((PalBot)bot).SubProfiling.Groups[update.GroupId].Members.Remove(update.UserId);
            }

            if (update.Type == GroupUpdateType.Join)
            {
                var nextMap = new DataMap(map);

                if (nextMap.ContainsKey("contacts"))
                {
                    nextMap = nextMap.GetValueMap("contacts");
                }
                if (nextMap.ContainsKey(update.UserId.ToString()))
                {
                    nextMap = nextMap.GetValueMap(update.UserId.ToString());
                }

                ((PalBot)bot).SubProfiling.Users[update.UserId].Process(nextMap);

                if (!((PalBot)bot).SubProfiling.Groups[update.GroupId].Members.ContainsKey(update.UserId))
                {
                    ((PalBot)bot).SubProfiling.Groups[update.GroupId].Members.Add(update.UserId, Role.User);
                }
                return;
            }
        }
コード例 #7
0
 /// <summary>
 /// Adds or overrides value in the cache.
 /// </summary>
 /// <param name="Field">The field info of the class.</param>
 /// <param name="Value">The value to store.</param>
 public void SetValue(FieldInfo Field, object Value)
 {
     if (DataMap.ContainsKey(Field))
     {
         DataMap[Field] = Value;
     }
     else
     {
         DataMap.Add(Field, Value);
     }
 }
コード例 #8
0
ファイル: User.cs プロジェクト: calico-crusade/PalringoApi
        /// <summary>
        /// Parse the users profile from subprofile
        /// </summary>
        /// <param name="bot"></param>
        /// <param name="data"></param>
        public void Parse(PalBot bot, DataMap data)
        {
            if (data.ContainsKey("sub-id"))
            {
                Id = data.GetValueInt("sub-id");
            }
            if (data.ContainsKey("status"))
            {
                Status = data.GetValue("status");
            }
            if (data.ContainsKey("rep_lvl"))
            {
                RepLevel = double.Parse(data.GetValue("rep_lvl"));
            }
            if (data.ContainsKey("nickname"))
            {
                Nickname = data.GetValue("nickname");
            }
            if (data.ContainsKey("rep"))
            {
                Reputation = long.Parse(data.GetValue("rep"));
            }
            if (data.ContainsKey("privileges"))
            {
                Privileges = uint.Parse(data.GetValue("privileges"));
            }
            if (data.ContainsKey("online-status"))
            {
                OnlineStatus = (Status)int.Parse(data.GetValue("online-status"));
            }
            if (data.ContainsKey("device-type"))
            {
                DeviceType = (Device)int.Parse(data.GetValue("device-type"));
            }

            if (data.ContainsKey("contact") && data.GetValue("contact") == "1" && !bot.Information.Contacts.ContainsKey(Id))
            {
                bot.Information.Contacts.Add(Id, this);
            }

            Updated();
        }
コード例 #9
0
ファイル: User.cs プロジェクト: Montaser1998/botsdotnet
        /// <summary>
        /// Parse the users profile from subprofile
        /// </summary>
        /// <param name="bot"></param>
        /// <param name="data"></param>
        public void Process(DataMap data)
        {
            if (data.ContainsKey("sub-id"))
            {
                Id = data.GetValueInt("sub-id").ToString();
            }
            if (data.ContainsKey("status"))
            {
                Status = data.GetValue("status");
            }
            if (data.ContainsKey("rep_lvl"))
            {
                RepLevel = double.Parse(data.GetValue("rep_lvl"));
            }
            if (data.ContainsKey("nickname"))
            {
                Nickname = data.GetValue("nickname");
            }
            if (data.ContainsKey("rep"))
            {
                Reputation = long.Parse(data.GetValue("rep"));
            }
            if (data.ContainsKey("privileges"))
            {
                Privileges = uint.Parse(data.GetValue("privileges"));
            }
            if (data.ContainsKey("online-status"))
            {
                OnlineStatus = (Status)int.Parse(data.GetValue("online-status"));
            }
            if (data.ContainsKey("device-type"))
            {
                DeviceType = (Device)int.Parse(data.GetValue("device-type"));
            }

            IsAContact = data.ContainsKey("contact") && data.GetValue("contact") == "1";
        }
コード例 #10
0
ファイル: Common.cs プロジェクト: zhangshiguang/mobile
        public static T Get <T> (this DataMap dataMap, string propertyName, T defaultValue)
        {
            var key = propertyName + "Key";

            if (!dataMap.ContainsKey(key))
            {
                return(defaultValue);
            }
            else
            {
                var t = typeof(T);
                if (t == typeof(bool))
                {
                    return((T)(object)dataMap.GetBoolean(key));
                }
                else if (typeof(T) == typeof(string))
                {
                    return((T)(object)dataMap.GetString(key));
                }
                else if (t == typeof(Guid))
                {
                    var s = dataMap.GetString(key);
                    return((T)(object)Guid.Parse(s));
                }
                else if (t == typeof(DateTime))
                {
                    var      s  = dataMap.GetString(key);
                    DateTime dt = new DateTime();
                    DateTime.TryParse(s, out dt);
                    return((T)(object)dt);
                }
                else
                {
                    throw new NotSupportedException(typeof(T).Name);
                }
            }
        }
コード例 #11
0
ファイル: LayoutUtils.cs プロジェクト: JWPLAY/AUBE
        public static void BindingByDataMap(this LayoutControl lc, DataMap map, params LayoutControlGroup[] lcgs)
        {
            if (lcgs == null || lcgs.Length == 0)
            {
                lcgs = lc.Items.OfType <LayoutControlGroup>().ToArray();
            }
            foreach (LayoutControlGroup lcg in lcgs)
            {
                foreach (LayoutControlGroup group in lcg.Items.OfType <LayoutControlGroup>().Where(x => x.Items.Count > 0))
                {
                    lc.BindingByDataMap(map, group);
                }

                foreach (LayoutControlItem item in lcg.Items.OfType <LayoutControlItem>().Where(x => x.Control != null))
                {
                    var columnName = item.GetFieldNameByControlNoPattern();

                    if (!string.IsNullOrEmpty(columnName) && map.ContainsKey(columnName))
                    {
                        item.SetControlValue(map.GetValue(columnName), null);
                    }
                }
            }
        }
コード例 #12
0
 /// <summary>
 /// Parses the information from the DataMap given by subprofile
 /// </summary>
 /// <param name="bot"></param>
 /// <param name="map"></param>
 public new void Parse(PalBot bot, DataMap map)
 {
     if (map.ContainsKey("sub-id"))
     {
         Id = int.Parse(map.GetValue("sub-id"));
     }
     if (map.ContainsKey("name"))
     {
         Name = map.GetValue("name");
     }
     if (map.ContainsKey("name1"))
     {
         FirstName = map.GetValue("name1");
     }
     if (map.ContainsKey("name2"))
     {
         MiddleNames = map.GetValue("name2");
     }
     if (map.ContainsKey("name3"))
     {
         Surname = map.GetValue("name3");
     }
     if (map.ContainsKey("lang"))
     {
         Language = (Language)int.Parse(map.GetValue("lang"));
     }
     if (map.ContainsKey("sex"))
     {
         Gender = (Sex)int.Parse(map.GetValue("sex"));
     }
     if (map.ContainsKey("relstatus"))
     {
         RelationshipStatus = (Relationship)int.Parse(map.GetValue("relstatus"));
     }
     if (map.ContainsKey("after"))
     {
         LookingFor = (LookingFor)int.Parse(map.GetValue("after"));
     }
     if (map.ContainsKey("about"))
     {
         AboutMe = map.GetValue("about");
     }
     if (map.ContainsKey("dob_d"))
     {
         DobDay = map.GetValueInt("dob_d");
     }
     if (map.ContainsKey("dob_m"))
     {
         DobMonth = map.GetValueInt("dob_m");
     }
     if (map.ContainsKey("dob_y"))
     {
         DobYear = map.GetValueInt("dob_y");
     }
     base.Parse(bot, map);
 }
 void UpdateUiForConfigDataMap(DataMap config)
 {
     bool uiUpdated = false;
     foreach (var configKey in config.KeySet ()) {
         if (!config.ContainsKey (configKey)) {
             continue;
         }
         int color = config.GetInt (configKey);
         if (Log.IsLoggable (Tag, LogPriority.Debug)) {
             Log.Debug (Tag, "Found watch face config key: " + configKey + " -> "
             + Integer.ToHexString (color));
         }
         if (UpdateUiForKey (configKey, color)) {
             uiUpdated = true;
         }
     }
     if (uiUpdated) {
         Invalidate ();
     }
 }
 void addIntKeyIfMissing(DataMap config, string key, int color)
 {
     if (!config.ContainsKey (key)) {
         config.PutInt (key, color);
     }
 }