public ExistVocabulary ( String vocabularyIRI ) : void | ||
vocabularyIRI | String | |
Résultat | void |
public OperatingSystemDatasourceParser(Stream stream, VocabularyHolder vocabularyHolder) { Init(stream); try { vocabularyHolder.ExistVocabulary(ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI); this.vocabularyHolder = vocabularyHolder; } catch (Exception ex) { this.vocabularyHolder = null; } }
/// <summary> /// Initialize method. /// </summary> /// <param name="defaultVocabularyIRI"></param> /// <param name="prprts"></param> public void Initialize(string defaultVocabularyIRI, Properties prprts) { if (defaultVocabularyIRI == null || defaultVocabularyIRI.Trim().Length == 0) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new NullReferenceException("defaultVocabularyIRI can not be null")); } /*Initializing VocabularyHolder*/ ODDRVocabularyService oddrVocabularyService = new ODDRVocabularyService(); oddrVocabularyService.Initialize(prprts); vocabularyHolder = oddrVocabularyService.vocabularyHolder; vocabularyHolder.ExistVocabulary(defaultVocabularyIRI); String oddrUaDeviceBuilderPath = prprts.GetProperty(ODDR_UA_DEVICE_BUILDER_PATH_PROP); String oddrUaDeviceDatasourcePath = prprts.GetProperty(ODDR_UA_DEVICE_DATASOURCE_PATH_PROP); String oddrUaDeviceBuilderPatchPaths = prprts.GetProperty(ODDR_UA_DEVICE_BUILDER_PATCH_PATHS_PROP); String oddrUaDeviceDatasourcePatchPaths = prprts.GetProperty(ODDR_UA_DEVICE_DATASOURCE_PATCH_PATHS_PROP); String oddrUaBrowserDatasourcePaths = prprts.GetProperty(ODDR_UA_BROWSER_DATASOURCE_PATH_PROP); String oddrUaOperatingSystemDatasourcePaths = prprts.GetProperty(ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP); Stream oddrUaDeviceBuilderStream = null; Stream oddrUaDeviceDatasourceStream = null; Stream[] oddrUaDeviceBuilderPatchStreams = null; Stream[] oddrUaDeviceDatasourcePatchStreams = null; Stream oddrUaBrowserDatasourceStream = null; Stream oddrUaOperatingSystemDatasourceStream = null; try { oddrUaDeviceBuilderStream = (Stream)prprts.Get(ODDR_UA_DEVICE_BUILDER_STREAM_PROP); } catch (Exception ex) { oddrUaDeviceBuilderStream = null; } try { oddrUaDeviceDatasourceStream = (Stream)prprts.Get(ODDR_UA_DEVICE_DATASOURCE_STREAM_PROP); } catch (Exception ex) { oddrUaDeviceDatasourceStream = null; } try { oddrUaDeviceBuilderPatchStreams = (Stream[])prprts.Get(ODDR_UA_DEVICE_BUILDER_PATCH_STREAMS_PROP); } catch (Exception ex) { oddrUaDeviceBuilderPatchStreams = null; } try { oddrUaDeviceDatasourcePatchStreams = (Stream[])prprts.Get(ODDR_UA_DEVICE_DATASOURCE_PATCH_STREAMS_PROP); } catch (Exception ex) { oddrUaDeviceDatasourcePatchStreams = null; } try { oddrUaBrowserDatasourceStream = (Stream)prprts.Get(ODDR_UA_BROWSER_DATASOURCE_STREAM_PROP); } catch (Exception ex) { oddrUaBrowserDatasourceStream = null; } try { oddrUaOperatingSystemDatasourceStream = (Stream)prprts.Get(ODDR_UA_OPERATINGSYSTEM_DATASOURCE_STREAM_PROP); } catch (Exception ex) { oddrUaOperatingSystemDatasourceStream = null; } String oddrThreshold = prprts.GetProperty(ODDR_THRESHOLD_PROP); if ((oddrUaDeviceBuilderPath == null || oddrUaDeviceBuilderPath.Trim().Length == 0) && oddrUaDeviceBuilderStream == null) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_DEVICE_BUILDER_PATH_PROP)); } if ((oddrUaDeviceDatasourcePath == null || oddrUaDeviceDatasourcePath.Trim().Length == 0) && oddrUaDeviceDatasourceStream == null) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP)); } String[] oddrUaDeviceBuilderPatchPathArray = null; if (oddrUaDeviceBuilderPatchPaths != null && oddrUaDeviceBuilderPatchPaths.Trim().Length != 0) { oddrUaDeviceBuilderPatchPathArray = oddrUaDeviceBuilderPatchPaths.Split(",".ToCharArray()); } else { oddrUaDeviceBuilderPatchPathArray = new String[0]; } String[] ooddrUaDeviceDatasourcePatchPathArray = null; if (oddrUaDeviceDatasourcePatchPaths != null && oddrUaDeviceDatasourcePatchPaths.Trim().Length != 0) { ooddrUaDeviceDatasourcePatchPathArray = oddrUaDeviceDatasourcePatchPaths.Split(",".ToCharArray()); } else { ooddrUaDeviceDatasourcePatchPathArray = new String[0]; } if (oddrUaDeviceBuilderPatchStreams == null) { oddrUaDeviceBuilderPatchStreams = new Stream[0]; } if (oddrUaDeviceDatasourcePatchStreams == null) { oddrUaDeviceDatasourcePatchStreams = new Stream[0]; } if ((oddrUaBrowserDatasourcePaths == null || oddrUaBrowserDatasourcePaths.Trim().Length == 0) && oddrUaBrowserDatasourceStream == null) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_BROWSER_DATASOURCE_PATH_PROP)); } if ((oddrUaOperatingSystemDatasourcePaths == null || oddrUaOperatingSystemDatasourcePaths.Trim().Length == 0) && oddrUaOperatingSystemDatasourceStream == null) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not find property " + ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP)); } if (oddrThreshold == null || oddrThreshold.Trim().Length == 0) { this.threshold = ODDR_DEFAULT_THRESHOLD; } else { try { this.threshold = int.Parse(oddrThreshold); if (this.threshold <= 0) { this.threshold = ODDR_DEFAULT_THRESHOLD; } } catch (FormatException x) { this.threshold = ODDR_DEFAULT_THRESHOLD; } } Dictionary<String, Device> devices = new Dictionary<String, Device>(); Stream stream = null; try { if (oddrUaDeviceDatasourceStream != null) { stream = oddrUaDeviceDatasourceStream; } else { stream = new FileStream(oddrUaDeviceDatasourcePath, FileMode.Open); } } catch (IOException ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " " + oddrUaDeviceDatasourcePath)); } /// TODO: Check stream. If stream is null DeviceDataSourceParser throws ArgumentNullException DeviceDatasourceParser deviceDatasourceParser = new DeviceDatasourceParser(stream, devices, vocabularyHolder); try { deviceDatasourceParser.Parse(); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + oddrUaDeviceDatasourcePath)); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } deviceDatasourceParser.patching = true; if (oddrUaDeviceDatasourcePatchStreams != null && oddrUaDeviceDatasourcePatchStreams.Length != 0) { for (int i = 0; i < oddrUaDeviceDatasourcePatchStreams.Length; i++) { stream = oddrUaDeviceDatasourcePatchStreams[i]; try { deviceDatasourceParser.SetStream(stream); deviceDatasourceParser.Parse(); } catch (ArgumentNullException ane) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open DeviceDatasource input stream " + i)); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse DeviceDatasource input stream " + i)); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } } } else { for (int i = 0; i < ooddrUaDeviceDatasourcePatchPathArray.Length; i++) { try { stream = new FileStream(ooddrUaDeviceDatasourcePatchPathArray[i], FileMode.Open); } catch (IOException ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " " + ooddrUaDeviceDatasourcePatchPathArray[i])); } try { deviceDatasourceParser.SetStream(stream); deviceDatasourceParser.Parse(); } catch (ArgumentNullException ane) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + ooddrUaDeviceDatasourcePatchPathArray[i])); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + ooddrUaDeviceDatasourcePatchPathArray[i])); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } } } List<IDeviceBuilder> builders = new List<IDeviceBuilder>(); try { if (oddrUaDeviceBuilderStream != null) { stream = oddrUaDeviceBuilderStream; } else { stream = new FileStream(oddrUaDeviceBuilderPath, FileMode.Open); } } catch (IOException ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_BUILDER_PATH_PROP + " " + oddrUaDeviceBuilderPath)); } /// TODO: Check stream. If stream is null DeviceBuilderParser throws ArgumentNullException DeviceBuilderParser deviceBuilderParser = new DeviceBuilderParser(stream, builders); try { deviceBuilderParser.Parse(); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + oddrUaDeviceBuilderPath)); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } if (oddrUaDeviceBuilderPatchStreams != null && oddrUaDeviceBuilderPatchStreams.Length != 0) { for (int i = 0; i < oddrUaDeviceBuilderPatchStreams.Length; i++) { stream = oddrUaDeviceBuilderPatchStreams[i]; try { deviceBuilderParser.SetStream(stream); deviceBuilderParser.Parse(); } catch (ArgumentNullException ane) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open DeviceBuilder input stream " + i)); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse DeviceBuilder input stream " + i)); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } } } else { for (int i = 0; i < oddrUaDeviceBuilderPatchPathArray.Length; i++) { try { stream = new FileStream(oddrUaDeviceBuilderPatchPathArray[i], FileMode.Open); } catch (IOException ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_DEVICE_BUILDER_PATCH_PATHS_PROP + " " + oddrUaDeviceBuilderPatchPathArray[i])); } try { deviceBuilderParser.SetStream(stream); deviceBuilderParser.Parse(); } catch (ArgumentNullException ane) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not open " + ODDR_UA_DEVICE_DATASOURCE_PATH_PROP + " :" + oddrUaDeviceBuilderPatchPathArray[i])); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + oddrUaDeviceBuilderPatchPathArray[i])); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } } } try { if (oddrUaBrowserDatasourceStream != null) { stream = oddrUaBrowserDatasourceStream; } else { stream = new FileStream(oddrUaBrowserDatasourcePaths, FileMode.Open); } } catch (IOException ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_BROWSER_DATASOURCE_PATH_PROP + " " + oddrUaBrowserDatasourcePaths)); } /// TODO: Check stream. If stream is null BrowserDatasourceParser throws ArgumentNullException BrowserDatasourceParser browserDatasourceParser = new BrowserDatasourceParser(stream, vocabularyHolder); try { browserDatasourceParser.Parse(); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + oddrUaBrowserDatasourcePaths)); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } try { if (oddrUaOperatingSystemDatasourceStream != null) { stream = oddrUaOperatingSystemDatasourceStream; } else { stream = new FileStream(oddrUaOperatingSystemDatasourcePaths, FileMode.Open); } } catch (IOException ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new ArgumentException("Can not open " + ODDR_UA_OPERATINGSYSTEM_DATASOURCE_PATH_PROP + " " + oddrUaOperatingSystemDatasourcePaths)); } /// TODO: Check stream. If stream is null OperatingSystemDatasourceParser throws ArgumentNullException OperatingSystemDatasourceParser operatingSystemDatasourceParser = new OperatingSystemDatasourceParser(stream, vocabularyHolder); try { operatingSystemDatasourceParser.Parse(); } catch (Exception ex) { throw new InitializationException(InitializationException.INITIALIZATION_ERROR, new Exception("Can not parse document: " + oddrUaOperatingSystemDatasourcePaths)); } try { stream.Close(); } catch (IOException ex) { logger.Warn("", ex); } deviceIdentificator = new DeviceIdentificator(deviceBuilderParser.DeviceBuilders(), deviceDatasourceParser.devices); deviceIdentificator.CompleteInit(); Dictionary<string, Browser> browsers = new Dictionary<string, Browser>(browserDatasourceParser.browsers); browserIdentificator = new BrowserIdentificator(new IBuilder[] { DefaultBrowserBuilder.Instance }, browsers); browserIdentificator.CompleteInit(); Dictionary<string, OSModel.OperatingSystem> operatingSystems = new Dictionary<string, OSModel.OperatingSystem>(operatingSystemDatasourceParser.operatingSystems); osIdentificator = new OSIdentificator(new IBuilder[] { DefaultOSBuilder.Instance }, operatingSystems); osIdentificator.CompleteInit(); deviceDatasourceParser = null; deviceBuilderParser = null; browserDatasourceParser = null; operatingSystemDatasourceParser = null; this.defaultVocabularyIRI = defaultVocabularyIRI; oddrVocabularyService = null; return; }
/// <exception cref="System.ArgumentNullException">Thrown when stream is null</exception> public DeviceDatasourceParser(Stream stream, Dictionary<string, Device> devices, VocabularyHolder vocabularyHolder) { try { Init(stream); } catch (ArgumentNullException ex) { throw new ArgumentNullException(ex.Message, ex); } this.devices = devices; try { vocabularyHolder.ExistVocabulary(ODDRVocabularyService.ODDR_LIMITED_VOCABULARY_IRI); this.vocabularyHolder = vocabularyHolder; } catch (Exception ex) { this.vocabularyHolder = null; } }