Beispiel #1
0
        protected override void SetClasses()
        {
            base.SetClasses();
            //ant-input-password-large ant-input-affix-wrapper ant-input-affix-wrapper-lg
            ClassMapper
            .If($"{PrefixCls}-password-large", () => Size == InputSize.Large)
            .If($"{PrefixCls}-password-small", () => Size == InputSize.Small);

            AffixWrapperClass = string.Join(" ", AffixWrapperClass, $"{PrefixCls}-password");

            if (VisibilityToggle)
            {
                Suffix = new RenderFragment((builder) =>
                {
                    int i = 0;
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-suffix");
                    builder.OpenComponent <AntIcon>(i++);
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-password-icon");
                    builder.AddAttribute(i++, "type", _eyeIcon);
                    builder.AddAttribute(i++, "onclick", CallbackFactory.Create(this, ToggleVisibility));
                    builder.CloseComponent();
                    builder.CloseElement();
                });
            }
        }
        public async Task Test_Executer()
        {
            IConfigInfo configInfo;
            var         controller = GetBucketForKey("thekey", out configInfo);

            _requestExecuter = new CouchbaseRequestExecuter(controller, configInfo, "default", _pending);

            var tcs = new TaskCompletionSource <IOperationResult <string> >();
            var cts = new CancellationTokenSource();

            var operation = new Mock <IOperation <string> >();

            operation.Setup(x => x.GetConfig()).Returns(new BucketConfig());
            operation.Setup(x => x.Write()).Throws(new Exception("bad kungfu"));
            operation.Setup(x => x.Key).Returns("thekey");
            operation.Setup(x => x.Completed).Returns(CallbackFactory.CompletedFuncWithRetryForCouchbase(
                                                          _requestExecuter, _pending, controller, tcs, cts.Token));
            operation.Setup(x => x.GetResultWithValue()).Returns(new OperationResult <string> {
                Success = true
            });

            var result = await _requestExecuter.SendWithRetryAsync(operation.Object, tcs);

            Assert.IsTrue(result.Success);
        }
Beispiel #3
0
        public void demo()
        {
            CallbackFactory callbackFactory = new CallbackFactory();

            callbackFactory.DingTalkEventShunt("123", "456", AccessToken.GetAccessToken());
            //return "2222";
        }
Beispiel #4
0
    //Create un pool ;)
    public Pool(int initialStock, CallbackFactory factoryMethod, PoolObject <Tpool> .PoolCallback initialize, PoolObject <Tpool> .PoolCallback finalize, bool isDynamic)
    {
        //inicializo la lista
        _poolList = new List <PoolObject <Tpool> >();

        //ahora guardamos los punteros que necesitamos
        _factoryMethod = factoryMethod;
        _isDynamic     = isDynamic;
        _count         = initialStock;
        _init          = initialize;
        _finalize      = finalize;

        //generamos el stock inicial

        for (int i = 0; i < _count; i++)
        {
            _poolList.Add(new PoolObject <Tpool>(_factoryMethod(), _init, _finalize));
        }

        //new line: desactivo el stock inicial para que empiece desactivado

        foreach (PoolObject <Tpool> poolObj in _poolList)
        {
            poolObj.IsActive = false;
        }
    }
