示例#1
0
        //public async Task<string> UploadToSharedAccess(Stream file, string filename, DateTimeOffset? expiry, SharedAccessBlobPermissions permissions = SharedAccessBlobPermissions.Read)
        //{
        //    string sasBlobToken;

        //    // Upload the media, filename as the name, check it doesn't already exist first.
        //    var client = await GetClientAsync();
        //    var blockBlob = client.GetBlockBlobClient(blobReference);

        //    // If container doesn’t exist, create it.
        //    await blobContainer.CreateIfNotExistsAsync();
        //    await blobContainer.SetPermissionsAsync(new BlobContainerPermissions
        //    {
        //        PublicAccess = BlobContainerPublicAccessType.Off
        //    });

        //    // Get a reference to the blob named blobReference
        //    CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(filename);
        //    await blockBlob.UploadFromStreamAsync(file);

        //    // Create a new access policy and define its constraints.
        //    // Note that the SharedAccessBlobPolicy class is used both to define the parameters of an ad-hoc SAS, and
        //    // to construct a shared access policy that is saved to the container's shared access policies.
        //    SharedAccessBlobPolicy adHocSAS = new SharedAccessBlobPolicy()
        //    {
        //        // When the start time for the SAS is omitted, the start time is assumed to be the time when the storage service receives the request.
        //        // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
        //        SharedAccessExpiryTime = expiry ?? DateTime.UtcNow.AddHours(24),
        //        Permissions = permissions
        //    };

        //    // Generate the shared access signature on the blob, setting the constraints directly on the signature.
        //    sasBlobToken = blockBlob.GetSharedAccessSignature(adHocSAS);

        //    Console.WriteLine("SAS for blob (ad hoc): {0}", sasBlobToken);
        //    Console.WriteLine();

        //    return blockBlob.Uri + sasBlobToken;
        //}



        private IMediaObject ProcessImage(IMediaObject media)
        {
            string fileName = Path.GetFileNameWithoutExtension(media.Url);
            string fileExt  = Path.GetExtension(media.Url);
            string tempDir  = _env.ContentRootPath + "\\Temporary\\" + typeof(ImageProcessor) + "\\";

            string tempGuid     = Guid.NewGuid().ToString();
            string tempFileName = tempDir + tempGuid + fileExt;

            // create three thumbnailed versions, and add to the array of files to upload.

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            // download the file.
            using (WebClient client = new())
            {
                client.DownloadFile(media.Url, tempFileName);
            }

            Task[] tasks = new Task[4]
            {
                Task.Factory.StartNew(() => media.ThumbUrl  = GenerateThumb(media, tempFileName, tempGuid, ".xs", 250)),
                Task.Factory.StartNew(() => media.SmallUrl  = GenerateThumb(media, tempFileName, tempGuid, ".sm", 600)),
                Task.Factory.StartNew(() => media.MediumUrl = GenerateThumb(media, tempFileName, tempGuid, ".md", 1280)),
                Task.Factory.StartNew(() => media.LargeUrl  = GenerateThumb(media, tempFileName, tempGuid, ".xl", 1920))
            };

            //Block until all tasks complete.
            Task.WaitAll(tasks);
            return(media);
        }
示例#2
0
 public void ServeSpecific(int index)
 {
     if (_mediaProvider.MediaObjectCollection.Count > index && index > -1)
     {
         CurrentMedia = _mediaProvider.MediaObjectCollection.ToList()[index];
     }
 }
示例#3
0
 public void Reset()
 {
     if (!_mediaProvider.MediaObjectCollection.Any())
     {
         return;
     }
     CurrentMedia = _mediaProvider.MediaObjectCollection.First();
 }
示例#4
0
 public Response(bool success, IMediaObject media, string message = "", string title = null)
 {
     Success = success;
     Message = message;
     Errors  = message;
     Title   = title.IsSet() ? title : success ? "Succeeded" : "Failed";
     Media   = media;
 }
示例#5
0
        // TODO: there are still several IMediaObject functions to be wrapped

        #region IDisposable Members

        /// <summary>
        /// Experimental code, not currently being called
        /// Not sure if it is necessary anyway
        /// </summary>
        public void Dispose()
        {
            if (mediaObject != null)
            {
                Marshal.ReleaseComObject(mediaObject);
                mediaObject = null;
            }
        }
示例#6
0
 /// <summary>
 /// Experimental code, not currently being called
 /// Not sure if it is necessary anyway
 /// </summary>
 public void Dispose()
 {
     if (mediaObject != null)
     {
         Marshal.ReleaseComObject(mediaObject);
         mediaObject = null;
     }
 }
 public static IMediaObject UpdateHostName(this IMediaObject mediaObject, string hostname)
 {
     mediaObject.LargeUrl  = new Uri(mediaObject.LargeUrl).ToUrlString(hostname);
     mediaObject.SmallUrl  = new Uri(mediaObject.SmallUrl).ToUrlString(hostname);
     mediaObject.MediumUrl = new Uri(mediaObject.MediumUrl).ToUrlString(hostname);
     mediaObject.ThumbUrl  = new Uri(mediaObject.ThumbUrl).ToUrlString(hostname);
     mediaObject.Url       = new Uri(mediaObject.Url).ToUrlString(hostname);
     return(mediaObject);
 }
 public static IMediaObject UpdateUrls(this IMediaObject target, IMediaObject source)
 {
     target.LargeUrl  = source.LargeUrl;
     target.SmallUrl  = source.SmallUrl;
     target.MediumUrl = source.MediumUrl;
     target.ThumbUrl  = source.ThumbUrl;
     target.Url       = source.Url;
     target.UniqueId  = source.UniqueId;
     return(target);
 }
