/// <summary> /// initialization using data in ConfigData object. /// This should be called immediately after the constructor. /// Each Station subclass should call base.initialize(configData, memory) from its own initialize() method. /// </summary> public override void Initialize(ConfigData configData, InstanceMemory memory, Resolver commandResolver) { base.Initialize(configData, memory, commandResolver); // do any other Station specific initialization here HomePath = configData.RequiredValue("homePath"); if (!(HomePath.EndsWith(@"\") || HomePath.EndsWith(@"/"))) HomePath += "/"; User = configData.Value("user"); Password = configData.Value("password"); IncludeSubfolders = configData.BoolValue("includeSubfolders", false); string possibleError; var unc = ConnectUnc(out possibleError); try { EntityName = configData.RequiredValue("entityName"); List<ConfigData> folderConfigs = configData.GetConfigSections("folder"); if (folderConfigs.Count == 0) throw new Exception("No folders configured for station " + this.GetType()); foreach (ConfigData folderConfig in folderConfigs) { string name = folderConfig.RequiredValue("name"); string status = folderConfig.Value("status"); if (status == null) status = name; string path = HomePath + name; if (Directory.Exists(path)) { Folder f = new Folder(name, status, path); Folders.Add(f); } else { Console.Error.WriteLine("WARNING: Directory not found: {0}", path); } } if (Folders.Count == 0) { string error = "No folders accessible for station " + this.GetType(); if (possibleError != null) error += "; " + possibleError; throw new Exception(error); } List<ConfigData> extConfigs = configData.GetConfigSections("extension"); foreach (ConfigData extConfig in extConfigs) { string ext = extConfig.Value(); if (string.IsNullOrEmpty(ext)) { throw new Exception("Property is empty: extension"); } Extensions.Add(ext); } } finally { if (unc != null) unc.Dispose(); } }
/// <summary> /// initialization using data in ConfigData object. /// This should be called immediately after the constructor. /// Each Station subclass should call base.initialize(configData, memory) from its own initialize() method. /// </summary> public virtual void Initialize(ConfigData configData, InstanceMemory memory, Resolver resolver) { // do any other global Station initialization here this.Memory = memory; stationDescription = configData.Value(Constants.StationDescription); entities = LoadStationEntities(configData); var max = configData.IntValue(Constants.StationMaxSearchResults); MaxSearchResults = max ?? int.MaxValue; var ageLimit = configData.IntValue(Constants.StationAgeLimit); AgeLimit = ageLimit ?? int.MaxValue; PopulateRoles(configData); PopulateOperations(configData); PopulateCommands(configData, resolver); PopulatePublicFields(configData); }
/// <summary> /// create a new Station, based on the station entityName specified in the portion of the config file. /// </summary> /// <param name="configData">portion of a config file describing this particular station</param> /// <param name="mem"></param> /// <returns>a new Station of object, of the desired flavor; returns null if the station is inactive</returns> private Station NewStation(ConfigData configData, InstanceMemory mem) { Station s; string stationClassName = configData.RequiredValue(Constants.StationClassName); //Console.Error.WriteLine("Creating new station: " + stationClassName); try { s = classFactory.InstantiateStationClass(stationClassName); if (s != null) { s.Initialize(configData, mem, this); } else { throw new Exception("Unable to create Station Class " + stationClassName); } } catch (Exception e) { throw new Exception("Unable to create Station Class " + stationClassName, e); } //log.WriteLine("Station type "+s.getStationDescription()+" successfully initialized"); return s; }
private void InitializeStation(InstanceMemory mem, ConfiguredStation cs) { Station s = null; try { s = NewStation(cs.ConfigData, mem); if (s != null) { s.Connect(); cs.Station = s; cs.Description = s.StationDescription; // allow station to provide an updated description cs.Enabled = true; } } catch (Exception e) { cs.Error = e.Message; errors += "Station not available: "; errorsDetail += "Station not available: "; if (s != null) { errors += s.ToString(); errorsDetail += s.ToString(); } errors += "\n"; errors += e.Message + "\n"; errorsDetail += "\n"; errorsDetail += e + "\n"; } }
private void ConfigureStations(InstanceMemory mem, ConfigData config) { // for each station element in the configStream file, // create a station and add it to the stations list List<ConfigData> stationConfigs = config.GetConfigSections(Constants.StationConfig); int index = 0; foreach (ConfigData sConfig in stationConfigs) { ConfiguredStation cs = new ConfiguredStation(index++, sConfig); cs.Description = sConfig.Value(Constants.StationDescription); if (string.IsNullOrWhiteSpace(cs.Description)) cs.Description = sConfig.Value(Constants.StationClassName); configuredStations.Add(cs); // if the Station is configured to be inactive, don't initialize bool active = sConfig.BoolValue(Constants.ActiveStation, true); if (active) { InitializeStation(mem, cs); } } }
/// <summary> /// alternate constructor -- performs the initialization, including reading the config /// file, instantiating and initializing the configured stations, /// specifying an alternate class factory to instantiate stations. /// </summary> /// <param name="configName">name of configuration file which describes this specific pipeline</param> /// <param name="memory">instance memory to be associated with this pipeline</param> /// <param name="stationCreator">used when we had problems finding classes in a different assembly</param> public Pipeline(string configName, InstanceMemory memory, ClassFactory stationCreator) { this.classFactory = stationCreator; this.memory = memory; // read config file Stream configStream = new FileStream(configName, FileMode.Open, FileAccess.Read); // TODO new way to get the resource file -- actually should use IOC / Dependency Injection // also accept a stream instead of a file ConfigData config = new ConfigData(configStream); errors = ""; errorsDetail = ""; ConfigureCommands(config); ConfigureStations(memory, config); ConfigFile = (configName); Description = (config.RequiredValue("description")); if (errors.Length > 0) { //Console.Error.WriteLine("WARNING: " + _errors); // leave it to the app to decide how to present error messages //throw new StationFailedException(_errors); // allow the constructor to succeed, caller can check HasError } }
/// <summary> /// constructor -- performs the initialization, including reading the config /// file, instantiating and initializing the configured stations. /// </summary> /// <param name="configName">name of configuration file which describes this specific pipeline</param> /// <param name="memory">instance memory to be associated with this pipeline</param> public Pipeline(string configName, InstanceMemory memory) : this(configName, memory, new DefaultClassFactory()) { }