Example #1
0
        public MetricDataSet CreateDataSet(string creater, string instance, string counter, string category, string groupID, string description = null)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group group = _gorillaCtx.Groups.Find(groupID);
                if (group == null)
                {
                    throw new GroupNotExistException();
                }

                UserProfile user = _gorillaCtx.UserProfiles.Find(creater);
                if (user == null)
                {
                    throw new UserNotFoundException(creater);
                }

                MetricDataSet data = new MetricDataSet();
                data.Instance    = instance;
                data.Counter     = counter;
                data.Category    = category;
                data.GroupID     = group.GroupID;
                data.Description = description;
                data.Creater     = creater;
                data.RecordCount = 0;

                _gorillaCtx.MetricDataSets.Add(data);
                _gorillaCtx.SaveChanges();

                return(data);
            }
        }
Example #2
0
        public DisplayMetricChart AddDataSet(string name, int datasetID, string legend, string type)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                MetricChart chart = _gorillaCtx.MetricCharts.Find(name);
                if (chart == null)
                {
                    throw new MetricChartNotFoundException();
                }

                MetricDataSet data = _gorillaCtx.MetricDataSets.Find(datasetID);
                if (data == null)
                {
                    throw new MetricDataSetNotFoundException();
                }

                if (!chart.GroupID.Equals(data.GroupID, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new MetricGroupDismatchException();
                }
                Chart_DataSet dataset = new Chart_DataSet();
                dataset.MetricChartName = name;
                dataset.MetricDataSetID = datasetID;
                dataset.Legend          = legend;
                dataset.Type            = type;

                _gorillaCtx.Chart_DataSet.Add(dataset);
                _gorillaCtx.SaveChanges();
                return(dataset.MetricChart);
            }
        }
Example #3
0
 public MetricDataSet GetDataSet(int id)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         MetricDataSet dataset = _gorillaCtx.MetricDataSets.Find(id);
         return(dataset);
     }
 }
        public List <MetricRecord> RetriveDataRecord(int id, int startIndex, int endIndex)
        {
            MetricDataSet dataset = _metricManager.GetDataSet(id);

            MembershipHelper.CheckMembership(dataset.GroupID, whoami());

            return(_metricManager.RetriveDataRecord(dataset.Id, startIndex, endIndex));
        }
        public List <MetricRecord> RetriveLastestDataRecord(int id, int count = 30)
        {
            MetricDataSet dataset = _metricManager.GetDataSet(id);

            MembershipHelper.CheckMembership(dataset.GroupID, whoami());

            return(_metricManager.RetriveLastestDataRecord(dataset, count));
        }
        public ActionResult InsertRecord(int id, string key, double value)
        {
            MetricDataSet dataset = _metricManager.GetDataSet(id);

            MembershipHelper.CheckMembership(dataset.GroupID, whoami());

            _metricManager.AppendDataRecord(id, key, value.ToString());
            return(new ActionResult());
        }
Example #7
0
 public MetricDataSet GetDataSet(string instance, string counter, string category, string group)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         MetricDataSet dataset = _gorillaCtx.MetricDataSets.Where(
             d => d.Instance == instance && d.Counter == counter && d.Category == category && d.GroupID == group
             ).FirstOrDefault();
         return(dataset);
     }
 }
Example #8
0
        public List <MetricRecord> RetriveLastestDataRecord(MetricDataSet dataset, int count = 100)
        {
            int startIndex = dataset.RecordCount - count;
            int endIndex   = dataset.RecordCount - 1;

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            return(RetriveDataRecord(dataset.Id, startIndex, endIndex));
        }
        public ActionResult DeleteDataSet(int id)
        {
            MetricDataSet dataset = _metricManager.GetDataSet(id);
            string        me      = whoami();

            if (!me.Equals(dataset.Creater))
            {
                MembershipHelper.CheckAdmin(dataset.GroupID, me);
            }

            _metricManager.DeleteDataSet(id);
            return(new ActionResult());
        }
Example #10
0
        public void DeleteDataSet(int id)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                MetricDataSet data = _gorillaCtx.MetricDataSets.Find(id);
                if (data == null)
                {
                    throw new MetricDataSetNotFoundException();
                }

                _gorillaCtx.MetricDataSets.Remove(data);
                _gorillaCtx.SaveChanges();
            }
        }
Example #11
0
        public void AppendDataRecord(int id, string key, string value)
        {
            if (System.Text.UTF8Encoding.UTF8.GetByteCount(key) > MetricRecordKeyTooLongException.MaxKeyLengthInByte)
            {
                throw new MetricRecordKeyTooLongException();
            }

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                MetricDataSet data = _gorillaCtx.MetricDataSets.Find(id);
                if (data == null)
                {
                    throw new MetricDataSetNotFoundException();
                }

                MetricEntity mentity = null;
                if ((data.RecordCount % MetricEntity.MaxMetricRecord) == 0)
                {
                    //create a new entity
                    mentity = new MetricEntity(id.ToString(), data.RecordCount.ToString(RowKeyFormat));
                }
                else
                {
                    //retrive the last entity
                    TableResult result = _metricData.ExecuteRetriveOperation(
                        TableOperation.Retrieve <DynamicTableEntity>(
                            id.ToString(),
                            ((data.RecordCount / MetricEntity.MaxMetricRecord) * MetricEntity.MaxMetricRecord).ToString(RowKeyFormat)
                            )
                        );

                    mentity = new MetricEntity((DynamicTableEntity)result.Result);
                }

                //insert new data record
                mentity.Put(key, value, DateTime.UtcNow);
                TableOperation insertOperation = TableOperation.InsertOrReplace(mentity.ToITableEntity());
                _metricData.Execute(insertOperation);

                data.RecordCount++;
                _gorillaCtx.SaveChanges();
            }
        }