示例#9
0
 public async Task DeleteStoredMedia(IMediaObject media)
 {
     if (media != null)
     {
         try { await Delete(media.BlobReference); } catch (Exception) { }
         try { await Remove(media.SmallUrl); } catch (Exception) { }
         try { await Remove(media.MediumUrl); } catch (Exception) { }
         try { await Remove(media.LargeUrl); } catch (Exception) { }
         try { await Remove(media.ThumbUrl); } catch (Exception) { }
     }
 }
示例#10
0
        public void SelectMedia(IMediaObject media)
        {
            int index = MediaCollection.IndexOf((IMediaObject)media);

            _mediaServer.ServeSpecific(index);
            SendPropertyChanged(nameof(CurrentMedia));
            _mediaTimer.Initialize(CurrentMedia.Duration, () => MediaHasEnded());
            if (Play)
            {
                _mediaTimer.Start();
            }
        }
        private void SetupVideo(IMediaObject media)
        {
            if (_currentElement == videoOne)
            {
                _queuedElement = videoTwo;
            }
            else
            {
                _queuedElement = videoOne;
            }

            (_queuedElement as MediaElement).Source = Source.Source;
        }
示例#12
0
        private string GenerateThumb(IMediaObject media, string tempFileName, string tempGuid, string prefix, int size)
        {
            try
            {
                string fileName = Path.GetFileNameWithoutExtension(media.Url);
                string fileExt  = Path.GetExtension(media.Url);
                string tempDir  = _env.ContentRootPath + "\\Temporary\\" + typeof(ImageProcessor) + "\\";

                string tempThumbFile = tempDir + tempGuid + prefix + fileExt;
                string thumbFilename = $"{media.Path}/{fileName}{prefix}{fileExt}";

                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                switch (fileExt.ToLowerInvariant())
                {
                case ".gif":
                    format = System.Drawing.Imaging.ImageFormat.Gif;
                    break;

                case ".bmp":
                    format = System.Drawing.Imaging.ImageFormat.Bmp;
                    break;

                case ".png":
                    format = System.Drawing.Imaging.ImageFormat.Png;
                    break;
                }

                ImageProcessor.ResizeImage(tempFileName, tempThumbFile, size, size, format);

                // foreach, file in the list of thumbnails
                // upload to the thumbLocation
                string url = "";
                using (FileStream fs = File.OpenRead(tempThumbFile))
                {
                    url = Upload(fs, thumbFilename).Result.Uri.ToUrlString();
                }

                // add the url to the array of urls to send back
                // remove the temporary image
                try { File.Delete(tempFileName); } catch (Exception) { }
                try { File.Delete(tempThumbFile); } catch (Exception) { }

                return(url);
            }
            catch (Exception)
            {
                // Thumbnailing failed, just send back the Url.
                return(media.Url);
            }
        }
示例#13
0
        private void Configure()
        {
            int hr;

            DMOWrapperFilter  dmoFilter        = new DMOWrapperFilter();
            IDMOWrapperFilter dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter;

            // Chorus - {efe6629c-81f7-4281-bd91-c9d604a95af6}
            // DmoFlip - {7EF28FD7-E88F-45bb-9CDD-8A62956F2D75}
            //hr = dmoWrapperFilter.Init(new Guid("{7EF28FD7-E88F-45bb-9CDD-8A62956F2D75}"), DMOCategory.AudioEffect);
            hr = dmoWrapperFilter.Init(new Guid("{efe6629c-81f7-4281-bd91-c9d604a95af6}"), DMOCategory.AudioEffect);
            DMOError.ThrowExceptionForHR(hr);

            m_imo = dmoWrapperFilter as IMediaObject;
        }
 public int CompareTo(IMediaObject obj)
 {
     if (Type != obj.Type)
     {
         return(0);
     }
     if (!Source.AbsolutePath.Equals(obj.Source.AbsolutePath))
     {
         return(0);
     }
     if (!Duration.Equals(obj.Duration))
     {
         return(0);
     }
     return(1);
 }
        private void SetupImage(IMediaObject media)
        {
            if (_currentElement == imageOne)
            {
                _queuedElement = imageTwo;
            }
            else
            {
                _queuedElement = imageOne;
            }

            var newSource = new BitmapImage();

            newSource.BeginInit();
            newSource.UriSource   = media.Source;
            newSource.CacheOption = BitmapCacheOption.OnLoad;
            newSource.EndInit();
            newSource.Freeze();
            (_queuedElement as Image).Source = newSource;
        }
