Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the MediaDataSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMediaDataSet(MediaData mediaData)
 {
     base.AddObject("MediaDataSet", mediaData);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new MediaData object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static MediaData CreateMediaData(global::System.Int32 id)
 {
     MediaData mediaData = new MediaData();
     mediaData.Id = id;
     return mediaData;
 }
        public Discussion cloneDiscussion(DiscCtx ctx, Discussion original, Person moderator, int i)
        {
            var d = new Discussion();
            d.Subject = injectNumber(original.Subject, i);

            //copy background
            d.Background = new RichText();
            d.Background.Text = original.Background.Text;
            foreach (var src in original.Background.Source)
            {
                var s = new Source();
                s.Text = src.Text;
                s.OrderNumber = src.OrderNumber;
                d.Background.Source.Add(s);
            }

            foreach (var media in original.Attachment)
            {
                var attach = new Attachment();
                attach.Discussion = d;
                attach.Format = media.Format;
                attach.Link = media.Link;
                attach.Name = media.Name;
                attach.Title = media.Title;
                attach.VideoEmbedURL = media.VideoEmbedURL;
                attach.VideoLinkURL = media.VideoLinkURL;
                attach.VideoThumbURL = media.VideoThumbURL;
                attach.OrderNumber = media.OrderNumber;

                if (media.Thumb != null)
                    attach.Thumb = (byte[]) media.Thumb.Clone();

                if (media.MediaData != null && media.MediaData.Data != null)
                {
                    var mediaClone = new MediaData();
                    mediaClone.Data = (byte[]) media.MediaData.Data.Clone();
                    attach.MediaData = mediaClone;
                }

                attach.Person = moderator;

                d.Attachment.Add(attach);
            }

            d.HtmlBackground = original.HtmlBackground;

            foreach (var topic in original.Topic)
            {
                var t = new Topic();
                t.Name = injectNumber(topic.Name, i);
                t.Person.Add(moderator);
                d.Topic.Add(t);
            }

            return d;
        }
Ejemplo n.º 5
0
        public static void AddAttachment(DiscCtx ctx,
                                         [CanBeNull]ArgPoint argPoint, [CanBeNull]Discussion discussion, [CanBeNull]Person personWithAvatar,
                                         SInAttachment attachment,
                                         int callerId)
        {
            var caller = ctx.Person.FirstOrDefault(p => p.Id == callerId);
            if (caller == null)
                return;

            Attachment lastAttachment = null;
            if (argPoint != null)
                lastAttachment = argPoint.Attachment.LastOrDefault();
            else if (discussion != null)
                lastAttachment = discussion.Attachment.LastOrDefault();
            else if (personWithAvatar != null)
                lastAttachment = personWithAvatar.Attachment.LastOrDefault();
                                        
            var dbMediaData = new MediaData {Data = attachment.MediaData};
                        
            var dbAttachent = attachment.ToDbEntity(ctx);
            dbAttachent.MediaData = dbMediaData;
            dbAttachent.OrderNumber = lastAttachment != null ? lastAttachment.OrderNumber + 1 : 1;

            //switch 
            {
                dbAttachent.Discussion = discussion;
                dbAttachent.PersonWithAvatar = personWithAvatar;
                dbAttachent.ArgPoint = argPoint;
            }

            dbAttachent.Person = caller;           
        }
Ejemplo n.º 6
0
        public static ArgPoint clonePoint(DiscCtx ctx, ArgPoint ap, Topic topic, Person owner, String name)
        {
            var top = ctx.Topic.FirstOrDefault(t0 => t0.Id == topic.Id);
            if (top == null)
                return null;

            var ownPoints = top.ArgPoint.Where(p0 => p0.Person.Id == owner.Id);
            int orderNr = 1;
            foreach (var pt in ownPoints)
            {
                if (pt.OrderNumber > orderNr)
                    orderNr = pt.OrderNumber;
            }

            var pointCopy = DaoUtils.NewPoint(top, orderNr + 1);
            pointCopy.Point = name;
            pointCopy.Description.Text = ap.Description.Text;

            foreach (var src in ap.Description.Source)
            {
                var newSrc = new Source {Text = src.Text};
                pointCopy.Description.Source.Add(newSrc);
            }

            foreach (var cmt in ap.Comment)
            {
                if (cmt.Person == null)
                    continue;

                var comment = new Comment();
                comment.Text = cmt.Text;
                var commentPersonId = cmt.Person.Id;
                comment.Person = ctx.Person.FirstOrDefault(p0 => p0.Id == commentPersonId);
                pointCopy.Comment.Add(comment);
            }

            var ownId = SessionInfo.Get().person.Id;
            var self = ctx.Person.FirstOrDefault(p0 => p0.Id == ownId);
            foreach (var media in ap.Attachment)
            {
                var attach = new Attachment();
                attach.ArgPoint = pointCopy;
                attach.Format = media.Format;
                attach.Link = media.Link;
                attach.Name = media.Name;
                attach.Title = media.Title;
                attach.VideoEmbedURL = media.VideoEmbedURL;
                attach.VideoLinkURL = media.VideoLinkURL;
                attach.VideoThumbURL = media.VideoThumbURL;
                attach.OrderNumber = media.OrderNumber;

                if (media.Thumb != null)
                    attach.Thumb = (byte[])media.Thumb.Clone();

                if (media.MediaData != null && media.MediaData.Data != null)
                {
                    var mediaClone = new MediaData();
                    mediaClone.Data = (byte[])media.MediaData.Data.Clone();
                    attach.MediaData = mediaClone;
                }

                attach.Person = self;
            }

            pointCopy.Person = self;

            pointCopy.Topic = top;

            return pointCopy;
        }
Ejemplo n.º 7
0
 public static MediaData CreateMediaData(byte[] data)
 {
     var res = new MediaData();
     res.Data = data;
     return res;
 }