예제 #1
0
        public static void GetRow()
        {
            Console.WriteLine("Start get row...");
            // PrepareTable();
            OTSClient otsClient = Config.GetClient();

            // 定义行的主键,必须与创建表时的TableMeta中定义的一致
            PrimaryKey primaryKey = new PrimaryKey();

            primaryKey.Add("key", new ColumnValue("the key"));

            Stopwatch      stopwatch = Stopwatch.StartNew();
            GetRowRequest  request   = new GetRowRequest("tableName", primaryKey); // 未指定读哪列,默认读整行
            GetRowResponse response  = otsClient.GetRow(request);

            stopwatch.Stop();

            PrimaryKey       primaryKeyRead = response.PrimaryKey;
            AttributeColumns attributesRead = response.Attribute;

            Console.WriteLine("Primary key read: ");
            foreach (KeyValuePair <string, ColumnValue> entry in primaryKeyRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Attributes read: ");
            foreach (KeyValuePair <string, ColumnValue> entry in attributesRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Get row succeed.");
            Console.WriteLine(stopwatch.Elapsed);
        }
예제 #2
0
        public static void GetRow()
        {
            Console.WriteLine("Start get row...");
            PrepareTable();
            OTSClient otsClient = Config.GetClient();

            // 定义行的主键,必须与创建表时的TableMeta中定义的一致
            PrimaryKey primaryKey = new PrimaryKey
            {
                { Pk1, new ColumnValue(0) },
                { Pk2, new ColumnValue("abc") }
            };

            GetRowRequest    request        = new GetRowRequest(TableName, primaryKey); // 未指定读哪列,默认读整行
            GetRowResponse   response       = otsClient.GetRow(request);
            PrimaryKey       primaryKeyRead = response.PrimaryKey;
            AttributeColumns attributesRead = response.Attribute;

            Console.WriteLine("Primary key read: ");
            foreach (KeyValuePair <string, ColumnValue> entry in primaryKeyRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Attributes read: ");
            foreach (KeyValuePair <string, ColumnValue> entry in attributesRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Get row succeed.");
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="res"></param>
 /// <returns></returns>
 public static T ConvertTo <T>(GetRowResponse res)
 {
     if (res == null || res.PrimaryKey.Count == 0)
     {
         return(default(T));
     }
     try
     {
         var obj = System.Activator.CreateInstance <T>();
         foreach (KeyValuePair <string, ColumnValue> entry in res.PrimaryKey)
         {
             obj.SetProperty(entry.Key, entry.Value);
         }
         foreach (KeyValuePair <string, ColumnValue> entry in res.Attribute)
         {
             obj.SetProperty(entry.Key, entry.Value);
         }
         return(obj);
     }
     catch (EmptyPrimaryKeyException ex)
     {
         return(default(T));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #4
0
        public ActionResult SearchLocation()
        {
            OTSClient  _oTSClient = OTSHelper.GetOTSClientLocation(_tableStoreModel);
            PrimaryKey pk         = new PrimaryKey();

            pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"])));
            pk.Add("t", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["t"]))));
            GetRowRequest  getRowRequest      = new GetRowRequest("L_100000000", pk);
            GetRowResponse response           = _oTSClient.GetRow(getRowRequest);
            StringBuilder  sbAttributeColumns = new StringBuilder();

            foreach (var item in response.Attribute)
            {
                if (item.Key == "l")
                {
                    byte[] lbyte = item.Value.BinaryValue;
                    Dictionary <string, int> dictionary = ByteIntHelper.GetLocationByByte(lbyte);
                    foreach (var dic in dictionary)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                }
            }
            ViewData["pk"]  = "设备:" + Request.Form["d"] + " 时间:" + Request.Form["t"];
            ViewData["att"] = sbAttributeColumns.ToString();
            return(View("Search", ViewBag));
        }
예제 #5
0
        public static void GetRowWithFilter()
        {
            Console.WriteLine("Start get row with filter ...");
            PrepareTable();
            OTSClient otsClient = Config.GetClient();

            // 定义行的主键,必须与创建表时的TableMeta中定义的一致
            PrimaryKey primaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(0) },
                { "pk1", new ColumnValue("abc") }
            };

            var rowQueryCriteria = new SingleRowQueryCriteria(TableName)
            {
                RowPrimaryKey = primaryKey
            };

            // 只返回col0的值等于5的行或者col1不等于ff的行
            var filter1 = new RelationalCondition("col0",
                                                  CompareOperator.EQUAL,
                                                  new ColumnValue(5));

            var filter2 = new RelationalCondition("col1", CompareOperator.NOT_EQUAL, new ColumnValue("ff"));

            var filter = new CompositeCondition(LogicOperator.OR);

            filter.AddCondition(filter1);
            filter.AddCondition(filter2);

            rowQueryCriteria.Filter = filter.ToFilter();
            rowQueryCriteria.AddColumnsToGet("col0");
            rowQueryCriteria.AddColumnsToGet("col1");

            GetRowRequest request = new GetRowRequest(rowQueryCriteria);

            // 查询
            GetRowResponse   response       = otsClient.GetRow(request);
            PrimaryKey       primaryKeyRead = response.PrimaryKey;
            AttributeColumns attributesRead = response.Attribute;

            Console.WriteLine("Primary key read: ");
            foreach (KeyValuePair <string, ColumnValue> entry in primaryKeyRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Attributes read: ");
            foreach (KeyValuePair <string, ColumnValue> entry in attributesRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Get row with filter succeed.");
        }
예제 #6
0
        public ActionResult SearchRoute()
        {
            OTSClient  _oTSClient = OTSHelper.GetOTSClientRoute(_tableStoreModel);
            PrimaryKey pk         = new PrimaryKey();

            pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"])));
            pk.Add("s", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["s"]))));
            GetRowRequest  getRowRequest      = new GetRowRequest("Route", pk);
            GetRowResponse response           = _oTSClient.GetRow(getRowRequest);
            StringBuilder  sbAttributeColumns = new StringBuilder();

            foreach (var item in response.Attribute)
            {
                switch (item.Key)
                {
                case "e":
                    sbAttributeColumns.Append(item.Key + ":" + item.Value.IntegerValue + "【" + TimeHelper.ConvertStringToDateTime(item.Value.IntegerValue.ToString()).ToString("yyyy-MM-dd HH:mm:ss fff") + "】;");
                    break;

                case "r":
                    byte[] lbyte = item.Value.BinaryValue;
                    Dictionary <string, int> dictionary = ByteIntHelper.GetRouteByByte(lbyte);
                    foreach (var dic in dictionary)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;

                case "ds":
                    byte[] ds = item.Value.BinaryValue;
                    Dictionary <string, int> dsDic = ByteIntHelper.GetDurationstatsByByte(ds);
                    foreach (var dic in dsDic)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;

                case "es":
                    byte[] es = item.Value.BinaryValue;
                    Dictionary <string, int> esDic = ByteIntHelper.GetEventStatsByByte(es);
                    foreach (var dic in esDic)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;
                }
            }
            ViewData["pk"]  = "设备:" + Request.Form["d"] + " 开始时间:" + Request.Form["s"];
            ViewData["att"] = sbAttributeColumns.ToString();
            return(View("Search", ViewBag));
        }
예제 #7
0
        public ActionResult SearchEvent()
        {
            OTSClient  _oTSClient = OTSHelper.GetOTSClientEvent(_tableStoreModel);
            PrimaryKey pk         = new PrimaryKey();

            pk.Add("d", new ColumnValue(Convert.ToInt64(Request.Form["d"])));
            pk.Add("et", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(Request.Form["et"]))));
            pk.Add("ei", new ColumnValue(ByteIntHelper.intToBytes2(Convert.ToInt64(Request.Form["ei"]), 1)));
            GetRowRequest  getRowRequest      = new GetRowRequest("E_100000000", pk);
            GetRowResponse response           = _oTSClient.GetRow(getRowRequest);
            StringBuilder  sbAttributeColumns = new StringBuilder();

            foreach (var item in response.Attribute)
            {
                switch (item.Key)
                {
                case "ep":
                    //事件参数字段暂不做处理
                    //byte[] ep = item.Value.BinaryValue;
                    break;

                case "t":
                    sbAttributeColumns.Append(item.Key + ":" + item.Value.IntegerValue + "【" + TimeHelper.ConvertStringToDateTime(item.Value.IntegerValue.ToString()).ToString("yyyy-MM-dd HH:mm:ss fff") + "】;");
                    break;

                case "l":
                    byte[] lbyte = item.Value.BinaryValue;
                    Dictionary <string, int> dictionary = ByteIntHelper.GetLocationByByte(lbyte);
                    foreach (var dic in dictionary)
                    {
                        sbAttributeColumns.Append(dic.Key + ":" + dic.Value + "; ");
                    }
                    break;
                }
            }

            ViewData["pk"]  = "设备:" + Request.Form["d"] + " 事件时间:" + Request.Form["et"] + " 事件ID:" + Request.Form["ei"];
            ViewData["att"] = sbAttributeColumns.ToString();
            return(View("Search", ViewBag));
        }