Пример #1
0
        public Membership AddMember(string groupID, string userid, string role = "user")
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
                if (user == null)
                {
                    throw new UserNotFoundException(userid);
                }

                if (user.IsRobot == true)
                {
                    throw new UpdateRobotMembershipException();
                }

                Membership member = _gorillaCtx.Memberships.Where(m => m.GroupID == groupID && m.MemberID == userid).FirstOrDefault();
                if (member == null)
                {
                    member          = new Membership();
                    member.GroupID  = groupID;
                    member.MemberID = user.Userid;
                    member.Role     = role;
                    _gorillaCtx.Memberships.Add(member);

                    _gorillaCtx.SaveChanges();
                }
                else
                {
                    member.Role = "user";
                    _gorillaCtx.SaveChanges();
                }

                return(member);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        public Group CreateGroup(string creater, string groupID, string displayName, string description, bool isOpen)
        {
            if (!Utils.IsValidID(groupID))
            {
                throw new InvalidIDException();
            }

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group group = GetGroupByID(groupID);
                if (group != null)
                {
                    throw new GroupAlreadyExistException(groupID);
                }

                //add group
                group             = new Group();
                group.GroupID     = groupID;
                group.DisplayName = displayName;
                group.Description = description;
                group.IsOpen      = isOpen;
                _gorillaCtx.Groups.Add(group);
                //add creater as default admin
                Membership member = new Membership();
                member.GroupID  = groupID;
                member.MemberID = creater;
                member.Role     = "admin";
                _gorillaCtx.Memberships.Add(member);

                _gorillaCtx.SaveChanges();
                return(group);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        public Category CreateCategory(string name, string groupID, string creater, string description = null)
        {
            if (!Utils.IsValidID(name))
            {
                throw new InvalidIDException(name, "name");
            }

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Category category = GetCategory(name, groupID, _gorillaCtx);
                if (category != null)
                {
                    throw new CategoryAlreadyExistException(name, groupID);
                }

                category                 = new Category();
                category.Name            = name;
                category.GroupID         = groupID;
                category.Creater         = creater;
                category.CreateTimestamp = DateTime.UtcNow;
                category.Description     = description;

                _gorillaCtx.Categories.Add(category);
                _gorillaCtx.SaveChanges();
                return(category);
            }
        }
Пример #6
0
 public void clearAtlineNotifCount(string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         NotificationCount notif = FindUserNotif(userid, _gorillaCtx);
         notif.UnreadAtlineMsgCount = 0;
         _gorillaCtx.SaveChanges();
     }
 }
Пример #7
0
 public void Remove(string userid, int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         List <FavouriteTopic> finds = _gorillaCtx.FavouriteTopics.Where(f => f.Userid.Equals(userid) && f.TopicID == topicID).ToList();
         _gorillaCtx.FavouriteTopics.RemoveRange(finds);
         _gorillaCtx.SaveChanges();
     }
 }
Пример #8
0
 public Topic AddTopic(Topic topic)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         topic = _gorillaCtx.Topics.Add(topic);
         _gorillaCtx.SaveChanges();
         return(topic);
     }
 }
Пример #9
0
 public void incrementImportantMsgCount(string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         NotificationCount notif = FindUserNotif(userid, _gorillaCtx);
         notif.UnreadImportantMsgCount++;
         _gorillaCtx.SaveChanges();
     }
 }
Пример #10
0
 public void PostSchema(Schema schema)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         if (Contain(schema.SchemaID))
         {
             throw new SchemaAlreadyExistException();
         }
         _gorillaCtx.Schemata.Add(schema);
         _gorillaCtx.SaveChanges();
     }
 }
Пример #11
0
 public void incrementTopicCount(int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         Topic topic = FindTopic(topicID, _gorillaCtx);
         if (topic != null)
         {
             topic.MsgCount++;
             _gorillaCtx.SaveChanges();
         }
     }
 }
Пример #12
0
 public void clearUnreadMsgCountOfFavouriteTopic(string userid, int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         FavouriteTopic ftopic = _gorillaCtx.FavouriteTopics.Where(f => f.Userid.Equals(userid) && f.TopicID == topicID).FirstOrDefault();
         if (ftopic != null)
         {
             ftopic.UnreadMsgCount = 0;
             _gorillaCtx.SaveChanges();
         }
     }
 }
