/// <summary> /// Creates a new instance of the VRP REST service client. /// </summary> /// <param name="settings">Solver settngs information.</param> /// <param name="servers">Available servers.</param> /// <param name="solveServiceValidator">Solver service validator.</param> /// <returns>Discovery service.</returns> public IDiscoveryService CreateService(SolveInfoWrap settings, ICollection <AgsServer> servers, ISolveServiceValidator solveServiceValidator) { Debug.Assert(settings != null); Debug.Assert(servers != null); Debug.Assert(solveServiceValidator != null); var serviceInfo = settings.DiscoveryService; if (serviceInfo == null) { // Creates discovery service stub to do nothing. return(new DiscoveryServiceStub()); } else { try { // Creates full discovery service. return(new DiscoveryService(serviceInfo, servers, solveServiceValidator)); } // If we couldn't connect to service - return stub. catch (InvalidOperationException ex) { Logger.Error(ex); return(new DiscoveryServiceStub()); } } }
/// <summary> /// Creates a new instance of the VRP REST service client. /// </summary> /// <param name="settings">Solver settngs information.</param> /// <param name="servers">Available servers.</param> /// <param name="solveServiceValidator">Solver service validator.</param> /// <returns>Discovery service.</returns> public IDiscoveryService CreateService(SolveInfoWrap settings, ICollection<AgsServer> servers, ISolveServiceValidator solveServiceValidator) { Debug.Assert(settings != null); Debug.Assert(servers != null); Debug.Assert(solveServiceValidator != null); var serviceInfo = settings.DiscoveryService; if (serviceInfo == null) { // Creates discovery service stub to do nothing. return new DiscoveryServiceStub(); } else { try { // Creates full discovery service. return new DiscoveryService(serviceInfo, servers, solveServiceValidator); } // If we couldn't connect to service - return stub. catch (InvalidOperationException ex) { Logger.Error(ex); return new DiscoveryServiceStub(); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="serviceSettings">Discovery service settings.</param> /// <param name="servers">Available arcgis-servers.</param> /// <param name="solveServiceValidator">Services validator.</param> public DiscoveryService(DiscoveryServiceInfo serviceSettings, ICollection <AgsServer> servers, ISolveServiceValidator solveServiceValidator) { Debug.Assert(serviceSettings != null); Debug.Assert(servers != null); Debug.Assert(solveServiceValidator != null); // Validate services config. solveServiceValidator.Validate(serviceSettings); _discoveryServiceConfig = serviceSettings; _server = ServiceHelper.FindServerByName(serviceSettings.ServerName, servers); // Initialize service if server was found successfully. if (_server != null) { Initialize(); } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes solver. /// </summary> /// <param name="settings">Current solve settings.</param> /// <param name="servers">Collection of ags servers.</param> /// <param name="solveServiceValidator">Object to perform service validation.</param> /// <param name="options">Options influencing services used by the application.</param> internal VrpSolver( SolveInfoWrap settings, ICollection <AgsServer> servers, ISolveServiceValidator solveServiceValidator, ServiceOptions options) { _solveServiceValidator = solveServiceValidator; _options = options; // init phase 1: set/validate configuration _InitSettings(settings, servers, _options); // Create discovery service. var factory = new DiscoveryServiceFactory(); _discoveryService = factory.CreateService(settings, servers, solveServiceValidator); // init phase 2: create services try { // check servers state ServiceHelper.ValidateServerState(_vrpServer); ServiceHelper.ValidateServerState(_routeServer); _discoveryService.ValidateServerState(); } catch (Exception e) { // do not fail here, will try to re-initialize later Logger.Error(e); } // attach events _asyncMgr.AsyncSolveCompleted += new AsyncSolveCompletedEventHandler( _asyncMgr_AsyncSolveCompleted); }