Esempio n. 1
0
        internal virtual KeyValuePairs[] ToKeyValuePairsArray()
        {
            KeyValuePairs[] array = new KeyValuePairs[_count];
            int             index = 0;

            bucket[] lbuckets = _buckets;
            for (int i = lbuckets.Length; --i >= 0;)
            {
                object?keyv = lbuckets[i].key;
                if ((keyv != null) && (keyv != _buckets))
                {
                    array[index++] = new KeyValuePairs(keyv, lbuckets[i].val);
                }
            }

            return(array);
        }
 public string this[string settingId, bool fromKeyValuePair]
 {
     get
     {
         if (KeyValuePairs.ContainsKey(settingId))
         {
             return(KeyValuePairs[settingId]);
         }
         return(String.Empty);
     }
     set
     {
         if (this[settingId, fromKeyValuePair] != value)
         {
             SetKeyValuePairs(settingId, value);
         }
     }
 }
Esempio n. 3
0
        public bool Remove(string key)
        {
            if (json.Type == JTokenType.Null)
            {
                return(false);
            }

            var  jsonObject = (JObject)json;
            bool removed    = jsonObject.Remove(key);

            if (!removed)
            {
                return(false);
            }

            KeyValuePairs.Remove(key);

            return(true);
        }
Esempio n. 4
0
        //// Test test
        //public void SortGenes(int satelliteId)
        //{
        //    Chromosome[satelliteId] = Chromosome[satelliteId].OrderBy(o => o.Turn).ToList();
        //}



        #region Filter_CollectionsList

        public List <int> getBestIncompleteCollections(bool nearlyFilled)
        {
            if (nearlyFilled)
            {
                return(KeyValuePairs.Where(x => x.Value.Worth >= AverageCollectionWorth &&
                                           (double)x.Value.L / 2 < x.Value.Photographs.Count() &&
                                           x.Value.L > x.Value.Photographs.Count())
                       .OrderByDescending(x => x.Value.Worth)
                       .ToDictionary(z => z.Key, y => y.Value).Keys.ToList());
            }
            else
            {
                return(KeyValuePairs.Where(x => x.Value.Worth >= AverageCollectionWorth &&
                                           (double)x.Value.L / 2 > x.Value.Photographs.Count() &&
                                           x.Value.L > x.Value.Photographs.Count())
                       .OrderByDescending(x => x.Value.Worth)
                       .ToDictionary(z => z.Key, y => y.Value).Keys.ToList());
            }
        }
Esempio n. 5
0
 public static bool GetEmbeddedGameInfo(out string o_gameTitle, out string o_gameVersion, out string o_gameURL, out string o_username, out string o_password)
 {
     try
     {
         var assembly = Assembly.GetExecutingAssembly();
         var stream   = assembly.GetManifestResourceStream("EmbeddedGame." + Program.Platform + ".txt");
         if (stream == null)
         {
             stream = assembly.GetManifestResourceStream("EmbeddedGame.txt");
         }
         if (stream != null)
         {
             var kvp = new KeyValuePairs();
             kvp.Load(stream);
             if (kvp.ContainsKey("game"))
             {
                 o_gameTitle   = kvp.GetString("game");
                 o_gameVersion = kvp.GetString("version");
                 o_gameURL     = kvp.GetString("url");
                 o_username    = kvp.GetString("username");
                 o_password    = kvp.GetString("password");
                 return(true);
             }
         }
         o_gameTitle   = default(string);
         o_gameVersion = default(string);
         o_gameURL     = default(string);
         o_username    = default(string);
         o_password    = default(string);
         return(false);
     }
     catch (Exception e)
     {
         Logger.Log("Caught Exception: {0}", e.ToString());
         o_gameTitle   = default(string);
         o_gameVersion = default(string);
         o_gameURL     = default(string);
         o_username    = default(string);
         o_password    = default(string);
         return(false);
     }
 }
