public void UpdateTag(IVariableWrapper sourceVariable) { var tagName = "{#" + sourceVariable.Name + "}"; var replaceTo = sourceVariable.StringValue; FormattedValue = Value.Replace(tagName, replaceTo); }
public void Update(IVariableWrapper buffer) { if (!(buffer is TimeVariableWrapper)) { return; } var variable = (TimeVariableWrapper)buffer; if (Name != variable.Name) { Name = variable.Name; } if (Value != variable.Value) { Value = variable.Value; } if (UseSeconds != variable.UseSeconds) { UseSeconds = variable.UseSeconds; } if (UseCurrentTime != variable.UseCurrentTime) { UseCurrentTime = variable.UseCurrentTime; } if (Format != variable.Format) { Format = variable.Format; } }
public void Update(IVariableWrapper buffer) { if (!(buffer is DateVariableWrapper)) { return; } var variable = (DateVariableWrapper)buffer; if (Name != variable.Name) { Name = variable.Name; } if (Value != variable.Value) { Value = variable.Value; } if (UseCurrentDate != variable.UseCurrentDate) { UseCurrentDate = variable.UseCurrentDate; } if (Format != variable.Format) { Format = variable.Format; } }
public ObjectActionProperties(IVariableWrapper variable, VariablesRepository variablesRepository, ObjectsRepository objectsRepository) { _variablesRepository = variablesRepository; _objectsRepository = objectsRepository; Variable = variable; Actions = new List <ObjectAction>(); }
/// <summary> /// При изменении переменной, обновляет все связанные с ней действия /// </summary> public void UpdateAllAssignedActions(IVariableWrapper variable, string oldName) { var hasChanges = false; if (variable == null || Common.IsSameName(variable.Name, oldName)) { return; } foreach (var vm in ViewModels.Where(t => t is IActionProperties && ((IActionProperties)t).ActionProperties.HasActions)) { var objectActions = ((IActionProperties)vm).ActionProperties.Actions; foreach (var action in objectActions.Where(t => t.TargetType == ActionTargetType.Variable)) { if (!Common.IsSameName(action.Result.TargetName, oldName)) { continue; } action.Result.TargetName = variable.Name; if (!hasChanges) { hasChanges = true; } } } if (hasChanges) { RefreshSelected(); } }
public VariableEditorViewModel(DataProvider dataProvider, IVariableWrapper variable = null) { _variablesRepository = dataProvider.VariablesRepository; _dialogsHelper = dataProvider.DialogsManager; _isCreateMode = variable == null; Title = $"{(variable == null ? "Создание" : "Редактирование")} переменной"; Switcher = new ValuesSwitcherViewModel(dataProvider, variable, _isCreateMode); }
private void Init() { Variable = _variablesRepository.Find(Action.Variable.Name)?.Clone(); InitConditionOperandsList(); HasChanges = false; Messenger.Default.Register <NotificationMessage <IVariableWrapper> >(this, OnVariableSelected); _objectsRepository.SelectionChanged += OnObjectSelected; }
/// <summary> /// Обновляет форматированный текст у всех переменных, содержащих этот тег /// </summary> public void UpdateTags(IVariableWrapper sourceVariable) { foreach (var variable in Variables .Where(t => t is StringVariableWrapper) .Cast <StringVariableWrapper>() .Where(variable => variable.IsContainTag(sourceVariable))) { variable.UpdateFormattedValue();// .UpdateTag(sourceVariable); } }
/// <summary> /// Создание нового объекта /// </summary> public CheckBoxViewModel(uint id, string name, IVariableWrapper variable, DataProvider dataProvider) { _objectsRepository = dataProvider.ObjectsRepository; Properties = new ObjectBaseProperties(id, name, dataProvider.CommonSettings.AppMode, _objectsRepository); TextProperties = new ObjectTextProperties(dataProvider.VariablesRepository); ActionProperties = new ObjectActionProperties(variable, dataProvider.VariablesRepository, _objectsRepository); ActionProperties.Variable.ValueChanged += OnValueChanged; IsChecked = ((BoolVariableWrapper)ActionProperties.Variable).IsSet; }
public bool IsEqualTo(IVariableWrapper compared) { if (!(compared is StringVariableWrapper)) { return(false); } var variable = (StringVariableWrapper)compared; return(Common.IsSameName(Name, variable.Name) && Value == variable.Value); }
/// <summary> /// Создание нового объекта /// </summary> public DatePickerViewModel(uint id, string name, IVariableWrapper variable, DataProvider dataProvider) { Properties = new ObjectBaseProperties(id, name, dataProvider.CommonSettings.AppMode, dataProvider.ObjectsRepository); TextProperties = new ObjectTextProperties(dataProvider.VariablesRepository); ActionProperties = new ObjectActionProperties(variable, dataProvider.VariablesRepository, dataProvider.ObjectsRepository); ActionProperties.Variable.ValueChanged += OnValueChanged; Date = ((DateVariableWrapper)ActionProperties.Variable).Value; IsRequired = false; }
/// <summary> /// Открывает Редактор переменных /// </summary> public async Task OpenVariableEditor( VariablesRepository repository, IVariableWrapper variable = null, WindowType hostIdentifier = WindowType.Root) { var viewModel = new VariableEditorViewModel(_dataProvider, variable); var view = new VariableEditor { ViewModel = viewModel }; await DialogHost.Show(view, Common.GetEnumDescription(hostIdentifier)); }
/// <summary> /// Добавление нового объекта /// </summary> public TextBoxViewModel(uint id, string name, IVariableWrapper variable, DataProvider dataProvider) { _objectsRepository = dataProvider.ObjectsRepository; Properties = new ObjectBaseProperties(id, name, dataProvider.CommonSettings.AppMode, dataProvider.ObjectsRepository); ActionProperties = new ObjectActionProperties(variable, dataProvider.VariablesRepository, dataProvider.ObjectsRepository); ActionProperties.Variable.ValueChanged += OnValueChanged; Text = ActionProperties.Variable.StringValue; IsMultiline = false; IsRequired = false; }
public bool IsEqualTo(IVariableWrapper compared) { if (!(compared is DateVariableWrapper)) { return(false); } var variable = (DateVariableWrapper)compared; return(Common.IsSameName(Name, variable.Name) && UseCurrentDate == variable.UseCurrentDate && Value == variable.Value); }
/// <summary> /// Заменяет измененный тег у текстовых полей всех объектов, содержащих этот тег /// </summary> /// <param name="sourceVariable"></param> public void UpdateAllFormattedText(IVariableWrapper sourceVariable) { var tagName = "{#" + sourceVariable.Name + "}"; var replaceTo = sourceVariable.StringValue; foreach (var viewModel in ViewModels .Where(t => t is ITextProperties) .Cast <ITextProperties>() .Where(obj => obj.TextProperties.Text.Contains(tagName))) { viewModel.TextProperties.FormattedText = viewModel.TextProperties.Text.Replace(tagName, replaceTo); } }
/// <summary> /// Создание нового объекта /// </summary> public TimePickerViewModel(uint id, string name, IVariableWrapper variable, DataProvider dataProvider) { Properties = new ObjectBaseProperties(id, name, dataProvider.CommonSettings.AppMode, dataProvider.ObjectsRepository); TextProperties = new ObjectTextProperties(dataProvider.VariablesRepository); ActionProperties = new ObjectActionProperties(variable, dataProvider.VariablesRepository, dataProvider.ObjectsRepository); ActionProperties.Variable.ValueChanged += OnValueChanged; var timeWrapper = (TimeVariableWrapper)ActionProperties.Variable; Time = timeWrapper.Value; UpdateBindingTime(); UseSeconds = timeWrapper.UseSeconds; IsRequired = false; }
public void Update(IVariableWrapper buffer) { if (!(buffer is StringVariableWrapper)) { return; } var variable = (StringVariableWrapper)buffer; if (Name != variable.Name) { Name = variable.Name; } if (Value != variable.Value) { Value = variable.Value; } }
/// <summary> /// Открывает Редактор действий для создания нового действия /// </summary> public async Task <ObjectAction> OpenActionEditor( IVariableWrapper variable, IEnumerable <ObjectAction> actions, ObjectsRepository objectsRepository, VariablesRepository variablesRepository, string rootPath, WindowType hostIdentifier = WindowType.Root) { var viewModel = new ActionEditorViewModel(variable, actions, _dataProvider); var view = new ActionEditor { ViewModel = viewModel }; await DialogHost.Show(view, Common.GetEnumDescription(hostIdentifier)); return(viewModel.IsSaved ? viewModel.Action : null); }
public bool AddOrUpdate(IVariableWrapper variable, string oldName = null) { if (!IsInitialized()) { return(false); } if (string.IsNullOrEmpty(variable.Name)) { ErrorMessage = EmptyNameMessage; return(false); } var nameIsChanged = !Common.IsSameName(oldName, variable.Name); IVariableWrapper selector; if (!string.IsNullOrEmpty(oldName)) { // Изменилось имя переменной if (nameIsChanged && IsExists(variable.Name)) { // Переименовали существующую переменную ErrorMessage = VariableExistsMessage(variable.Name); return(false); } selector = Find(oldName); } else { selector = Find(variable.Name); } if (selector == null) { Variables.Add(variable); } else { selector.Update(variable); VariableChanged?.Invoke(variable, oldName); UpdateTags(variable); } return(true); }
public IVariableWrapper Add(VariableType type = VariableType.String, object value = null, bool isAssigned = false) { if (!IsInitialized()) { return(null); } IVariableWrapper wrapper = null; var name = MakeName(); switch (type) { case VariableType.String: wrapper = new StringVariableWrapper(name, this, isAssigned); break; case VariableType.Bool: wrapper = new BoolVariableWrapper(name, isAssigned); break; case VariableType.Date: wrapper = new DateVariableWrapper(name, isAssigned); break; case VariableType.Time: wrapper = new TimeVariableWrapper(name, isAssigned); break; } if (wrapper == null) { ErrorMessage = $"Запрос на создание переменной неизвестного типа \"{type}\""; return(null); } Variables.Add(wrapper); if (value != null) { wrapper.Set(value); } return(wrapper); }
public ActionEditorViewModel( IVariableWrapper variable, IEnumerable <ObjectAction> actions, DataProvider dataProvider) { _isInEditMode = false; _actions = actions; _objectsRepository = dataProvider.ObjectsRepository; _variablesRepository = dataProvider.VariablesRepository; _dialogsHelper = dataProvider.DialogsManager; Action = new ObjectAction(variable); Title = "Создание действия"; Init(); ConditionOperand = ConditionOperands.Count == 0 ? null : ConditionOperands[0]; Operation = ActionOperation.SetValue; TargetName = TargetIsEmpty ? null : TargetNames[0]; //HasChanges = false; }
public ValuesSwitcherViewModel(DataProvider dataProvider, IVariableWrapper variable = null, bool isCreateMode = true, bool isSubscribedToUpdates = false) { _variablesRepository = dataProvider.VariablesRepository; _dialogsManager = dataProvider.DialogsManager; if (variable == null) { IsEnabled = false; IsCreateMode = isCreateMode; Variable = CreateVariable(VariableType.String); } else { IsEnabled = true; IsCreateMode = isCreateMode; Variable = variable.Clone(); OldName = Variable.Name; } HasChanges = false; }
private static string WrongFormatMessage(IVariableWrapper variable = null) { return(variable == null ? "Несоответствие условия заданномму типу." : $"Тип значения переменной \"{variable.Name}\" не соответствует типу условия ({variable.GetType()})."); }
public bool IsContainTag(IVariableWrapper sourceVariable) { var tagName = "{#" + sourceVariable.Name + "}"; return(Value.Contains(tagName)); }
public VariableManager(IVariableWrapper variableWrapper, IVariableInfoCollection variableInfoCollection) { _variableWrapper = variableWrapper; _variableInfoCollection = variableInfoCollection; _variableInfoCollection.Open(ConfigurationProvider.VariableSettingsFile); }
public ObjectAction(IVariableWrapper variable) { Variable = variable; }
private bool ConditionIsTrue(IVariableWrapper variable, ActionCondition condition) { if (condition == null) { return(false); } var type = condition.Operand.GetType(); #region Сравнение со строкой if (type == typeof(ActionInputOperand)) { if (!(variable is StringVariableWrapper) || !(condition.Value is string)) { ErrorMessage = WrongFormatMessage(variable); return(false); } var operand = (ActionInputOperand)condition.Operand; var value = ((StringVariableWrapper)variable).Value.Trim().ToLower(); var comparedValue = ((string)condition.Value).Trim().ToLower(); switch (operand) { case ActionInputOperand.Set: return(!string.IsNullOrEmpty(value)); case ActionInputOperand.NotSet: return(string.IsNullOrEmpty(value)); case ActionInputOperand.Equal: return(string.Equals(value, comparedValue)); case ActionInputOperand.NotEqual: return(!string.Equals(value, comparedValue)); case ActionInputOperand.Contains: return(value.Contains(comparedValue)); } ErrorMessage = UnknownOperationMessage; return(false); } #endregion #region Сравнение с логическим значением if (type == typeof(ActionSelectorOperand)) { if (!(variable is BoolVariableWrapper)) { ErrorMessage = WrongFormatMessage(variable); return(false); } var boolVariable = (BoolVariableWrapper)variable; var operand = (ActionSelectorOperand)condition.Operand; switch (operand) { case ActionSelectorOperand.Set: return(boolVariable.IsSet); case ActionSelectorOperand.NotSet: return(!boolVariable.IsSet); } ErrorMessage = UnknownOperationMessage; return(false); } #endregion #region Сравнение с датой if (type == typeof(ActionDateOperand)) { if (!(variable is DateVariableWrapper)) { ErrorMessage = WrongFormatMessage(variable); return(false); } var dateVariable = (DateVariableWrapper)variable; var operand = (ActionDateOperand)condition.Operand; switch (operand) { } ErrorMessage = UnknownOperationMessage; return(false); } #endregion #region Сравнение со временем if (type == typeof(ActionDateOperand)) { if (!(variable is TimeVariableWrapper)) { ErrorMessage = WrongFormatMessage(variable); return(false); } } #endregion ErrorMessage = UnknownOperationMessage; return(false); }