Ejemplo n.º 1
0
        public void UpdateTag(IVariableWrapper sourceVariable)
        {
            var tagName   = "{#" + sourceVariable.Name + "}";
            var replaceTo = sourceVariable.StringValue;

            FormattedValue = Value.Replace(tagName, replaceTo);
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
 public ObjectActionProperties(IVariableWrapper variable, VariablesRepository variablesRepository, ObjectsRepository objectsRepository)
 {
     _variablesRepository = variablesRepository;
     _objectsRepository   = objectsRepository;
     Variable             = variable;
     Actions = new List <ObjectAction>();
 }
Ejemplo n.º 5
0
        /// <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();
            }
        }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 private void Init()
 {
     Variable = _variablesRepository.Find(Action.Variable.Name)?.Clone();
     InitConditionOperandsList();
     HasChanges = false;
     Messenger.Default.Register <NotificationMessage <IVariableWrapper> >(this, OnVariableSelected);
     _objectsRepository.SelectionChanged += OnObjectSelected;
 }
Ejemplo n.º 8
0
 /// <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);
     }
 }
Ejemplo n.º 9
0
 /// <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;
 }
Ejemplo n.º 10
0
        public bool IsEqualTo(IVariableWrapper compared)
        {
            if (!(compared is StringVariableWrapper))
            {
                return(false);
            }
            var variable = (StringVariableWrapper)compared;

            return(Common.IsSameName(Name, variable.Name) &&
                   Value == variable.Value);
        }
Ejemplo n.º 11
0
 /// <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;
 }
Ejemplo n.º 12
0
        /// <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));
        }
Ejemplo n.º 13
0
 /// <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;
 }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        /// <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);
            }
        }
Ejemplo n.º 16
0
        /// <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;
        }
Ejemplo n.º 17
0
        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;
            }
        }
Ejemplo n.º 18
0
        /// <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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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;
        }
Ejemplo n.º 22
0
        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;
        }
Ejemplo n.º 23
0
 private static string WrongFormatMessage(IVariableWrapper variable = null)
 {
     return(variable == null
         ? "Несоответствие условия заданномму типу."
         : $"Тип значения переменной \"{variable.Name}\" не соответствует типу условия ({variable.GetType()}).");
 }
Ejemplo n.º 24
0
        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);
 }
Ejemplo n.º 26
0
 public ObjectAction(IVariableWrapper variable)
 {
     Variable = variable;
 }
Ejemplo n.º 27
0
        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);
        }