Beispiel #5
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (EnterButton.IsT0 && !EnterButton.AsT0)
            {
                Suffix = builder =>
                {
                    var i = 0;
                    builder.OpenComponent <Icon>(i++);
                    builder.AddAttribute(i++, "Class", $"{PrefixCls}-search-icon");
                    if (Loading)
                    {
                        builder.AddAttribute(i++, "Type", "loading");
                    }
                    else
                    {
                        builder.AddAttribute(i++, "Type", "search");
                    }
                    builder.AddAttribute(i++, "OnClick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                    builder.CloseComponent();
                };
            }
            else
            {
                AddOnAfter = builder =>
                {
                    builder.OpenComponent <Button>(_sequence++);
                    builder.AddAttribute(_sequence++, "Class", $"{PrefixCls}-search-button");
                    builder.AddAttribute(_sequence++, "Type", "primary");
                    builder.AddAttribute(_sequence++, "Size", Size);

                    if (Loading)
                    {
                        builder.AddAttribute(_sequence++, "Loading", true);
                    }
                    else
                    {
                        builder.AddAttribute(_sequence++, "OnClick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                    }

                    EnterButton.Switch(boolean =>
                    {
                        if (boolean)
                        {
                            builder.AddAttribute(_sequence++, "Icon", "search");
                        }
                    }, str =>
                    {
                        builder.AddAttribute(_sequence++, "ChildContent", new RenderFragment((b) =>
                        {
                            b.AddContent(_sequence++, str);
                        }));
                    });

                    builder.CloseComponent();
                };
            }
        }
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (EnterButton.Value == null)
            {
                Suffix = new RenderFragment((builder) =>
                {
                    builder.OpenComponent <Icon>(35);
                    builder.AddAttribute(36, "class", $"{PrefixCls}-search-icon");
                    builder.AddAttribute(37, "type", "search");
                    builder.AddAttribute(38, "onclick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                    builder.CloseComponent();
                });
            }
            else
            {
                AddOnAfter = new RenderFragment((builder) =>
                {
                    builder.OpenComponent <Button>(_sequence++);
                    builder.AddAttribute(_sequence++, "class", $"{PrefixCls}-search-button");
                    builder.AddAttribute(_sequence++, "type", "primary");
                    builder.AddAttribute(_sequence++, "size", Size);

                    if (_isSearching)
                    {
                        builder.AddAttribute(_sequence++, "loading", true);
                    }
                    else
                    {
                        var e = new EventCallbackFactory().Create(this, HandleSearch);
                        builder.AddAttribute(_sequence++, "onclick", e);
                    }

                    EnterButton.Switch(boolean =>
                    {
                        if (boolean)
                        {
                            builder.AddAttribute(_sequence++, "icon", "search");
                        }
                    }, str =>
                    {
                        builder.AddAttribute(_sequence++, "ChildContent", new RenderFragment((b) =>
                        {
                            b.AddContent(_sequence++, str);
                        }));
                    });

                    builder.CloseComponent();
                });
            }
        }
Beispiel #7
0
        public GenericPool(int initialStock, CallbackFactory factoryMethod, PoolObject <T> .PoolCallback init, PoolObject <T> .PoolCallback dispose)
        {
            poolStack          = new Stack <PoolObject <T> >();
            activePoolStack    = new Stack <PoolObject <T> >();
            this.factoryMethod = factoryMethod;
            this.init          = init;
            this.dispose       = dispose;

            for (int i = 0; i < initialStock; i++)
            {
                poolStack.Push(new PoolObject <T>(this.factoryMethod(), this.init, this.dispose));
            }
        }
Beispiel #8
0
        public RpcBindingHost(IConnection <TMarshal> connection, IPlatformBinder <TMarshal> parameterBinder, IScheduler baseScheduler)
        {
            this.connection   = connection;
            bindingRepository = new BindingRepository(new IntIdGenerator());

            if (baseScheduler is IDisposable disposable)
            {
                disposables.Add(disposable);
            }

            // ReSharper disable once InvokeAsExtensionMethod
            var baseMessages = Observable.ObserveOn(connection, baseScheduler);

            callbackExecutor = new CallbackExecutor <TMarshal>(new IntIdGenerator(),
                                                               connection,
                                                               baseMessages.Select(m => m.CallbackResult)
                                                               .Where(m => m != null));
            var callbackFactory = new CallbackFactory <TMarshal>(callbackExecutor);
            var binder          = new ObjectBinderBuilder <TMarshal>().Use(typeof(CallbackBinder <TMarshal>), callbackFactory)
                                  .Use(typeof(OutgoingValueBinder <TMarshal>), bindingRepository)
                                  .Use(typeof(PlatformBinder <TMarshal>), parameterBinder).Build();

            methodExecutor   = new MethodExecutor <TMarshal>(bindingRepository.Objects, binder);
            propertyExecutor = new PropertyExecutor <TMarshal>(bindingRepository.Objects, binder);

            disposables.Add(Observable.ObserveOn((callbackExecutor as IObservable <DeleteCallback>), baseScheduler)
                            .Subscribe(OnDeleteCallback));
            disposables.Add(Observable.ObserveOn((callbackExecutor as IObservable <CallbackExecution <TMarshal> >), baseScheduler)
                            .Subscribe(OnCallbackExecution));

            // ReSharper disable once InvokeAsExtensionMethod

            disposables.Add(baseMessages
                            .Select(m => m.MethodExecution)
                            .Where(m => m != null)
                            .Subscribe(OnMethodExecution));
            disposables.Add(baseMessages
                            .Select(m => m.PropertyGet)
                            .Where(m => m != null)
                            .Subscribe(OnPropertyGetExecution));
            disposables.Add(baseMessages
                            .Select(m => m.PropertySet)
                            .Where(m => m != null)
                            .Subscribe(OnPropertySetExecution));
            disposables.Add(baseMessages
                            .Select(m => m.DynamicObjectRequest)
                            .Where(m => m != null)
                            .Subscribe(OnDyanmicObjectRequest));

            disposables.Add(connection);
        }
Beispiel #9
0
    public Pool(int initialStock, CallbackFactory factoryMethod, PoolObject <T> .PoolCallback initialize, PoolObject <T> .PoolCallback finalize, bool isDinamic)
    {
        _poolList      = new List <PoolObject <T> >();
        _factoryMethod = factoryMethod;
        _isDinamic     = isDinamic;
        _count         = initialStock;
        _init          = initialize;
        _finalize      = finalize;

        for (int i = 0; i < _count; i++)
        {
            _poolList.Add(new PoolObject <T>(_factoryMethod(), _init, _finalize));
        }
    }
        public async Task DelegateCreated()
        {
            var callbackExecutor     = Mock.Of <ICallbackExecutor <object> >();
            var callbackExecutorMock = Mock.Get(callbackExecutor);

            callbackExecutorMock.Setup(_ => _.Execute(It.Is <CallbackExecutionParameters <object> >(c => c.Id == 9 && (string)c.Parameters[0].Value == "input"))).Returns(Task.FromResult <object>("result"));
            callbackExecutorMock.SetupGet(_ => _.CanExecute).Returns(true);
            var callbackFactory = new CallbackFactory <object>(callbackExecutor);

            Func <string, Task <string> > del = (Func <string, Task <string> >)callbackFactory.CreateCallback(9,
                                                                                                              typeof(Func <string, Task <string> >), ctx => { });

            Assert.Equal("result", await del("input"));
        }
 public Svamlet Post(CallbackEventModel model)
 {
     var sinch = new CallbackFactory(new Locale("en-US"));
     Svamlet result = null;
     var builder = sinch.CreateIceSvamletBuilder();
     if (NumberConfigContext.Current().Any(c => c.From == model.From)) {
     var config = NumberConfigContext.Current().FirstOrDefault(c => c.From == model.From);
     result = builder.ConnectPstn(config.To).WithCli(model.To.Endpoint).WithoutCallbacks().Model;
     }
     else {
     result = builder.Say("Invalid caller id!").Hangup().Model;
     }
     return result;
 }
Beispiel #12
0
    public Pool(int initialStock, CallbackFactory factory, PoolObject <T> .PoolCallback initialize, PoolObject <T> .PoolCallback finalize, bool isDinamic)
    {
        _poolList = new List <PoolObject <T> >();

        _factory  = factory;
        _dinamic  = isDinamic;
        _stock    = initialStock;
        _init     = initialize;
        _finalize = finalize;

        for (int i = 0; i < _stock; i++)
        {
            _poolList.Add(new PoolObject <T>(_factory(), _init, _finalize));
        }
    }
Beispiel #13
0
        public async Task <IActionResult> LogIn(LogInViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("LogIn"));
            }

            var client = HttpContext.GetClient() ?? new HttpPilotClient();

            var serverUrl = ApplicationConst.PilotServerUrl;

            try
            {
                client.Connect(serverUrl);
            }
            catch (Exception ex)
            {
                _logger.LogError(1, "Не удалось подключиться к серверу", ex);
                ModelState.AddModelError("", "Сервер недоступен.");
                return(View());
            }

            var serviceCallbackProxy = CallbackFactory.Get <IServerCallback>();
            var serverApi            = client.GetServerApi(serviceCallbackProxy);

            var protectedPassword = model.Password.EncryptAes();
            var useWindowsAuth    = model.Login.Contains('\\') || model.Login.Contains('/');
            var dbInfo            = serverApi.OpenDatabase(model.DatabaseName, model.Login, protectedPassword, useWindowsAuth);

            if (dbInfo == null)
            {
                ModelState.AddModelError("", "Авторизация не удалась, проверьте данные и повторите вход");
                return(View("LogIn", model));
            }
            var sid = Guid.NewGuid();

            await SignInAsync(dbInfo, model.DatabaseName, protectedPassword, sid, model.RememberMe);

            HttpContext.SetClient(client, sid);
            DMetadata dMetadata = serverApi.GetMetadata(dbInfo.MetadataVersion);

            //DMetadata dMetadata = serverApi.GetMetadata(0);
            Debug.WriteLine(dMetadata.Types.ToString());
            Debug.WriteLine(dMetadata.Version.ToString());
            HttpContext.Session.SetSessionValues(SessionKeys.MetaTypes, dMetadata.Types.ToDictionary(x => x.Id, y => y));

            return(RedirectToAction("Index", "Files"));
        }
