private void _Do(IEvent e) { if (e is IActionableEvent) { IBaseCommand doCommand = (e as IActionableEvent).NewDoCommand(); if (doCommand is IEntityModifier) { IEntityModifier m = (doCommand as IEntityModifier); Assert.IsTrue(m is IEventProducing); EM.ApplyMod(m); } else if (doCommand is IIndependentModifier) { IIndependentModifier m = (doCommand as IIndependentModifier); Assert.IsTrue(m is IEventProducing); EM.ApplyMod(m); } else if (doCommand is Command) { throw new NotImplementedException(); } else { throw new Exception(); } } }
private IEvent _Undo(bool countNonActionable = true) // TODO { IEvent e = allEvents.Pop(); // Make method for this if (e is IActionableEvent) { IBaseCommand undoCommand = (e as IActionableEvent).NewUndoCommand(); if (undoCommand is IEntityModifier) { IEntityModifier m = (undoCommand as IEntityModifier); Assert.IsTrue(m is IEventProducing); (m as IEventProducing).DontRecordEvent = true; EM.ApplyMod(m); } else if (undoCommand is IIndependentModifier) { IIndependentModifier m = (undoCommand as IIndependentModifier); Assert.IsTrue(m is IEventProducing); (m as IEventProducing).DontRecordEvent = true; EM.ApplyMod(m); } else if (undoCommand is Command) { throw new NotImplementedException(); } else { throw new Exception("Cannot apply undo command: " + undoCommand.GetType().Name); } } return(e); }
public static void Execute(this IBaseCommand baseQueryBuilder) { using (var command = baseQueryBuilder.Connection.CreateCommand(baseQueryBuilder.Sql, baseQueryBuilder.Parameters)) { command.ExecuteNonQuery(); } }
public void Execute(UIApplication app) { UIDocument uiDoc = app.ActiveUIDocument; Document doc = uiDoc.Document; this.application = app.Application; Debug("[STREAMVR] EXECUTING STREAMING SERVER EVENT!1!!"); this.Converter = new GenericConverter(Debug); this.Command_GetAll = new GetAll(Debug, this.Converter); this.Command_Get = new Get(Debug, this.Converter); this.Command_Set = new Set(Debug, uiDoc, this.Converter); this.Command_Paint = new Paint(Debug, this.Converter); this.Command_Create = new Create(Debug, this.Converter); this.Command_Export = new Export(Debug, this.Converter, StreamVRApp.Instance.ModelServerURL); this.Command_ExportMaterial = new ExportMaterial(Debug, this.Converter, StreamVRApp.Instance.ModelServerURL); this.Command_Delete = new Delete(Debug, this.Converter); Message request = StreamVRApp.Instance.CurrentRequest; Debug("[STREAMVR] REQUEST: " + JsonConvert.SerializeObject(request)); Message response = HandleClientRequest(doc, request); StreamVRApp.Instance.CurrentResponse = response; }
/// <summary> /// Initializes a new instance of the <see cref="MainViewModel"/> class. /// </summary> /// <param name="downloadReportCommand"> /// The download report command. /// </param> /// <param name="ignoreCommand"> /// The ignore command. /// </param> /// <param name="openUriCommand"> /// The open uri command. /// </param> /// <param name="clipboardCommand"> /// The clipboard command. /// </param> /// <param name="daily"> /// The daily. /// </param> /// <param name="monthly"> /// The monthly. /// </param> /// <param name="settingsViewModel">Settings viewmodel.</param> public MainViewModel( IDownloadReportCommand downloadReportCommand, IBaseCommand ignoreCommand, OpenUriCommand openUriCommand, IBaseCommand clipboardCommand, DailyViewModel daily, MonthlyViewModel monthly, SettingsViewModel settingsViewModel) { downloadReportCommand.ReportDownloaded += this.ReportDownloaded; downloadReportCommand.Executing += (sender, args) => { this.IsBusy = true; }; this.DownloadReportCommand = downloadReportCommand; ignoreCommand.Executed += (sender, args) => { this.Error = null; }; this.IgnoreCommand = ignoreCommand; this.OpenUriCommand = openUriCommand; this.ClipboardCommand = clipboardCommand; this.daily = daily; this.monthly = monthly; this.settings = settingsViewModel; }
public static async Task ExecuteAsync(this IBaseCommand baseQueryBuilder) { using (var command = baseQueryBuilder.Connection.CreateCommand(baseQueryBuilder.Sql, baseQueryBuilder.Parameters)) { await command.ExecuteNonQueryAsync(); } }
private void AddCommandToLegendItem(IList commands, IBaseCommand command) { if (commands != null && command != null && !commands.Contains(command)) { commands.Add(command); } }
public void Validate(SpreadSheet spreadSheet, IBaseCommand command) { var createNewSpreadSheetCommand = command as CreateNewSpreadSheetCommand; if (createNewSpreadSheetCommand == null) { throw new ArgumentException("Invalid command type", nameof(command)); } if (createNewSpreadSheetCommand.Width <= 0) { throw new ValidationException($"Width should more than 0. Parameter name: {nameof(createNewSpreadSheetCommand.Width)}"); } if (createNewSpreadSheetCommand.Height <= 0) { throw new ValidationException($"Height should more than 0. Parameter name: {nameof(createNewSpreadSheetCommand.Height)}"); } // Breaks unit test because console window is not opened during tests I suppose if ((createNewSpreadSheetCommand.Width * Globals.CellSize) + 1 >= Console.WindowWidth) { throw new ValidationException($"Width should be less than window width. Parameter name: {createNewSpreadSheetCommand.Width}"); } if (createNewSpreadSheetCommand.Height >= Console.WindowHeight) { throw new ValidationException($"Height should be less than window height. Parameter name: {nameof(createNewSpreadSheetCommand.Height)}"); } }
public void Finish(IBaseCommand command) { if (!command.isRetained) { retained.Remove(command); cache.Enqueue(command); } }
public CommandExecutionResult CheckContext(IBaseCommand command) { var result = new CommandExecutionResult(this.teclyn); this.CheckContextInternal(command, result); return(result); }
public void Validate(SpreadSheet spreadSheet, IBaseCommand command) { var quitCommand = command as QuitCommand; if (quitCommand == null) { throw new ArgumentException("Invalid command type", nameof(command)); } }
/// <summary> /// Metode der bruges til at pushe en IAmazingCommand på stakken udefra. Den benyttes når en kommando udføres for første gang. /// </summary> /// <param name="cmd"></param> public void PushUndoStack(IBaseCommand cmd) { DebugText = string.Format("Undo: *push* {0}", cmd.ToString()); _undoStack.Push(cmd); _redoStack.Clear(); OnPropertyChanged("RedoStack"); OnPropertyChanged("UndoStack"); }
protected IKey AddCommandInternal(IBaseCommand command, object keyData, bool once) { keyData = keyData ?? _uidGenerator; if (!Rapid.KeyFactoryCollection.Create(keyData, out var key, out var errorMessage) || !AddCommandInternal(command, key, once, out errorMessage)) { throw new Exception(errorMessage); } return(key); }
private void AddButton(IBaseCommand command, IList itemCollection, RibbonControlSize size = RibbonControlSize.Large) { if (command != null && itemCollection != null) { var item = command.ToFluentButton(size); if (item != null) { itemCollection.Add(item); } } }
public async Task <ActionResult> ExecutePost(IBaseCommand command, string returnUrl) { await this.CommandService.ExecuteGeneric(command); if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = this.Request.UrlReferrer?.ToString(); } return(Redirect(returnUrl)); }
private void AddBackstageTabItem(IBaseCommand command, IList itemCollection, RibbonControlSize size = RibbonControlSize.Large) { if (command != null && itemCollection != null) { var item = command.ToBackstageTabItem(size); if (item != null) { itemCollection.Add(item); } } }
public static bool TryExecute(this IBaseCommand baseQueryBuilder) { try { Execute(baseQueryBuilder); return(true); } catch (Exception) { return(false); } }
internal void OnSharedAddCommand(IBaseCommand command) { var internalCommand = (BaseCommand)command; foreach (var context in _commandContexts) { if (!ReferenceEquals(context, _sharedContext)) { context.AddSharedCommand(internalCommand); } } }
void ReleaseCommands() { IBaseCommand[] clone = new IBaseCommand[_retained.Count]; _retained.CopyTo(clone); for (int i = 0, cloneLength = clone.Length; i < cloneLength; i++) { IBaseCommand command = clone[i]; command.Release(); command.onFinish -= OnFinish; } }
void OnFinish(IBaseCommand command) { Type type = command.GetType(); Queue <IBaseCommand> cached; if (!_cache.TryGetValue(type, out cached)) { _cache[type] = cached = new Queue <IBaseCommand>(); } cached.Enqueue(command); _retained.Remove(command); }
void ExecuteCommand(Type type, Action <IBaseCommand> executeCommand) { IBaseCommand command = GetCommand(type); executeCommand(command); if (command.isRetained) { _retained.Add(command); } else { command.Release(); } }
public static IEnumerable <IBaseCommand <T> > Nodes <T>(this IBaseCommand <T> command) where T : IModel { var list = new List <Type>(); for (var node = command; node != null; node = node.DecoratedHandler) { bool isNodeTypeExists = list.Any(x => x.Equals(node.GetType())); if (isNodeTypeExists) { throw new Exception("This is an infinite cycle!"); } list.Add(node.GetType()); yield return(node); } }
/// <summary> /// 获取快速访问菜单按钮 /// </summary> /// <param name="command">命令</param> /// <param name="size">尺寸</param> /// <returns>快速访问菜单按钮</returns> public static QuickAccessMenuItem ToQuickAccessMenuItem(this IBaseCommand command, RibbonControlSize size = RibbonControlSize.Large) { QuickAccessMenuItem item = null; if (command != null) { item = new QuickAccessMenuItem() { IsChecked = true, Icon = command.Icon, Target = command.ToFluentButton(size, false) }; } return(item); }
/// <summary> /// 获取快速访问菜单按钮 /// </summary> /// <param name="command">命令</param> /// <param name="size">尺寸</param> /// <returns>快速访问菜单按钮</returns> public static BackstageTabItem ToBackstageTabItem(this IBaseCommand command, RibbonControlSize size = RibbonControlSize.Large) { BackstageTabItem item = null; if (command != null) { item = new BackstageTabItem() { Header = command.Header, Icon = command.Icon, Content = command.ToFluentButton(size, false) }; } return(item); }
private void AddSharedCommand(IBaseCommand command) { if (_commands.TryGetValue(command.Name, out var existing)) { //It's possible for multiple shared contexts to contain the same command, so just ignore these cases if (ReferenceEquals(command, existing)) { return; } throw new ArgumentException($"A different command with the name {command.Name} already exists in context {Name}", nameof(command)); } _commands.Add(command.Name, command); }
private void AddQuickAccessMenuItem(IBaseCommand command, IList itemCollection, RibbonControlSize size = RibbonControlSize.Large) { if (command != null && itemCollection != null) { var button = command.ToQuickAccessMenuItem(size); if (button != null) { var item = command.ToQuickAccessMenuItem(size); if (item != null) { itemCollection.Add(item); } } } }
private bool AddCommandInternal(IBaseCommand command, IKey key, bool once, out string errorMessage) { if (!ValidateKey(key, out errorMessage)) { return(false); } if (once) { _commandsToRemove.Add(key); } var commands = _dispatching ? _commandsToAdd : _commands; commands.Add(key, command); errorMessage = string.Empty; return(true); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; this.application = commandData.Application.Application; this.Converter = new GenericConverter(Debug); this.Command_GetAll = new GetAll(Debug, this.Converter); this.Command_Get = new Get(Debug, this.Converter); this.Command_Set = new Set(Debug, uiDoc, this.Converter); this.Command_Paint = new Paint(Debug, this.Converter); this.Command_Create = new Create(Debug, this.Converter); this.Command_Export = new Export(Debug, this.Converter); this.serverUrl = "192.168.0.119:7002"; this.userName = this.application.Username; this.roomCode = "123456"; this.startingViews = GetView3Ds(doc); this.startingView = this.startingViews.FirstOrDefault(e => e.Name == "3D View 3"); Debug("SERVER CONN"); Debug(serverUrl); Debug(userName); Debug(roomCode); StreamVRUI startUI = CreateUI(false); bool? start = startUI.ShowDialog(); if (start != true) { return(Result.Cancelled); } this.serverUrl = startUI.ServerURL; this.roomCode = startUI.RoomCode; this.startingView = this.startingViews.FirstOrDefault(v => v.Name == startUI.StartingView); this.CreateShutdownForm(); this.ListenForMessages(uiDoc); return(Result.Succeeded); }
public void Validate(SpreadSheet spreadSheet, IBaseCommand command) { var insertNumberCommand = command as InsertNumberCommand; if (insertNumberCommand == null) { throw new ArgumentException("Invalid command type", nameof(command)); } if (insertNumberCommand.X1 < Globals.SpreadSheetStartIndex) { throw new ValidationException( $"X1 should be greater than or equal to {Globals.SpreadSheetStartIndex}. Parameter name: {nameof(insertNumberCommand.X1)}"); } if (insertNumberCommand.Y1 < Globals.SpreadSheetStartIndex) { throw new ValidationException( $"Y1 should be greater than or equal to {Globals.SpreadSheetStartIndex}. Parameter name:" + $" {nameof(insertNumberCommand.Y1)}"); } if (insertNumberCommand.V1 < 0) { throw new ValidationException($"V1 should be greater than 0. Parameter name: {nameof(insertNumberCommand.V1)}"); } try { _ = spreadSheet[insertNumberCommand.X1, insertNumberCommand.Y1]; } catch (IndexOutOfRangeException) { throw new ValidationException( $"Index is out of range of spread sheet. Parameter name: {nameof(insertNumberCommand.X1)} or {nameof(insertNumberCommand.Y1)}"); } if (insertNumberCommand.V1.ToString().Length > Globals.CellSize) { throw new ValidationException( $"Inserted value is more than cell size. Parameter name: {nameof(insertNumberCommand.V1)}"); } }
/// <summary> /// 获取按钮 /// </summary> /// <param name="command">命令</param> /// <param name="size">尺寸</param> /// <param name="useIcon">使用图标</param> /// <returns>按钮</returns> public static Fluent.Button ToFluentButton(this IBaseCommand command, RibbonControlSize size = RibbonControlSize.Large, bool useIcon = true) { Button button = null; if (command != null) { button = new Button() { Header = command.Header, Name = command.Name, ToolTip = command.ToolTip, Size = size, Command = command }; if (useIcon) { button.Icon = command.Icon; button.LargeIcon = command.LargeIcon; } } return(button); }
/// <summary> /// 添加图层组工具 /// </summary> /// <param name="commandFactory"></param> /// <param name="layers"></param> /// <returns></returns> public static IBaseCommand GetAddGroupCommand(this ICommandFactory commandFactory, ILayerCollection layers) { IBaseCommand command = null; if (commandFactory != null && layers != null) { string name = "addGroup"; command = commandFactory.Commands?.FirstOrDefault(x => x.Name == name); if (command == null) { command = new BaseCommand() { Header = "添加分组", Name = name, ExecuteCommand = (obj) => layers.AddGroup(), Icon = ResourcesHelper.GetBitmapImage("Group16.png"), LargeIcon = ResourcesHelper.GetBitmapImage("Group32.png"), ToolTip = "添加分组" }; commandFactory.Commands.Add(command); } } return(command); }
/// <summary> /// Возвращает полный текст команды с подставленными параметрами /// </summary> /// <returns></returns> public static string GetCommandFullText(IBaseCommand command) { var text = new StringBuilder(command.Command.CommandText); foreach (IDataParameter prm in command.Command.Parameters) { if (prm.DbType == DbType.AnsiString || prm.DbType == DbType.AnsiStringFixedLength || prm.DbType == DbType.String || prm.DbType == DbType.StringFixedLength) { text.Replace(prm.ParameterName, "'" + prm.Value + "'"); } else text.Replace(prm.ParameterName, prm.Value.ToString()); } return text.ToString(); }
private void addParametersToCommand(IBaseCommand command, List<FieldData> listFieldData) { foreach (FieldData fieldData in listFieldData) { if (fieldData.ObjectType == typeof(Byte[])) command.Add("@" + fieldData.FieldName, fieldData.ObjectValue, DbType.Binary); else command.Add("@" + fieldData.FieldName, fieldData.ObjectValue); } }
/// <summary> /// Заполняет параметры команды на обновление в соответствии со значениями свойств, помеченных DBReadAttribute. /// </summary> /// <param name="command">Хранимая процедура</param> /// <param name="obj">Объект</param> public static void FillUpdateCommandParameters(IBaseCommand command, object obj) { FillCommandParameters(command, obj, true); }
/// <summary> /// Заполняет параметры команды в соответствии со значениями свойств, помеченных DBReadAttribute. /// </summary> /// <param name="command">Команда</param> /// <param name="obj">Объект</param> /// <param name="withPrimaryKey">Добавлять ли параметр, соотв. первичному ключу.</param> /// /// TODO: Переписать с использованием GetDBColumnsValues private static void FillCommandParameters(IBaseCommand command, object obj, bool withPrimaryKey) { // получаем тип объекта Type objType = obj.GetType(); // перебираем его свойства (публичные нестатические) foreach (PropertyInfo prop in objType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { DBReadAttribute dbReadAttribute = DBAttributesManager.GetDBReadAttribute(prop); if (dbReadAttribute != null && (!dbReadAttribute.PrimaryKey || dbReadAttribute.PrimaryKey && withPrimaryKey)) { if (prop.PropertyType == typeof(MLString)) { MLString value = (MLString)ObjectPropertiesMapper.GetPropertyValue(prop, obj); command.Add("@" + dbReadAttribute.FieldName + RussianEnding, value[CultureManager.Languages.Russian]); command.Add("@" + dbReadAttribute.FieldName + EnglishEnding, value[CultureManager.Languages.English]); } else if (prop.PropertyType == typeof(TNKBPIdentifier)) { TNKBPIdentifier value = (TNKBPIdentifier)ObjectPropertiesMapper.GetPropertyValue(prop, obj); command.Add("@" + dbReadAttribute.FieldName, value.ToString()); } else { command.Add("@" + dbReadAttribute.FieldName, ObjectPropertiesMapper.GetPropertyValue(prop, obj)); } } } }
/// <summary> /// Заполняет параметры команды на добавление в соответствии со значениями свойств, помеченных DBReadAttribute. /// </summary> /// <param name="command">Команда.</param> /// <param name="obj">Объект</param> public static void FillInsertCommandParameters(IBaseCommand command, object obj) { FillCommandParameters(command, obj, false); }