Exemple #1
0
		private HttpServerError StartServer()
		{
			try
			{
				_httpServer = new HttpServer(10);
				_httpServer.ProcessRequest += httpServer_ProcessRequest;
				_cacheSettings = new CacheSettings();
				_httpServer.Start("http://+:" + _port + "/TWAIN@Web/");
			}
			catch (Exception ex)
			{
				_logger.ErrorFormat("Code: {0}, Text: {1}", ((System.Net.HttpListenerException)ex).ErrorCode, ex);
				return new HttpServerError { Code = ((System.Net.HttpListenerException)ex).ErrorCode, Text = ex.ToString() };
			}

			try
			{
				var fwHelper = new FierwallHelper();
				fwHelper.AddRuleForPort(_port);
			}
			catch (Exception e)
			{
				return new HttpServerError { Code = 0, Text = e.ToString() }; 
			}
			return null;
		}
		public ActionResult GetScannerParameters(IScannerManager scannerManager, CacheSettings cashSettings, int? sourceIndex)
		{
			var queryResult = new GetScannerParametersQuery(scannerManager, cashSettings, sourceIndex).Execute(_markerAsync);
			
			if (queryResult.Validate())
				return new ActionResult{Content = Encoding.UTF8.GetBytes(queryResult.Serialize()), ContentType = "text/json"};

			throw new Exception(queryResult.Error);
		}
		public GetScannerParametersQuery(IScannerManager scannerManager, CacheSettings cacheSettings, int? sourceIndex)
		{
			if (scannerManager == null) throw new Exception("Невозможно получить параметры сканирования, т.к. менеджер источников данных не был инициализирован");

			_scannerManager = scannerManager;
			_cacheSettings = cacheSettings;
			_sourceIndex = sourceIndex;

			_logger = LogManager.GetLogger(typeof(GetScannerParametersQuery));
		}