Beispiel #14
0
    public Pool(int initialStock, CallbackFactory factoryMethod, PoolObject <T> .PoolCallback initialize, PoolObject <T> .PoolCallback finalize, bool isDinamic)
    {
        _poolList = new List <PoolObject <T> >();

        //Guardamos los punteros para cuando los necesitemos.
        _factoryMethod = factoryMethod;
        _isDinamic     = isDinamic;
        _count         = initialStock;
        _init          = initialize;
        _finalize      = finalize;

        //Generamos el stock inicial.
        for (int i = 0; i < _count; i++)
        {
            _poolList.Add(new PoolObject <T>(_factoryMethod(), _init, _finalize));
        }
    }
Beispiel #15
0
    private CallbackFactory _factoryMethod;         //Referencia al método para factory

    public Pool(int initialStock, CallbackFactory factoryMethod, PoolObject <T> .PoolCallback initialize, PoolObject <T> .PoolCallback finalize, bool isDinamic)
    {
        _poolList = new List <PoolObject <T> >(); //Creo la lista de objetos

        //Guardamos los punteros para cuando los necesitemos.
        _factoryMethod = factoryMethod; //Guardo el factory method
        _isDinamic     = isDinamic;     //Guardo si es dinámico
        _count         = initialStock;  //Guardo la cantidad de elementos
        _init          = initialize;    //Guardo el método para inicializar
        _finalize      = finalize;      //Guardo el método para finalizar

        //Generamos el stock inicial.
        for (int i = 0; i < _count; i++)                                           //Por cada iteración
        {
            _poolList.Add(new PoolObject <T>(_factoryMethod(), _init, _finalize)); //Creo un pool object y lo agrego a la lista de elementos
        }
    }
