public static FolderReactionModel CreateReaction(InstantActionSaveModel instantActionSaveModel)
		{
			var reaction = new FolderReactionModel();


			var extentions = instantActionSaveModel.TargetFiles.Select(x => Path.GetExtension(x))
				.Distinct()
				.Select(x => "*" + x);

			foreach (var ext in extentions)
			{
				reaction.Filter.AddIncludeFilter(ext);
			}


			foreach (var action in instantActionSaveModel.Actions)
			{
				reaction.AddAction(action);
			}

			reaction.Destination.AbsoluteFolderPath = instantActionSaveModel.OutputFolderPath;


			return reaction;
		}
		public FileFilterViewModel(FolderReactionModel reactionModel, FileReactiveFilter filter)
			: base(reactionModel, filter)
		{
			FileFilterModel = filter;

			
		}
		private string MakeFilePath(FolderReactionModel reaction)
		{
			return Path.Combine(
				SaveFolder.FullName,
				reaction.Guid.ToString() + UPDATE_RECORD_EXTENTION
				)
				;
		}
		public void ClearRecord(FolderReactionModel reaction)
		{
			var filename = MakeFilePath(reaction);

			var fileInfo = new FileInfo(filename);
			if (fileInfo.Exists)
			{
				fileInfo.Delete();
			}
		}
		public static void SaveReaction(this IFolderReactionMonitorModel moonitor, FolderReactionModel reaction)
		{
			var folder = moonitor.FindReactionParentFolder(reaction);
			if (folder != null)
			{
				folder.SaveReaction(reaction);
			}
			else
			{
				// 削除されたリアクション、またはフォルダが削除されている
			}
		}
		public ReactionEditViewModelBase(PageManager pageManager, FolderReactionModel reactionModel)
		{
			PageManager = pageManager;
			Reaction = reactionModel;
			_CompositeDisposable = new CompositeDisposable();


			IsValid = new ReactiveProperty<bool>(false)
				.AddTo(_CompositeDisposable);

			ValidateState = IsValid
				.Select(x => x ? ValidationState.Valid : ValidationState.Invalid)
				.ToReactiveProperty(ValidationState.WaitFirstValidate)
				.AddTo(_CompositeDisposable);
		}
		public WorkFolderEditViewModel(PageManager pageManager, FolderReactionModel reactionModel)
			: base(pageManager, reactionModel)
		{

			Reaction.ObserveProperty(x => x.IsWorkFolderValid)
				.Subscribe(x => IsValid.Value = x)
				.AddTo(_CompositeDisposable);


			WorkFolderPath = Reaction.ObserveProperty(x => x.WorkFolder)
				.Select(x => x?.FullName ?? "<not selected>")
				.ToReactiveProperty()
				.AddTo(_CompositeDisposable);

		}
		public ReactionListItemViewModel(FolderReactionManagePageViewModel pageVM, FolderReactionModel reactionModel)
		{
			PageVM = pageVM;
			Reaction = reactionModel;

			Name = Reaction.Name.ToString();

			var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

			FilePath = Reaction.WorkFolder?.FullName ?? "<no setting>";

			IsInactive = false == Reaction.IsEnable;

			IsInvalid = false == Reaction.IsValid;

			IsSelected = false;
		}
		public FilterViewModelBase(FolderReactionModel reactionModel, ReactiveFilterBase filter)
		{
			ReactionModel = reactionModel;
			Filter = filter;
			_CompositeDisposable = new CompositeDisposable();

			FilterType = Filter.OutputItemType.ToString();


			IncludeFilterText = new ReactiveProperty<string>("");

			IncludeFilterPatterns = Filter.IncludeFilter
				.ToReadOnlyReactiveCollection()
				.AddTo(_CompositeDisposable);



			ExcludeFilterText = new ReactiveProperty<string>("");

			ExcludeFilterPatterns = Filter.ExcludeFilter
				.ToReadOnlyReactiveCollection()
				.AddTo(_CompositeDisposable);

			/*
			SampleItems = FolderFilter.ObserveProperty(x => x.FolderFilterPattern)
				.Throttle(TimeSpan.FromSeconds(0.25))
				.SelectMany(x => FolderFilter.DirectoryFilter(ReactionModel.WorkFolder))
				.Select(x => $"/{x.Name}")
				.ToReadOnlyReactiveCollection()
				.AddTo(_CompositeDisposable);
				*/

			AddIncludeFilterTextCommand = IncludeFilterText
				.Select(x => Filter.IsValidFilterPatternText(x))
				.ToReactiveCommand<string>();

			AddIncludeFilterTextCommand.Subscribe(AddIncludeFilterText);


			AddExcludeFilterTextCommand = ExcludeFilterText
				.Select(x => Filter.IsValidFilterPatternText(x))
				.ToReactiveCommand<string>();

			AddExcludeFilterTextCommand.Subscribe(AddExcludeFilterText);
		}
		public ActionsEditViewModel(FolderReactionModel reactionModel, PageManager pageManager, IAppPolicyManager appPolicyManager)
			: base(pageManager, reactionModel)
		{
			_AppPolicyManager = appPolicyManager;

			Reaction.ObserveProperty(x => x.IsActionsValid)
				.Subscribe(x => IsValid.Value = x)
				.AddTo(_CompositeDisposable);


			// TODO: CollectionChangedをマージしてReactiveCollectionにする方法を使ってまとめる
			// Note: AppLaunchActionViewModelをAppOptionValueInstance1つずつに対して作成している
			Actions = new ObservableCollection<AppLaunchActionViewModel>(
				Reaction.Actions.Select(
					x =>
					{
						var appLaunchAction = x as AppLaunchReactiveAction;
						return new AppLaunchActionViewModel(this, Reaction, appLaunchAction);
					}
					)
				);

			Actions.CollectionChangedAsObservable()
				.Subscribe(itemPair => 
				{
					var onceRemoveItems = Reaction.Actions.ToArray();
					foreach (var onceRemoveItem in onceRemoveItems)
					{
						Reaction.RemoveAction(onceRemoveItem);
					}
					
					foreach(var reAdditem in Actions)
					{
						Reaction.AddAction(reAdditem.Action);
					}
				});

			IsActionsEmpty = Actions.ObserveProperty(x => x.Count)
				.Select(x => x == 0)
				.ToReactiveProperty();

			IsActionsEmpty.Subscribe();
		}
		public FilterEditViewModel(PageManager pageManager, FolderReactionModel reactionModel)
			: base(pageManager, reactionModel)
		{
			Reaction.ObserveProperty(x => x.IsFilterValid)
				.Subscribe(x => IsValid.Value = x)
				.AddTo(_CompositeDisposable);


			// 
			// Reactionが持っていないフィルターモデルは個々で作成する


			var currentFilterType = Reaction.Filter.OutputItemType;

			FileFilterViewModel fileFilterVM;
			FolderFilterViewModel folderFilterVM;

			if (currentFilterType == FolderItemType.File)
			{
				fileFilterVM = new FileFilterViewModel(Reaction, Reaction.Filter as FileReactiveFilter);
				folderFilterVM = new FolderFilterViewModel(Reaction, new FolderReactiveFilter());
			}
			else if (currentFilterType == FolderItemType.Folder)
			{
				fileFilterVM = new FileFilterViewModel(Reaction, new FileReactiveFilter());
				folderFilterVM = new FolderFilterViewModel(Reaction, Reaction.Filter as FolderReactiveFilter);
			}
			else
			{
				throw new Exception();
			}

			Filters = new List<FilterViewModelBase>();
			Filters.Add(fileFilterVM);
			Filters.Add(folderFilterVM);


			SelectedFilterVM = Reaction.ToReactivePropertyAsSynchronized(x => x.Filter,
				convert: (model) => Filters.Single(y => y.Filter == model),
				convertBack: (vm) => vm.Filter
				);
		}
		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 AppLaunchActionViewModel(ActionsEditViewModel editVM, FolderReactionModel reactionModel, AppLaunchReactiveAction appAction)
			 : base(reactionModel)
		{
			EditVM = editVM;
			Action = appAction;

			AppPolicy = appAction.AppPolicy;
			if (AppPolicy != null)
			{
				AppName = AppPolicy.AppName;
				AppGuid = AppPolicy.Guid;

				UsingOptions = Action.Options.ToReadOnlyReactiveCollection(x =>
					new AppOptionInstanceViewModel(Action, x)
					);

				Action.Options.ObserveElementPropertyChanged()
					.Subscribe(x => Action.Validate());
			}
			else
			{
				AppName = "<App not found>";
			}
		}
		public List<FolderItemUpdateRecord> GetRecord(FolderReactionModel reaction)
		{
			var filename = MakeFilePath(reaction);

			List<FolderItemUpdateRecord> list = null;

			if (File.Exists(filename))
			{
				try
				{
					var record = Util.FileSerializeHelper.LoadAsync<FolderItemUpdateRecord[]>(filename);

					list = record.ToList();
				}
				catch(Exception e)
				{
					File.Delete(filename);
					System.Diagnostics.Debug.WriteLine(e.Message);
				}
			}
			
			return list ?? new List<FolderItemUpdateRecord>();
			
		}
		public ReactionMonitor(FolderReactionModel reaction, IFolderReactionMonitorModel monitor, IHistoryManager history)
		{
			Reaction = reaction;
			Monitor = monitor;
			HistoryManager = history;

			NowProcessing = false;
			IsTerminated = false;

			Start();
		}
		// Reactionmodelを受け取ってVMを生成する

		public ReactionViewModel(FolderReactionModel reaction, PageManager pageManager, IAppPolicyManager appPolicyManager)
		{
			_CompositeDisposable = new CompositeDisposable();
			Reaction = reaction;
			PageManager = pageManager;
			_AppPolicyManager = appPolicyManager;


			IsReactionValid = Reaction.ObserveProperty(x => x.IsValid)
				.ToReactiveProperty()
				.AddTo(_CompositeDisposable);

			ReactionWorkName = Reaction.ToReactivePropertyAsSynchronized(x => x.Name)
				.AddTo(_CompositeDisposable);

			WorkFolderEditVM = new WorkFolderEditViewModel(PageManager, Reaction);
			FilterEditVM = new FilterEditViewModel(PageManager, Reaction);
			ActionsEditVM = new ActionsEditViewModel(Reaction, PageManager, _AppPolicyManager);
			DestinationEditVM = new DestinationEditViewModel(PageManager, Reaction);


			EditVMList = new List<ReactionEditViewModelBase>()
			{
				WorkFolderEditVM,
				FilterEditVM,
				ActionsEditVM,
				DestinationEditVM
			};

			IsEnable = Reaction.ToReactivePropertyAsSynchronized(x => x.IsEnable)
				.AddTo(_CompositeDisposable);

			// see@ http://stackoverflow.com/questions/1833830/timespan-parse-time-format-hhmmss
			// https://msdn.microsoft.com/en-us/library/ee372286.aspx
			MonitorIntervalSeconds = Reaction.ToReactivePropertyAsSynchronized(
				x => x.CheckInterval
				, convert: (timespan) => ((int)timespan.TotalSeconds).ToString()
				, convertBack: (seconds) => TimeSpan.FromSeconds(int.Parse(seconds))
				, ignoreValidationErrorValue: true
			)
			.AddTo(_CompositeDisposable);

			MonitorIntervalSeconds.SetValidateNotifyError(text =>
			{
				int temp;
				if (false == int.TryParse(text, out temp))
				{
					return "Number Only";
				}

				return null;
			});

			


		}
