コード例 #1
0
ファイル: FileFolder.cs プロジェクト: jblindberg/Clouseau
        /// <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();
            }
        }
コード例 #2
0
ファイル: Pipeline.cs プロジェクト: jblindberg/Clouseau
        /// <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;
        }
コード例 #3
0
ファイル: Pipeline.cs プロジェクト: jblindberg/Clouseau
        /// <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
            }
        }
コード例 #4
0
ファイル: Pipeline.cs プロジェクト: jblindberg/Clouseau
        /// <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;
        }
コード例 #5
0
        public override void Initialize(ConfigData configData)
        {
            base.Initialize(configData);

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