Beispiel #16
0
        public object ReceiveCallBack(string EventType)
        {
            // 获取钉钉加密解密引擎实例
            //var dingTalk = new DingTalkCrypt(token,encodingAesKey,suiteKey);

            //var strEncrypt = JObject.Parse(data)["encrypt"]?.ToString();
            //// 解密后的postbody
            //string refPostBody = "";
            //if (dingTalk.DecryptMsg(signature, timestamp, nonce, strEncrypt, ref refPostBody) != 0)
            //    throw new Exception("钉钉解密回调消息体错误【signature = " + signature + " | timestamp = " + timestamp + " | nonce = " + nonce + " | PostBody = " + strEncrypt + "】");

            // 钉钉回调事件分流
            CallbackFactory callbackFactory = new CallbackFactory();
            // 新建线程执行具体业务逻辑
            Task task = new Task(() => callbackFactory.DingTalkEventShunt(EventType, "", AccessToken.GetAccessToken()));

            task.Start();
            //Task task = new Task(() => callbackFactory.DingTalkEventShunt(JObject.Parse(refPostBody)["EventType"]?.ToString(), refPostBody, AccessToken.GetAccessToken()));
            //task.Start();
            // 接收完参数后立即按要求返回加密success对象,避免因业务逻辑执行时间过长导致钉钉认为接口调用失败
            //string encrypt = "";
            //string re_signature = "";
            //string re_timeStamp = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).Ticks.ToString();
            //// 生成随机串
            //string strSource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            //StringBuilder strRd = new StringBuilder();
            //Random rd = new Random();
            //for (int i = 0; i < 6; i++)
            //{
            //    strRd.Append(strSource.Substring(rd.Next(0, strSource.Length), 1));
            //}
            //string re_nonce = strRd.ToString();
            //dingTalk.EncryptMsg("success", re_timeStamp, re_nonce, ref encrypt, ref re_signature);
            //Hashtable jsonMap = new Hashtable
            //    {
            //        {"encrypt", encrypt},
            //        {"nonce", re_nonce},
            //        {"timeStamp", re_timeStamp},
            //        {"msg_signature", re_signature}
            //    };
            //return jsonMap;
            return("");
        }