Пример #13
0
        public DisplayMetricChart RemoveDataSet(string name, int datasetID)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Chart_DataSet dataset = _gorillaCtx.Chart_DataSet.Where(
                    c => c.MetricChartName == name && c.MetricDataSetID == datasetID
                    ).FirstOrDefault();

                _gorillaCtx.Chart_DataSet.Remove(dataset);
                _gorillaCtx.SaveChanges();
                return(_gorillaCtx.MetricCharts.Find(name));
            }
        }
Пример #14
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();
            }
        }
Пример #15
0
        public void SetDefaultGroup(string groupID, string userid)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
                if (user == null)
                {
                    throw new UserNotFoundException(userid);
                }

                user.DefaultGroup = groupID;
                _gorillaCtx.SaveChanges();
            }
        }
Пример #16
0
 public Membership UpdateMembership(string groupID, string admin, string userid, string role)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         Membership member = CheckMembership(groupID, userid, _gorillaCtx);
         if ("robot".Equals(member.Role))
         {
             throw new UpdateRobotMembershipException();
         }
         member.Role = role;
         _gorillaCtx.SaveChanges();
         return(member);
     }
 }
Пример #17
0
 public SchemaManager()
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         Schema defaultSchema = _gorillaCtx.Schemata.Find("none");
         if (defaultSchema == null)
         {
             defaultSchema               = new Schema();
             defaultSchema.SchemaID      = "none";
             defaultSchema.SchemaContent = "";
             _gorillaCtx.Schemata.Add(defaultSchema);
             _gorillaCtx.SaveChanges();
         }
     }
 }
Пример #18
0
 public void AddFavouriteTopic(string userid, int topicID)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         if (_gorillaCtx.FavouriteTopics.Where(f => f.Userid.Equals(userid) && f.TopicID == topicID).Count() == 0)
         {
             FavouriteTopic ftopic = new FavouriteTopic();
             ftopic.TopicID        = topicID;
             ftopic.Userid         = userid;
             ftopic.UnreadMsgCount = 0;
             _gorillaCtx.FavouriteTopics.Add(ftopic);
             _gorillaCtx.SaveChanges();
         }
     }
 }
Пример #19
0
        public NotificationCount FindUserNotif(string userid, MSGorillaEntities _gorillaCtx)
        {
            NotificationCount notifCount = _gorillaCtx.NotificationCounts.Find(userid);

            if (notifCount == null)
            {
                notifCount        = new NotificationCount();
                notifCount.Userid = userid;
                notifCount.UnreadAtlineMsgCount    = notifCount.UnreadHomelineMsgCount = 0;
                notifCount.UnreadOwnerlineMsgCount = notifCount.UnreadReplyCount = 0;

                notifCount = _gorillaCtx.NotificationCounts.Add(notifCount);
                _gorillaCtx.SaveChanges();
            }
            return(notifCount);
        }
Пример #20
0
 public void DeleteUser(string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
         if (user != null)
         {
             _gorillaCtx.UserProfiles.Remove(user);
             _gorillaCtx.SaveChanges();
         }
         else
         {
             throw new UserNotFoundException(userid);
         }
     }
 }
Пример #21
0
        //WossTableLogger
        private static void LogError(Object exception)
        {
            AWException excep = exception as AWException;

            if (file != null)
            {
                file.WriteLine(JsonConvert.SerializeObject(excep));
                file.Flush();
            }

            using (var ctx = new MSGorillaEntities())
            {
                ctx.AWExceptions.Add(excep);
                ctx.SaveChanges();
            }
        }
Пример #22
0
        public DisplayMetricChart CreateChart(string name, string group, string title, string subtitle = null)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                MetricChart chart = new MetricChart();
                chart.Name     = name;
                chart.GroupID  = group;
                chart.Title    = title;
                chart.SubTitle = subtitle;

                _gorillaCtx.MetricCharts.Add(chart);
                _gorillaCtx.SaveChanges();

                return(chart);
            }
        }
