private static async Task RawTest(bool hasSessionId, RegisterOptions registerOptions, CallOptions callOptions) { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, registerOptions); MyCallback myCallback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke(myCallback, callOptions, myOperation.Procedure); long?expectedCaller = null; if (hasSessionId) { expectedCaller = dualChannel.CallerSessionId; } if (callOptions.DiscloseMe == false && registerOptions.DiscloseCaller == true) { Assert.That(myCallback.ErrorUri, Is.EqualTo(WampErrors.DiscloseMeNotAllowed)); } else { Assert.That(myOperation.Details.Caller, Is.EqualTo(expectedCaller)); } }
public void Can_register_files_with_exclude() { using (var testDirectory = new WorkingDirectorySession()) { File.WriteAllText(Path.Combine(testDirectory.Directory, "file1.txt"), "test"); File.WriteAllText(Path.Combine(testDirectory.Directory, "file2.txt"), "test"); Directory.CreateDirectory(Path.Combine(testDirectory.Directory, "nested")); File.WriteAllText(Path.Combine(testDirectory.Directory, "nested", "file3.txt"), "test"); File.WriteAllText(Path.Combine(testDirectory.Directory, "nested", "file4.txt"), "test"); Directory.CreateDirectory(Path.Combine(testDirectory.Directory, "nested", "nested2")); File.WriteAllText(Path.Combine(testDirectory.Directory, "nested", "nested2", "file5.txt"), "test"); var webBuilder = new Mock <IWebBuilder>(); var options = new RegisterOptions(); options.Matcher = new Matcher(); options.Matcher.AddInclude("**/*"); options.Matcher.AddExclude("**/file3.*"); webBuilder.Setup(x => x.Register("/file1.txt", It.IsAny <Func <HttpContext, Task> >(), null, true)); webBuilder.Setup(x => x.Register("/file2.txt", It.IsAny <Func <HttpContext, Task> >(), null, true)); webBuilder.Setup(x => x.Register("/nested/file3.txt", It.IsAny <Func <HttpContext, Task> >(), null, true)); webBuilder.Setup(x => x.Register("/nested/file4.txt", It.IsAny <Func <HttpContext, Task> >(), null, true)); webBuilder.Setup(x => x.Register("/nested/nested2/file5.txt", It.IsAny <Func <HttpContext, Task> >(), null, true)); webBuilder.Object.RegisterDirectory(testDirectory.Directory, options); webBuilder.Verify(x => x.Register("/file1.txt", It.IsAny <Func <HttpContext, Task> >(), null, true), Times.Exactly(1)); webBuilder.Verify(x => x.Register("/file2.txt", It.IsAny <Func <HttpContext, Task> >(), null, true), Times.Exactly(1)); webBuilder.Verify(x => x.Register("/nested/file3.txt", It.IsAny <Func <HttpContext, Task> >(), null, true), Times.Never); webBuilder.Verify(x => x.Register("/nested/file4.txt", It.IsAny <Func <HttpContext, Task> >(), null, true), Times.Exactly(1)); webBuilder.Verify(x => x.Register("/nested/nested2/file5.txt", It.IsAny <Func <HttpContext, Task> >(), null, true), Times.Exactly(1)); } }
public void It_should_register_a_new_dwolla_user() { // arrange var registerService = new DwollaRegisterService(); var options = new RegisterOptions { ClientId = TestAppKey, ClientSecret = TestAppSecret, Email = TestEmail, Password = "******", Pin = "1111", FirstName = "TestFirst", LastName = "TestLast", Address = "555 Not Real", City = "Seattle", State = "WA", Zip = "98119", Phone = "2065551234", DateOfBirth = new DateTime(1980, 1, 1), AccountType = "Personal", AcceptTerms = true }; // act DwollaResponse <DwollaUser> response = registerService.RegisterUser(options); // assert response.Success.ShouldBeTrue(); }
public async Task <bool> Run <TRetorno, TParametro>(CalleeRequest <TRetorno, TParametro> calleeReq) where TParametro : class { try { RegisterOptions registerOptions = new RegisterOptions(); bool result = false; IWampClientConnectionMonitor monitor = this._channel.RealmProxy.Monitor; monitor.ConnectionEstablished += OnConnectionEstablished; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; registerOptions.Invoke = "roundrobin"; var operation = new AbstractCalleeOperation <TRetorno, TParametro>(calleeReq.Run, calleeReq.NomeMetodo); IWampRealmProxy realm = this._channel.RealmProxy; Task <IAsyncDisposable> registrationTask = realm.RpcCatalog.Register(operation, registerOptions); result = this._channel.RealmProxy.Monitor.IsConnected; return(result); } catch (System.Exception ex) { throw; } }
public override void Register(IWampCallee callee, long requestId, RegisterOptions options, string procedure) { InnerAction(callee, authorizer => authorizer.CanRegister(options, procedure), () => base.Register(callee, requestId, options, procedure), exception => callee.RegisterError(requestId, exception)); }
public static void RegisterInterfaceImplementations(this TinyIoCContainer container, string @namespace, RegisterOptions options = RegisterOptions.AsMultiInstance, RegisterTypes registerTypes = RegisterTypes.AsInterfaceTypes, Assembly[] assemblies = null) { if (assemblies == null) assemblies = new[] { Assembly.GetExecutingAssembly() }; var interfaces = GetInterfacesFromNamespace(@namespace, assemblies); foreach (var i in interfaces) { var implementation = GetImplementingType(i, assemblies); if ((registerTypes & RegisterTypes.AsObjects) == RegisterTypes.AsObjects) { var o = container.Register(typeof(object), implementation, i.Name); if (options == RegisterOptions.AsSingleton) o.AsSingleton(); else o.AsMultiInstance(); } if ((registerTypes & RegisterTypes.AsInterfaceTypes) == RegisterTypes.AsInterfaceTypes) { var o = container.Register(i, implementation); if (options == RegisterOptions.AsSingleton) o.AsSingleton(); else o.AsMultiInstance(); } } }
public static RegisterOptions WithDefaults(this RegisterOptions options) { RegisterOptions result = new RegisterOptions(options); result.Invoke = result.Invoke ?? WampInvokePolicy.Default; result.Match = result.Match ?? WampMatchPattern.Default; return(result); }
public WampCalleeRpcOperation(string procedure, IWampCallee callee, RegisterOptions options, IWampCalleeInvocationHandler <TMessage> handler, WampCalleeOperationCatalog <TMessage> catalog) : base(callee, procedure, options) { mHandler = handler; mCatalog = catalog; }
public Registration(WampMessage <MockRaw> message) { mRequestId = (long)message.Arguments[0].Value; MockRawFormatter formatter = new MockRawFormatter(); mOptions = formatter.Deserialize <RegisterOptions> (formatter.Serialize(message.Arguments[1].Value)); mProcedure = (string)message.Arguments[2].Value; }
public long?LookupRegistrationId(string procedureUri, RegisterOptions options = null) { string match = null; if (options != null) { match = options.Match; } return(base.LookupGroupId(procedureUri, match)); }
/// <summary> /// Hosts a WAMP session management service for the given realm. /// </summary> /// <param name="hostedRealm">The given realm.</param> /// <param name="uriValidator">The <see cref="IWampUriValidator"/> to use to verify GOODBYE message reason uri (see also <see cref="GoodbyeMessage.Reason"/>).</param> /// <returns>A disposable: disposing it will unregister the hosted session management service.</returns> public static IDisposable HostSessionManagementService(this IWampHostedRealm hostedRealm, IWampUriValidator uriValidator = null) { WampSessionManagementService service = new WampSessionManagementService(hostedRealm, uriValidator); RegisterOptions registerOptions = new RegisterOptions { DiscloseCaller = true }; CompositeDisposable disposable = HostDisposableService(hostedRealm, service, new CalleeRegistrationInterceptor(registerOptions)); return(disposable); }
public bool CanRegister(RegisterOptions options, string procedure) { if (WampRestrictedUris.IsRestrictedUri(procedure)) { throw new WampException(WampErrors.InvalidUri, $"register for restricted procedure URI '{procedure}'"); } else { return(Authorizer.CanRegister(options, procedure)); } }
private void VerifyInvokePoliciesAreCompatible(RegisterOptions registerOptions) { if (RegisterOptions.Invoke != registerOptions.Invoke) { string messageDetails = $"register for already registered procedure '{this.Procedure}' with conflicting invocation policy (has {this.RegisterOptions.Invoke} and {registerOptions.Invoke} was requested)"; throw new WampException (WampErrors.ProcedureExistsInvocationPolicyConflict, messageDetails); } }
private MatchRpcOperationCatalog GetInnerCatalog(RegisterOptions options) { MatchRpcOperationCatalog result = mInnerCatalogs.FirstOrDefault (innerCatalog => innerCatalog.Handles(options)); if (result == null) { throw new WampException(WampErrors.InvalidOptions, "unknown match type: " + options.Match); } return(result); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { RegisterOptions.Register(services, Configuration); var provider = services.BuildServiceProvider(); var dataBaseOption = provider.GetService <IOptions <DatabaseOption> >().Value; RegisterServices.Register(services, dataBaseOption); RegisterMappers.Register(services); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
private WampProcedureRegistration CreateRegistration(RegisterOptions registerOptions, string procedureUri) { WampProcedureRegistration result = new WampProcedureRegistration(procedureUri, registerOptions); result.Empty += OnRegistrationEmpty; long registrationId = mRegistrationIdToRegistration.Add(result); result.RegistrationId = registrationId; OnRegistrationAdded(result); return(result); }
private async Task MethodInfoTest(bool hasSessionId, RegisterOptions registerOptions, CallOptions callOptions) { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyService service = new MyService(); Task registerTask = calleeChannel.RealmProxy.Services.RegisterCallee(service, new CalleeRegistrationInterceptor(registerOptions)); await registerTask; IAddService calleeProxy = callerChannel.RealmProxy.Services.GetCalleeProxyPortable <IAddService>(new CalleeProxyInterceptor(callOptions)); WampException caughtException = null; try { int seven = calleeProxy.Add2(3, 4); } catch (WampException ex) { caughtException = ex; } InvocationDetails details = service.Details; long?expectedCaller = null; if (hasSessionId) { expectedCaller = dualChannel.CallerSessionId; } if (registerOptions.DiscloseCaller == true && callOptions.DiscloseMe == false) { Assert.That(caughtException.ErrorUri, Is.EqualTo(WampErrors.DiscloseMeNotAllowed)); Assert.That(details, Is.EqualTo(null)); } else { Assert.That(details.Caller, Is.EqualTo(expectedCaller)); } }
private IEnumerable <OperationToRegister> GetServiceMethodsOfType (Func <object> instance, Type type, ICalleeRegistrationInterceptor interceptor) { foreach (var method in type.GetPublicInstanceMethods()) { if (interceptor.IsCalleeProcedure(method)) { IWampRpcOperation operation = CreateRpcMethod(instance, interceptor, method); RegisterOptions options = interceptor.GetRegisterOptions(method); yield return(new OperationToRegister(operation, options)); } } }
public static void RegisterInterfaceImplementations(this TinyIoCContainer container, string @namespace, RegisterOptions options = RegisterOptions.AsMultiInstance, RegisterTypes registerTypes = RegisterTypes.AsInterfaceTypes, Assembly[] assemblies = null) { if (assemblies == null) { assemblies = new [] { Assembly.GetExecutingAssembly() } } ; var interfaces = GetInterfacesFromNamespace(@namespace, assemblies); foreach (var i in interfaces) { var implementation = GetImplementingType(i, assemblies); if (implementation != null) { if ((registerTypes & RegisterTypes.AsObjects) == RegisterTypes.AsObjects) { var o = container.Register(typeof(object), implementation, i.Name); if (options == RegisterOptions.AsSingleton) { o.AsSingleton(); } else { o.AsMultiInstance(); } } if ((registerTypes & RegisterTypes.AsInterfaceTypes) == RegisterTypes.AsInterfaceTypes) { var o = container.Register(i, implementation); if (options == RegisterOptions.AsSingleton) { o.AsSingleton(); } else { o.AsMultiInstance(); } } } } } }
public string RegisterService(RegisterOptions options) { if (_consulServiceInstance != null) { _logger.LogInformation("Service is already registered."); return(_consulServiceInstance.Id); } var regConfig = Common.GetServiceRegisterConfiguration(_config, options); _consulServiceInstance = new ConsulServiceInstance(regConfig); _canRun = true; Run(regConfig.Discovery.PingInterval * 1000); return(_consulServiceInstance.Id); }
private RegisterOptions DefineRegisterCommand(ArgumentSyntax syntax) { var options = new RegisterOptions(); syntax.DefineCommand("register", ref command, Command.Register, "Create a new registration."); syntax.DefineOption("m|email", ref options.Email, "Email used for registration and recovery contact. (default: None)"); syntax.DefineOption("register-unsafely-without-email", ref options.NoEmail, "Create registration without email."); syntax.DefineOption("agree-tos", ref options.AgreeTos, $"Agree to the ACME Subscriber Agreement (default: {options.AgreeTos})"); syntax.DefineOption("update-registration", ref options.Update, $"With the register verb, indicates that details associated with an existing registration, such as the e-mail address, should be updated, rather than registering a new account. (default: None)"); syntax.DefineOption("thumbprint", ref options.Thumbprint, $"Print thumbprint of the account."); syntax.DefineOption("server", ref options.Server, s => new Uri(s), $"ACME Directory Resource URI. (default: {options.Server})"); syntax.DefineOption("p|path", ref options.Path, $"File path used to load/save the registration. (default: {options.Path})"); syntax.DefineOption("f|force", ref options.Force, $"If registering new account, overwrite the existing configuration if needed."); return(options); }
public Task <IAsyncDisposable> Register(IWampRpcOperation operation, RegisterOptions options) { if (!IsConnected) { throw new WampSessionNotEstablishedException(); } RegisterRequest registerRequest = new RegisterRequest(operation, mFormatter); long id = mPendingRegistrations.Add(registerRequest); registerRequest.RequestId = id; mProxy.Register(id, options, operation.Procedure); return(registerRequest.Task); }
public async Task <IAsyncDisposable> RegisterCallResponse <TResponse>(string procName, Func <IRequestContext, IMessage, Task <TResponse> > onMessage) { if (Log.IsInfoEnabled) { Log.Info($"Registering call with response: [{procName}]"); } var rpcOperation = new RpcResponseOperation <TResponse>(procName, onMessage); var realm = _channel.RealmProxy; var registerOptions = new RegisterOptions { Invoke = "roundrobin" }; return(await realm.RpcCatalog.Register(rpcOperation, registerOptions)); }
public void Register(IWampCallee callee, long requestId, RegisterOptions options, string procedure) { try { options = options.WithDefaults(); ValidateRegisterUri(procedure, options.Match); RegisterRequest registerRequest = new RegisterRequest(callee, requestId); mCalleeCatalog.Register(registerRequest, options, procedure); } catch (WampException exception) { mLogger.ErrorFormat(exception, "Failed registering procedure '{ProcedureUri}'. Registration request id: {RequestId} ", procedure, requestId); callee.RegisterError(requestId, exception); } }
public async Task <IAsyncDisposable> RegisterCall(string procName, Func <IRequestContext, IMessage, Task> onMessage) { if (Log.IsInfoEnabled) { Log.Info($"Registering call: [{procName}]"); } var rpcOperation = new RpcOperation(procName, onMessage); var realm = _channel.RealmProxy; var registerOptions = new RegisterOptions { Invoke = "single" }; // Todo this operation can cause a deadlock - even with configureawait(False) return(await realm.RpcCatalog.Register(rpcOperation, registerOptions)); }
public void Register(IWampCallee callee, long requestId, RegisterOptions options, string procedure) { try { options.Invoke = options.Invoke ?? WampInvokePolicy.Default; options.Match = options.Match ?? WampMatchPattern.Default; ValidateRegisterUri(procedure, options.Match); RegisterRequest registerRequest = new RegisterRequest(callee, requestId); mCalleeCatalog.Register(registerRequest, options, procedure); } catch (WampException exception) { mLogger.ErrorFormat(exception, "Failed registering procedure '{0}'. Registration request id: {1} ", procedure, requestId); callee.RegisterError(requestId, exception); } }
public async Task <bool> Run(CallerResult <TRetorno, TParametro> rpcPub) { RegisterOptions registerOptions = new RegisterOptions(); var callback = new AbstractCallerCallback <TRetorno>(rpcPub.Resultado); bool result = true; IWampClientConnectionMonitor monitor = this._channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; registerOptions.Invoke = "roundrobin"; IWampRealmProxy realm = this._channel.RealmProxy; var parameters = new object[] { rpcPub.Parametros }; realm.RpcCatalog.Invoke(callback, new CallOptions(), rpcPub.NomeMetodo, parameters); return(result); }
public long Register(IRegisterRequest request, RegisterOptions options, string procedure) { WampCalleeRpcOperation <TMessage> operation = new WampCalleeRpcOperation <TMessage>(procedure, request.Callee, options, mInvocationHandler, this); try { IWampRegistrationSubscriptionToken token = mCatalog.Register(operation, options); long registrationId = token.TokenId; operation.RegistrationId = registrationId; CompositeDisposable disposable = new CompositeDisposable(token, operation); bool alreadyRegistered = !mOperationToDisposable.TryAdd(operation, disposable); request.Registered(registrationId); // If the operation is already registered, ignore it. if (!alreadyRegistered) { operation.Open(); } return(registrationId); } catch (Exception) { operation.Dispose(); throw; } }
/// <summary> /// Hosts a WAMP testament service for the given realm. /// </summary> /// <param name="hostedRealm">The given realm.</param> /// <returns>A disposable: disposing it will unregister the hosted testaments service.</returns> public static IDisposable HostTestamentService(this IWampHostedRealm hostedRealm) { WampTestamentService service = new WampTestamentService(hostedRealm); RegisterOptions registerOptions = new RegisterOptions { DiscloseCaller = true }; CompositeDisposable disposable = HostDisposableService(hostedRealm, service, new CalleeRegistrationInterceptor(registerOptions)); DealerFeatures dealerFeatures = hostedRealm.Roles.Dealer.Features; dealerFeatures.TestamentMetaApi = true; IDisposable featureDisposable = Disposable.Create(() => { dealerFeatures.TestamentMetaApi = null; }); disposable.Add(featureDisposable); return(disposable); }
public bool CanRegister(RegisterOptions options, string procedure) => false;
public RegisterRequest(RegisterOptions opts) { CreateVerbosityCommand = () => new SetVerbosityCommand(opts); CreateRegisterCommand = () => new RegisterCommand(opts.ToRegisterUserModel()); CreateLogJwtCommand = jwt => new LogJwtCommand(jwt); }