public void Run(IApplication application, IFile file)
        {
            if (file == null)
            {
                countingAppender.Application(application.Path);
                Process.Start(application.Path);
            }
            else
            {
                string arguments = file.Path;
                if (!String.IsNullOrEmpty(application.Arguments))
                {
                    TokenWriter writer = new TokenWriter(application.Arguments);
                    arguments = writer.Format(new KeyValueCollection()
                        .Add("FilePath", file.Path)
                        .Add("DirectoryPath", System.IO.Path.GetDirectoryName(file.Path))
                    );

                    countingAppender.File(application.Path, application.Arguments, file.Path);
                }
                else
                {
                    countingAppender.File(application.Path, file.Path);
                }

                Process.Start(new ProcessStartInfo(application.Path, arguments));
                EventManager.RaiseProcessStarted(application, file);
            }
        }
        public void Run(IApplication application, IFile file)
        {
            if (file == null)
            {
                countingAppender.Application(application.Path);
                Process.Start(application.Path);
            }
            else
            {
                string arguments = file.Path;
                if (!String.IsNullOrEmpty(application.Arguments))
                {
                    TokenWriter writer = new TokenWriter(application.Arguments);
                    arguments = writer.Format(new KeyValueCollection()
                                              .Add("FilePath", file.Path)
                                              .Add("DirectoryPath", System.IO.Path.GetDirectoryName(file.Path))
                                              );

                    countingAppender.File(application.Path, application.Arguments, file.Path);
                }
                else
                {
                    countingAppender.File(application.Path, file.Path);
                }

                Process.Start(new ProcessStartInfo(application.Path, arguments));
                EventManager.RaiseProcessStarted(application, file);
            }
        }
Esempio n. 3
0
        public static void Test()
        {
            TokenWriter writer = new TokenWriter("Hello, my name is {Name} and I am from {City}.");
            string      result = writer.Format(new KeyValueCollection().Add("Name", "Peter").Add("City", "Prague"));

            Console.WriteLine(result);
        }
        public void Run(IApplication application, IFile file, bool isAdministratorRequired = false)
        {
            string arguments = null;

            if (file == null)
            {
                if (!String.IsNullOrEmpty(application.EmptyArguments))
                {
                    arguments = application.EmptyArguments;
                    countingAppender.Application(application.Path, arguments);
                }
                else
                {
                    countingAppender.Application(application.Path);
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(application.FileArguments))
                {
                    TokenWriter writer = new TokenWriter(application.FileArguments);
                    arguments = writer.Format(new KeyValueCollection()
                                              .Add("FilePath", file.Path)
                                              .Add("DirectoryPath", Path.GetDirectoryName(file.Path))
                                              );

                    countingAppender.File(application.Path, application.FileArguments, file.Path);
                }
                else
                {
                    arguments = file.Path;
                    countingAppender.File(application.Path, file.Path);
                }
            }

            ProcessStartInfo info = arguments == null ? new ProcessStartInfo(application.Path) : new ProcessStartInfo(application.Path, arguments);

            if (isAdministratorRequired || application.IsAdministratorRequired)
            {
                info.Verb = "runas";
            }

            try
            {
                Process.Start(info);
                EventManager.RaiseProcessStarted(application, file);
            }
            catch (Win32Exception e)
            {
                // "The operation was canceled by the user".
                if (e.NativeErrorCode != 1223)
                {
                    throw;
                }
            }
        }
Esempio n. 5
0
        private static void TryBackupFile(UploadSettings configuration, string filePath)
        {
            if (!String.IsNullOrEmpty(configuration.BackupTemplate))
            {
                TokenWriter writer = new TokenWriter(configuration.BackupTemplate);

                int    order       = 0;
                string newFilePath = null;
                do
                {
                    string newFileName = writer.Format(token =>
                    {
                        if (token == "FileName")
                        {
                            return(Path.GetFileNameWithoutExtension(filePath));
                        }

                        if (token == "Extension")
                        {
                            return(Path.GetExtension(filePath).Substring(1));
                        }

                        if (token == "Order")
                        {
                            return((++order).ToString());
                        }

                        throw Ensure.Exception.NotSupported($"Not supported token '{token}' in backup template '{configuration.BackupTemplate}'.");
                    });

                    string currentNewFilePath = Path.Combine(Path.GetDirectoryName(filePath), newFileName);

                    if (currentNewFilePath == newFilePath || order > 100)
                    {
                        throw Ensure.Exception.InvalidOperation($"Maximum path probing reached on path '{newFilePath}'.");
                    }

                    newFilePath = currentNewFilePath;
                }while (File.Exists(newFilePath));

                File.Copy(filePath, newFilePath);
            }
        }