public App() { InitializeComponent(); Container.Services.AddSingleton <IProvider <HttpClientHandler>, HttpClientHandlerProvider>(); Container.Services.AddSingleton <IProvider <HttpClient>, HttpClientProvider>(); Container.Services.AddSingleton <IAuthenticatingMessageInspector, AuthenticatingMessageInspector>(); Container.Services.AddSingleton <ITokenService, TokenService>(serviceProvider => new TokenService("https://cas.dev.optoplus.cloud:8543/cas/v1/tickets", "services.dev.optoplus.cloud/optoplus-services-web")); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <CredentialSoap, CredentialSoapClient>(serviceProvider, new EndpointAddress("https://services.dev.optoplus.cloud:8443/optoplus-services-web/CredentialSoap"))); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <GroupSoap, GroupSoapClient>(serviceProvider, new EndpointAddress("https://services.dev.optoplus.cloud:8443/optoplus-services-web/GroupSoap"))); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <ProductSoap, ProductSoapClient>(serviceProvider, new EndpointAddress("https://services.dev.optoplus.cloud:8443/optoplus-services-web/ProductSoap"))); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <PersonSoap, PersonSoapClient>(serviceProvider, new EndpointAddress("https://services.dev.optoplus.cloud:8443/optoplus-services-web/PersonSoap"))); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <ComputeSoap, ComputeSoapClient>(serviceProvider, new EndpointAddress("https://services.dev.optoplus.cloud:8443/optoplus-services-web/ComputeSoap"))); Container.Services.AddSingleton <MainModel>(); Container.Services.AddSingleton <MenuModel>(); Container.Services.AddSingleton <LoginModel>(); Container.Services.AddSingleton <LensPreviewModel>(); Container.Services.AddSingleton <ITranslateService, TranslateService>(); Container.Services.AddSingleton <EntityTemplate <object>, IdentifiableTemplate>(); MainPage = new MainPage(); }
private ComputeSoap ProviderComputeSoap() { IAuthenticatingMessageInspector authenticatingMessageInspector = new AuthenticatingMessageInspector { HttpRequestMessageProperty = new HttpRequestMessageProperty() }; authenticatingMessageInspector.HttpRequestMessageProperty.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + LoginManager.RefreshServiceTicket()); authenticatingMessageInspector.HttpRequestMessageProperty.Headers.Set("X-Grant", LoginManager.XGrant); LoggingMessageInspector loggingMessageInspector = new LoggingMessageInspector(); ICallbackMessageInspector callbackMessageInspector = new CallbackMessageInspector(); callbackMessageInspector.RequestCallbacks.Add(message => Logger.LogEvent("REQUEST " + message)); callbackMessageInspector.ResponseCallbacks.Add(message => Logger.LogEvent("RESPONSE")); ICollection <IClientMessageInspector> inspectors = new Collection <IClientMessageInspector>() { authenticatingMessageInspector, loggingMessageInspector, callbackMessageInspector }; ICollection <Action <HttpWebResponse> > handlers = new Collection <Action <HttpWebResponse> >() { HttpWebReponseHandler }; ICollection <Action <FaultException> > faultHandlers = new Collection <Action <FaultException> >() { FaultHandler }; ICollection <Action <Exception> > exceptionHandlers = new Collection <Action <Exception> >() { ExceptionHandler }; return(ClientBaseUtils.InitClientBase <ComputeSoap, ComputeSoapClient>(new EndpointAddress(configuration.AppSettings.Settings[OPTOPLUS_API_ENDPOINT].Value + "/optoplus-services-web/ComputeSoap"), inspectors, handlers, faultHandlers, exceptionHandlers)); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Container.Services.AddSingleton <IProvider <HttpClientHandler>, HttpClientHandlerProvider>(); Container.Services.AddSingleton <IProvider <HttpClient>, HttpClientProvider>(); Container.Services.AddSingleton <IAuthenticatingMessageInspector, AuthenticatingMessageInspector>(); Container.Services.AddSingleton <ITokenService, TokenService>(serviceProvider => new TokenService("http://cas.int.optoplus.cloud/cas/v1/tickets", "services.int.optoplus.cloud/optoplus-services-web")); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <CredentialSoap, CredentialSoapClient>(serviceProvider, new EndpointAddress("http://services.int.optoplus.cloud/optoplus-services-web/CredentialSoap"), BasicHttpSecurityMode.None, HttpClientCredentialType.Basic)); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <GroupSoap, GroupSoapClient>(serviceProvider, new EndpointAddress("http://services.int.optoplus.cloud/optoplus-services-web/GroupSoap"), BasicHttpSecurityMode.None, HttpClientCredentialType.Basic)); Container.Services.AddSingleton(serviceProvider => ClientBaseUtils.InitClientBase <ComputeSoap, ComputeSoapClient>(serviceProvider, new EndpointAddress("http://services.int.optoplus.cloud/optoplus-services-web/ComputeSoap"), BasicHttpSecurityMode.None, HttpClientCredentialType.Basic)); Container.Services.AddSingleton <MainModel>(); Container.Services.AddSingleton <LoginModel>(); Container.Services.AddSingleton <ViewModel>(); }
protected override void OnStart(string[] args) { if (args.Length >= 2) { CredentialManager.SaveCredentials(ServiceName, new NetworkCredential(args[0], args[1])); Logger.LogEvent("Credential changed to " + args[0], eventType: EventTypes.Configuration); RecursiveSave(args.Skip(2), new List <string>() { CAS_API_ENDPOINT, OPTOPLUS_API_ENDPOINT, INPUT_PATH, OUTPUT_PATH, PROCESSED_PATH, ERROR_PATH, SURFACE_PATH, ANALYSIS_PATH, OUTPUT_FORMAT, GAX, LAPGAX }); } string defaultPath = Path.Combine(Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)), ServiceName); string defaultFallbackPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ServiceName); string chosenDefaultPath = null; string[] attemptedPaths = { defaultPath, defaultFallbackPath }; foreach (string attemptedPath in attemptedPaths) { try { Directory.CreateDirectory(attemptedPath); chosenDefaultPath = attemptedPath; break; } catch (Exception e) { Logger.LogEvent("Unable to use " + attemptedPath + " as default directory" + Environment.NewLine + e.StackTrace, EventLogEntryType.Warning); } } new List <string>() { INPUT_PATH, OUTPUT_PATH, PROCESSED_PATH, ERROR_PATH, SURFACE_PATH, ANALYSIS_PATH }.FindAll(key => configuration.AppSettings.Settings[key] is null || string.IsNullOrWhiteSpace(configuration.AppSettings.Settings[key].Value)).ForEach( key => { if (chosenDefaultPath != null) { SaveSetting(key, Path.Combine(chosenDefaultPath, key)); } else { string error = key + ": unable to find a writable default path. Please check the previous Application warnings emitted by " + ServiceName + " or manually specify a writable path for " + key; Logger.LogEvent(error, EventLogEntryType.Warning); throw new Exception(error); } } ); new List <string>() { INPUT_PATH, OUTPUT_PATH, PROCESSED_PATH, ERROR_PATH, SURFACE_PATH, ANALYSIS_PATH }.ForEach(key => Directory.CreateDirectory(configuration.AppSettings.Settings[key].Value)); if (configuration.AppSettings.Settings[OUTPUT_FORMAT] is null) { SaveSetting(OUTPUT_FORMAT, OutputFormat.sdf.ToString()); } Logger.LogEvent(configuration.AppSettings.Settings.AllKeys.Select(key => key + " " + configuration.AppSettings.Settings[key].Value).Aggregate((v1, v2) => string.Join(Environment.NewLine, new List <string> { v1, v2 }))); NetworkCredential NetworkCredential = CredentialManager.GetCredentials(ServiceName); if (!new List <string>() { CAS_API_ENDPOINT, OPTOPLUS_API_ENDPOINT }.All(key => configuration.AppSettings.Settings.AllKeys.Contains(key)) || NetworkCredential is null) { Environment.FailFast("Missing Parameter"); } SDFWriter = new SDFWriter(configuration.AppSettings.Settings[SURFACE_PATH].Value); HMFWriter = new HMFWriter(configuration.AppSettings.Settings[SURFACE_PATH].Value); XYZWriter = new XYZWriter(configuration.AppSettings.Settings[SURFACE_PATH].Value); OmaWriter = new OmaWriter(configuration.AppSettings.Settings[OUTPUT_PATH].Value, configuration.AppSettings.Settings[GAX].Value, configuration.AppSettings.Settings[LAPGAX].Value); AnalysisWriter = new AnalysisWriter(configuration.AppSettings.Settings[ANALYSIS_PATH].Value); IAuthenticatingMessageInspector authenticatingMessageInspector = new AuthenticatingMessageInspector { HttpRequestMessageProperty = new HttpRequestMessageProperty() }; LoggingMessageInspector loggingMessageInspector = new LoggingMessageInspector(); ICallbackMessageInspector callbackMessageInspector = new CallbackMessageInspector(); callbackMessageInspector.RequestCallbacks.Add(message => Logger.LogEvent("REQUEST " + message)); callbackMessageInspector.ResponseCallbacks.Add(message => Logger.LogEvent("RESPONSE")); ICollection <IClientMessageInspector> inspectors = new Collection <IClientMessageInspector>() { authenticatingMessageInspector, loggingMessageInspector, callbackMessageInspector }; ICollection <Action <HttpWebResponse> > handlers = new Collection <Action <HttpWebResponse> >() { HttpWebReponseHandler }; ICollection <Action <FaultException> > faultHandlers = new Collection <Action <FaultException> >() { FaultHandler }; ICollection <Action <Exception> > exceptionHandlers = new Collection <Action <Exception> >() { ExceptionHandler }; IProvider <HttpClientHandler> HttpClientHandlerProvider = new HttpClientHandlerProvider(); IProvider <HttpClient> HttpClientProvider = new HttpClientProvider(HttpClientHandlerProvider); IAuthenticationService authenticationService = new AuthenticationService(new Uri(new Uri(configuration.AppSettings.Settings[CAS_API_ENDPOINT].Value), "cas/v1/tickets/"), "optoplus", HttpClientProvider); CredentialSoap credentialSoap = ClientBaseUtils.InitClientBase <CredentialSoap, CredentialSoapClient>(new EndpointAddress(configuration.AppSettings.Settings[OPTOPLUS_API_ENDPOINT].Value + "/optoplus-services-web/CredentialSoap"), inspectors, handlers, faultHandlers, exceptionHandlers); CredentialGroupingSoap credentialGroupingSoap = ClientBaseUtils.InitClientBase <CredentialGroupingSoap, CredentialGroupingSoapClient>(new EndpointAddress(configuration.AppSettings.Settings[OPTOPLUS_API_ENDPOINT].Value + "/optoplus-services-web/CredentialGroupingSoap"), inspectors, handlers, faultHandlers, exceptionHandlers); LogoutSoap logoutSoap = ClientBaseUtils.InitClientBase <LogoutSoap, LogoutSoapClient>(new EndpointAddress(configuration.AppSettings.Settings[OPTOPLUS_API_ENDPOINT].Value + "/optoplus-services-web/LogoutSoap"), inspectors, handlers, faultHandlers, exceptionHandlers); SharedServiceProvider.Reset(); SharedServiceProvider.Services.Clear(); SharedServiceProvider.Services.AddSingleton(serviceProvider => HttpClientHandlerProvider); SharedServiceProvider.Services.AddSingleton(serviceProvider => HttpClientProvider); SharedServiceProvider.Services.AddSingleton(serviceProvider => authenticatingMessageInspector); SharedServiceProvider.Services.AddSingleton(serviceProvider => loggingMessageInspector); SharedServiceProvider.Services.AddSingleton(serviceProvider => callbackMessageInspector); SharedServiceProvider.Services.AddSingleton(serviceProvider => authenticationService); SharedServiceProvider.Services.AddSingleton(serviceProvider => credentialSoap); SharedServiceProvider.Services.AddSingleton(serviceProvider => credentialGroupingSoap); SharedServiceProvider.Services.AddSingleton(serviceProvider => logoutSoap); RequestBuilder = new RequestBuilder(ProviderComputeSoap); Watcher = new FileSystemWatcher(configuration.AppSettings.Settings[INPUT_PATH].Value, "*" + LdsFileExtension); Watcher.Created += Watcher_Created; Watcher.Renamed += Watcher_Renamed; LoginManager = new LoginManager(Logger, ServiceName, authenticationService, authenticatingMessageInspector, credentialSoap, credentialGroupingSoap); LoginManager.Login(10000, LoggedIn); }