Esempio n. 17
0
		private async void DeleteReaction(FolderReactionModel reaction)
		{
			var reactionFileName = MakeReactionSaveFilePath(reaction);

			var reactionFileInfo = new FileInfo(reactionFileName);
			if (reactionFileInfo.Exists)
			{
				await Task.Run(() => reactionFileInfo.Delete());
			}
		}
Esempio n. 18
0
		public void SaveReaction(FolderReactionModel reaction)
		{
			var reactionFileName = MakeReactionSaveFilePath(reaction);

			var reactionFileInfo = new FileInfo(reactionFileName);
			if (reactionFileInfo.Exists)
			{
				reactionFileInfo.Delete();
			}

			FileSerializeHelper.Save(reactionFileInfo, reaction);
		}
Esempio n. 19
0
		public string MakeReactionSaveFilePath(FolderReactionModel reaction)
		{
			return Path.Combine(Folder.FullName, reaction.Guid.ToString() + REACTION_EXTENTION);
		}
Esempio n. 20
0
		public FolderModel FindReactionParent(FolderReactionModel model)
		{
			if (Reactions.Contains(model))
			{
				return this;
			}

			foreach (var child in Children)
			{
				var folder = child.FindReactionParent(model);
				if (folder != null) { return folder; }
			}

			return null;
		}
		public void SaveRecord(FolderReactionModel reaction, List<FolderItemUpdateRecord> records)
		{
			var filename = MakeFilePath(reaction);

			FileSerializeHelper.Save(filename, records.ToArray());
		}
