Esempio n. 1
0
        public static Attachment AttachCloudEntry(ArgPoint Point, StorageSelectionEntry selEntry)
        {
            var a = new Attachment {
                Name = selEntry.Title
            };

            try
            {
                a.Format = (int)GetImgFmt(selEntry.Title);  //may throw exception in case of unsupported file format
            }
            catch (Exception)
            {
                throw new IncorrectAttachmentFormat();
            }

            a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(selEntry.PathName));
            a.Title     = "";// selEntry.Title;
            a.Link      = selEntry.Title;
            if (a.Format == (int)AttachmentFormat.Pdf)
            {
                a.Thumb = TryCreatePdfThumb(selEntry.PathName);
            }

            if (Point != null)
            {
                a.ArgPoint = Point;
            }
            return(a);
        }
Esempio n. 2
0
        public static ArgPoint NewPoint(Topic t, int orderNumber)
        {
            if (t == null)
            {
                return(null);
            }

            //create new point
            ArgPoint pt = new ArgPoint();

            pt.Point = "Your title here/タイトル";
            pt.RecentlyEnteredSource   = "Your web url link here/URLリンク";
            pt.RecentlyEnteredMediaUrl = "Your media link here/画像URLリンク";
            DaoUtils.EnsurePtDescriptionExists(pt);

            pt.Description.Text = NEW_DESCRIPTION;
            pt.Topic            = PrivateCenterCtx.Get().Topic.FirstOrDefault(t0 => t0.Id == t.Id);
            int selfId = SessionInfo.Get().person.Id;
            var pers   = PrivateCenterCtx.Get().Person.FirstOrDefault(p0 => p0.Id == selfId);

            pt.Person         = pers;
            pt.SharedToPublic = true;
            pt.SideCode       = DaoUtils.GetGeneralSide(SessionInfo.Get().person,
                                                        SessionInfo.Get().discussion);
            pt.OrderNumber = orderNumber;

            return(pt);
        }
Esempio n. 3
0
        public static void AddSource(RichText r)
        {
            if (r == null)
            {
                return;
            }

            var dlg = new SourceDialog();

            dlg.ShowDialog();

            if (dlg.Source == null)
            {
                return;
            }

            DaoUtils.AddSource(dlg.Source, r);
        }
Esempio n. 4
0
        public static Attachment AttachScreenshot(ArgPoint Point, Bitmap screenshot)
        {
            var screenPath = Utils.RandomFilePath(".png");

            screenshot.Save(screenPath, ImageFormat.Png);

            var a = new Attachment();

            a.Name      = screenPath;
            a.Format    = (int)AttachmentFormat.PngScreenshot;
            a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(screenPath));
            a.Title     = "Screenshot, " + Environment.MachineName + " " + DateTime.Now;
            a.Link      = a.Title;
            if (Point != null)
            {
                a.ArgPoint = Point;
            }
            return(a);
        }
Esempio n. 5
0
 void InjectCommentNotifications()
 {
     for (int i = 0; i < _commentItems.Items.Count; ++i)
     {
         var item      = _commentItems.ItemContainerGenerator.ContainerFromIndex(i);
         var commentUC = Utils.FindChild <CommentUC>(item);
         if (commentUC != null)
         {
             var comment = (Comment)commentUC.DataContext;
             if (comment != null)
             {
                 commentUC.SetNotification(false);
                 if (DaoUtils.IsCommentNewForUs(_ctx, comment.Id))
                 {
                     commentUC.SetNotification(true);
                 }
             }
         }
     }
 }
Esempio n. 6
0
        //if URL==null, shows URL input dialog. else uses provided URL, no dialog
        private static Attachment AttachPdfFromURL(ArgPoint Point, string Url)
        {
            string UrlToUse = Url;

            if (UrlToUse == null)
            {
                InpDialog dlg = new InpDialog();
                dlg.ShowDialog();
                UrlToUse = dlg.Answer;

                UrlToUse = UrlToUse.ToLower();
                if (UrlToUse == null || !UrlToUse.StartsWith("http://") || UrlToUse.EndsWith(".pdf"))
                {
                    return(null);
                }
            }

            string tmpFile = DownloadPdfFromUrl(UrlToUse);

            if (tmpFile == null)
            {
                return(null);
            }

            Attachment res = new Attachment();

            res.Name      = UrlToUse;
            res.Format    = (int)AttachmentFormat.Pdf;
            res.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(tmpFile));
            res.Title     = "";
            res.Thumb     = TryCreatePdfThumb(tmpFile);
            res.Link      = Url;

            if (Point != null)
            {
                Point.Attachment.Add(res);
            }
            ///PublicBoardCtx.Get().SaveChanges();

            return(res);
        }
