private void CopyItem(object sender, ExecutedRoutedEventArgs e)
 {
     if (RoomEditor.Instance.SelectedObj != null)
     {
         var cmd = new CopyCommand();
         cmd.Execute(RoomEditor.Instance.SelectedObj);
     }
 }
Exemple #2
0
        public void TestMissingSourceFile()
        {
            string      src = Path.Combine(TestConstants.TestDirectory, "a.txt");
            string      dst = Path.Combine(TestConstants.TestDirectory, "b.txt");
            CopyCommand cc  = new CopyCommand(src, dst);

            Assert.Throws <FileNotFoundException>(() => cc.Execute());
            Assert.IsFalse(File.Exists(dst));
        }
Exemple #3
0
        public void TestNullSourceFilePath()
        {
            string      src = null;
            string      dst = Path.Combine(TestConstants.TestDirectory, "b.txt");
            CopyCommand cc  = new CopyCommand(src, dst);

            Assert.Throws <ArgumentNullException>(() => cc.Execute());
            Assert.IsFalse(File.Exists(dst));
        }
Exemple #4
0
        public void TestNullDestinationFilePath()
        {
            string       src      = Path.Combine(TestConstants.TestDirectory, "a.txt");
            string       dst      = null;
            const string expected = "12345";

            File.WriteAllText(src, expected);
            CopyCommand cc = new CopyCommand(src, dst);

            Assert.Throws <ArgumentNullException>(() => cc.Execute());
            Assert.IsFalse(File.Exists(dst));
        }
Exemple #5
0
        public void TestExistingDestinationFile()
        {
            string       src      = Path.Combine(TestConstants.TestDirectory, "a.txt");
            string       dst      = Path.Combine(TestConstants.TestDirectory, "b.txt");
            const string expected = "12345";

            File.WriteAllText(src, expected);
            File.Create(dst).Dispose();
            CopyCommand cc = new CopyCommand(src, dst);

            Assert.Throws <IOException>(() => cc.Execute());
            Assert.IsTrue(File.Exists(dst));
        }
        public void ShouldRollbackFileCopy()
        {
            // Given
            var command = new CopyCommand (FilePath, DestinyFilePath);
            command.Execute ();

            // When
            command.Rollback ();

            // Then
            Assert.IsTrue (File.Exists (FilePath));
            Assert.IsFalse (File.Exists (DestinyFilePath));
        }
Exemple #7
0
        public void TestSimple()
        {
            string       src      = Path.Combine(TestConstants.TestDirectory, "a.txt");
            string       dst      = Path.Combine(TestConstants.TestDirectory, "b.txt");
            const string expected = "12345";

            File.WriteAllText(src, expected);
            CopyCommand cc = new CopyCommand(src, dst);

            cc.Execute();
            string actual = File.ReadAllText(dst);

            Assert.AreEqual(expected, actual);
        }
Exemple #8
0
        public void Execute_NonExistingFile_ExternalDependencyNotFound()
        {
            var nonExistingFile = @"Temp\nonExistingFile.txt";
            var targetFile      = @"Temp\Target\TextCopy.txt";

            var copyInfo = Mock.Of <ICopyCommand>
                           (
                c => c.SourceFullPath == nonExistingFile &&
                c.FullPath == targetFile
                           );


            var command = new CopyCommand(copyInfo);

            Assert.Throws <ExternalDependencyNotFoundException>(() => command.Execute());
        }
Exemple #9
0
        public void Execute_NonExistingFile_ExternalDependencyNotFound()
        {
            var nonExistingFile = @"Temp\nonExistingFile.txt";
            var targetFile      = @"Temp\Target\TextCopy.txt";

            var copyArgs = Mock.Of <ICopyCommandArgs>
                           (
                c => c.SourceName == new LiteralScalarResolver <string>(Path.GetFileName(nonExistingFile)) &&
                c.SourcePath == new LiteralScalarResolver <string>(Path.GetDirectoryName(nonExistingFile)) &&
                c.DestinationName == new LiteralScalarResolver <string>(Path.GetFileName(targetFile)) &&
                c.DestinationPath == new LiteralScalarResolver <string>(Path.GetDirectoryName(targetFile))
                           );

            var command = new CopyCommand(copyArgs);

            Assert.Throws <ExternalDependencyNotFoundException>(() => command.Execute());
        }