Esempio n. 6
0
 public static TileBehaviour CreateFromName(string name, Tile tile, KeyValuePairs kvp)
 {
     if (s_tileBehaviours.ContainsKey(name))
     {
         try
         {
             var type        = s_tileBehaviours[name];
             var constructor = type.GetConstructor(new Type[] { typeof(Tile), typeof(KeyValuePairs) });
             return((TileBehaviour)constructor.Invoke(new object[] { tile, kvp }));
         }
         catch (TargetInvocationException e)
         {
             throw e.InnerException;
         }
     }
     else
     {
         App.Log("Error: Unrecognised tile behaviour " + name);
         return(new TileBehaviour(tile, kvp));
     }
 }
Esempio n. 7
0
        public ButtonTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
        {
            m_poweredModelPath    = kvp.GetString("powered_model", tile.ModelPath);
            m_altPoweredModelPath = kvp.GetString("alt_powered_model", m_poweredModelPath);

            m_soundPath = kvp.GetString("sound", null);

            bool connected = kvp.GetBool("connected", false);

            m_connectivity    = new bool[6];
            m_connectivity[0] = kvp.GetBool("connected_front", connected);
            m_connectivity[1] = kvp.GetBool("connected_right", connected);
            m_connectivity[2] = kvp.GetBool("connected_back", connected);
            m_connectivity[3] = kvp.GetBool("connected_left", connected);
            m_connectivity[4] = kvp.GetBool("connected_top", connected);
            m_connectivity[5] = kvp.GetBool("connected_bottom", connected);

            m_type     = kvp.GetEnum("type", ButtonType.Momentary);
            m_inverted = kvp.GetBool("inverted", false);
            m_colour   = kvp.GetString("colour");
        }
Esempio n. 8
0
        public void Save(TextWriter writer)
        {
            var kvp = new KeyValuePairs();

            kvp.SetColour("background_colour", BackgroundColour);
            kvp.Set("background_image", BackgroundImage);
            kvp.SetColour("ambient_colour", AmbientColour);
            kvp.SetColour("light_colour", LightColour);
            kvp.SetVector("light_direction", LightDirection);
            kvp.SetColour("light2_colour", Light2Colour);
            kvp.SetVector("light2_direction", Light2Direction);

            kvp.Set("model", ModelPath);
            kvp.Set("foreground_model", ModelPath);
            kvp.Set("animation", AnimPath);

            kvp.Set("render_pass", RenderPass);
            kvp.Set("foreground_render_pass", ForegroundRenderPass);
            kvp.Set("cast_shaows", CastShadows);

            kvp.Save(writer);
        }
Esempio n. 9
0
        public static int Update(this SqlConnection connection, string table, KeyValuePairs kvs, MySearchUtil util = null, SqlTransaction trans = null)
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                throw new ArgumentNullException(nameof(table), "数据表不能为空");
            }
            if (kvs == null || kvs.Any(kv => kv.Key == "Id"))
            {
                throw new ArgumentNullException(nameof(kvs), "要更新的列不能为空,并且不能包含Id列");
            }

            util = util ?? new MySearchUtil();

            var cols = string.Join(",", kvs.Where(kv => kv.Key != "Id").Select(kv => $"{kv.Key}=@{kv.Key}"));

            var where = util.GetWhere();
            var param = util.GetParam();

            var sql = $"UPDATE {table} SET {cols} WHERE {where}";

            return(connection.Execute(sql, param, trans));
        }
Esempio n. 10
0
    public void Config2Json()
    {
        List <KeyValueNode> nodeList = new List <KeyValueNode> ();

        foreach (var pairs in _settingDic)
        {
            KeyValueNode node = new KeyValueNode();
            node.Key   = pairs.Key;
            node.Value = pairs.Value;
            nodeList.Add(node);
        }
        KeyValuePairs _pairs = new KeyValuePairs();

        _pairs.ConfigInfoList = nodeList;

        string jsonStr = JsonUtility.ToJson(_pairs);

        SaveConfig(jsonStr);

        Debug.Log("Setting Changed");
        AssetDatabase.Refresh();
    }
