Exemplo n.º 1
0
        /// <inheritdoc />
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (!Unique)
            {
                return(ValidationResult.Success);
            }
            if (value is null)
            {
                return(ValidationResult.Success);
            }
            if (validationContext.ObjectInstance is null)
            {
                return(ValidationResult.Success);
            }

            if (validationContext.TryGetDbContext(out var context))
            {
                var            conn          = context.Database.GetDbConnection();
                ICustomCommand customCommand = null;

                lock (Queries)
                {
                    if (Queries.ContainsKey(validationContext.ObjectType))
                    {
                        customCommand = Queries[validationContext.ObjectType];
                    }
                }

                if (customCommand is null)
                {
                    customCommand = validationContext.CreateFilteredCountQuery(true, validationContext.MemberName);
                    lock (Queries)
                    {
                        Queries[validationContext.ObjectType] = customCommand;
                    }
                }

                if (string.IsNullOrEmpty(customCommand.SqlStatement))
                {
                    return(ValidationResult.Success);
                }

                if (conn.State == ConnectionState.Broken ||
                    conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                var cmd = customCommand.CreateCommand(conn, validationContext.ObjectInstance);

                var cnt = Convert.ToInt32(cmd.ExecuteScalar());

                if (cnt > 0)
                {
                    return(new ValidationResult("has already been used", new[] { validationContext.MemberName }));
                }
            }

            return(ValidationResult.Success);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Action <object> toDo  = new Action <object>(sInfo => Console.WriteLine("Receiver performed first action : {0} - {1} ", sInfo, DateTime.Now.ToLongTimeString()));
            Action <object> toDo1 = new Action <object>(sInfo =>
            {
                string ss = sInfo.ToString();
                if (sInfo is string)
                {
                    ss = (string)sInfo;
                }
                Console.WriteLine("Receiver performed second action : {0} ", DateTime.Now.AddSeconds(ss.Length).ToLongTimeString());
            });

            CustomReceiverFactory recFactory  = new CustomReceiverFactory();
            CustomCommandFactory  cmdFactory  = new CustomCommandFactory();
            CustomSenderFactory   sendFactory = new CustomSenderFactory();

            ICustomReceiver rec  = recFactory.Create(toDo);
            ICustomCommand  cmd  = cmdFactory.Create(rec);
            ICustomSender   send = sendFactory.Create(cmd);

            send.ExecuteCommand("step1");
            send.ExecuteCommand("step2");

            rec.DettachCommand();
            rec.AttachCommand(toDo1, null);

            send.ExecuteCommand("this is dummy 1");
            send.ExecuteCommand("this is dummy 2 again");

            Console.WriteLine("quit?");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void Detect()
        {
            SpeechSynthesisService.Speak("What do you want?");
            var command = SpeechRecognitionService.Listen();

            if (string.IsNullOrEmpty(command))
            {
                return;
            }
            var intent = IntentService.GetIntent(command);

            if (CommandsHelper.GetCoreCommandIntents().Contains(intent.TopScoringIntent.Name) && intent.TopScoringIntent.Score > 0.7)
            {
                var factory     = new CoreCommandFactory();
                var coreCommand = factory.Create(intent.TopScoringIntent.Name);
                var response    = coreCommand.Execute(new List <string>());
                var output      = response.ElementAtOrDefault(0);
                if (output != null)
                {
                    SpeechSynthesisService.Speak(output);
                }
                return;
            }
            ICustomCommand customCommand = SearchCommand(_commandRepository, command);

            if (customCommand == null)
            {
                CreateCustomCommand(command, _commandRepository);
            }
            else
            {
                customCommand.Execute();
            }
        }
Exemplo n.º 4
0
        public static Task <TResult> Handle <TResult>(this CommandHandler handler, ICustomCommand <TResult> command)
        {
            var queryType    = command.GetType();
            var resultType   = typeof(TResult);
            var handleMethod = typeof(CommandHandler).GetTypeInfo().GetDeclaredMethod(nameof(CommandHandler.Handle)).MakeGenericMethod(queryType, resultType);

            return((Task <TResult>)handleMethod.Invoke(handler, new[] { command }));
        }
Exemplo n.º 5
0
        public void SetCommand(ICustomCommand aCommand, ICustomValidator aValidator = null)
        {
            Validator = (aValidator == null) ? new CustomValidator() : aValidator;

            if (aCommand == null)
            {
                throw new ArgumentNullException("Command is null");
            }
            Command = aCommand;
        }
Exemplo n.º 6
0
        public void SetCommand(ICustomCommand aCommand, ICustomValidator aValidator = null)
        {
            Validator = (aValidator == null) ? new CustomValidator() : aValidator;

            if (aCommand == null)
            {
                throw new ArgumentNullException("Command is null");
            }
            Command = aCommand;
        }
        private MenuViewModel CreateGridControlMenuViewModel()
        {
            var menu = new MenuViewModel(string.Format("{0}_GridControlMenu", MenuSuffix))
            {
                NotUseGlobalLayoutSettings = true
            };

            if (GridControlNewCommand == null)
            {
                GridControlNewCommand = new DelegateCustomCommand(this, OnGridControlNew, OnCanGridControlNew);
            }
            if (GridControlDeleteCommand == null)
            {
                GridControlDeleteCommand = new DelegateCustomCommand(this, OnGridControlDelete, OnCanGridControlDelete);
            }

            var bar = new BarItem
            {
                Name      = "GridControlMenuBarItemCommands",
                Caption   = StringResources.Commands,
                GlyphSize = GlyphSizeType.Small
            };

            menu.Bars.Add(bar);

            bar.MenuItems.Add(new CommandMenuItem
            {
                Caption        = StringResources.New,
                Command        = GridControlNewCommand,
                ImageSmall     = ImageResources.DCLAddNew16.GetBitmapImage(),
                ImageLarge     = ImageResources.DCLAddNew32.GetBitmapImage(),
                HotKey         = new KeyGesture(Key.F7),
                GlyphSize      = GlyphSizeType.Small,
                GlyphAlignment = GlyphAlignmentType.Top,
                DisplayMode    = DisplayModeType.Default,
                IsVisible      = true,
                Priority       = 1
            });

            bar.MenuItems.Add(new CommandMenuItem
            {
                Caption        = StringResources.Delete,
                Command        = GridControlDeleteCommand,
                ImageSmall     = ImageResources.DCLDelete16.GetBitmapImage(),
                ImageLarge     = ImageResources.DCLDelete32.GetBitmapImage(),
                HotKey         = new KeyGesture(Key.F9),
                GlyphSize      = GlyphSizeType.Small,
                GlyphAlignment = GlyphAlignmentType.Top,
                DisplayMode    = DisplayModeType.Default,
                IsVisible      = true,
                Priority       = 3
            });

            return(menu);
        }
Exemplo n.º 8
0
    private void AddEditRow(ICustomCommand action)
    {
        var go = new GameObject();

        go.transform.SetParent(transform, false);

        var row = new Row {
            container = go, action = action
        };

        _rows.Add(row);

        go.transform.SetSiblingIndex(transform.childCount - 2);

        var group = go.AddComponent <HorizontalLayoutGroup>();

        group.spacing = 10f;

        var text       = prefabManager.CreateText(go.transform, action.displayName);
        var textLayout = text.GetComponent <LayoutElement>();

        textLayout.flexibleWidth = 1000f;

        var btnEdit = prefabManager.CreateButton(go.transform, "Edit");

        btnEdit.button.onClick.AddListener(() =>
        {
            var e = action.Edit();
            e?.AddListener(() =>
            {
                customCommands.onChange.Invoke();
                text.text = action.displayName;
            });
        });
        var btnLayout = btnEdit.GetComponent <LayoutElement>();

        btnLayout.minWidth       = 160f;
        btnLayout.preferredWidth = 160f;

        var btnRemove = prefabManager.CreateButton(go.transform, "X");

        btnRemove.button.onClick.AddListener(() =>
        {
            customCommands.Remove(action);
            _rows.Remove(row);
            Destroy(go);
        });
        btnRemove.buttonColor = Color.red;
        btnRemove.textColor   = Color.white;
        var btnRemoveLayout = btnRemove.GetComponent <LayoutElement>();

        btnRemoveLayout.minWidth       = 46f;
        btnRemoveLayout.preferredWidth = 46f;
    }
        public ICustomSender Create(params dynamic[] args)
        {
            ICustomCommand   aCommand   = args.OfType <ICustomCommand>().FirstOrDefault();
            ICustomValidator aValidator = args.OfType <ICustomValidator>().FirstOrDefault();

            if (aCommand == null)
            {
                return(new CustomSender());
            }
            else
            {
                var retObj = new CustomSender();
                retObj.SetCommand(aCommand, aValidator);
                return(retObj);
            }
        }
        public SecondViewModel(ICustomCommand okCmd, ICustomCommand cancelCmd)
        {
            OkCmd     = okCmd;
            CancelCmd = cancelCmd;

            OkCmd.ExecuteMethod = p =>
            {
                (p as IView).DialogResult = true;
                (p as IView).Close();
            };

            CancelCmd.ExecuteMethod = p =>
            {
                (p as IView).DialogResult = false;
                (p as IView).Close();
            };
        }
Exemplo n.º 11
0
        public CustomLookUpEdit()
        {
            _isPkg                    = false;
            IsSimpleMode              = true;
            AutoComplete              = true;
            AllowSpinOnMouseWheel     = false;
            ImmediatePopup            = true;
            NullValue                 = null;
            PopupCloseMode            = PopupCloseMode.Normal;
            AllowNullInput            = true; // Gets or sets whether end-users can set the editor's value to a null reference by pressing the CTRL+DEL or CTRL+0 key combinations.
            MaxFetchItemsCount        = 50;
            ClosePopupOnLostFocus     = false;
            ValidateOnEnterKeyPressed = true;
            AutoComplete              = false;

            // делаем, чтобы автопоиск осуществлялся по условию "содержит" (по-умолчанию "начинается с")
            FilterCondition = DevExpress.Data.Filtering.FilterCondition.Contains;

            DataContextChanged         += OnDataContextChanged;
            EditValueChanged           += OnCustomEditValueChanged;
            _openReferenceWindowCommand = new DelegateCustomCommand(OnShowWindow, CanShowWindow);

            PopupOpening += OnPopupOpening;
        }
Exemplo n.º 12
0
        public void Execute(object parameter)
        {
            ICustomCommand command = parameter as ICustomCommand;

            command.Clear();
        }
Exemplo n.º 13
0
 public void Remove(ICustomCommand command)
 {
     _commands.Remove(command);
     onChange.Invoke();
 }
Exemplo n.º 14
0
 /// <summary>
 /// 添加指令
 /// </summary>
 /// <param name="cmd">指令</param>
 public void AddCommand(ICustomCommand cmd)
 {
     this.commands.Add(cmd);
 }
Exemplo n.º 15
0
 public void RemoveCommand()
 {
     Validator = null;
     Command   = null;
 }
 public ViewModelBase(ICustomCommand command)
 {
     _command = command;
     RegisterCommands();
 }
Exemplo n.º 17
0
 public CustomCommand(ICustomCommand target) => Target = target;
 public static void SetCommand(DependencyObject obj, ICustomCommand value)
 {
     obj.SetValue(CommandProperty, value);
 }
Exemplo n.º 19
0
        // Coroutines /-/-/-/-/-/-/-/-/-/-/-/-/

        // RUN AUTH MODULE
        private IEnumerator I_RunModule(AuthModule module)
        {
            ModuleRunning = true;
            int  retrys          = 0;
            bool module_retrying = false;

            module.OnEnter();

            IAsyncModule asyncModule = module as IAsyncModule;

            if (asyncModule != null)
            {
                ProcessResult ares = ProcessResult.None;
                do
                {
                    if (module_retrying)
                    {
                        module.OnEnter();
                        module_retrying = false;
                    }

                    ares = asyncModule.AsyncResult();

                    if (ares == ProcessResult.Failure)
                    {
                        Logger.LogWarning("Got Error during process of AsyncModule " + module.GetException(), this);

                        if (retrys < MaximunErrorRetrys)
                        {
                            yield return(new WaitForSeconds(0.5f));

                            Logger.LogWarning("Retrying... " + retrys, this);
                            retrys++;
                            module_retrying = true;
                        }
                    }

                    yield return(new WaitForEndOfFrame());
                } while (ares != ProcessResult.Completed);

                yield return(new WaitUntil(() => ares == ProcessResult.Completed || retrys >= MaximunErrorRetrys));
            }

            retrys = 0;

            if (module.IsValid(WasRequestedByGuest, auth.CurrentUser))
            {
                module.Execute(this);

                ProcessResult tres       = ProcessResult.None;
                float         time_enter = Time.time;

                do
                {
                    if (module_retrying)
                    {
                        module.OnEnter();
                        module.Execute(this);
                        time_enter = Time.time;

                        module_retrying = false;
                    }

                    tres = module.GetResult();

                    //Debug.Log("MODULE " + module.GetType().Name + " RESULT: " + tres);

                    if (Input.GetKey(KeyCode.Escape) && Time.time - time_enter >= 0.15f)
                    {
                        RequestExit();
                    }

                    //Interrumpt the module when you're about to upgrade the acocount
                    float diff = Time.time - ExitTime;
                    if (IsAuthenticated && (module.IsInterruptible() && ExitRequest && diff > 0.2f && diff < 0.5f))
                    {
                        fsm.MoveNext(AuthCheckCommand.GoBack);
                        yield break;
                    }

                    if (diff >= 0.55f)
                    {
                        ExitTime = 0;
                    }

                    if (tres == ProcessResult.Failure)
                    {
                        Logger.LogWarning("Got Error during process of module " + module.GetException(), this);

                        if (retrys < MaximunErrorRetrys)
                        {
                            yield return(new WaitForSeconds(0.5f));

                            Logger.LogWarning("Retrying... " + retrys, this);
                            retrys++;
                            module_retrying = true;
                        }
                    }

                    yield return(new WaitForEndOfFrame());
                } while (tres != ProcessResult.Completed);

                if (tres == ProcessResult.Completed)
                {
                    Logger.Log("Module completed: " + module.GetType().Name, this, true);
                    module.OnFinish(this, ExitRequest);

                    ICustomCommand cmd = module as ICustomCommand;

                    fsm.MoveNext(cmd != null ? cmd.GetNextCommand() : AuthCheckCommand.Next);
                    ExitRequest = false;
                }
            }
            else
            {
                fsm.MoveNext(AuthCheckCommand.Next);
                yield break;
            }

            ModuleRunning = false;
            yield return(0);
        }
 public ViewModelBase(ICustomCommand loginCommand)
 {
     _loginCommand = loginCommand;
     RegisterCommands();
 }