Example #1
0
        public void FileIsExecuted()
        {
            WindowsFile testfile = GetTestFile("test.txt");

            AssertFileIsExecuted(testfile, ExpectedEditor);

            testfile = new WindowsFile(@"C:\WINDOWS\system32\NOTEPAD.EXE");
            AssertFileIsExecuted(testfile, testfile.ToString());

            testfile = new WindowsFile("setup.msi");
            AssertFileIsExecuted(testfile, ExpectedMsiExecutableOpener);

            testfile = GetTestFile("test.bat");
            AssertFileIsExecuted(testfile, ExpectedBatchFileOpener);

            testfile = GetTestFile("test.jpg");
            AssertFileIsExecuted(testfile, ExpectedPhotoViewer);

            testfile = GetTestFile("test.bmp");
            AssertFileIsExecuted(testfile, ExpectedPhotoViewer);

            testfile = GetTestFile("test.png");
            AssertFileIsExecuted(testfile, ExpectedPhotoViewer);

            testfile = GetTestFile("test.gif");
            AssertFileIsExecuted(testfile, ExpectedPhotoViewer);
        }
Example #2
0
        private void AssertHandleIsRetrieved(WindowsFile windowsFile, string expectedHandle)
        {
            string handle = windowsFile.FindExecutable();

            Assert.AreEqual(expectedHandle, handle, $"Handle is not {expectedHandle} for file {windowsFile}");
            Assert.IsNotNull(handle, $"Handle is null for file {windowsFile}");
        }
Example #3
0
 public virtual string ReadAllText(string path)
 {
     try{
         return(WindowsFile.ReadAllText(path.Replace('/', '\\')));
     }catch (Exception) {
         return(null);
     }
 }
Example #4
0
        private void AssertHandleIsRetrievedWithTry(WindowsFile windowsFile, string expectedHandle)
        {
            bool isSuccess = windowsFile.TryFindExecutable(out string path, out HandleType handleType);

            Assert.IsTrue(isSuccess, $"Could not find an executable or app for {windowsFile}");
            Assert.AreEqual(expectedHandle, path, $"Path is not {expectedHandle} for file {windowsFile}");
            Assert.AreNotEqual(HandleType.NotFound, handleType, $"Handle type is not found for {windowsFile}");
        }
Example #5
0
        private void AssertFileIsExecuted(WindowsFile file, string expectedHandle)
        {
            bool isExecuted = file.TryExecute();

            Assert.AreEqual(true, isExecuted, "Process was not executed successfully");
            Assert.IsNotNull(file.ExecutedProcess, "Process was executed successully but testFile.ExecutedProcess is null");
            Assert.AreEqual(expectedHandle, file.ExecutedProcess.Name);
        }
Example #6
0
        public void TextFilesOpenedWithEditor()
        {
            string defaultEditor = WindowsFile.GetDefaultTextEditor();

            Assert.IsNotNull(defaultEditor);
            Assert.AreNotEqual("", defaultEditor, $"Blank string returned for the default text editor");
            Assert.AreEqual(ExpectedEditor, defaultEditor, $"Default text editor was not the expected {ExpectedEditor}");
        }
Example #7
0
        private void AssertFileOpenedWithCorrectExecutable(string fileExtension, string expectedExecutable)
        {
            string associatedExecutable = WindowsFile.GetAssociatedExecutable(fileExtension);

            Assert.IsNotNull(associatedExecutable);
            Assert.AreNotEqual("", associatedExecutable, $"Blank string returned for the default executable for {fileExtension}");
            Assert.AreEqual(expectedExecutable, associatedExecutable, $"Default executable for {fileExtension} was not the expected {expectedExecutable}");
        }
Example #8
0
 public virtual void WriteAllText(string path, string text)
 {
     try
     {
         WindowsFile.WriteAllText(path.Replace('/', '\\'), text);
     }
     catch (Exception)
     {
     }
 }
Example #9
0
 public virtual void WriteAllLines(string path, string[] lines)
 {
     try
     {
         WindowsFile.WriteAllLines(path.Replace('/', '\\'), lines);
     }
     catch (Exception)
     {
     }
 }