Esempio n. 11
0
        /// <summary>
        /// 更新指定表的指定字段
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="table"></param>
        /// <param name="kvs"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int Update(this SqlConnection connection, string table, KeyValuePairs kvs, int id)
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                throw new ArgumentNullException(nameof(table), "数据表不能为空");
            }
            if (kvs == null || kvs.Any(kv => kv.Key == "Id"))
            {
                throw new ArgumentNullException(nameof(kvs), "要更新的列不能为空,且不能包含Id字段");
            }

            var columns = new List <string>();
            var param   = new DynamicParameters();

            param.Add("Id", id);
            foreach (var kv in kvs.Where(kv => kv.Key != "Id"))
            {
                columns.Add($"{kv.Key}=@{kv.Key}");
                param.Add(kv.Key, kv.Value);
            }
            var sql = $"UPDATE [{table}] SET {string.Join(",", columns)} WHERE Id=@Id";

            return(connection.Execute(sql, param));
        }
Esempio n. 12
0
        /// <summary>
        /// 更新同比环比数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Result UpdateLastData(int id)
        {
            var entity = Load(id);

            if (entity == null)
            {
                return(ResultUtil.AuthFail("请求的数据不存在"));
            }

            int lastMonthYear  = entity.Year;
            int lastMonthMonth = entity.Month;

            int lastYearYear  = entity.Year - 1;
            int lastYearMonth = entity.Month;

            if (lastMonthMonth == 1)
            {
                lastMonthMonth = 12;
                lastMonthYear  = lastMonthYear - 1;
            }
            else
            {
                lastMonthMonth = lastMonthMonth - 1;
            }

            KeyValuePairs kvs = new KeyValuePairs();

            kvs.Add(@"UPDATE Base_MonthReport SET LastMonthXY=(SELECT XY FROM Base_MonthReport WHERE SalerId=@SalerId AND Year=@Year AND Month=@Month) WHERE Id=@Id",
                    new { Id = id, Year = lastMonthYear, Month = lastMonthMonth, SalerId = entity.SalerId });
            kvs.Add(@"UPDATE Base_MonthReport SET LastYearXY=(SELECT XY FROM Base_MonthReport WHERE SalerId=@SalerId AND Year=@Year AND Month=@Month) WHERE Id=@Id",
                    new { Id = id, Year = lastYearYear, Month = lastYearMonth, SalerId = entity.SalerId });

            var result = db.ExecuteTran(kvs);

            return(result ? ResultUtil.Success() : ResultUtil.Fail());
        }
Esempio n. 13
0
 /// <summary>
 /// 执行一组带参数的sql语句
 /// </summary>
 /// <param name="sqls"></param>
 /// <returns></returns>
 public bool ExecuteTran(KeyValuePairs sqls)
 {
     using (var conn = GetConnection())
     {
         conn.Open();
         using (var tran = conn.BeginTransaction())
         {
             try
             {
                 foreach (var s in sqls)
                 {
                     conn.Execute(s.Key, s.Value, tran);
                 }
                 tran.Commit();
                 return(true);
             }
             catch
             {
                 tran.Rollback();
                 return(false);
             }
         }
     }
 }
Esempio n. 14
0
        private void Load(IFileStore store)
        {
            var kvp = new KeyValuePairs();

            using (var reader = store.OpenTextFile(m_path))
            {
                kvp.Load(reader);
            }

            if (kvp.Count == 0)
            {
                LegacyLoad(store);
            }
            else
            {
                // Read in the title and levels
                m_title = kvp.GetString("title", "Untitled Campaign");
                m_levels.AddRange(kvp.GetStringArray("levels", new string[0]));
                m_checkpoints.AddRange(kvp.GetIntegerArray("checkpoints", new int[0]));
                m_id = kvp.GetInteger("id", MathUtils.SimpleStableHash(m_path));
                m_initialLevelsUnlocked = kvp.GetInteger("initial_levels_unlocked", 1);
                m_hidden = kvp.GetBool("hidden", false);
            }
        }
Esempio n. 15
0
        public static int Update <T>(this SqlConnection connection, KeyValuePairs kvs, MySearchUtil util, SqlTransaction trans = null)
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Update(table, kvs, util, trans));
        }