Esempio n. 7
0
        //if URL==null, shows URL input dialog. else uses provided URL, no dialog
        private static Attachment AttachFromURL(ArgPoint Point, string Url)
        {
            string UrlToUse = Url;

            if (UrlToUse == null)
            {
                InpDialog dlg = new InpDialog();
                dlg.ShowDialog();
                UrlToUse = dlg.Answer;

                if (UrlToUse == null || !UrlToUse.StartsWith("http://"))
                {
                    return(null);
                }
            }

            string tmpFile = DownloadImageFromURL(UrlToUse);

            if (tmpFile == null)
            {
                return(null);
            }

            Attachment res = new Attachment();

            res.Name      = UrlToUse;
            res.Format    = (int)AttachmentFormat.Jpg; //all downloads are jpg
            res.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(tmpFile));
            res.Title     = "";
            res.Link      = Url;

            if (Point != null)
            {
                Point.Attachment.Add(res);
            }
            //PublicBoardCtx.Get().SaveChanges();

            return(res);
        }
Esempio n. 8
0
        private void Run(Discussion A, Discussion B)
        {
            if (A == null || B == null)
            {
                return;
            }

            Tuple <int, int, string> range = GetRange();

            if (range.Item3 != "")
            {
                return;
            }

            var ctx = PublicBoardCtx.Get();

            var moderator = ctx.Person.FirstOrDefault(p => p.Name == "moderator");

            if (moderator == null)
            {
                MessageDlg.Show("Cannot find moderator in DB");
                return;
            }

            for (int i = range.Item1; i <= range.Item2; i++)
            {
                var disc = cloneDiscussion(ctx, A, moderator, i);
                DaoUtils.SetGeneralSide(moderator, disc, (int)SideCode.Neutral);
                ctx.AddToDiscussion(disc);

                var disc2 = cloneDiscussion(ctx, B, moderator, i);
                DaoUtils.SetGeneralSide(moderator, disc2, (int)SideCode.Neutral);
                ctx.AddToDiscussion(disc2);
            }
            ctx.SaveChanges();

            MessageDlg.Show("Done");
        }
Esempio n. 9
0
        private void SetStyle()
        {
            if (DataContext != null && DataContext is ArgPoint)
            {
                ArgPoint p = (ArgPoint)DataContext;
                if (p.Person == null)
                {
                    return;
                }

                var numUnread = DaoUtils.NumCommentsUnreadBy(new DiscCtx(ConfigManager.ConnStr), p.Id).Total();
                ToggleDot(numUnread > 0);

                mask.Background = new SolidColorBrush(Utils.IntToColor(p.Person.Color));
                switch ((SideCode)p.SideCode)
                {
                case SideCode.Pros:
                    //lblSide.Content = "PROS";
                    //lblPerson.Background = DiscussionColors.prosBrush;
                    break;

                case SideCode.Cons:
                    //lblSide.Content = "CONS";
                    //lblPerson.Background = DiscussionColors.consBrush;
                    break;

                case SideCode.Neutral:
                    //lblSide.Content = "NEUTRAL";
                    //lblPerson.Background = DiscussionColors.neutralBrush;
                    break;

                default:
                    throw new NotSupportedException();
                }
                //lblPerson.Content = p.Person.Name;
            }
        }
Esempio n. 10
0
        private static Attachment AttachAsBlob(string filter, AttachmentFormat format, bool autoInferenceOfFormat,
                                               ArgPoint Point)
        {
            var openFileDialog1 = new OpenFileDialog {
                Filter = filter, RestoreDirectory = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string attachmentName = Path.GetFileName(openFileDialog1.FileName);

                var a = new Attachment {
                    Name = attachmentName, Title = attachmentName, Link = openFileDialog1.FileName
                };

                if (autoInferenceOfFormat)
                {
                    format = GetImgFmt(openFileDialog1.FileName);
                }
                switch (format)
                {
                case AttachmentFormat.Pdf:
                    a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName));
                    a.Thumb     = TryCreatePdfThumb(openFileDialog1.FileName);
                    break;

                case AttachmentFormat.Jpg:
                    a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(openFileDialog1.FileName));
                    break;

                case AttachmentFormat.Png:
                    a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(openFileDialog1.FileName));
                    break;

                case AttachmentFormat.Bmp:
                    a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(openFileDialog1.FileName));
                    break;

                case AttachmentFormat.ExcelDocSet:
                    a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName));
                    break;

                case AttachmentFormat.WordDocSet:
                    a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName));
                    break;

                case AttachmentFormat.PowerPointDocSet:
                    a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName));
                    break;
                }
                a.Format = (int)format;
                a.Name   = attachmentName;

                if (Point != null)
                {
                    Point.Attachment.Add(a);
                }

                return(a);
            }

            return(null);
        }
Esempio n. 11
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);
        }