コード例 #1
0
ファイル: Database.cs プロジェクト: xhydongda/Easydata
        public Dictionary <ulong, ClockValues> Read(List <ulong> sids, long start, long end)
        {
            if (_State != DatabaseState.Opened || sids == null || sids.Count == 0)
            {
                return(null);
            }
            Dictionary <int, List <ulong> > rp_sids = new Dictionary <int, List <ulong> >();

            lock (lockthis)
            {
                foreach (KeyValuePair <int, RP> pair in _RPs)
                {
                    foreach (ulong sid in sids)
                    {
                        if (pair.Value.ContainsSid(sid))
                        {
                            int days = pair.Key;
                            if (!rp_sids.ContainsKey(days))
                            {
                                rp_sids.Add(days, new List <ulong>());
                            }
                            rp_sids[days].Add(sid);
                        }
                    }//按rp分组
                }
            }
            Dictionary <ulong, ClockValues> result = new Dictionary <ulong, ClockValues>();

            foreach (KeyValuePair <int, List <ulong> > pair in rp_sids)
            {
                RP rp = null;
                lock (lockthis)
                {
                    if (_RPs.ContainsKey(pair.Key))
                    {
                        rp = _RPs[pair.Key];
                    }
                    else
                    {
                        continue;
                    }
                }
                Dictionary <ulong, ClockValues> lst = rp.Read(pair.Value, start, end);
                if (lst != null)
                {
                    foreach (KeyValuePair <ulong, ClockValues> item in lst)
                    {
                        if (!result.ContainsKey(item.Key))
                        {
                            result.Add(item.Key, item.Value);
                        }
                        else
                        {
                            result[item.Key].AddRange(item.Value);
                        }
                    }
                }
            }//写入对应rp
            return(result);
        }
コード例 #2
0
 public Shard(RP rp, ulong id, long start, long end)
 {
     RP      = rp;
     ID      = id;
     Start   = start;
     End     = end;
     Path    = string.Format("{0}{1}\\", rp.Path, id);
     WalPath = Path;
 }
コード例 #3
0
ファイル: Database.cs プロジェクト: xhydongda/Easydata
 /// <summary>
 /// 注册sids,只有注册后的数据点才能读写.
 /// </summary>
 /// <param name="sids">[Sid]</param>
 /// <param name="days">存储时限</param>
 /// <returns>注册成功的sid数量</returns>
 public int AddSids(List <ulong> sids, int days)
 {
     lock (lockthis)
     {
         if (_RPs.ContainsKey(days))
         {
             return(_RPs[days].AddSids(sids));
         }
         else
         {
             RP newrp = new RP(days, this);
             _RPs[days] = newrp;
             info.RPs.Add(days);
             save();
             return(newrp.AddSids(sids));
         }
     }
 }
コード例 #4
0
ファイル: Database.cs プロジェクト: xhydongda/Easydata
        //从配置文件中加载rp列表.
        private void load()
        {
            string str = _Path + config_file;

            if (File.Exists(str))
            {
                using (StreamReader sr = new StreamReader(str))
                {
                    string json = sr.ReadToEnd();
                    info = JsonConvert.DeserializeObject <DatabaseInfo>(json);
                }
                foreach (int days in info.RPs)
                {
                    _RPs[days] = new RP(days, this);
                }
            }
            else
            {
                info = new DatabaseInfo();
            }
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: xhydongda/Easydata
        public int Write(Dictionary <ulong, ClockValues> points)
        {
            if (_State != DatabaseState.Opened || points == null || points.Count == 0)
            {
                return(0);
            }
            Dictionary <int, Dictionary <ulong, ClockValues> > rp_points = new Dictionary <int, Dictionary <ulong, ClockValues> >();

            lock (lockthis)
            {
                foreach (KeyValuePair <int, RP> pair in _RPs)
                {
                    foreach (KeyValuePair <ulong, ClockValues> sidvalues in points)
                    {
                        if (pair.Value.ContainsSid(sidvalues.Key))
                        {
                            int days = pair.Key;
                            if (!rp_points.ContainsKey(days))
                            {
                                rp_points.Add(days, new Dictionary <ulong, ClockValues>());
                            }
                            rp_points[days].Add(sidvalues.Key, sidvalues.Value);
                        }
                    }//按rp分组
                }
            }
            int result = 0;

            foreach (KeyValuePair <int, Dictionary <ulong, ClockValues> > pair in rp_points)
            {
                RP rp = null;
                lock (lockthis)
                {
                    rp = _RPs[pair.Key];
                }
                result += rp.Write(pair.Value);
            }//写入对应rp
            return(result);
        }