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); } }
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); } }
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); } }
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); } }
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); } }
public void clearAtlineNotifCount(string userid) { using (var _gorillaCtx = new MSGorillaEntities()) { NotificationCount notif = FindUserNotif(userid, _gorillaCtx); notif.UnreadAtlineMsgCount = 0; _gorillaCtx.SaveChanges(); } }
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(); } }
public Topic AddTopic(Topic topic) { using (var _gorillaCtx = new MSGorillaEntities()) { topic = _gorillaCtx.Topics.Add(topic); _gorillaCtx.SaveChanges(); return(topic); } }
public void incrementImportantMsgCount(string userid) { using (var _gorillaCtx = new MSGorillaEntities()) { NotificationCount notif = FindUserNotif(userid, _gorillaCtx); notif.UnreadImportantMsgCount++; _gorillaCtx.SaveChanges(); } }
public void PostSchema(Schema schema) { using (var _gorillaCtx = new MSGorillaEntities()) { if (Contain(schema.SchemaID)) { throw new SchemaAlreadyExistException(); } _gorillaCtx.Schemata.Add(schema); _gorillaCtx.SaveChanges(); } }
public void incrementTopicCount(int topicID) { using (var _gorillaCtx = new MSGorillaEntities()) { Topic topic = FindTopic(topicID, _gorillaCtx); if (topic != null) { topic.MsgCount++; _gorillaCtx.SaveChanges(); } } }
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(); } } }
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)); } }
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(); } }
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(); } }
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); } }
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(); } } }
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(); } } }
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); }
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); } } }
//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(); } }
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); } }
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(); } }
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(); } }
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); } }
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(); } }
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); } }
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); } }
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)); } }
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); } }