public virtual ActionResult Cadastrar(TClient model) { try { model.Password = TClient.HashPassword(model.PasswordString); TempData["Alert"] = new Alert("success", "Seu cliente foi cadastrado com sucesso"); model.Save(); TPreference.SavePreferences(model); return(RedirectToAction("Index")); } catch (SimpleValidationException ex) { ViewBag.MostraSenha = true; ViewBag.EnumProfileClient = EnumHelper.ListAll <ProfileClient>().ToSelectList(x => x, x => x.Description()); return(HandleViewException(model, ex)); } }
public virtual ActionResult EsqueciMinhaSenha(string email) { var usuario = TClient.FindByEmail(email); if (usuario != null && usuario.IsActive) { //var passwordReset = TResetPassword.GenerateResetPassword(usuario); //Uri uri = Request.Url; //var link = string.Format("{0}://{1}/usuarios/nova-senha?token={2}", uri.Scheme, uri.Authority, passwordReset.Token); //passwordReset.UpdateLink(link); //try { new MailController().RecuperarSenha(passwordReset).Deliver(); } catch { } return(Json(new { sucesso = "sucesso" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { erro = "E-mail não encontrado ou conta desativada" }, JsonRequestBehavior.AllowGet)); } }
/// <nodoc/> public RequestHandler(MultiplexingServer <TClient> parent, TClient client) { m_parent = parent; m_client = client; m_stream = parent.m_connectivityProvider.GetStreamForClient(client); Name = I($"{parent.Name}.RequestHandler({parent.m_connectivityProvider.Describe(client)})"); m_stopRequestedByClient = false; m_requestListener = new GenericServer <Request>( name: Name, config: m_parent.m_requestHandlingConfig, listener: AcceptRequestAsync); m_sendResponseBlock = new ActionBlock <Response>( SendResponseAsync, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 1 }); // streaming must be sequential // chain block completions: either one completes the other var continuationDone = TaskSourceSlim.Create <Unit>(); m_requestListener.Completion.ContinueWith(_ => m_sendResponseBlock.Complete()); m_sendResponseBlock.Completion.ContinueWith(async _ => { m_requestListener.Complete(); if (!m_stopRequestedByClient) { var succeeded = await Response.DisconnectResponse.TrySerializeAsync(m_stream); Logger.Verbose("({0}) Sending DisconnectResponse {1}.", Name, succeeded ? "Succeeded" : "Failed"); } Logger.Verbose("({0}) Disconnecting client...", Name); bool ok = TryDisconnectClient(m_client); Logger.Verbose("({0}) Disconnecting client {1}.", Name, ok ? "Succeeded" : "Failed"); continuationDone.SetResult(Unit.Void); }); // set the completion task to be the completion of both listener and sender blocks, as well as the cleanup continuation m_completion = TaskUtilities.SafeWhenAll(new[] { m_requestListener.Completion, m_sendResponseBlock.Completion, continuationDone.Task }); }
public TClient GetClient <TClient> () where TClient : class, IInvokeClient { Type type = typeof(TClient); if (cache.ContainsKey(type)) { return(cache[type] as TClient); } else { TClient client = ActivatorUtilities.CreateInstance <TClient> (this._serviceProvider); lock (lockObj) { if (!cache.ContainsKey(type)) { cache.Add(type, client); } } return(client); } }
public TRequest(TClient client, IDirigentControl ctrl, string cmdLine) { this.ctrl = ctrl; Client = client; Commands = new Queue <ICommand>(); cmdRepo = new MyCommandRepo(ctrl); // parse commands and fill cmd queue List <string> tokens = null; string restAfterUid; SplitToUuidAndRest(cmdLine, out Uid, out restAfterUid); try { if (!string.IsNullOrEmpty(restAfterUid)) { SplitToWordTokens(restAfterUid, out tokens); } if (tokens != null && tokens.Count > 0) { var cmdList = cmdRepo.ParseCmdLineTokens(tokens, WriteResponseLine); Commands = new Queue <ICommand>(cmdList); } } catch (Exception e) { // take just first line of exception description string excMsg = e.ToString(); var crPos = excMsg.IndexOf('\r'); var lfPos = excMsg.IndexOf('\n'); if (crPos >= 0 || lfPos >= 0) { excMsg = excMsg.Substring(0, Math.Min(crPos, lfPos)); } WriteResponseLine("ERROR: " + Tools.JustFirstLine(e.Message)); Finished = true; } }
public virtual TClient CreateCustomArmClient <TClient>(params object[] parameters) where TClient : Microsoft.Rest.ServiceClient <TClient> { List <Type> types = new List <Type>(); var containsDelegatingHandler = false; foreach (object obj in parameters) { if (obj.GetType().Name.Equals("DelegatingHandler[]")) { containsDelegatingHandler = true; } types.Add(obj.GetType()); } var copiedParameters = parameters; if (!containsDelegatingHandler) { types.Add((new DelegatingHandler[0]).GetType()); var parameterList = copiedParameters.ToList(); parameterList.Add(new DelegatingHandler[0]); copiedParameters = parameterList.ToArray(); } var constructor = typeof(TClient).GetConstructor(types.ToArray()); if (constructor == null) { throw new InvalidOperationException(string.Format(Resources.InvalidManagementClientType, typeof(TClient).Name)); } TClient client = (TClient)constructor.Invoke(copiedParameters); foreach (ProductInfoHeaderValue userAgent in _userAgents.Keys) { client.UserAgent.Add(userAgent); } return(client); }
public virtual ActionResult Login(Login model) { model.SudDomain = Subdomain.Painel; var usuario = TClient.Authenticate(model); if (usuario != null) { FormsAuthentication.SetAuthCookie(model.Username, model.Remember); HttpContext.User = new GenericPrincipal(new GenericIdentity(model.Username), new string[] { }); var idioma = "pt-br"; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(idioma); Thread.CurrentThread.CurrentUICulture = new CultureInfo(idioma); var cookie = Request.Cookies["linguagem"]; if (cookie == null) { cookie = new HttpCookie("linguagem") { Value = idioma } } ; if (cookie.Value != idioma) { cookie.Value = idioma; } Response.Cookies.Add(cookie); if (!string.IsNullOrWhiteSpace(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } return(RedirectToAction(MVC.Home.Index())); } else { ViewBag.Alerta = new Alert("error", TClient.GetErrorLogin(model)); return(View(model)); } }
public virtual TClient CreateCustomClient <TClient>(params object[] parameters) where TClient : ServiceClient <TClient> { List <Type> types = new List <Type>(); foreach (object obj in parameters) { types.Add(obj.GetType()); } var constructor = typeof(TClient).GetConstructor(types.ToArray()); if (constructor == null) { throw new InvalidOperationException(string.Format(Resources.InvalidManagementClientType, typeof(TClient).Name)); } TClient client = (TClient)constructor.Invoke(parameters); client.UserAgent.Add(ApiConstants.UserAgentValue); return(client); }
public override TClient CreateCustomClient <TClient>(params object[] parameters) { TClient client = ManagementClients.FirstOrDefault(o => o is TClient) as TClient; if (client == null) { if (throwWhenNotAvailable) { throw new ArgumentException( string.Format("TestManagementClientHelper class wasn't initialized with the {0} client.", typeof(TClient).Name)); } else { var realClient = base.CreateCustomClient <TClient>(parameters); var newRealClient = realClient.WithHandler(HttpMockServer.CreateInstance()); realClient.Dispose(); return(newRealClient); } } return(client); }
private void btnConnect_Click(object sender, EventArgs e) { if (txtIP1.Text == "" || txtIP2.Text == "") { return; } string serverIP1 = txtIP1.Text; string serverIP2 = txtIP2.Text; string clientIP = "127.0.0.1"; if (clientCalc1 == null) { clientCalc1 = new TClient(GetDataArrived1); } clientCalc1.ClientBeginConnect(serverIP1, 5000, clientIP); if (clientCalc2 == null) { clientCalc2 = new TClient(GetDataArrived2); } clientCalc2.ClientBeginConnect(serverIP2, 5001, clientIP); }
public TClient CreateClient <TClient>(params object[] parameters) where TClient : ServiceClient <TClient> { List <Type> types = new List <Type>(); foreach (object obj in parameters) { types.Add(obj.GetType()); } var constructor = typeof(TClient).GetConstructor(types.ToArray()); if (constructor == null) { throw new InvalidOperationException(string.Format(Resources.InvalidManagementClientType, typeof(TClient).Name)); } TClient client = (TClient)constructor.Invoke(parameters); client.UserAgent.Add(ApiConstants.UserAgentValue); if (OnClientCreated != null) { ClientCreatedArgs args = new ClientCreatedArgs { CreatedClient = client, ClientType = typeof(TClient) }; OnClientCreated(this, args); client = (TClient)args.CreatedClient; } // Add the logging handler var withHandlerMethod = typeof(TClient).GetMethod("WithHandler", new[] { typeof(DelegatingHandler) }); TClient finalClient = (TClient)withHandlerMethod.Invoke(client, new object[] { new HttpRestCallLogger() }); client.Dispose(); return(finalClient); }
public SecurityContext Init(Func <IIdentity> identityGetter, Subdomain subdomain) { _identityGetter = identityGetter; _isAuthenticated = TryGet(x => x.IsAuthenticated, false); var username = TryCast(x => x.Name, string.Empty); if (_isAuthenticated && !string.IsNullOrEmpty(username)) { if (subdomain == Subdomain.Admin) { var user = TUser.FindByUsername(username); if (user != null) { _user = new UserSecurity(user, subdomain); } } else { var model = TClient.FindByUsername(username); if (model != null) { _user = new UserSecurity(model); } } } else { _user = null; } if (_user == null) { _isAuthenticated = false; } return(this); }
public virtual ActionResult Index() { var clientes = TClient.ListAll().ToList(); return(View(clientes)); }
public void InvokeMethod(TClient client) { _method.Invoke(client); }
public void RetryMethod(TClient client) { _retryCount++; _method.Invoke(client); }
public ClientsWindowController() { context = new SentinelDBEntities(); tClient = new TClient(context); tContacte = new TContacte(context); }
public override void OnProcess() { TClient.UpdateRoleSight(EntityInfo, SightOpt); }
public AfegirClientWindowController(SentinelDBEntities context) { tClient = new TClient(context); tContacte = new TContacte(context); }
public virtual TClient CreateCustomArmClient <TClient>(params object[] parameters) where TClient : Microsoft.Rest.ServiceClient <TClient> { List <Type> types = new List <Type>(); List <object> parameterList = new List <object>(); List <DelegatingHandler> handlerList = new List <DelegatingHandler> { DefaultCancelRetryHandler.Clone() as CancelRetryHandler }; if (parameters.FirstOrDefault(parameter => parameter is IClaimsChallengeProcessor) is IClaimsChallengeProcessor claimsChallengeProcessor) { handlerList.Add(new ClaimsChallengeHandler(claimsChallengeProcessor)); } var customHandlers = GetCustomHandlers(); if (customHandlers != null && customHandlers.Any()) { handlerList.AddRange(customHandlers); } bool hasHandlers = false; foreach (object obj in parameters) { var paramType = obj.GetType(); types.Add(paramType); if (paramType == typeof(DelegatingHandler[])) { handlerList.AddRange(obj as DelegatingHandler[]); parameterList.Add(handlerList.ToArray()); hasHandlers = true; } else { parameterList.Add(obj); } } if (!hasHandlers) { types.Add((new DelegatingHandler[0]).GetType()); parameterList.Add(handlerList.ToArray()); } var constructor = typeof(TClient).GetConstructor(types.ToArray()); if (constructor == null) { throw new InvalidOperationException(string.Format(Resources.InvalidManagementClientType, typeof(TClient).Name)); } TClient client = (TClient)constructor.Invoke(parameterList.ToArray()); foreach (ProductInfoHeaderValue userAgent in _userAgents.Keys) { client.UserAgent.Add(userAgent); } client.TrySetMaxTimesForRetryAfterHandler(); client.TrySetRetryCountofRetryPolicy(); return(client); }
public void RemoveConnectedService() { IMessagingSystemFactory aServiceMessaging = new TcpMessagingSystemFactory(); IMessagingSystemFactory aLocalMessaging = new SynchronousMessagingSystemFactory(); // Create services. TService aService1 = new TService(aServiceMessaging, "tcp://127.0.0.1:8097/"); TService aService2 = new TService(aServiceMessaging, "tcp://127.0.0.1:8098/"); // Create the backup router. IBackupConnectionRouterFactory aBackupRouterFactory = new BackupConnectionRouterFactory(aServiceMessaging); IBackupConnectionRouter aBackupRouter = aBackupRouterFactory.CreateBackupConnectionRouter(); List <RedirectEventArgs> aRedirections = new List <RedirectEventArgs>(); AutoResetEvent aFailedRedirectionsCompleted = new AutoResetEvent(false); int aFailedRedirections = 0; aBackupRouter.AllRedirectionsFailed += (x, y) => { ++aFailedRedirections; if (aFailedRedirections == 2) { aFailedRedirectionsCompleted.Set(); } }; aBackupRouter.AddReceivers(new string[] { "tcp://127.0.0.1:8097/", "tcp://127.0.0.1:8098/" }); IDuplexInputChannel aBackupRouterInputChannel = aLocalMessaging.CreateDuplexInputChannel("BackupRouter"); aBackupRouter.AttachDuplexInputChannel(aBackupRouterInputChannel); // Create clients connected to the backup router. TClient aClient1 = new TClient(aLocalMessaging, "BackupRouter"); TClient aClient2 = new TClient(aLocalMessaging, "BackupRouter"); try { // Start both services. aService1.myInputChannel.StartListening(); aService2.myInputChannel.StartListening(); // Connect client 1 and 2. aClient1.myOutputChannel.OpenConnection(); aClient2.myOutputChannel.OpenConnection(); Thread.Sleep(300); Assert.AreEqual(2, aService1.myConnectedClients.Count); // Remove service1 from available services. aBackupRouter.RemoveReceiver(aService1.myInputChannel.ChannelId); // Give some time to redirect clients to service 2. Thread.Sleep(1000); // Send the request message. - the router reopen the connection when the message is sent. aClient1.myOutputChannel.SendMessage("Hello from 1"); aClient1.myResponseMessageReceived.WaitOne(); aClient2.myOutputChannel.SendMessage("Hello from 2"); aClient2.myResponseMessageReceived.WaitOne(); Assert.AreEqual(2, aService2.myReceivedMessages.Count); Assert.AreEqual("Hello from 1", aService2.myReceivedMessages[0]); Assert.AreEqual("Hello from 2", aService2.myReceivedMessages[1]); Assert.AreEqual(1, aClient1.myReceivedResponses.Count); Assert.AreEqual(1, aClient2.myReceivedResponses.Count); Assert.AreEqual("Response for Hello from 1", aClient1.myReceivedResponses[0]); Assert.AreEqual("Response for Hello from 2", aClient2.myReceivedResponses[0]); } finally { aBackupRouter.RemoveAllReceivers(); aClient1.Dispose(); aClient2.Dispose(); aService1.Dispose(); aService2.Dispose(); } }
public void SendMessageReceiveResponse() { IMessagingSystemFactory aServiceMessaging = new TcpMessagingSystemFactory(); IMessagingSystemFactory aLocalMessaging = new SynchronousMessagingSystemFactory(); // Create services. TService aService1 = new TService(aServiceMessaging, "tcp://127.0.0.1:8097/"); TService aService2 = new TService(aServiceMessaging, "tcp://127.0.0.1:8098/"); // Create the backup router. IBackupConnectionRouterFactory aBackupRouterFactory = new BackupConnectionRouterFactory(aServiceMessaging); IBackupConnectionRouter aBackupRouter = aBackupRouterFactory.CreateBackupConnectionRouter(); List <RedirectEventArgs> aRedirections = new List <RedirectEventArgs>(); AutoResetEvent aRedirectionEvent = new AutoResetEvent(false); aBackupRouter.ConnectionRedirected += (x, y) => { lock (aRedirections) { aRedirections.Add(y); aRedirectionEvent.Set(); } }; aBackupRouter.AddReceivers(new string[] { "tcp://127.0.0.1:8097/", "tcp://127.0.0.1:8098/" }); Assert.AreEqual(2, aBackupRouter.AvailableReceivers.Count()); IDuplexInputChannel aBackupRouterInputChannel = aLocalMessaging.CreateDuplexInputChannel("BackupRouter"); aBackupRouter.AttachDuplexInputChannel(aBackupRouterInputChannel); // Create clients connected to the backup router. TClient aClient1 = new TClient(aLocalMessaging, "BackupRouter"); TClient aClient2 = new TClient(aLocalMessaging, "BackupRouter"); try { // Start both services. aService1.myInputChannel.StartListening(); aService2.myInputChannel.StartListening(); // Connect client 1. aClient1.myOutputChannel.OpenConnection(); Thread.Sleep(300); Assert.AreEqual(1, aService1.myConnectedClients.Count); // Disconnect client 1. aClient1.myOutputChannel.CloseConnection(); Thread.Sleep(300); Assert.AreEqual(0, aService1.myConnectedClients.Count); // Connect client 1 and 2. EneterTrace.Info("Client1 opens connection."); aClient1.myOutputChannel.OpenConnection(); EneterTrace.Info("Client2 opens connection."); aClient2.myOutputChannel.OpenConnection(); Thread.Sleep(300); Assert.AreEqual(2, aService1.myConnectedClients.Count); // Stop service 1. aService1.myInputChannel.StopListening(); aService1.myConnectedClients.Clear(); aRedirectionEvent.WaitOne(); aRedirectionEvent.WaitOne(); // Give some time until the service has connections. Thread.Sleep(500); Assert.AreEqual(2, aService2.myConnectedClients.Count); // Start service 1 again and stop Service 2. aService1.myInputChannel.StartListening(); aService2.myInputChannel.StopListening(); aService2.myConnectedClients.Clear(); aRedirectionEvent.WaitOne(); aRedirectionEvent.WaitOne(); // Give some time until the service has connections. Thread.Sleep(300); Assert.AreEqual(2, aService1.myConnectedClients.Count); aService2.myInputChannel.StartListening(); // Send the request message. aClient1.myOutputChannel.SendMessage("Hello from 1"); aClient1.myResponseMessageReceived.WaitOne(); aClient2.myOutputChannel.SendMessage("Hello from 2"); aClient2.myResponseMessageReceived.WaitOne(); Assert.AreEqual(2, aService1.myReceivedMessages.Count); Assert.AreEqual(0, aService2.myReceivedMessages.Count); Assert.AreEqual("Hello from 1", aService1.myReceivedMessages[0]); Assert.AreEqual("Hello from 2", aService1.myReceivedMessages[1]); Assert.AreEqual(1, aClient1.myReceivedResponses.Count); Assert.AreEqual(1, aClient2.myReceivedResponses.Count); Assert.AreEqual("Response for Hello from 1", aClient1.myReceivedResponses[0]); Assert.AreEqual("Response for Hello from 2", aClient2.myReceivedResponses[0]); } finally { aBackupRouter.RemoveAllReceivers(); aClient1.Dispose(); aClient2.Dispose(); aService1.Dispose(); aService2.Dispose(); } }
public override void OnProcess() { TClient.UpdateRoleList(new List <EntityInfo>(EntityInfoList)); }
public virtual ActionResult Excluir(int id) { var cliente = TClient.Load(id); return(PartialView("_excluir", cliente)); }
public virtual ActionResult ListarCliente(int id) { var cliente = TClient.Load(id); return(PartialView("_listar-cliente", cliente)); }
public override void OnProcess() { TClient.UpdateRole(RoleInfo, true); Console.WriteLine($"Res:{this.Res}"); }
public virtual ActionResult Excluir(int id, object diff) { TPreference.Delete(x => x.Client.Id == id); TClient.Delete(id); return(RedirectToAction("Index")); }
// (4) Send The Recieved Data to All Clients in The Room public static void OnRecievedData(IAsyncResult ar) { TClient client = (TClient)ar.AsyncState; byte[] aryRet = client.GetRecievedData(ar); if (aryRet.Length < 1) { client.ReadSocket.Close(); ClientsList.Remove(client); return; } else { Message msg = new Message(aryRet); if (msg.enumCommand == Command.Join) { if (msg.strRoom != null) { client.room = msg.strRoom; client.uname = msg.strName; Message userjoined = new Message(); userjoined.strName = msg.strName; userjoined.enumCommand = Command.Join; userjoined.strRoom = msg.strRoom; userjoined.strMessage = msg.strName + " has joined " + msg.strRoom; parent.Invoke(parent.multicast_msg_2room, userjoined); //notify all room users for new joining parent.Invoke(parent.sendroomlistdelobj, msg.strRoom); //send list of users to the newly joined usr //parent.Invoke(parent.usersynobj, client); } else { client.uname = msg.strName; //Message selroom = new Message(); //selroom.enumCommand = Command.Msg; //selroom.strMessage = "Connected.Please Select Room."; //selroom.strName = "Server"; //client.ReadSocket.Send(selroom.ToByte()); } } else if (msg.enumCommand == Command.Msg) { parent.Invoke(parent.multicast_msg_2room, msg); } else if (msg.enumCommand == Command.Draw) { parent.Invoke(parent.multicast_msg_2room, msg); } else if (msg.enumCommand == Command.Left) { if (client.room != null) { Message userleft = new Message(); userleft.enumCommand = Command.Left; userleft.strMessage = client.uname + " has left " + client.room; userleft.strRoom = client.room; parent.Invoke(parent.multicast_msg_2room, userleft); } string temproom = client.room; client.room = msg.strRoom; if (temproom != null) { parent.Invoke(parent.sendroomlistdelobj, temproom); } parent.Invoke(parent.sendroomlistdelobj, client.room); Message userjoin = new Message(); userjoin.enumCommand = Command.Join; userjoin.strMessage = client.uname + " has joined " + client.room; userjoin.strRoom = msg.strRoom; parent.Invoke(parent.multicast_msg_2room, userjoin); Message clearCmd = new Message(); clearCmd.enumCommand = Command.Draw; clearCmd.strMessage = Command.Clear.ToString() + "?"; clearCmd.strName = client.uname; client.ReadSocket.Send(clearCmd.ToByte()); } client.SetupRecieveCallback(); } }
public new TClient CreateCustomArmClient <TClient>(params object[] parameters) where TClient : ServiceClient <TClient> { TClient client = nextClient() as TClient; return(client); }
// (3) Maintaining Socket For Each Client private static void Add_Client(Socket sockClient) { Newclient = new TClient(sockClient); ClientsList.Add(Newclient); Newclient.SetupRecieveCallback(); }
internal IEnumerable donemClients() { TClient tClient = new TClient(context); return(tClient.getAll()); }