예제 #1
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 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);
        }
예제 #2
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();
            }
        }