Example #1
0
        public void AddSourceArgPoint(int pointId, string text, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var point = ctx.ArgPoint.FirstOrDefault(ap => ap.Id == pointId);
                if (point == null)
                {
                    return;
                }

                var lastSrc = point.Description.Source.OrderBy(s => s.OrderNumber).LastOrDefault();

                int orderNumber = lastSrc != null ? lastSrc.OrderNumber + 1 : 1;

                var source = new Source
                {
                    OrderNumber = orderNumber,
                    RichText    = null,
                    Text        = text
                };
                point.Description.Source.Add(source);

                ctx.SaveChanges();
            }
        }
        public void Dispose()
        {
            if (_cachedEntity != null && _mediaStream != null)
            {
                // Get the new entity from the Entity Framework object state manager.
                ObjectStateEntry entry = this.context.ObjectStateManager.GetObjectStateEntry(_cachedEntity);

                if (entry.State == EntityState.Unchanged)
                {
                    {
                        var ctx = new DiscCtx(ConfigManager.ConnStr);
                        ctx.Attach(_cachedEntity);
                        _cachedEntity.MediaData.Data = _mediaStream.ToArray();
                        ctx.SaveChanges();
                    }
                }
                else
                {
                    // A problem must have occurred when saving the entity to the database,
                    // so we should delete the entity
                    var mediaData = _cachedEntity.MediaData;
                    _cachedEntity.MediaData = null;
                    var ctx = new DiscCtx(ConfigManager.ConnStr);
                    if (mediaData != null)
                    {
                        ctx.Attach(mediaData);
                        ctx.DeleteObject(mediaData);
                    }
                    ctx.Attach(_cachedEntity);
                    ctx.DeleteObject(_cachedEntity);

                    throw new DataServiceException("An error occurred. The media resource could not be saved.");
                }
            }
        }
Example #3
0
        public void AddComment(SComment comment)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var argPoint = ctx.ArgPoint.FirstOrDefault(ap => ap.Id == comment.ArgPointId);
                if (argPoint == null)
                {
                    return;
                }

                var person = ctx.Person.FirstOrDefault(ap => ap.Id == comment.PersonId);
                if (person == null)
                {
                    return;
                }

                var newComment = new Comment {
                    ArgPoint = argPoint, Person = person, Text = comment.Text
                };

                argPoint.Comment.Add(newComment);

                ctx.SaveChanges();
            }
        }
Example #4
0
 public bool MoveAttachmentDown(int attachmentId)
 {
     using (var ctx = new DiscCtx(ConfigManager.ConnStr))
     {
         var res = DAL.Helper.SwapAttachmentWithNeib(ctx, false, attachmentId);
         ctx.SaveChanges();
         return(res);
     }
 }
Example #5
0
 public bool MoveSourceDown(int sourceId)
 {
     using (var ctx = new DiscCtx(ConfigManager.ConnStr))
     {
         var res = DAL.Helper.SwapSourceWithNeib(ctx, false, sourceId);
         ctx.SaveChanges();
         return(res);
     }
 }
Example #6
0
        public static bool Log(DiscCtx ctx, StEvent e, int userId, int discussionId, int topicId, DeviceType devType)
        {
            var pers = ctx.Person.FirstOrDefault(p0 => p0.Id == userId);

            if (pers == null && userId != -1)
            {
                return(false);
            }

            var disc = ctx.Discussion.FirstOrDefault(d0 => d0.Id == discussionId);

            if (disc == null)
            {
                return(false);
            }

            var topic = ctx.Topic.FirstOrDefault(t0 => t0.Id == topicId);

            if (topic == null)
            {
                return(false);
            }

            if (!topic.Running && e != StEvent.RecordingStarted &&
                e != StEvent.RecordingStopped)
            {
                return(false);
            }

            var s = new StatsEvent
            {
                DiscussionId   = discussionId,
                DiscussionName = disc.Subject,
                TopicId        = topicId,
                TopicName      = topic.Name,
                UserId         = userId
            };

            if (pers != null)
            {
                s.UserName = pers.Name;
            }
            else
            {
                s.UserName = "******";
            }
            s.Event      = (int)e;
            s.Time       = DateTime.Now;
            s.DeviceType = (int)devType;

            ctx.AddToStatsEvent(s);
            ctx.SaveChanges();

            return(true);
        }
Example #7
0
        protected override void Setup()
        {
            base.Setup();

            var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);

            foreach (var p in ctx.Person)
            {
                p.Online = false;
            }
            ctx.SaveChanges();
        }
Example #8
0
        public void RemoveComment(int commentId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var dbComment = ctx.Comment.FirstOrDefault(c => c.Id == commentId);
                if (dbComment == null)
                {
                    return;
                }

                ctx.DeleteObject(dbComment);
                ctx.SaveChanges();
            }
        }
Example #9
0
        public void ChangeCommentText(int commentId, string newText)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var dbComment = ctx.Comment.FirstOrDefault(c => c.Id == commentId);
                if (dbComment == null)
                {
                    return;
                }

                if (newText != dbComment.Text)
                {
                    dbComment.Text = newText;
                    ctx.SaveChanges();
                }
            }
        }
Example #10
0
        public void AddAttachmentToDiscussion(int discussionId, SInAttachment attachment, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var discussion = ctx.Discussion.FirstOrDefault(d => d.Id == discussionId);
                if (discussion == null)
                {
                    return;
                }

                DAL.Helper.AddAttachment(ctx, argPoint: null,
                                         discussion: discussion, personWithAvatar: null,
                                         attachment: attachment,
                                         callerId: callerId);

                ctx.SaveChanges();
            }
        }
