Пример #1
0
        public PhotoModel(Attachment attachment)
        {
            if (!IsPhoto(attachment))
            {
                throw new WrongAttachmentTypeException(typeof(Photo), attachment.Type);
            }

            AttachmentType = AttachmentModelType.Photo;
            var photo = (Photo)attachment.Instance;

            Uri = photo.Sizes.OrderBy(size => size.Height).Last().Url.AbsoluteUri;
            //PrintUri();

            /*//it's awful
             * var ext = uri.Split('/').Last().Split('.').Skip(1).First().Split('?').First();
             * Console.WriteLine(ext);
             * var filename = $@"..\..\..\files\attachments\{System.Guid.NewGuid()}.{ext}";
             * Console.WriteLine(filename);
             * using (var client = new WebClient())
             * {
             *  client.DownloadFile(uri,filename);
             * }
             *
             * Filename = filename;*/
        }
Пример #2
0
 public LinkModel(Attachment attachment)
 {
     if (!IsLink(attachment))
     {
         throw new WrongAttachmentTypeException(typeof(Link), attachment.Type);
     }
     else
     {
         //Console.WriteLine("Link condition!");
         AttachmentType = AttachmentModelType.Link;
         var link = (Link)attachment.Instance;
         //Title = link.Title;
         Uri = link.Uri.AbsoluteUri;
     }
 }
Пример #3
0