public object GetValue(IBuilderContext context)
            {
                WorkItem workItem = (WorkItem)context.Locator.Get(new DependencyResolutionLocatorKey(typeof(WorkItem), null));

                IChannelFactoryService channelFactory = workItem.Services.Get <IChannelFactoryService>(ensureExists);

                return(channelFactory.CreateChannel(serviceType));
            }
예제 #2
0
        public static string LoadClientConfig(IChannelFactoryService channelFactoryService)
        {
            string configFileName = null;

            FileService fileService = new FileService();

            fileService.SettingsService = channelFactoryService.CreateChannel(typeof(ISettingsService)) as ISettingsService;

            if (fileService.SettingsService != null)
            {
                string configFileText = fileService.GetFile("client.config");
                configFileName = CreateTempFile(configFileText);
            }

            return(configFileName);
        }
        private void LoginThread(object state)
        {
            IChannelFactoryService channelFactoryService = null;
            string    error     = null;
            Exception exception = null;

            try
            {
                channelFactoryService             = ServiceActivator.CreateInstance <IChannelFactoryService>(UserSessionService, TokenCache);
                UserSessionService.ConfigFilename = ConfigHelper.LoadClientConfig(channelFactoryService);
            }
            catch (SecurityNegotiationException ex)
            {
                exception = ex;
                error     = StringResources.Login_InvalidCredentials;
                TokenCache.Flush();
            }
            catch (MessageSecurityException ex)
            {
                exception = ex;
                error     = StringResources.Login_InvalidCredentials;
                TokenCache.Flush();
            }
            catch (Exception ex)
            {
                exception = ex;
                error     = ex.ToString();
                TokenCache.Flush();
            }
            finally
            {
                channelFactoryService.Dispose();
            }

            if (exception != null)
            {
                try
                {
                    EventLog.WriteEntry(StringResources.Title, string.Format("{0} - {1}", StringResources.Login_Login, exception.ToString()), EventLogEntryType.Warning);
                }
                catch
                {
                }
            }

            System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <string>(LoginCompleted), error);
        }
예제 #4
0
        protected override void AddServices()
        {
            base.AddServices();

            RootWorkItem.Services.Add <IUserSessionService>(_userSessionService);

            if (_userSessionService.ActivationUri != null)
            {
                ShellHyperlink hyperlink = HyperlinkService.ConvertToShellHyperlink(_userSessionService.ActivationUri);

                if (hyperlink.Data.ContainsKey("ModuleId"))
                {
                    //Add shellhyperlink to workitem to prevent dialogs being lodad before the module is fully loaded. See NavigationBarView.xaml.cs function NavigationBarSelectionChangedEventHandler
                    //Hyperlink is removed from workitem in HyperlinkService.cs function ExecuteHyperlink(ShellHyperlink hyperlink)
                    RootWorkItem.Items.Add(hyperlink);
                }
            }

            if (string.IsNullOrEmpty(_userSessionService.DomainUser))
            {
                _userSessionService.UserId = string.Format("{0}\\{1}", Environment.UserDomainName, Environment.UserName);
            }
            else
            {
                _userSessionService.Password = _password;
            }

            RootWorkItem.Items.Add(_tokenCache);

            IChannelFactoryService factoryService = ServiceActivator.CreateInstance <IChannelFactoryService>(_userSessionService, _tokenCache);

            RootWorkItem.Services.Add <IChannelFactoryService>(factoryService);

            IAuthorizationService authorizationService = ServiceActivator.CreateInstance <IAuthorizationService>();

            RootWorkItem.Services.Add <IAuthorizationService>(authorizationService);

            IFavoritesService favoritesService = RootWorkItem.Services.AddNew <FavoritesService, IFavoritesService>();

            RootWorkItem.Services.AddNew <ShellModuleService, IShellModuleService>();
            RootWorkItem.Services.AddNew <FileService, IFileService>();

            _settingsService = ServiceActivator.CreateInstance <IUXSettingsService>(ContainerName);
            RootWorkItem.Services.Add <IUXSettingsService>(_settingsService);

            RootWorkItem.Services.AddNew <HyperlinkService, IHyperlinkService>();

            ThreadPool.QueueUserWorkItem((e) =>
            {
                try
                {
                    _settingsService.LoadSettings();
                    favoritesService.LoadFavorites();
                }
                catch (Exception)
                {
                }

                _settingsLoadedEvent.Set();
            });
        }