Exemple #10
0
        public ServiceCallResult Process(string id, string database, string from, string to, bool reccursive, bool @override, bool exact)
        {
            return(ExecuteCommand(() => delegate
            {
                var context = new SitecoreEditorContext(id, database);

                var command = new CopyCommand(
                    context.Item,
                    LanguageManager.GetLanguage(from),
                    to.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(LanguageManager.GetLanguage),
                    reccursive,
                    exact,
                    @override);

                command.Execute();
            }));
        }
Exemple #11
0
        private void ToolbarButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                switch ((sender as FrameworkElement).Tag.ToString().Replace("toolbar.", ""))
                {
                case "new":
                    NewFileCommand.Execute(null);
                    break;

                case "open":
                    OpenFileCommand.Execute(null);
                    break;

                case "save":
                    SaveFileCommand.Execute(null);
                    break;

                case "cut":
                    CutCommand.Execute(null);
                    break;

                case "copy":
                    CopyCommand.Execute(null);
                    break;

                case "paste":
                    PasteCommand.Execute(null);
                    break;

                case "build":
                    BuildRunCommand.Execute(false);
                    break;

                case "buildrun":
                    BuildRunCommand.Execute(true);
                    break;

                case "close":
                    CloseTabCommand.Execute(null);
                    break;
                }
            } catch (Exception ex) {
                Debug.Fail(ex.Message);
            }
        }
Exemple #12
0
        public void TestBadPermissions()
        {
            string       src      = Path.Combine(TestConstants.TestDirectory, "a.txt");
            string       dst      = Path.Combine(TestConstants.TestDirectory, "b.txt");
            const string expected = "12345";

            File.WriteAllText(src, expected);
            CopyCommand cc = new CopyCommand(src, dst);

#if __MonoCS__
            Syscall.chmod(src, FilePermissions.S_IWUSR);
#else
            FileSecurity srcSecurity = File.GetAccessControl(src);
            var          currentUser = System.Security.Principal.WindowsIdentity.GetCurrent();
            srcSecurity.AddAccessRule(new FileSystemAccessRule(
                                          currentUser.User, FileSystemRights.ReadData, AccessControlType.Deny));
            File.SetAccessControl(src, srcSecurity);
#endif
            Assert.Throws <UnauthorizedAccessException>(() => cc.Execute());
        }
Exemple #13
0
        public void Execute_ExistingFile_FileIsCopied()
        {
            var existingFile = @"Temp\Text.txt";
            var targetFile   = @"Temp\Target\TextCopy.txt";

            File.WriteAllText(existingFile, "a little text");

            var copyInfo = Mock.Of <ICopyCommand>
                           (
                c => c.SourceFullPath == existingFile &&
                c.FullPath == targetFile
                           );


            var command = new CopyCommand(copyInfo);

            command.Execute();

            Assert.That(File.Exists(existingFile), Is.True);
            Assert.That(File.Exists(targetFile), Is.True);
        }
Exemple #14
0
        public void Execute_ExistingFileInNotExistingDirectory_FileIsCopied()
        {
            var existingFile = @"Temp\Text.txt";
            var targetFile   = @"Temp\TargetNotExisting\TextCopy.txt";

            File.WriteAllText(existingFile, "a little text");

            var copyArgs = Mock.Of <ICopyCommandArgs>
                           (
                c => c.SourceName == new LiteralScalarResolver <string>(Path.GetFileName(existingFile)) &&
                c.SourcePath == new LiteralScalarResolver <string>(Path.GetDirectoryName(existingFile)) &&
                c.DestinationName == new LiteralScalarResolver <string>(Path.GetFileName(targetFile)) &&
                c.DestinationPath == new LiteralScalarResolver <string>(Path.GetDirectoryName(targetFile))
                           );

            var command = new CopyCommand(copyArgs);

            command.Execute();

            Assert.That(File.Exists(existingFile), Is.True);
            Assert.That(File.Exists(targetFile), Is.True);
        }
 private void OnExecuteCopy(object sender, ExecutedRoutedEventArgs e)
 {
     CopyCommand?.Execute(e.Parameter);
 }
