private void RegisterServices() { var endpoint = loginSettings.Endpoint; var serverUserService = new UserService(endpoint); Guid sessionId; using (var channelManager = serverUserService.CreateChannelManager()) using (var channel = channelManager.CreateChannel()) { var currentUser = channel.Service.UserLogin(loginSettings.User, loginSettings.Password).Result as Administrator; sessionId = currentUser.SessionId; Container.RegisterInstance(currentUser); } Container.RegisterInstance(serverUserService); Container.RegisterType<ChannelManager<IServerTcpService>> (new InjectionFactory(c => serverUserService.CreateChannelManager(sessionId))); var serverService = new ServerService(endpoint); Container.RegisterInstance(serverService); Container.RegisterType<ChannelManager<IServerTcpService>> (new InjectionFactory(c => serverService.CreateChannelManager(sessionId))); var queuePlanService = new QueuePlanService(endpoint); Container.RegisterInstance(queuePlanService); Container.RegisterType<DuplexChannelManager<IQueuePlanTcpService>> (new InjectionFactory(c => queuePlanService.CreateChannelManager(sessionId))); var templateService = new TemplateService(endpoint); Container.RegisterInstance(templateService); Container.RegisterType<ChannelManager<ITemplateTcpService>> (new InjectionFactory(c => templateService.CreateChannelManager(sessionId))); var theme = string.IsNullOrEmpty(portalSettings.Theme) ? Templates.Themes.Default : portalSettings.Theme; var templateManager = new TemplateManager(Templates.Apps.Common, theme); Container.RegisterInstance<ITemplateManager>(templateManager); }
public async void Connect() { bool connected = false; try { if (string.IsNullOrWhiteSpace(Settings.Endpoint)) { throw new QueueException("Не указан адрес сервера"); } using (var userService = new UserService(Settings.Endpoint)) using (var channelManager = userService.CreateChannelManager()) using (var channel = channelManager.CreateChannel()) { connectButton.Enabled = false; userControl.Initialize(await channel.Service.GetUserLinks(UserRole)); if (Settings.User != Guid.Empty) { userControl.Select<User>(new User() { Id = Settings.User }); } passwordTextBox.Focus(); connected = true; connectionGroupBox.Enabled = false; loginGroupBox.Enabled = true; } } catch (OperationCanceledException) { } catch (CommunicationObjectAbortedException) { } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } catch (FaultException ex) { UIHelper.Warning(ex.Reason.ToString()); } catch (Exception ex) { UIHelper.Warning(ex.Message); } finally { connectButton.Enabled = true; } if (connected) { OnConnected(this, null); } }
private async void officeGridView_CellClick(object sender, DataGridViewCellEventArgs eventArgs) { int rowIndex = eventArgs.RowIndex, columnIndex = eventArgs.ColumnIndex; if (rowIndex >= 0 && columnIndex >= 0) { var row = officesGridView.Rows[rowIndex]; var cell = row.Cells[columnIndex]; var office = row.Tag as Office; switch (cell.OwningColumn.Name) { case LoginColumn: using (var f = new OfficeLoginForm(office.Id)) { if (f.ShowDialog() == DialogResult.OK) { office.Endpoint = f.Settings.Endpoint; office.SessionId = f.SessionId; using (var channel = ChannelManager.CreateChannel()) { try { office = await taskPool.AddTask(channel.Service.EditOffice(office)); UIHelper.Information("Вход успешно выполнен. Управление доступно."); } catch (OperationCanceledException) { } catch (CommunicationObjectAbortedException) { } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } catch (FaultException exception) { UIHelper.Warning(exception.Reason.ToString()); } catch (Exception exception) { UIHelper.Warning(exception.Message); } } } } break; case ManageColumn: if (office.SessionId != Guid.Empty) { var officeServerUserService = new UserService(office.Endpoint); using (var officeChannelManager = officeServerUserService.CreateChannelManager()) using (var officeChannel = officeChannelManager.CreateChannel()) { try { var administrator = await taskPool.AddTask(officeChannel.Service.OpenUserSession(office.SessionId)); Process.Start(new ProcessStartInfo() { UseShellExecute = true, FileName = "Queue.Administrator.exe", Arguments = string.Format("--AutoLogin --Endpoint=\"{0}\" --SessionId={1}", office.Endpoint, administrator.SessionId), WorkingDirectory = Environment.CurrentDirectory }); } catch (OperationCanceledException) { } catch (CommunicationObjectAbortedException) { } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } catch (FaultException exception) { UIHelper.Warning(exception.Reason.ToString()); } catch (Exception exception) { UIHelper.Warning(exception.Message); } } } else { UIHelper.Warning("Вход не выполнен"); } break; } } }
public async void Connect() { serverUserService = new UserService(Endpoint); channelManager = serverUserService.CreateChannelManager(); var result = await Window.ExecuteLongTask(async () => { using (var channel = channelManager.CreateChannel()) { return await channel.Service.GetUserLinks(userRole); } }); if (result == null) { return; } Users = result.Select(u => new UserComboBoxItem(u.Id, u.ToString())).ToArray(); if (AppSettings.User != Guid.Empty) { SelectedUser = Users.SingleOrDefault(u => u.Id == AppSettings.User); } if (SelectedUser == null) { SelectedUser = Users.First(); } IsConnected = true; if (IsConnected && IsRemember) { Login(); } }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); container = new UnityContainer(); container.RegisterInstance(container); ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(container)); configuration = new ConfigurationManager(Product.Operator.AppName, SpecialFolder.ApplicationData); container.RegisterInstance(configuration); loginSettings = configuration.GetSection<LoginSettings>(LoginSettings.SectionKey); container.RegisterInstance(loginSettings); loginFormSettings = configuration.GetSection<LoginFormSettings>(LoginFormSettings.SectionKey); container.RegisterInstance(loginFormSettings); hubSettings = configuration.GetSection<HubSettings>(HubSettings.SectionKey); container.RegisterInstance(hubSettings); ParseOptions(); if (options.AutoLogin) { endpoint = options.Endpoint; try { using (var serverUserService = new UserService(endpoint)) using (var channelManager = serverUserService.CreateChannelManager()) using (var channel = channelManager.CreateChannel()) { sessionId = Guid.Parse(options.SessionId); currentUser = channel.Service.OpenUserSession(sessionId).Result as QueueOperator; } } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message); return; } container.RegisterInstance<User>(currentUser); container.RegisterInstance<QueueOperator>(currentUser); RegisterServices(); Application.Run(new OperatorForm()); } else { while (true) { var loginForm = new LoginForm(UserRole.Operator); if (loginForm.ShowDialog() == DialogResult.OK) { configuration.Save(); endpoint = loginSettings.Endpoint; currentUser = loginForm.CurrentUser as QueueOperator; sessionId = currentUser.SessionId; container.RegisterInstance<User>(currentUser); container.RegisterInstance<QueueOperator>(currentUser); RegisterServices(); loginForm.Dispose(); using (var f = new OperatorForm()) { Application.Run(f); if (f.IsLogout) { ResetSettings(); continue; } } } break; } } }
private static void RegisterServices() { qualityService = new QualityService(hubSettings.Endpoint); container.RegisterInstance(qualityService); container.RegisterType<DuplexChannelManager<IQualityTcpService>> (new InjectionFactory(c => qualityService.CreateChannelManager())); serverService = new ServerService(endpoint); container.RegisterInstance(serverService); container.RegisterType<ChannelManager<IServerTcpService>> (new InjectionFactory(c => serverService.CreateChannelManager(sessionId))); userService = new UserService(endpoint); container.RegisterInstance(userService); container.RegisterType<ChannelManager<IUserTcpService>> (new InjectionFactory(c => userService.CreateChannelManager(sessionId))); queuePlanService = new QueuePlanService(endpoint); container.RegisterInstance(queuePlanService); container.RegisterType<DuplexChannelManager<IQueuePlanTcpService>> (new InjectionFactory(c => queuePlanService.CreateChannelManager(sessionId))); }
private static void RegisterServices() { serverService = new ServerService(endpoint); container.RegisterInstance(serverService); container.RegisterType<ChannelManager<IServerTcpService>> (new InjectionFactory(c => serverService.CreateChannelManager(sessionId))); userService = new UserService(endpoint); container.RegisterInstance(userService); container.RegisterType<ChannelManager<IUserTcpService>> (new InjectionFactory(c => userService.CreateChannelManager(sessionId))); templateService = new TemplateService(endpoint); container.RegisterInstance(templateService); container.RegisterType<ChannelManager<ITemplateTcpService>> (new InjectionFactory(c => templateService.CreateChannelManager(sessionId))); workplaceService = new WorkplaceService(endpoint); container.RegisterInstance(workplaceService); container.RegisterType<ChannelManager<IWorkplaceTcpService>> (new InjectionFactory(c => workplaceService.CreateChannelManager(sessionId))); queuePlanService = new QueuePlanService(endpoint); container.RegisterInstance(queuePlanService); container.RegisterType<DuplexChannelManager<IQueuePlanTcpService>> (new InjectionFactory(c => queuePlanService.CreateChannelManager(sessionId))); lifeSituationService = new LifeSituationService(endpoint); container.RegisterInstance(lifeSituationService); container.RegisterType<ChannelManager<ILifeSituationTcpService>> (new InjectionFactory(c => lifeSituationService.CreateChannelManager(sessionId))); var theme = string.IsNullOrEmpty(administratorSettings.Theme) ? Templates.Themes.Default : administratorSettings.Theme; templateManager = new TemplateManager(Templates.Apps.Common, theme); container.RegisterInstance<ITemplateManager>(templateManager); }
private async void Login() { if (serverUserService != null) { serverUserService.Dispose(); } serverUserService = new UserService(LoginSettings.Endpoint); if (channelManager != null) { channelManager.Dispose(); } channelManager = serverUserService.CreateChannelManager(); using (var channel = channelManager.CreateChannel()) { try { loginButton.Enabled = false; CurrentUser = await taskPool.AddTask(channel.Service.UserLogin(LoginSettings.User, LoginSettings.Password)); if (!LoginFormSettings.IsRemember) { LoginSettings.Password = string.Empty; } ApplicationSettings.Language = languageControl.Selected<Language>(); DialogResult = DialogResult.OK; } catch (OperationCanceledException) { } catch (CommunicationObjectAbortedException) { } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } catch (FaultException ex) { UIHelper.Warning(ex.Reason.ToString()); } catch (Exception ex) { UIHelper.Warning(ex.Message); } finally { loginButton.Enabled = true; } } }
private async void loginButton_Click(object sender, EventArgs e) { using (var serverUserService = new UserService(Settings.Endpoint)) using (var channelManager = serverUserService.CreateChannelManager()) using (var channel = channelManager.CreateChannel()) { try { loginButton.Enabled = false; var user = await taskPool.AddTask(channel.Service.UserLogin(Settings.User, Settings.Password)); SessionId = user.SessionId; DialogResult = DialogResult.OK; } catch (OperationCanceledException) { } catch (CommunicationObjectAbortedException) { } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } catch (FaultException exception) { UIHelper.Warning(exception.Reason.ToString()); } catch (Exception exception) { UIHelper.Warning(exception.Message); } finally { loginButton.Enabled = true; } } }