/// <summary>
 ///     Populate the set of roles which this station supports.  May be a zero-length list.
 /// </summary>
 /// <param name="configData">ConfigData for this station</param>
 protected virtual void PopulateRoles(ConfigData configData)
 {
     roles = configData.Values(Constants.StationRole).ToList();
 }
        private void PopulatePublicFields(ConfigData configData)
        {
            var publicFieldConfigs = configData.GetConfigSections(Constants.CustomFieldConfig);
            foreach (var pubConfig in publicFieldConfigs)
            {
                var name = pubConfig.RequiredValue(Constants.CustomFieldName);
                var label = pubConfig.Value(Constants.CustomFieldLabel);
                var type = pubConfig.Value(Constants.CustomFieldType);
                var searchable = pubConfig.BoolValue(Constants.CustomFieldSearchable, false);
                var pub = pubConfig.BoolValue(Constants.CustomFieldPublic, false);

                var field = new CustomFieldDefinition(name, type)
                {
                    Label = label,
                    Searchable = searchable,
                    Public = pub
                };
                customFields.Add(field);
            }
        }
        /// <summary>
        /// Populate the set of commands which this station supports.  May be a zero-length list.
        /// </summary>
        /// <param name="configData">ConfigData for this station</param>
        /// <param name="commandResolver"></param>
        protected virtual void PopulateCommands(ConfigData configData, Resolver commandResolver)
        {
            var commandNames = configData.Values(Constants.StationCommand).ToList();

            foreach (var name in commandNames)
            {
                if (commandResolver == null)
                {
                    throw new Exception(string.Format("No CommandResolver available for command {0}, station {1}",
                        name, StationDescription));
                }
                var cmd = commandResolver.GetCommandByName(name);
                if (cmd == null)
                {
                    throw new Exception(string.Format("No Command found for commandName {0}, station {1}",
                        name, StationDescription));
                }
                Register(cmd);
            }
        }
        /// <summary>
        ///     Populate the set of operations which this station supports.
        ///     Required: opCode
        ///     Optional: opLabel (defaults to opCode)
        ///     Optional: operandCount (defaults to zero)
        /// </summary>
        /// <param name="configData">ConfigData for this station</param>
        protected virtual void PopulateOperations(ConfigData configData)
        {
            operations = new List<OperationDefinition>(Criterion.Definitions);
                // start with copy of the standard operations

            // add the custom operations
            var opConfig = configData.GetConfigSections(Constants.Operation);
            foreach (var cd in opConfig)
            {
                var code = cd.RequiredValue(Constants.OperationCode);

                var operandCount = cd.IntValue(Constants.OperationOperandCount);
                if (!operandCount.HasValue) operandCount = 0;

                var label = cd.Value(Constants.OperationLabel);
                if (label == null) label = code;

                operations.Add(new OperationDefinition(code, operandCount.Value, label));
            }
        }
        /// <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);
        }
        protected virtual List<StationEntity> LoadStationEntities(ConfigData configData)
        {
            var entitiesList = new List<StationEntity>();
            var entityConfigs = configData.GetConfigSections(Constants.StationEntity);
            foreach (var entityConfig in entityConfigs)
            {
                var entityName = entityConfig.RequiredValue(Constants.StationEntityName);
                var entity = new StationEntity(entityName);
                var entityLocation = entityConfig.Value(Constants.StationEntityLocation);
                entity.Location = (entityLocation);
                var fieldConfigs = entityConfig.GetConfigSections(Constants.StationField);
                foreach (var fieldConfig in fieldConfigs)
                {
                    var field = new StationField(fieldConfig.RequiredValue(Constants.StationFieldName));
                    field.Type = (fieldConfig.RequiredValue(Constants.StationFieldType));

                    // if location is empty, just use field name as default location
                    var location = fieldConfig.Value(Constants.StationFieldLocation);
                    if (location == null) location = field.Name;
                    field.Location = (location);

                    field.Level = (fieldConfig.IntValue(Constants.StationFieldLevel));
                    // TODO set other field properties -  referredEntity, referredEntityField
                    entity.AddField(field);
                }
                var sortField = entityConfig.Value(Constants.StationEntitySortField);
                if (sortField != null)
                {
                    entity.SortField = (sortField);
                    var sortOrder = entityConfig.Value(Constants.StationEntitySortOrder);
                    if (sortOrder != null && sortOrder.ToUpper().StartsWith("DESC"))
                    {
                        entity.DescendingSort = (true);
                    }
                }
                entitiesList.Add(entity);
            }
            return entitiesList;
        }
