public void DeleteFileShouldRemoveFileFromDisk()
        {
            var wrapper = new FileSystemWrapper();
            var date = DateTime.Now;
            string destinationPath = string.Format("{0}\\TestResults\\{1}\\{2}", StrixPlatform.Environment.WorkingDirectory, date.Year, date.Month);
            string fullPath = destinationPath + "\\Strix_losuiltje.png";
            string originalFullPath = StrixPlatform.Environment.WorkingDirectory + "\\TestFiles\\Strix_losuiltje.png";

            if (!System.IO.Directory.Exists(destinationPath))
            {
                System.IO.Directory.CreateDirectory(destinationPath);
            }

            if (!System.IO.File.Exists(fullPath))
            {
                System.IO.File.Copy(originalFullPath, fullPath);
            }

            string root = Path.Combine(StrixPlatform.Environment.WorkingDirectory, "TestResults");
            string fileName = "Strix_losuiltje";
            string fileExtension = "png";
            wrapper.DeleteFile(string.Format("{0}\\{1}.{2}", System.IO.Path.Combine(root, date.Year.ToString(), date.Month.ToString()), fileName, fileExtension));
            wrapper.ProcessDeleteQueue();
            bool result = System.IO.File.Exists(fullPath);
            Assert.IsFalse(result);
        }
Exemplo n.º 2
0
        public override Task DeleteAsync(string id)
        {
            var path = ResolvePath(id);

            _fileSystemWrapper.DeleteFile(path);

            return(Task.FromResult(0));
        }
Exemplo n.º 3
0
        private void UpdateFileInformation(SPFile file)
        {
            string extension = Path.GetExtension(file.Name);

            if (extension != ".jpg" && extension != ".png" && extension != ".vtt")
            {
                string guiID      = file.UniqueId.ToString();
                string tempfile   = file.Name.Replace(file.Item.DisplayName, guiID);
                string tempvideo  = string.Empty;
                string tempPoster = string.Empty;

                SPContext context = SPContext.Current;

                if (context == null)
                {
                    context = SPContext.GetContext(file.Web);
                }

                FFMpegProcessWrapper wrapper    = new FFMpegProcessWrapper(context);
                FileSystemWrapper    filesystem = new FileSystemWrapper();

                if (!filesystem.DirectoryExists(wrapper.settings.InputVideoPath))
                {
                    filesystem.CreateDirectory(wrapper.settings.InputVideoPath);
                }

                bool Isnew = false;

                if (filesystem.DirectoryExists(wrapper.settings.InputVideoPath))
                {
                    tempvideo = Path.Combine(wrapper.settings.InputVideoPath, tempfile);

                    if (!filesystem.FileExists(tempvideo))
                    {
                        filesystem.CreateFile(tempvideo);
                        Isnew = true;
                    }

                    if (Isnew)
                    {
                        Stream filestream = file.OpenBinaryStream();
                        filesystem.DemandFileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, tempvideo);
                        filesystem.WriteStreamToFile(filestream, tempvideo);
                        filestream.Flush();
                        filestream.Close();
                    }
                }

                SPSecurity.RunWithElevatedPrivileges(
                    delegate()
                {
                    if (Isnew)
                    {
                        VideoFile video    = new VideoFile(tempvideo);
                        video.UniqueId     = file.UniqueId;
                        video.infoGathered = false;

                        try
                        {
                            wrapper.GetVideoInfo(video);

                            if (video.infoGathered)
                            {
                                try
                                {
                                    file.Item[BuildFieldId.Audio_Format]     = video.AudioFormat;
                                    file.Item[BuildFieldId.Content_Bitrate]  = video.BitRate;
                                    file.Item[BuildFieldId.Content_Duration] = video.Duration.TotalMinutes;
                                    file.Item[BuildFieldId.Content_Height]   = video.Height;
                                    file.Item[BuildFieldId.Content_Width]    = video.Width;
                                    file.Item[BuildFieldId.Video_Format]     = video.VideoFormat;
                                    file.Item.SystemUpdate(false);
                                }
                                catch (Exception ex)
                                {
                                    ex.ToString();
                                }
                            }

                            wrapper.GetVideoPoster(video);

                            try
                            {
                                tempPoster = tempvideo.Replace(Path.GetExtension(tempvideo), ".jpg");

                                while (!filesystem.FileExists(tempPoster))
                                {
                                    Thread.Sleep(1000);
                                }

                                if (filesystem.FileExists(tempPoster))
                                {
                                    Stream posterStream = null;

                                    try
                                    {
                                        posterStream = filesystem.FileOpenRead(tempPoster);

                                        if (posterStream != null)
                                        {
                                            string PosterFile = file.Item.DisplayName + ".jpg";
                                            if (PosterFile.IndexOf('-') > -1)
                                            {
                                                PosterFile = PosterFile.Split(new char[1] {
                                                    '-'
                                                })[0].ToString();
                                            }

                                            SPFile poster = null;

                                            try
                                            {
                                                poster = file.ParentFolder.Files[PosterFile];
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.ToString();
                                                poster = null;
                                            }

                                            if (poster == null)
                                            {
                                                poster = file.ParentFolder.Files.Add(PosterFile, posterStream, true);
                                                poster.Update();

                                                poster.Item[SPBuiltInFieldId.ContentTypeId] = ContentTypes.ContentTypeId.Video;

                                                if (video.infoGathered)
                                                {
                                                    poster.Item[BuildFieldId.Content_Buffer]   = wrapper.settings.Buffer;
                                                    poster.Item[BuildFieldId.Content_AutoPlay] = wrapper.settings.AutoPlay;
                                                    poster.Item[BuildFieldId.Content_Loop]     = wrapper.settings.Loop;
                                                    poster.Item[BuildFieldId.Audio_Format]     = video.AudioFormat;
                                                    poster.Item[BuildFieldId.Content_Bitrate]  = video.BitRate;
                                                    poster.Item[BuildFieldId.Content_Duration] = video.Duration.TotalMinutes;
                                                    poster.Item[BuildFieldId.Content_Height]   = video.Height;
                                                    poster.Item[BuildFieldId.Content_Width]    = video.Width;
                                                    poster.Item[BuildFieldId.Video_Format]     = video.VideoFormat;
                                                }
                                                poster.Item.SystemUpdate(false);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        ex.ToString();
                                    }
                                    finally
                                    {
                                        if (posterStream != null)
                                        {
                                            posterStream.Flush();
                                            posterStream.Close();
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.ToString();
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.ToString();
                        }
                        finally
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(tempvideo))
                                {
                                    filesystem.DemandFileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, tempvideo);
                                    filesystem.DeleteFile(tempvideo);
                                }
                                if (!string.IsNullOrEmpty(tempPoster))
                                {
                                    filesystem.DemandFileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, tempPoster);
                                    filesystem.DeleteFile(tempPoster);
                                }
                            }
                            catch (Exception ex)
                            {
                                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                            }
                        }
                    }
                });
            }
        }