public PandocTaskViewModel()
        {
            Model = new PandocTask();

            AddTargetFile = new RelayCommand(() =>
                {
                    Model.TargetFiles.Add(new TargetFile());
                });

            RemoveTargetFile = new RelayCommand<TargetFile>(file =>
                {
                    Model.TargetFiles.Remove(file);
                }, file => file != null);

            Do = new RelayCommand(() =>
                {
                    IsBusy = true;
                    Task.Factory.StartNew(() =>
                        {
                            Result = PandocRunner.Run(this.GetLocator().Config.Model.PandocExePath, Model).Last();
                        }).ContinueWith(task =>
                            {
                                IsBusy = false;
                            });
                }, () => !IsBusy);
        }
Esempio n. 2
0
        public TaskListViewModel()
        {
            Tasks = new ObservableCollection<PandocTask>(TaskRepository.ToList());
            SelectedTask = Tasks.Any() ? Tasks.First() : null;

            Add = new RelayCommand(() =>
                {
                    var task = new PandocTask();
                    Tasks.Add(task);
                });

            Save = new RelayCommand(() =>
                {
                    var trans = TaskRepository.BeginBatch();
                    foreach (var task in Tasks)
                    {
                        if (TaskRepository.Exists(task.Key))
                            trans.Update(task);
                        else trans.Add(task);
                    }
                    trans.Commit();
                });

            Load = new RelayCommand(() =>
                {
                    Tasks.Clear();
                    foreach (var task in TaskRepository.GetAll())
                    {
                        Tasks.Add(task);
                    }
                });
        }
Esempio n. 3
0
        public static IEnumerable<PandocTaskResult> Run(string pandocExePath, PandocTask task, Action<PandocTask, PandocTaskResult> callback = null)
        {
            if (pandocExePath == null) throw new ArgumentNullException("pandocExePath");
            if (task == null) throw new ArgumentNullException("task");

            var results = new List<PandocTaskResult>();
            var result = new PandocTaskResult();
            var msgBuilder = new StringBuilder(task.SourceFile + "\n");

            if (task.TargetFiles.Count < 1) throw new InvalidOperationException("At least 1 target file needed for the task!");

            foreach (var targetFile in task.TargetFiles)
            {
                var actResult = new PandocTaskResult() { OutputFile = targetFile.Path };
                result.OutputFile = Path.GetFileName(targetFile.Path);
                msgBuilder.Append(result.OutputFile);

                try
                {
                    var args = BuildArguments(task.SourceFile, targetFile.Path, task.Config);

                    var startInfo = new ProcessStartInfo(pandocExePath, args);
                    startInfo.UseShellExecute = false;
                    startInfo.RedirectStandardOutput = true;
                    startInfo.CreateNoWindow = true;

                    var process = System.Diagnostics.Process.Start(startInfo);

                    while (!process.HasExited) ;

                    msgBuilder.AppendLine(" successful.");
                    actResult.Message = "Successful";
                    actResult.Failed = false;
                }
                catch (Exception e)
                {
                    Debugger.Break();
                    msgBuilder.AppendLine(" failed with: ");
                    msgBuilder.AppendLine(e.Message);
                    result.Exception = e;
                    result.Failed = true;
                    actResult.Message = "Failed with " + e.Message;
                    actResult.Exception = e;
                    actResult.Failed = true;
                }

                results.Add(actResult);
                if (callback != null) callback(task, actResult);
            }

            result.Message = msgBuilder.ToString();
            if (callback != null) callback(task, result);
            results.Add(result);
            return results;
        }