Esempio n. 22
0
		public void AddReaction(FolderReactionModel reaction)
		{
			// Note: 特にインポートした時にGuidが重複しているときの対策
			if (null != FindReaction(reaction.Guid))
			{
				FolderReactionModel.ResetGuid(reaction);
			}

			_Reactions.Add(reaction);

			SaveReaction(reaction);
		}
		internal void SelectReaction(FolderReactionModel reaction)
		{
			var reactionParentFolder = Monitor.FindReactionParentFolder(reaction);

			SelectFolder(reactionParentFolder);


			var reactionListItem = CurrentFolder.Value.ReactionItems.SingleOrDefault(x => x.Reaction == reaction);

			if (reactionListItem != null)
			{
				CurrentFolder.Value.SelectReaction(reactionListItem);
			}
		}
		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");
						}
					}

				}
			}

			
		}
		internal void ShowReaction(FolderReactionModel reaction)
		{
			PageManager.OpenReaction(reaction.Guid);
		}
		internal async Task<bool> DeleteFolderReactionFile(FolderReactionModel reaction)
		{
			// 確認ダイアログを表示
			var result = await ShowReactionDeleteConfirmDialog();

			// 削除
			if (result != null && result.HasValue && result.Value == true)
			{
				Monitor.StopMonitoring(reaction);

				var reactionSaveFoler = Monitor.FindReactionParentFolder(reaction);
				reactionSaveFoler.RemoveReaction(reaction.Guid);

				return true;
			}
			else
			{
				return false;
			}

			
		}
		public ActionViewModelBase(FolderReactionModel reactionModel)
		{
			ReactionModel = reactionModel;
			_CompositeDisposable = new CompositeDisposable();
		}
		public void StopMonitoring(FolderReactionModel reaction)
		{
			if (_RunningReactions.ContainsKey(reaction.Guid))
			{
				var monitor = _RunningReactions[reaction.Guid];

				monitor.Dispose();

				_RunningReactions.Remove(reaction.Guid);
			}
		}
		public FolderFilterViewModel(FolderReactionModel reactionModel, FolderReactiveFilter filter)
			: base(reactionModel, filter)
		{
			FolderFilter = filter;			
		}
Esempio n. 30
0
		public FolderReactionModel ReactionCopyTo(FolderReactionModel target, FolderModel destFolder)
		{
			throw new NotImplementedException("ReactionCopyTo is still implement.");
		}