Exemple #16
0
 private void _copyButton_Click(object sender, EventArgs e)
 {
     _copyCommand.Execute();
 }
Exemple #17
0
        void WpfKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Z &&
                (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                UndoBuff.UndoCommand();
                //SelectionManager.SelectObject(null);
            }
            else if (e.Key == System.Windows.Input.Key.Y &&
                     (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                UndoBuff.RedoCommand();
                //SelectionManager.SelectObject(null);
            }
            else if (e.Key == System.Windows.Input.Key.X &&
                     (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                if (_activeTool is SelectionTool && SelectionManager.SelectedObjects.Count > 0)
                {
                    var cmd = new CutCommand(this);
                    cmd.CheckApplicability();
                    cmd.Execute();
                    cmd.Dispose();
                }
            }
            else if (e.Key == System.Windows.Input.Key.C &&
                     (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                if (_activeTool is SelectionTool && SelectionManager.SelectedObjects.Count > 0)
                {
                    var cmd = new CopyCommand(this);
                    cmd.Execute();
                    cmd.Dispose();
                }
            }
            else if (e.Key == System.Windows.Input.Key.V &&
                     (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                if (_activeTool is SelectionTool)
                {
                    var cmd = new PasteCommand(this);
                    cmd.Execute();
                    cmd.Dispose();
                }
            }
            else if (e.Key == System.Windows.Input.Key.Delete)
            {
                if (SelectionManager.SelectedObjects.Count > 0)
                {
                    UndoBuff.AddCommand(new DeleteGraphicsObject(SelectionManager.SelectedObjects.Cast <FrameworkElement>().FirstOrDefault()));
                }
                else if (_activeTool is SelectionTool && SelectionManager.SelectedObjects.Count > 0)
                {
                    foreach (var el in SelectionManager.SelectedObjects.Cast <FrameworkElement>())
                    {
                        UndoBuff.AddCommand(new DeleteGraphicsObject(el));
                    }
                }
                SelectionManager.SelectObject(null);
            }
            else if (e.Key == System.Windows.Input.Key.Add && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                DocumentCommands.First(c => c.command is ZoomInCommand).command.Execute();
            }
            else if (e.Key == System.Windows.Input.Key.Subtract && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None)
            {
                DocumentCommands.First(c => c.command is ZoomOutCommand).command.Execute();
            }

            else if (e.Key == System.Windows.Input.Key.Escape)
            {
                //NotifySetCurrentTool(toolsList[0]);
            }
            else if (e.Key == System.Windows.Input.Key.F5)
            {
                UpdateCanvasByXaml();
            }
            else if (_activeTool is SelectionTool)
            {
                if (e.Key == System.Windows.Input.Key.Left)
                {
                    (_activeTool as SelectionTool).MoveHelper(-1, 0);
                }
                if (e.Key == System.Windows.Input.Key.Right)
                {
                    (_activeTool as SelectionTool).MoveHelper(1, 0);
                }
                if (e.Key == System.Windows.Input.Key.Up)
                {
                    (_activeTool as SelectionTool).MoveHelper(0, -1);
                }
                if (e.Key == System.Windows.Input.Key.Down)
                {
                    (_activeTool as SelectionTool).MoveHelper(0, 1);
                }
            }


            MainPanel.UpdateLayout();
        }
 public void ShouldThrowExceptionIfFileDoesntExist()
 {
     // When
     var command = new CopyCommand (@"c:\temp\abc.txt", DestinyFilePath);
     command.Execute ();
 }