Example #11
0
        public void AddAttachmentToOwnAvatar(SInAttachment attachment, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var avatarOwner = ctx.Person.FirstOrDefault(p => p.Id == callerId);
                if (avatarOwner == null)
                {
                    return;
                }

                DAL.Helper.AddAttachment(ctx, argPoint: null,
                                         discussion: null, personWithAvatar: avatarOwner,
                                         attachment: attachment,
                                         callerId: callerId);

                ctx.SaveChanges();
            }
        }
Example #12
0
        public void AddAttachmentToPoint(int pointId, SInAttachment attachment, int callerId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var point = ctx.ArgPoint.FirstOrDefault(ap => ap.Id == pointId);
                if (point == null)
                {
                    return;
                }

                DAL.Helper.AddAttachment(ctx, argPoint: point,
                                         discussion: null, personWithAvatar: null,
                                         attachment: attachment,
                                         callerId: callerId);

                ctx.SaveChanges();
            }
        }
        public static ScreenshotResponse Read(Dictionary <byte, object> par)
        {
            var res = new ScreenshotResponse();

            res.screenshots = new Dictionary <int, byte[]>();
            using (var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr))
            {
                var shapeIds = (int[])par[(byte)DiscussionParamKey.ArrayOfInts];
                for (int i = 0; i < shapeIds.Length; i++)
                {
                    int mediaId     = (int)par[(byte)i];
                    var mediaEntity = ctx.MediaDataSet.Single(m => m.Id == mediaId);
                    res.screenshots.Add(shapeIds[i], mediaEntity.Data);
                    ctx.DeleteObject(mediaEntity);
                }
                ctx.SaveChanges(); //deleted entities
                return(res);
            }
        }
Example #14
0
        public void RemoveAttachment(int attachmentId)
        {
            using (var ctx = new DiscCtx(ConfigManager.ConnStr))
            {
                var attachment = ctx.Attachment.FirstOrDefault(at => at.Id == attachmentId);
                if (attachment == null)
                {
                    return;
                }

                if (attachment.MediaData != null)
                {
                    ctx.DeleteObject(attachment.MediaData);
                }
                ctx.DeleteObject(attachment);

                ctx.SaveChanges();
            }
        }
Example #15
0
        private void ChangeDbOnlineStatus(int dbId, bool online, int deviceType)
        {
            lock (DbInstancesOnline)
            {
                if (online)
                {
                    if (!DbInstancesOnline.ContainsKey(dbId))
                    {
                        DbInstancesOnline.Add(dbId, 1);
                    }
                    else
                    {
                        DbInstancesOnline[dbId] = DbInstancesOnline[dbId] + 1;
                    }
                }
                else
                {
                    if (!DbInstancesOnline.ContainsKey(dbId))
                    {
                        DbInstancesOnline.Add(dbId, 0);
                    }
                    else
                    {
                        DbInstancesOnline[dbId] = DbInstancesOnline[dbId] - 1;
                    }
                }

                var    ctx = new DiscCtx(Discussions.ConfigManager.ConnStr);
                Person p   = ctx.Person.FirstOrDefault(p0 => p0.Id == _dbId);
                if (p != null)
                {
                    p.Online = DbInstancesOnline[dbId] > 0;
                    if (online)
                    {
                        //only change dev type if user goes online
                        p.OnlineDevType = deviceType;
                    }
                    ctx.SaveChanges();
                    broadcastOnlineListChanged();
                }
            }
        }
Example #16
0
        public void CheckPersist()
        {
            if (!_pendingChanges)
            {
                return;
            }
            _pendingChanges = false;

            using (var dbCtx = new DiscCtx(Discussions.ConfigManager.ConnStr))
            {
                var topic  = dbCtx.Topic.FirstOrDefault(t0 => t0.Id == _topicId);
                var str    = new MemoryStream();
                var writer = new BinaryWriter(str);
                if (this.Write(writer))
                {
                    topic.Annotation = str.ToArray();
                    dbCtx.SaveChanges();
                }
            }
        }
        //all the changes will be cached locally without refreshing/redropping the context
        public static void pushDismissal(ArgPoint ap, DiscCtx ctx)
        {
            var persId = SessionInfo.Get().person.Id;

            var apId = ap.Id;

            ap = ctx.ArgPoint.Single(ap0 => ap0.Id == apId);

            foreach (var c in ap.Comment)
            {
                //skip "new comment"
                if (c.Person == null)
                {
                    continue;
                }

                var existing = c.ReadEntry.FirstOrDefault(re => re.Person.Id == persId);
                if (existing == null)
                {
                    var entry = new CommentPersonReadEntry
                    {
                        Comment = c,
                        Person  = ctx.Person.Single(p => p.Id == persId)
                    };
                    ctx.AddToCommentPersonReadEntry(entry);
                }
            }

            try
            {
                ctx.SaveChanges();
            }
            catch
            {
            }

            UISharedRTClient.Instance.clienRt.SendCommentsRead(SessionInfo.Get().person.Id,
                                                               ap.Topic.Id,
                                                               ap.Id, -1);
        }
        public static Dictionary <byte, object> Write(Dictionary <int, byte[]> screenshots)
        {
            using (var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr))
            {
                var res = new Dictionary <byte, object>();

                //array of integers (shape Ids)
                var shapeIds = screenshots.Keys.ToArray();
                res.Add((byte)DiscussionParamKey.ArrayOfInts, shapeIds);

                for (int i = 0; i < shapeIds.Length; i++)
                {
                    var md = new MediaData {
                        Data = screenshots[shapeIds[i]]
                    };
                    ctx.AddToMediaDataSet(md);
                    ctx.SaveChanges();//save here, need Id
                    res.Add((byte)i, md.Id);
                }
                return(res);
            }
        }