示例#1
0
        public List <CounterRecord> GetCounterRecords(string name, string groupID, int start = 0, int end = -1)
        {
            string query = TableQuery.CombineFilters(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, ToRecordPK(groupID, name)),
                TableOperators.And,
                TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, ToRecordRK(start))
                );

            if (end > 0)
            {
                query = TableQuery.CombineFilters(
                    query,
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, ToRecordRK(end))
                    );
            }

            TableQuery <DynamicTableEntity> q       = new TableQuery <DynamicTableEntity>().Where(query);
            List <CounterRecord>            records = new List <CounterRecord>();

            foreach (var entity in _counterRecord.ExecuteQuery(q))
            {
                records.Add(CounterRecordHelper.ParseEntity(entity));
            }
            return(records);
        }
示例#2
0
        public DisplayCounterRecords GetLatestCounterRecord(string path, string name, string group = null, int count = 30)
        {
            string me = whoami();

            if (string.IsNullOrEmpty(group))
            {
                group = MembershipHelper.DefaultGroup(me);
            }
            else
            {
                MembershipHelper.CheckMembership(group, me);
            }

            CounterSet counterSet = _counterManager.GetCounterSet(group, name);

            if (counterSet == null)
            {
                throw new CounterSetNotFoundException();
            }

            int start = counterSet.RecordCount - count > 0 ? counterSet.RecordCount - count : 0;
            List <DisplayRecord> records = new List <DisplayRecord>();

            foreach (var record in _counterManager.GetCounterRecords(name, group, start))
            {
                DisplayRecord rec = new DisplayRecord(record.Key, CounterRecordHelper.GetValue(record, path));
                records.Add(rec);
            }

            return(new DisplayCounterRecords(name, group, path, start, records));
        }
示例#3
0
        public CounterRecord GetSingleCounterRecord(string groupID, string name, int number = 0)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve(
                ToRecordPK(groupID, name),
                ToRecordRK(number));

            return(CounterRecordHelper.ParseEntity(
                       _counterRecord.ExecuteRetriveOperation(retrieveOperation).Result as DynamicTableEntity
                       ));
        }
示例#4
0
        public void InsertCounterRecord(CounterRecord record, string name, string groupID)
        {
            int id;
            DynamicTableEntity entity = CounterRecordHelper.ToTableEntity(record, "pk", "rk");

            int loopCount = 0;

            while (true)
            {
                try
                {
                    CounterSetEntity counterSet = GetCounterSet(groupID, name);
                    if (counterSet == null)
                    {
                        throw new CounterSetNotFoundException();
                    }

                    id = counterSet.RecordCount;
                    counterSet.RecordCount++;

                    TableOperation updateOperation = TableOperation.InsertOrReplace(counterSet);
                    _counterSet.Execute(updateOperation);

                    break;
                }
                catch (Exception e)
                {
                    loopCount++;
                    if (loopCount >= 100)
                    {
                        throw e;
                    }
                }
            }

            entity.PartitionKey = ToRecordPK(groupID, name);
            entity.RowKey       = ToRecordRK(id);
            TableOperation insertOperation = TableOperation.Insert(entity);

            _counterRecord.Execute(insertOperation);
        }
示例#5
0
        public DisplayCounterChart GetCounterChart(string path, string name, string group = null)
        {
            string me = whoami();

            if (string.IsNullOrEmpty(group))
            {
                group = MembershipHelper.DefaultGroup(me);
            }
            else
            {
                MembershipHelper.CheckMembership(group, me);
            }

            CounterSet cs = _counterManager.GetCounterSet(group, name);

            if (cs == null)
            {
                throw new CounterSetNotFoundException();
            }

            CounterRecord record = _counterManager.GetSingleCounterRecord(group, name, cs.RecordCount - 1);

            CounterRecord.ComplexValue cv = CounterRecordHelper.Get(record, path);
            if (cv == null)
            {
                return(null);
            }

            DisplayCounterChart dcc = new DisplayCounterChart();

            dcc.Title          = cv.Name;
            dcc.MainCounter    = new DisplayCounter(path, cv.Type);
            dcc.RelatedCounter = new List <DisplayCounter>();
            foreach (var value in cv.RelatedValues)
            {
                dcc.RelatedCounter.Add(new DisplayCounter(string.Format("{0}.{1}", path, value.Name), value.Type));
            }

            return(dcc);
        }
示例#6
0
        public DisplayCounterRecords GetCounterRecord(string path, string name, string group = null, int start = 0, int end = -1)
        {
            string me = whoami();

            if (string.IsNullOrEmpty(group))
            {
                group = MembershipHelper.DefaultGroup(me);
            }
            else
            {
                MembershipHelper.CheckMembership(group, me);
            }

            List <DisplayRecord> records = new List <DisplayRecord>();

            foreach (var record in _counterManager.GetCounterRecords(name, group, start, end))
            {
                DisplayRecord rec = new DisplayRecord(record.Key, CounterRecordHelper.GetValue(record, path));
                records.Add(rec);
            }

            return(new DisplayCounterRecords(name, group, path, start, records));
        }