Exemple #7
0
 public ConfiguredStation(int id, ConfigData configData)
 {
     this.id = id;
     this.ConfigData = configData;
 }
Exemple #8
0
        /// <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();
            }
        }
Exemple #9
0
        /// <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;
        }
Exemple #10
0
        /// <summary>
        /// create a new StationCommand, based on the StationCommand class name specified in the
        /// portion of the config file.
        /// </summary>
        /// <param name="configData">portion of a config file describing this particular stationCommand</param>
        /// <returns> a new StationCommand of object, of the desired flavor;
        /// returns null if the stationCommand is inactive</returns>
        private StationCommand NewStationCommand(ConfigData configData)
        {
            StationCommand cmd;
            string stationCommandClassName = configData.RequiredValue(Constants.CommandClassName);

            //// if the command is configured to be inactive, just return null
            //String active = configData.value(Constants.ACTIVE_COMMAND);
            //if (!String.IsNullOrEmpty(active) && active.Equals(Constants.FALSE, StringComparison.InvariantCultureIgnoreCase))
            //{
            //    //Console.Error.WriteLine("ignoring inactive command: " + stationCommandClassName);
            //    return null;
            //}

            //Console.Error.WriteLine("Creating new stationCommand: " + stationCommandClassName);
            try
            {
                cmd = classFactory.InstantiateStationCommandClass(stationCommandClassName);
                if (cmd != null)
                {
                    cmd.Initialize(configData);
                }
                else
                {
                    throw new Exception("Unable to create StationCommand Class " + stationCommandClassName);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Unable to create StationCommand Class " + stationCommandClassName, e);
            }
            //log.WriteLine("Command type "+s.getStationCommandDescription()+" successfully initialized");
            return cmd;
        }
Exemple #11
0
        private void InitializeCommand(ConfigData cmdConfig, ConfiguredStationCommand cc)
        {
            StationCommand cmd = null;
            try
            {
                cmd = NewStationCommand(cmdConfig);
                if (cmd != null)
                {
                    cc.StationCommand = cmd;
                    cc.Description = cmd.Description; // allow command to provide an updated description
                    //cc.enabled = true;
                }
            }
            catch (Exception e)
            {
                cc.Error = e.Message;

                errors += "Command not available: ";
                errorsDetail += "Command not available: ";
                if (cmd != null)
                {
                    errors += cmd.ToString();
                    errorsDetail += cmd.ToString();
                }
                errors += "\n";
                errors += e.Message + "\n";

                errorsDetail += "\n";
                errorsDetail += e + "\n";
            }
        }
Exemple #12
0
        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);
                }
            }
        }
Exemple #13
0
        private void ConfigureCommands(ConfigData config)
        {
            // for each command element in the configStream file,
            // create a StationCommand and add it to the Commands list
            List<ConfigData> commandConfigs = config.GetConfigSections(Constants.CommandConfig);
            int index = 0;
            foreach (ConfigData cmdConfig in commandConfigs)
            {
                ConfiguredStationCommand cc = new ConfiguredStationCommand(index++);

                cc.Description = cmdConfig.Value(Constants.CommandDescription);
                if (string.IsNullOrWhiteSpace(cc.Description))
                    cc.Description = cmdConfig.Value(Constants.CommandClassName);

                configuredCommands.Add(cc);

                InitializeCommand(cmdConfig, cc);
                //// if the Command is configured to be inactive, don't initialize
                //String active = cmdConfig.value(Constants.ACTIVE_STATION);
                //if (active == null || !active.Equals(Constants.FALSE, StringComparison.InvariantCultureIgnoreCase))
                //{
                //    InitializeCommand(cmdConfig, cc);
                //}

            }
        }
Exemple #14
0
        /// <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
            }
        }
        public override void Initialize(ConfigData configData)
        {
            base.Initialize(configData);

            retryPath = configData.RequiredValue("retryPath");
            retryUser = configData.RequiredValue("retryUser");
            retryPassword = configData.RequiredValue("retryPassword");
        }