Esempio n. 16
0
 public static string GetUpdateColumns(KeyValuePairs kvs)
 {
     return(string.Join(",", kvs.Where(kv => kv.Key != "Id").Select(kv => $"{kv.Key}=@{kv.Key}")));
 }
Esempio n. 17
0
 /// <summary>
 /// 是否包含主键
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool ContainsKey(Key key)
 {
     return(KeyValuePairs.ContainsKey(key));
 }
Esempio n. 18
0
 /// <summary>
 /// 清空
 /// </summary>
 public void Clear()
 {
     KeyValuePairs.Clear();
     ValueKeyPairs.Clear();
 }
 protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
 {
     KeyValuePairs.Add(new KeyValuePair <string, string>(name, value));
     return(true);
 }
Esempio n. 20
0
 public AttributesInfoDTO(KeyValuePairs pair)
 {
     Key   = pair.Key;
     Value = pair.Value;
 }
Esempio n. 21
0
 //ICipherisePayload
 public bool PayloadResponseFromApp(KeyValuePairs kvpGet)
 {
     //Payload retrieved from the Cipherise App.
     //Verify the data in kvpGet.
     return(true);
 }
 public ConveyorTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
 {
     PoweredMode   = kvp.GetEnum("powered_mode", ConveyorMode.Stopped);
     UnpoweredMode = kvp.GetEnum("unpowered_mode", ConveyorMode.Forwards);
     Animation     = kvp.GetString("animation", null);
 }
Esempio n. 23
0
 public Task<KeyValuePairs> GetInstitutions()
 {
     var func = new Func<KeyValuePairs>(() => {
         var request = new RestRequest("institutions", Method.GET);
         var response = Client.Execute(request);
         if (response.StatusCode != HttpStatusCode.OK) {
             throw new Exception(response.StatusDescription);
         }
         JsonObject[] institutions = JsonConvert.DeserializeObject<JsonObject[]>(response.Content);
         var kvp = new KeyValuePairs();
         foreach (JsonObject institution in institutions) {
             kvp.Add(institution["type"].ToString(), institution["name"].ToString());
         }
         return kvp;
     });
     return Task.Factory.StartNew(func);
 }