Пример #23
0
        public void LeaveGroup(string userid, string groupID)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                foreach (var member in _gorillaCtx.Memberships.Where(f => f.MemberID == userid && f.GroupID == groupID))
                {
                    _gorillaCtx.Memberships.Remove(member);
                }

                UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
                if (user.DefaultGroup.Equals(groupID, StringComparison.InvariantCultureIgnoreCase))
                {
                    user.DefaultGroup = "microsoft";
                }
                _gorillaCtx.SaveChanges();
            }
        }
Пример #24
0
 public void RemoveMember(string groupID, string admin, string userid)
 {
     using (var _gorillaCtx = new MSGorillaEntities())
     {
         Membership member = _gorillaCtx.Memberships.SqlQuery(
             "select * from membership where groupid={0} and memberid={1}",
             groupID,
             userid).FirstOrDefault();
         if (member != null)
         {
             _gorillaCtx.Memberships.Remove(member);
             UserProfile removedUser = _gorillaCtx.UserProfiles.Find(userid);
             removedUser.DefaultGroup = "microsoft";
         }
         _gorillaCtx.SaveChanges();
     }
 }
Пример #25
0
        public Group UpdateGroup(string admin, Group group)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group groupUpdate = _gorillaCtx.Groups.Find(group.GroupID);
                if (groupUpdate == null)
                {
                    throw new GroupNotExistException();
                }
                groupUpdate.Description = group.Description;
                groupUpdate.DisplayName = group.DisplayName;
                groupUpdate.IsOpen      = group.IsOpen;

                _gorillaCtx.SaveChanges();
                return(groupUpdate);
            }
        }
Пример #26
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();
            }
        }
Пример #27
0
        public UserProfile AddUser(UserProfile user)
        {
            if (!Utils.IsValidID(user.Userid))
            {
                throw new InvalidIDException("User");
            }

            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile temp = _gorillaCtx.UserProfiles.Find(user.Userid);
                if (temp != null)
                {
                    throw new UserAlreadyExistException(user.Userid);
                }
                user.MessageCount = 0;
                _gorillaCtx.UserProfiles.Add(user);
                _gorillaCtx.SaveChanges();
                return(user);
            }
        }
Пример #28
0
        public Membership JoinGroup(string userid, string groupID)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                Group group = GetGroupByID(groupID, _gorillaCtx);
                if (group == null)
                {
                    throw new GroupNotExistException();
                }

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

                if (user.IsRobot)
                {
                    throw new UpdateRobotMembershipException();
                }

                Membership member = _gorillaCtx.Memberships.SqlQuery(
                    "select * from membership where groupid={0} and memberid={1}",
                    groupID,
                    userid).FirstOrDefault();

                if (member != null)
                {
                    return(member);
                }

                member          = new Membership();
                member.GroupID  = groupID;
                member.MemberID = userid;
                member.Role     = group.IsOpen ? "user" : "pending";
                _gorillaCtx.Memberships.Add(member);
                _gorillaCtx.SaveChanges();

                return(member);
            }
        }
Пример #29
0
        public UserProfile UpdateUser(UserProfile user)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile originUser = _gorillaCtx.UserProfiles.Find(user.Userid);
                if (originUser == null)
                {
                    throw new UserNotFoundException(user.Userid);
                }

                originUser.Password     = user.Password;
                originUser.DisplayName  = user.DisplayName;
                originUser.Description  = user.Description;
                originUser.PortraitUrl  = user.PortraitUrl;
                originUser.MessageCount = user.MessageCount;

                _gorillaCtx.SaveChanges();

                return(_gorillaCtx.UserProfiles.Find(user.Userid));
            }
        }
Пример #30
0
        public UserProfile CreateGroupRobotAccount(string groupID, string admin, UserProfile robot)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                robot.IsRobot = true;
                try
                {
                    new AccountManager().AddUser(robot);
                }
                catch (UpdateRobotMembershipException e) { }

                Membership member = new Membership();
                member.GroupID  = groupID;
                member.MemberID = robot.Userid;
                member.Role     = "robot";
                _gorillaCtx.Memberships.Add(member);

                _gorillaCtx.SaveChanges();

                return(robot);
            }
        }