public DestinationEditViewModel(PageManager pageManager, FolderReactionModel reactionModel) : base(pageManager, reactionModel) { _CompositeDisposable = new CompositeDisposable(); Destination = reactionModel.Destination as AbsolutePathReactiveDestination; Reaction.ObserveProperty(x => x.IsDestinationValid) .Subscribe(x => IsValid.Value = x) .AddTo(_CompositeDisposable); OutputNamePattern = reactionModel.Destination.ToReactivePropertyAsSynchronized(x => x.OutputNamePattern) .AddTo(_CompositeDisposable); OutputFolderPath = Destination.AbsoluteFolderPath; OutputPathSample = Observable.Merge( Destination.ObserveProperty(x => x.AbsoluteFolderPath).Where(x => false == String.IsNullOrWhiteSpace(x)).ToUnit(), Destination.ObserveProperty(x => x.OutputNamePattern).Throttle(TimeSpan.FromSeconds(0.75)).ToUnit(), Reaction.ObserveProperty(x => x.OutputType).ToUnit() ) .Select(_ => Destination.TestRename()) .Where(x => false == String.IsNullOrEmpty(x)) .Select(x => { if (Reaction.OutputType == ReactiveFolder.Models.Util.FolderItemType.Folder) { return Path.Combine(Destination.AbsoluteFolderPath, x); } else { return Path.Combine(Destination.AbsoluteFolderPath, x) + ".extention"; } }) .ToReadOnlyReactiveProperty() .AddTo(_CompositeDisposable); }
public void Execute(InstantActionTargetFile targetFile) { lock (_OutputFolderPathLock) { var reaction = new FolderReactionModel(); var dir = new DirectoryInfo(Path.GetDirectoryName(targetFile.FilePath)); using (var context = new ReactiveStreamContext(dir, targetFile.FilePath)) { var dest = new AbsolutePathReactiveDestination(); if (false == String.IsNullOrEmpty(this.OutputFolderPath) && Directory.Exists(this.OutputFolderPath) ) { dest.AbsoluteFolderPath = this.OutputFolderPath; } else { targetFile.Failed("File process failed, due to OutputFolder not exist."); return; } var streams = _Actions.Cast<ReactiveStraightStreamBase>().ToList(); streams.Add(dest); foreach (var action in streams) { if (false == context.IsRunnning) { break; } action.Execute(context); } if (context.IsCompleted) { targetFile.Complete(context.OutputPath); } else { if (context.FailedMessage.Count > 0) { targetFile.Failed("Failed due to " + context.FailedMessage[0]); } else { targetFile.Failed("Failed"); } } } } }