Inheritance: IDisposable, IHasCheckerAction, ICoreElement
Exemple #1
0
        public Result<bool> Add(Scenario item)
        {
            Resulting.EnableExceptionHandling = false;
            var result = CheckScenario(item);
            Resulting.EnableExceptionHandling = true;
            if (result.Value && !_scenarios.Contains(item))
                _scenarios.Add(item);

            item.AfterActionServerEvent += (x) =>
            {
                Pyrite.ServerThreading.UpdateClients();
            };

            return result;
        }
Exemple #2
0
        public Result<bool> CheckScenario(Scenario item)
        {
            var result = new Result<bool>();

            if (item.ActionBag == null)
                result.AddWarning(new Warning("Необходимо выбрать вид действия"));
            if (string.IsNullOrEmpty(item.Name))
                result.AddWarning(new Warning("Необходимо ввести имя сценария"));
            if (_scenarios.Count(x => x.Name == item.Name && item.Guid != x.Guid) > 0)
                result.AddWarning(new Warning("Действие с таким именем уже существует"));
            if (_scenarios.Count(x => x.ServerCommand == item.ServerCommand && !string.IsNullOrEmpty(x.ServerCommand) && item.Guid != x.Guid) > 0)
                result.AddWarning(new Warning("Действие с такой командой сервера уже существует"));

            result.Value = result.Warnings.Count() == 0;
            return result;
        }
        public EditScenarioViewContext(Scenario scenario)
        {
            if (scenario == null)
            {
                scenario = new Scenario();
                scenario.CurrentPyrite = App.Pyrite;
                scenario.AfterAction += (scen) => App.RaiseItemExecutedEvent(scen);
            }

            this._scenario = scenario;

            ScenarioName = this._scenario.Name;
            ScenarioCategory = this._scenario.Category;
            ScenarioIndex = this._scenario.Index;
            IsScenarioActive = this._scenario.IsActive;
            IsScenarioUsedInServerThreading = this._scenario.UseServerThreading;
            IsScenarioUseOnOffState = this._scenario.UseOnOffState;
        }
Exemple #4
0
        public Result<Scenario> Clone()
        {
            var res = new Result<Scenario>();
            var clone = ModulesControl.CloneAction(this.Action).Value;

            var item = new Scenario()
            {
                ActionBag = new ActionBag() { Action = clone },
                Category = this.Category,
                Guid = this.Guid,
                IsActive = this.IsActive,
                UseOnOffState = this.UseOnOffState,
                Index = this.Index,
                Name = this.Name,
                ServerCommand = this.ServerCommand,
                UseServerThreading = this.UseServerThreading,
                CurrentPyrite = this.CurrentPyrite
            };

            item.ForAllActionAndChecker(x =>
            {
                if (x is ICoreElement)
                    ((ICoreElement)x).CurrentPyrite = this.CurrentPyrite;
            });

            if (item.Action == null)
            {
                if (this.Action is DoubleComplexAction)
                    item.ActionBag.Action = new DoubleComplexAction();
                else item.ActionBag.Action = new DoNothingAction();
            }

            res.Value = item;
            return res;
        }
 public void UpdateScenarioClone()
 {
     _scenario = GetTargetScenario();
     if (_scenario != null)
         _scenario = _scenario.Clone().Value;
 }
 public void Refresh()
 {
     _scenario = null;
 }
        public void SetScenario(Scenario scenario)
        {
            if (scenario == null)
            {
                this.DataContext = new EditScenarioViewContext(null);
            }
            else
            {
                _tempItem = scenario;
                Scenario = scenario.Clone().Value;

                this.DataContext = new EditScenarioViewContext(Scenario);

                if (scenario.ActionBag.Action is DoubleComplexAction)
                {
                    var scenarioView = new DoubleScenarioActionView();
                    scenarioView.Changed += (o, e) => EnableButtons();
                    scenarioView.ActionBag = Scenario.ActionBag;
                    this.borderScenarioHolder.Child = scenarioView;
                }
                else
                {
                    var scenarioView = new SingleActionScenarioView();
                    scenarioView.Changed += (o, e) => EnableButtons();
                    scenarioView.ActionBag = Scenario.ActionBag;
                    this.borderScenarioHolder.Child = scenarioView;
                }
            }
            DisableButtons();
        }
Exemple #8
0
        public ScenariosView()
        {
            InitializeComponent();

            this.DataContext = new ScenariosViewContext();

            scenarioView.Applying += (o, e) =>
            {
                this.lvItems.Items.Refresh();
            };

            this.btCreate.Click += (o, e) =>
            {
                var scenario = new Scenario();
                scenario.CurrentPyrite = App.Pyrite;
                scenario.AfterAction += (scen) => App.RaiseItemExecutedEvent(scen);

                if (cbMode.SelectedIndex == 0)
                {
                    scenario.ActionBag = new ActionBag() { Action = App.Pyrite.ModulesControl.CreateActionInstance(typeof(DoubleComplexAction), true).Value };
                }
                else
                {
                    scenario.ActionBag = new ActionBag() { Action = App.Pyrite.ModulesControl.CreateActionInstance(typeof(DoNothingAction), true).Value };
                }

                scenario.ActionBag.Action.Refresh();

                scenario.ServerCommand = Guid.NewGuid().ToString();
                scenario.Name = "Новый сценарий " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                App.Pyrite.ScenariosPool.Add(scenario);
                RefreshListView();
                lvItems.SelectedItem = new ScenariosViewContext.ScenarioViewItem() { Scenario = scenario };
                App.Pyrite.CommitChanges();
            };

            this.btRemove.Click += (o, e) =>
            {
                RemoveCurrentScenario();
            };

            this.lvItems.SelectionChanged += (o, e) =>
            {
                if (_lockSelectionChangedEvent)
                    return;

                if (lvItems.SelectedValue != null && scenarioView.WasChanged)
                {
                    if (BeginConfirmationDialog() == MessageBoxResult.Cancel)
                    {
                        _lockSelectionChangedEvent = true;
                        lvItems.SelectedItem = e.RemovedItems[0];
                        _lockSelectionChangedEvent = false;
                    }
                }
                else
                    BeginEditSelectedScenario();
            };

            this.KeyDown += (o, e) =>
            {
                var element = FocusManager
                    .GetFocusedElement(Window.GetWindow(this)); //get current focused element
                if (e.Key == Key.Delete
                    && element is ListBoxItem
                    && this.lvItems.Items.Contains(((ListViewItem)element).DataContext))
                    RemoveCurrentScenario();
            };

            Refresh();
        }
Exemple #9
0
 public void RemoveScenario(Scenario item)
 {
     item.PrepareToRemove();
     _scenarios.Remove(item);
 }
Exemple #10
0
 public static void RaiseItemExecutedEvent(Scenario scenario)
 {
     if (ItemExecuted != null)
         ItemExecuted(scenario);
 }