Esempio n. 24
0
        public bool OpenConnection(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                Logger.Log(this, "Unable to connect to the SQL database: No connection specified.", LogLevel.Error);
                return(false);
            }
            internalState         = ConnectionState.Connecting;
            connection            = PostgreSQLTools.CreateDataConnection(connectionString);
            internalState         = ConnectionState.Open;
            connection.OnClosing += (sender, args) => internalState = ConnectionState.Closed;
            connection.OnClosed  += (sender, args) => internalState = ConnectionState.Closed;
            metadata              = connection.GetTable <Metadata>();
            try
            {
                var version = from entry in metadata
                              where entry.Key == "version"
                              select entry.Value;

                var count = version.Count();
                if (count != 1)
                {
                    Logger.Log(this, "Zero or multiple 'version' entries found in the Metadata table. The database connection will be dropped.", LogLevel.Error);
                    HandleConnectionFailure();
                    return(false);
                }

                if (version.First() != Bot.DatabaseVersion)
                {
                    Logger.Log(this, $"Bot and database version do not match (bot is at {Bot.DatabaseVersion}, database is at {version.First()}). The database will now be upgraded.", LogLevel.Info);
                    if (!UpgradeDatabase(version.First()))
                    {
                        Logger.Log(this, "Upgrade failed. The database connection will be dropped.", LogLevel.Warning);
                        HandleConnectionFailure();
                        return(false);
                    }
                }
            }
            catch (NpgsqlException e)
            {
                if (e.Message.ToLower().Contains("metadata") && e.Message.ToLower().Contains("does not exist"))
                {
                    Logger.Log(this, "Metadata table not found. A new tableset will be created.", LogLevel.Warning);
                    try
                    {
                        DropTables();
                        CreateTables();
                    }
                    catch (NpgsqlException f)
                    {
                        Logger.Log(this, $"Unable to create a new tableset: An exception occurred({f.GetType()}: {f.Message}). The database connection will be dropped.", LogLevel.Error);
                        HandleConnectionFailure();
                        return(false);
                    }
                    AddMetadata();
                    Logger.Log(this, "Writing metadata...", LogLevel.Info);
                }
                else
                {
                    Logger.Log(this, $"Unable to retrieve the database version: An exception occurred ({e.GetType()}: {e.Message}). The database connection will be dropped.", LogLevel.Error);
                    HandleConnectionFailure();
                    return(false);
                }
            }

            //UserCredentials = connection.GetTable<UserCredential>();
            Quotes         = connection.GetTable <Quote>();
            UserStatistics = connection.GetTable <UserStatistic>();
            Emoticons      = connection.GetTable <UsedEmoticon>();
            KeyValuePairs  = connection.GetTable <KeyValuePair>();
            LinkedUrls     = connection.GetTable <LinkedUrl>();
            Users          = connection.GetTable <User>();
            Words          = connection.GetTable <UsedWord>();
            ChatLog        = connection.GetTable <ChatLog>();
            MiscData       = connection.GetTable <MiscData>();

            try
            {
                // These methods are actually not pure, because they'll throw an exception
                // if their backing database tables are not found. It's a bit of a hack,
                // but this is the easiest way to check whether those tables exist.

                // ReSharper disable ReturnValueOfPureMethodIsNotUsed
                //UserCredentials.FirstOrDefault();
                Quotes.FirstOrDefault();
                UserStatistics.FirstOrDefault();
                Emoticons.FirstOrDefault();
                KeyValuePairs.FirstOrDefault();
                LinkedUrls.FirstOrDefault();
                Users.FirstOrDefault();
                Words.FirstOrDefault();
                ChatLog.FirstOrDefault();
                MiscData.FirstOrDefault();
                // ReSharper restore ReturnValueOfPureMethodIsNotUsed
            }
            catch (Exception e)
            {
                Logger.Log(this, $"Database integrity check failed ({e.GetType().Name}: {e.Message})", LogLevel.Error);
                HandleConnectionFailure();
                return(false);
            }

            return(true);
        }
 public ExtensionTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
 {
 }
Esempio n. 26
0
        // Copies the values in this Hashtable to an KeyValuePairs array.
        // KeyValuePairs is different from Dictionary Entry in that it has special
        // debugger attributes on its fields.

        internal virtual KeyValuePairs[] ToKeyValuePairsArray()
        {

            KeyValuePairs[] array = new KeyValuePairs[count];
            int index = 0;
            bucket[][] lbuckets = buckets;
            for (int i = lbuckets.Length; --i >= 0; )
            {
                for (int j = buckets[i].Length; --j >= 0; )
                {
                    Object keyv = lbuckets[i][j].key;
                    if ((keyv != null) && (keyv != buckets))
                    {
                        array[index++] = new KeyValuePairs(keyv, lbuckets[i][j].val);
                    }
                }
            }

            return array;
        }
Esempio n. 27
0
 public TelepadTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
 {
     Colour    = kvp.GetString("colour", "green");
     Animation = kvp.GetString("animation", null);
     PFX       = kvp.GetString("pfx", null);
 }
Esempio n. 28
0
        public static int Update <T>(this SqlConnection connection, int[] ids, KeyValuePairs kvs, SqlTransaction tran = null) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Update(table, kvs, ids));
        }
Esempio n. 29
0
 //ICipherisePayload
 public void PayloadToSend(ref KeyValuePairs kvpSet, ref string[] astrGetKeys)
 {
     //Payload to send to the Cipherise App.
 }
Esempio n. 30
0
 public AnimSet(string path, IFileStore store)
 {
     m_path = path;
     m_kvp  = new KeyValuePairs();
     Load(store);
 }
Esempio n. 31
0
 public override void VisitKeyValue(object key, object value, int depth)
 {
     base.VisitKeyValue(key, value, depth);
     KeyValuePairs.Add(String.Format("{0} = {1}", Values[Values.Count - 2], Values[Values.Count - 1]));
 }
Esempio n. 32
0
 public void SetServerData(KeyValuePairs data)
 {
     serverData = SetData(serverData, data);
 }