public static void MoveTo(this IOperationController controller, IOperation target) { var isRollBack = controller.Operations.Contains(target); var isRollForward = controller.RollForwardTargets.Contains(target); if (isRollBack is false && isRollForward is false) { return; } if (isRollBack) { while (controller.Peek() != target) { controller.Undo(); } } if (isRollForward) { while (controller.RollForwardTargets.FirstOrDefault() != target) { controller.Redo(); } controller.Redo(); } }
/// <summary> /// OperationManagerのUndoStackとマージします。 /// 統合されたOperationはUndoStackから除外されます。 /// Operationが統合された場合OperationManagerのRedoStackはクリアされます。 /// </summary> public IOperation Merge(IOperationController operationController) { if (operationController.CanUndo is false) { return(this); } if (MergeJudge is null) { return(this); } var topCommand = operationController.Peek(); var mergeInfo = MergeJudge; while (topCommand is MergeableOperation mergeableOperation) { if (MergeJudge.CanMerge(mergeableOperation.MergeJudge) is false) { break; } mergeInfo = mergeableOperation.MergeJudge; _rollBack = mergeableOperation._rollBack; operationController.Pop(); topCommand = operationController.Peek(); } MergeJudge = MergeJudge.Update(mergeInfo); return(this); }
private static void _distinct_internal <T>(this IOperationController controller, object key, Func <T, T, IOperation> generateMergedOperation) where T : class, IMergeableOperation { var operations = controller.Operations.ToList(); var mergeable = operations .OfType <T>() .Where(x => x.MergeJudge.GetMergeKey() == key) .ToArray(); var first = mergeable.FirstOrDefault(); var last = mergeable.LastOrDefault(); if (first is null || last is null) { return; } var lastIndex = 0; foreach (var operation in mergeable) { lastIndex = operations.IndexOf(operation); operations.RemoveAt(lastIndex); } var newOperation = generateMergedOperation(first, last); operations.Insert(lastIndex, newOperation); controller.Flush(); operations.ForEach(x => controller.Push(x)); }
/// <summary> /// OperationManagerのUndoStackとマージします。 /// 統合されたOperationはUndoStackから除外されます。 /// Operationが統合された場合OperationManagerのRedoStackはクリアされます。 /// </summary> /// <param name="operationController"></param> /// <returns></returns> public IOperation Merge(IOperationController operationController) { if (operationController.CanUndo is false) { return(this); } if (MergeJudge is null) { return(this); } var topCommand = operationController.Peek(); var prevValue = PrevProperty; var mergeInfo = MergeJudge; while (topCommand is MergeableOperation <T> propertyChangeOperation) { if (MergeJudge.CanMerge(propertyChangeOperation.MergeJudge) is false) { break; } mergeInfo = propertyChangeOperation.MergeJudge; prevValue = propertyChangeOperation.PrevProperty; operationController.Pop(); topCommand = operationController.Peek(); } PrevProperty = prevValue; MergeJudge = mergeInfo; return(this); }
public AuthorityOperationDecorator(IOperationController operationController, string role) { OperationController = operationController; Role = role; AuthorizedUsers = new Dictionary <string, List <string> >(); AuthorizedUsers["Delete"] = new List <String>() { "Doctor", "Secretary" }; AuthorizedUsers["Edit"] = new List <String>() { "Doctor", "Secretary" }; AuthorizedUsers["Get"] = new List <String>() { "Secretary", "Doctor", "Patient" }; AuthorizedUsers["GetAll"] = new List <String>() { "Secretary", "Doctor", "Patient" }; AuthorizedUsers["GetOperationsByDoctor"] = new List <String>() { "Doctor" }; AuthorizedUsers["Save"] = new List <String>() { "Doctor" }; }
public static void ExecuteSetProperty <T, TProperty>(this IOperationController controller, T owner, string propertyName, TProperty value) { var operation = owner .GenerateSetPropertyOperation(propertyName, value) .Merge(controller); controller.Execute(operation); }
// IOperationController をIObservable<Unit>に変換 public static IObservable <Unit> StackChangedAsObservable(this IOperationController self) { return(Observable .FromEventPattern <Action <object, OperationStackChangedEventArgs>, OperationStackChangedEventArgs>( h => self.StackChanged += h, h => self.StackChanged -= h) .ToUnit() .StartWithDefault()); }
public static IOperation PushTo(this IOperation _this, IOperationController controller) { if (_this is IMergeableOperation mergeableOperation) { _this = mergeableOperation.Merge(controller); } return(controller.Push(_this)); }
public static IOperation Execute(this IOperation _this, IOperationController controller) { if (_this is IMergeableOperation mergeableOperation) { _this = mergeableOperation.Merge(controller); } return(controller.Execute(_this)); }
public override IPropertyBuilder OperationController(IOperationController controller) { _operationController = controller; foreach (var suBuilder in _suBuilders) { suBuilder.OperationController(_operationController); } return(this); }
public static IOperation ExecuteAndCombineTop(this IOperation _this, IOperationController controller) { if (controller.Operations.Any()) { var prev = controller.Pop(); _this.RollForward(); var newOperation = prev.CombineOperations(_this).ToCompositeOperation(); newOperation.Messaage = _this.Messaage; return(controller.Push(newOperation)); } return(controller.Execute(_this)); }
public static void ExecuteRemoveAt <T>(this IOperationController controller, IList <T> list, int index) { if (list is IList iList) { var operation = iList.ToRemoveAtOperation(index); controller.Execute(operation); } else { var target = list[index]; var operation = list.ToRemoveOperation(target); controller.Execute(operation); } }
public Geometry2DVm(Geometry2D.Geometry2D model, IOperationController operationController) { Model = model; var o = Model.Origin; Points = Model.Select(x => new Point2DVm(x, operationController)).ToArray(); for (var iterator = 0; iterator < Points.Length; ++iterator) { var index = iterator; Points[index].PropertyChanged += (s, e) => { Model[index] = Points[index].Model; OnPropertyChanged(nameof(Geometry)); }; } }
public static IDisposable BindPropertyChanged <T>(this IOperationController controller, INotifyPropertyChanged owner, string propertyName, bool autoMerge = true) { var prevValue = FastReflection.GetProperty <T>(owner, propertyName); var callFromOperation = false; owner.PropertyChanged += PropertyChanged; return(new Disposer(() => owner.PropertyChanged -= PropertyChanged)); // local function void PropertyChanged(object sender, PropertyChangedEventArgs args) { if (callFromOperation) { return; } if (args.PropertyName == propertyName) { callFromOperation = true; T newValue = FastReflection.GetProperty <T>(owner, propertyName); var operation = owner .GenerateAutoMergeOperation(propertyName, newValue, prevValue, $"{sender.GetHashCode()}.{propertyName}", Operation.DefaultMergeSpan); if (autoMerge) { operation = operation.Merge(controller); } operation .AddPreEvent(() => callFromOperation = true) .AddPostEvent(() => callFromOperation = false); prevValue = newValue; controller.Push(operation); callFromOperation = false; } } }
public Operatable(IOperationController operationController) { OperationController = operationController; }
public virtual IPropertyBuilder OperationController(IOperationController controller) { _operationController = controller; return(this); }
public ConnectionViewModel(IOperationController controller) { }
public static void ExecuteRemoveItems <T>(this IOperationController controller, IList <T> list, IEnumerable <T> value) { var operation = list.ToRemoveRangeOperation(value); controller.Execute(operation); }
public OperationVm(IOperation operation, IOperationController controller) { Name = operation.Message; GotoCommand = new ViewModelCommand(() => controller.MoveTo(operation)); IsRedo = controller.Operations.All(x => x != operation); }
public void Interact(IOperationController operationController) { Debug.Assert(operationController != null); operationController.Accept(this); }
public ConnectionCreator(ObservableCollection <IConnectionDataContext> connecions, IOperationController @operator) { var removeOperation = Operation.Empty; //! コネクション接続完了コマンド ConnectCommand = new ReactiveCommand <CompletedCreateConnectionEventArgs>(); ConnectCommand.Subscribe((e) => { var operation = make_remove_duplication_plugs_operation(new[] { e.ConnectionDataContext.DestPlug, e.ConnectionDataContext.SourcePlug }) .CombineOperations(connecions.ToAddOperation(e.ConnectionDataContext)) .ToCompositeOperation(); operation.Message = "コネクション接続"; if (removeOperation.IsEmpty()) { operation.ExecuteTo(@operator); } else { operation.ExecuteAndCombineTop(@operator); } }); //! コネクション接続開始コマンド StartNewConnectionCommand = new ReactiveCommand <StartCreateConnectionEventArgs>(); StartNewConnectionCommand.Subscribe((e) => { removeOperation = make_remove_duplication_plugs_operation(e.SenderPlugs); if (removeOperation.IsNotEmpty()) { removeOperation.ExecuteTo(@operator); } }); //! コネクション削除 IOperation make_remove_duplication_plugs_operation(IPlugDataContext[] plugs) { var removeConnections = connecions.Where(x => plugs?.Contains(x.DestPlug) is true || plugs?.Contains(x.SourcePlug) is true).ToArray(); if (removeConnections.Length is 0) { return(Operation.Empty); } var operation = connecions .ToRemoveRangeOperation(removeConnections); operation.Message = "コノクションの削除"; return(operation); } }
public PlugViewModel(IOperationController controller) { _operationController = controller; }
public NodeViewModel3(IOperationController operationController) { }
public static void ExecuteInsert <T>(this IOperationController controller, IList <T> list, T value, int index) { var operation = new InsertOperation <T>(@list, value, index); controller.Execute(operation); }
public static void Distinct <T>(this IOperationController controller, object key) { _distinct_internal <MergeableOperation <T> >(controller, key, (x, y) => MergeableOperation <T> .MakeMerged(x, y, false)); }
public Secured( ISystemController systemController, IBlockController blockController, IOperationController operationController, ISerializationController serializationController ) { this.RequiresAuthentication(); var logger = LogManager.GetCurrentClassLogger(); Get["/master"] = parameters => View["Views/Home/Master.cshtml"]; Get["/"] = parameters => View["Views/Home/Master.cshtml"]; Post["/api/fonts"] = parameters => { try { return(Response.AsJson(new FontInfo { Fonts = systemController.GetFonts(), Sizes = systemController.GetFontSizes(), Indexes = systemController.GetFontHeightIndex() })); } catch (Exception ex) { var exception = new Exception("Ошибка загрузки шрифтов", ex); logger.Error(exception); throw exception; } }; Post["/api/datetimeformats"] = parameters => { try { return(Response.AsJson(systemController.GetDatetimeFormats())); } catch (Exception ex) { var exception = new Exception("Ошибка загрузки форматов даты/времени", ex); logger.Error(exception); throw exception; } }; Post["/api/screenResolution"] = parameters => { try { var data = this.Bind <ScreenResolutionRequest>(); if (!data.RefreshData) { var screenInfo = systemController.GetDatabaseScreenInfo(); if (screenInfo == null) { screenInfo = systemController.GetSystemScreenInfo(); systemController.SetDatabaseScreenInfo(screenInfo); } return(Response.AsJson(screenInfo)); } else { var screenInfo = systemController.GetSystemScreenInfo(); systemController.SetDatabaseScreenInfo(screenInfo); return(Response.AsJson(screenInfo)); } } catch (Exception ex) { var exception = new Exception("Ошибка загрузки информации о экранах", ex); logger.Error(exception); throw exception; } }; Post["/api/setBackground"] = parameters => { try { var data = this.Bind <ScreenBackgroundRequest>(); blockController.SetBackground(data.Color); return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка установки фона", ex); logger.Error(exception); throw exception; } }; Get["/api/background"] = parameters => { try { return(Response.AsJson(blockController.GetBackground())); } catch (Exception ex) { var exception = new Exception("Ошибка загрузки фона", ex); logger.Error(exception); throw exception; } }; Post["/api/addTextBlock"] = parameters => { try { var textBlock = blockController.AddTextBlock(); var block = _mapper.Map <TextBlockDto>(textBlock); return(Response.AsJson(block)); } catch (Exception ex) { var exception = new Exception("Ошибка добавления текстового блока", ex); logger.Error(exception); throw exception; } }; Post["/api/addTableBlock"] = parameters => { try { var tableBlock = blockController.AddTableBlock(); var block = _mapper.Map <TableBlockDto>(tableBlock); return(Response.AsJson(block)); } catch (Exception ex) { var exception = new Exception("Ошибка добавления таблицы", ex); logger.Error(exception); throw exception; } }; Post["/api/addPictureBlock"] = parameters => { try { var pictureBlock = blockController.AddPictureBlock(); var block = _mapper.Map <PictureBlockDto>(pictureBlock); return(Response.AsJson(block)); } catch (Exception ex) { var exception = new Exception("Ошибка добавления картинки", ex); logger.Error(exception); throw exception; } }; Post["/api/addDateTimeBlock"] = parameters => { try { var dateTimeBlock = blockController.AddDateTimeBlock(); var block = _mapper.Map <DateTimeBlockDto>(dateTimeBlock); return(Response.AsJson(block)); } catch (Exception ex) { var exception = new Exception("Ошибка добавления блока даты/времени", ex); logger.Error(exception); throw exception; } }; Get["/api/blocks"] = parameters => { try { var blocks = GetBlocks(blockController); return(Response.AsJson(blocks)); } catch (Exception ex) { var exception = new Exception("Ошибка загрузки блоков", ex); logger.Error(exception); throw exception; } }; Post["/api/moveAndResize"] = parameters => { try { var block = this.Bind <SizeAndPositionDto>(); blockController.MoveAndResizeBlock(block.Id, block.Height, block.Width, block.Left, block.Top); return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка изменения размеров и положения блока", ex); logger.Error(exception); throw exception; } }; Post["/api/saveBlock"] = parameters => { var savers = new Dictionary <string, Action>() { { "text", () => SaveBlock <TextBlock, TextBlockDto>(b => blockController.SaveTextBlock(b)) }, { "table", () => SaveBlock <TableBlock, TableBlockDto>(b => blockController.SaveTableBlock(b)) }, { "picture", () => SaveBlock <PictureBlock, PictureBlockDto>(b => blockController.SavePictureBlock(b)) }, { "datetime", () => SaveBlock <DateTimeBlock, DateTimeBlockDto>(b => blockController.SaveDateTimeBlock(b)) } }; try { var data = this.Bind <BlockDto>(); savers.First(kvp => kvp.Key.Equals(data.Type, StringComparison.InvariantCultureIgnoreCase)).Value.Invoke(); return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка сохранения блоков", ex); logger.Error(exception); throw exception; } }; Post["/api/deleteBlock"] = parameters => { try { var data = this.Bind <BlockDto>(); blockController.DeleteBlock(data.Id); return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка удаления блоков", ex); logger.Error(exception); throw exception; } }; Post["/api/copyBlock"] = parameters => { var copiers = new Dictionary <string, Func <object> > { { "text", () => CopyBlock <TextBlock, TextBlockDto>(b => blockController.CopyTextBlock(b)) }, { "table", () => CopyBlock <TableBlock, TableBlockDto>(b => blockController.CopyTableBlock(b)) }, { "picture", () => CopyBlock <PictureBlock, PictureBlockDto>(b => blockController.CopyPictureBlock(b)) }, { "datetime", () => CopyBlock <DateTimeBlock, DateTimeBlockDto>(b => blockController.CopyDateTimeBlock(b)) } }; try { var data = this.Bind <BlockDto>(); return(copiers.First(kvp => kvp.Key.Equals(data.Type, StringComparison.InvariantCultureIgnoreCase)).Value.Invoke()); } catch (Exception ex) { var exception = new Exception("Ошибка копирования блоков", ex); logger.Error(exception); throw exception; } }; Post["/api/startShow"] = parameters => { try { operationController.StartShow(); return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка запуска полноэкранного режима", ex); logger.Error(exception); throw exception; } }; Post["/api/stopShow"] = parameters => { try { operationController.StopShow(); return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка остановки полноэкранного режима", ex); logger.Error(exception); throw exception; } }; Post["/api/parseCSV"] = parameters => { try { var linesSeparator = new char[] { '\r', '\n' }; var itemSeparator = ','; var data = this.Bind <CsvDataDto>(); var lines = data.Text.Split(linesSeparator, StringSplitOptions.RemoveEmptyEntries); var result = new CsvTableDto(); result.Header.AddRange(lines.First().Split(itemSeparator)); var rowIndex = 0; foreach (var line in lines.Skip(1)) { var cells = line.Split(itemSeparator); var delta = cells.Length - result.Header.Count; if (delta > 0) { for (int i = 0; i < delta; i++) { result.Header.Add(string.Empty); } } result.Rows.Add(new RowDto { Index = rowIndex, Cells = cells }); rowIndex++; } return(Response.AsJson(result)); } catch (Exception ex) { var exception = new Exception("Ошибка чтения csv", ex); logger.Error(exception); throw exception; } }; Get["/api/downloadConfig"] = parameters => { try { var response = new Response { ContentType = "text/xml", Contents = (stream) => serializationController.SerializeXML(new ConfigDto { Background = blockController.GetBackground(), Blocks = GetBlocks(blockController).ToList() }).CopyTo(stream) }; response.Headers.Add("Content-Disposition", "attachment; filename=config.xml"); return(response); } catch (Exception ex) { var exception = new Exception("Ошибка выгрузки конфигурации", ex); logger.Error(exception); throw exception; } }; Post["/api/uploadConfig"] = parameters => { try { var data = this.Bind <ConfigDataDto>(); var configDto = serializationController.Deserialize <ConfigDto>(data.Text); blockController.SetBackground(configDto.Background); blockController.Cleanup(); foreach (var b in configDto.Blocks) { if (b is TextBlockDto textBlock) { var block = _mapper.Map <TextBlock>(textBlock); blockController.SaveTextBlock(block); } if (b is TableBlockDto tableBlock) { var block = _mapper.Map <TableBlock>(tableBlock); blockController.SaveTableBlock(block); } if (b is PictureBlockDto pictureBlock) { var block = _mapper.Map <PictureBlock>(pictureBlock); blockController.SavePictureBlock(block); } } return(Response.AsJson(true)); } catch (Exception ex) { var exception = new Exception("Ошибка загрузки конфигурации", ex); logger.Error(exception); throw exception; } }; }
public PlugViewModel3(IOperationController controller) : base(controller) { }
public OperationConsole(IOperationController controller) { this.controller = controller; }
public static void ExecuteRemove <T>(this IOperationController controller, IList <T> list, T value) { var operation = list.ToRemoveOperation(value); controller.Execute(operation); }
public OperationRecorder(IOperationController controller) { _root = controller; }