Example #10
0
 public virtual void WriteAllBytes(string path, byte[] bytes)
 {
     try
     {
         WindowsFile.WriteAllBytes(path.Replace('/', '\\'), bytes);
     }
     catch (Exception)
     {
     }
 }
Example #11
0
 public virtual void FileDelete(string path)
 {
     try
     {
         WindowsFile.Delete(path.Replace('/', '\\'));
     }
     catch (Exception)
     {
     }
 }
Example #12
0
 public virtual bool FileExists(string path)
 {
     try
     {
         return(WindowsFile.Exists(path.Replace('/', '\\')));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #13
0
 public virtual byte[] ReadAllBytes(string path)
 {
     try
     {
         return(WindowsFile.ReadAllBytes(path.Replace('/', '\\')));
     }
     catch (Exception)
     {
         return(null);
     }
 }
        private void ExecuteDrop(EventTranscriptionParameter <DragEventArgs> parameter)
        {
            if (!parameter.EventArgs.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }

            var filePaths = (string[])parameter.EventArgs.Data.GetData(DataFormats.FileDrop, true);

            droppedFiles   = filePaths.Select(x => WindowsFile.CreateFromPath(x)).ToArray();
            IsDropMenuOpen = true;
        }
Example #15
0
        private WindowsFile GetTestFile(string fileName)
        {
            string assemblyLocation  = Assembly.GetExecutingAssembly().Location;
            string assemblyDirectory = Path.GetDirectoryName(assemblyLocation);

            Assert.IsNotNull(assemblyDirectory, "Could not find the current assembly location");

            string   testFilePath = Path.Combine(assemblyDirectory, "TestFiles", fileName);
            FileInfo testFile     = new FileInfo(testFilePath);

            Assert.IsTrue(testFile.Exists, $"Test file could not be found at {testFilePath}");

            WindowsFile windowsFile = new WindowsFile(testFile);

            return(windowsFile);
        }
Example #16
0
        public void HandleIsRetrieved()
        {
            WindowsFile testfile = GetTestFile("test.txt");

            AssertHandleIsRetrieved(testfile, ExpectedEditor);

            testfile = GetTestFile("test.jpg");
            AssertHandleIsRetrievedWithTry(testfile, ExpectedPhotoViewer);

            testfile = GetTestFile("test.bmp");
            AssertHandleIsRetrievedWithTry(testfile, ExpectedPhotoViewer);

            testfile = GetTestFile("test.png");
            AssertHandleIsRetrievedWithTry(testfile, ExpectedPhotoViewer);

            testfile = GetTestFile("test.gif");
            AssertHandleIsRetrievedWithTry(testfile, ExpectedPhotoViewer);
        }
Example #17
0
        public override void Execute(object parameter)
        {
            var active = MainViewModel.ActiveDirectoryContainer.ActiveView;
            //get data from clipboard
            var data = Clipboard.GetDataObject();

            //files
            var paths = (string[])data.GetData(DataFormats.FileDrop, true);

            if (paths == null)
            {
                MessageBox.Show("Schowek jest pusty");
                return;
            }

            //get flag indicating whether it is copy or cut
            var  stream   = (MemoryStream)data.GetData("Preferred DropEffect", true);
            bool copyFlag = stream.ReadByte() == 5 ? true : false;

            //change paths into IDirectoryViewItems
            var items = new IDirectoryViewItem[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                items[i] = WindowsFile.CreateFromPath(paths[i]);
            }

            MultiFileOperation operation;

            if (copyFlag)
            {
                operation = new CopyOperation(items, active.FullPath, new WindowsFileSystem(), active.FileSystem);
            }
            else
            {
                operation = new MoveOperation(items, active.FullPath, new WindowsFileSystem(), active.FileSystem);
            }

            OperationManager.ExecuteOperation(operation);
        }
Example #18
0
        public virtual string[] ReadAllLines(string path)
        {
            try
            {
                IList <string> lines  = WindowsFile.ReadAllLines(path.Replace('/', '\\'));
                int            length = lines.Count;

                string[] linesArray = new string[length];
                int      i          = 0;
                foreach (var line in lines)
                {
                    linesArray[i] = line;
                    i++;
                }

                return(linesArray);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #19
0
 public void Upload(WindowsFile file)
 {
     connection.UploadFile(file.FullName, file.Name);
 }