Beispiel #17
0
        protected override void SetClasses()
        {
            base.SetClasses();
            //ant-input-password-large ant-input-affix-wrapper ant-input-affix-wrapper-lg
            ClassMapper
            .If($"{PrefixCls}-password-large", () => Size == InputSize.Large)
            .If($"{PrefixCls}-password-small", () => Size == InputSize.Small)
            .If($"{PrefixCls}-password-rtl", () => RTL);

            AffixWrapperClass = string.Join(" ", AffixWrapperClass, $"{PrefixCls}-password");

            if (VisibilityToggle)
            {
                Suffix = new RenderFragment((builder) =>
                {
                    int i = 0;
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-suffix");
                    builder.OpenComponent <Icon>(i++);
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-password-icon");
                    builder.AddAttribute(i++, "type", _eyeIcon);
                    builder.AddAttribute(i++, "onclick", CallbackFactory.Create <MouseEventArgs>(this, async args =>
                    {
                        var element = await JsInvokeAsync <HtmlElement>(JSInteropConstants.GetDomInfo, Ref);

                        IsFocused = true;
                        await this.FocusAsync(Ref);

                        ToggleVisibility(args);

                        if (element.SelectionStart != 0)
                        {
                            await Js.SetSelectionStartAsync(Ref, element.SelectionStart);
                        }
                    }));
                    builder.CloseComponent();
                    builder.CloseElement();
                });
            }
        }
        public async Task When_TransportFailure_Occurs_CheckConfigUpdate_Is_Called_For_ExecuteAsync_T()
        {
            var mockConnection = new Mock <IConnection>();

            mockConnection.Setup(x => x.IsConnected).Returns(false);

            var mockConnectionPool = new Mock <IConnectionPool>();

            mockConnectionPool.Setup(x => x.Acquire()).Returns(mockConnection.Object);
            mockConnectionPool.SetupGet(x => x.Configuration).Returns(new PoolConfiguration {
                UseEnhancedDurability = false
            });

            var service = new MultiplexingIOService(mockConnectionPool.Object);

            var mockOperation = new Mock <IOperation <string> >();

            mockOperation.Setup(x => x.Opaque).Returns(1);
            mockOperation.Setup(x => x.Exception).Returns(new TransportFailureException());

            var opqueue = new ConcurrentDictionary <uint, IOperation>();

            opqueue.TryAdd(mockOperation.Object.Opaque, mockOperation.Object);

            var mockController = new Mock <IClusterController>();

            mockController.Setup(x => x.CheckConfigUpdate(It.IsAny <string>(), It.IsAny <IPEndPoint>())).Verifiable();

            TaskCompletionSource <IOperationResult <string> > tcs = new TaskCompletionSource <IOperationResult <string> >();

            mockOperation.Setup(x => x.Completed)
            .Returns(CallbackFactory.CompletedFuncWithRetryForCouchbase <string>(null, opqueue, mockController.Object, tcs,
                                                                                 new CancellationToken()));

            await service.ExecuteAsync(mockOperation.Object);

            mockController.VerifyAll();
        }
        public void CallbackCreated()
        {
            var callbackFactory = new CallbackFactory <object>(Mock.Of <ICallbackExecutor <object> >());

            Assert.NotNull(callbackFactory.CreateCallback(1, null, ctx => { }));
        }
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (EnterButton.IsT0 && !EnterButton.AsT0)
            {
                if (ClassicSearchIcon)
                {
                    Suffix = builder =>
                    {
                        builder.OpenComponent <Icon>(1);
                        builder.AddAttribute(2, "Class", $"{PrefixCls}-search-icon");
                        if (Loading)
                        {
                            builder.AddAttribute(3, "Type", "loading");
                        }
                        else
                        {
                            builder.AddAttribute(4, "Type", "search");
                        }
                        builder.AddAttribute(5, "OnClick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                        builder.CloseComponent();
                    };
                }
                else
                {
                    AddOnAfter = builder =>
                    {
                        builder.OpenComponent <Button>(6);
                        builder.AddAttribute(7, "Class", $"{PrefixCls}-search-button");
                        builder.AddAttribute(8, "Type", "default");
                        builder.AddAttribute(9, "Size", Size);
                        builder.AddAttribute(10, "Loading", Loading);
                        if (!Loading)
                        {
                            builder.AddAttribute(12, "OnClick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                        }
                        builder.AddAttribute(13, "Icon", "search");

                        builder.CloseComponent();
                    };
                }
            }
            else
            {
                AddOnAfter = builder =>
                {
                    builder.OpenComponent <Button>(11);
                    builder.AddAttribute(12, "Class", $"{PrefixCls}-search-button");
                    builder.AddAttribute(13, "Type", "primary");
                    builder.AddAttribute(14, "Size", Size);
                    builder.AddAttribute(15, "Loading", Loading);
                    if (!Loading)
                    {
                        builder.AddAttribute(16, "OnClick", CallbackFactory.Create <MouseEventArgs>(this, HandleSearch));
                    }

                    EnterButton.Switch(boolean =>
                    {
                        if (boolean)
                        {
                            builder.AddAttribute(17, "Icon", "search");
                        }
                    }, str =>
                    {
                        builder.AddAttribute(18, "ChildContent", new RenderFragment((b) =>
                        {
                            b.AddContent(19, str);
                        }));
                    });

                    builder.CloseComponent();
                };
            }
        }