示例#16
0
        public static string ToIcon(this IMediaObject mediaObject)
        {
            string output;

            switch (mediaObject.GenericFileType)
            {
            case GenericFileType.Image:
                output = mediaObject.SmallUrl;
                break;

            case GenericFileType.Excel:
                return(Engine.Resource("/images/icons/excel.png"));

            case GenericFileType.PDF:
                return(Engine.Resource("/images/icons/pdf.png"));

            case GenericFileType.PowerPoint:
                return(Engine.Resource("/images/icons/powerpoint.png"));

            case GenericFileType.Word:
                return(Engine.Resource("/images/icons/word.png"));

            case GenericFileType.Photoshop:
                return(Engine.Resource("/images/icons/photoshop.png"));

            case GenericFileType.Audio:
                return(Engine.Resource("/images/icons/audio.png"));

            case GenericFileType.Video:
                return(Engine.Resource("/images/icons/video.png"));

            case GenericFileType.Unknown:
            default:
                return(Engine.Resource("/images/icons/file.png"));
            }
            if (!output.IsSet())
            {
                output = MediaBase.NoImageUrl;
            }
            return(output);
        }
示例#17
0
 public void NextMedia()
 {
     if (CurrentMedia != null)
     {
         var mediaCollection = _mediaProvider.MediaObjectCollection.ToList();
         var currentIndex    = mediaCollection.ToList().IndexOf(CurrentMedia);
         if (currentIndex + 1 < mediaCollection.Count)
         {
             CurrentMedia = mediaCollection[currentIndex + 1];
         }
         else
         {
             CurrentMedia = mediaCollection.FirstOrDefault();
         }
     }
     else
     {
         if (_mediaProvider.MediaObjectCollection.Any())
         {
             CurrentMedia = _mediaProvider.MediaObjectCollection.FirstOrDefault();
         }
     }
 }
示例#18
0
 public void PreviousMedia()
 {
     if (CurrentMedia != null)
     {
         var mediaCollection = _mediaProvider.MediaObjectCollection.ToList();
         var currentIndex    = mediaCollection.ToList().IndexOf(CurrentMedia);
         if (currentIndex - 1 >= 0)
         {
             CurrentMedia = mediaCollection[currentIndex - 1];
         }
         else
         {
             CurrentMedia = mediaCollection.Last();
         }
     }
     else
     {
         if (_mediaProvider.MediaObjectCollection.Any())
         {
             CurrentMedia = _mediaProvider.MediaObjectCollection.FirstOrDefault();
         }
     }
 }
示例#19
0
        public async Task <IMediaObject> RefreshMedia(IMediaObject media, string tempDirectory)
        {
            // copy record of original files into new object
            MediaObject old = new();

            media.CopyProperties(old);

            // download the orignal file, and save it to temp.
            string tempFile = tempDirectory + media.UniqueId;

            using (WebClient client = new())
            {
                client.DownloadFile(new Uri(media.Url), tempFile);
            }

            using (FileStream fileStream = File.OpenRead(tempFile))
            {
                // reupload to a new location, and process.
                await ProcessUpload(fileStream, media.Filename, media.FileType, media.FileSize, media.Path);
            }

            // save the new file urls to the media object
            return(media);
        }
示例#20
0
 public MediaObject(IMediaObject mediaResult, int?directoryId = null) : base(mediaResult)
 {
     DirectoryId = directoryId;
 }
示例#21
0
 /// <summary>
 /// Creates a new Media Object
 /// </summary>
 /// <param name="mediaObject">Media Object COM interface</param>
 internal MediaObject(IMediaObject mediaObject)
 {
     this.mediaObject = mediaObject;
     mediaObject.GetStreamCount(out inputStreams, out outputStreams);
 }
示例#22
0
 public ContentMedia(IMediaObject mediaResult) : base(mediaResult)
 {
 }
 public IMediaObjectInfo NewMediaObject(string blogid, string username, string password, IMediaObject mediaObject)
 {
     throw new NotImplementedException();
 }
示例#24
0
 public static string ToJson(this IMediaObject mediaObject)
 {
     return(Newtonsoft.Json.JsonConvert.SerializeObject(mediaObject));
 }
示例#25
0
 public MediaBase(IMediaObject mediaResult)
 {
     mediaResult.CopyProperties(this);
 }
示例#26
0
 public PropertyFloorplan(IMediaObject media)
     : base(media)
 {
 }
 public bool Equals(IMediaObject other)
 => CompareTo(other) == 1;
示例#28
0
 /// <summary>
 /// Creates a new Media Object
 /// </summary>
 /// <param name="mediaObject">Media Object COM interface</param>
 internal MediaObject(IMediaObject mediaObject)
 {
     this.mediaObject = mediaObject;
     mediaObject.GetStreamCount(out inputStreams, out outputStreams);
 }
示例#29
0
 public PropertyMedia(IMediaObject media)
     : base(media)
 {
 }