예제 #1
0
        /// <summary>
        /// Loads the AttributeSet from a predefined location (based on the executable path).
        /// </summary>
        /// <remarks>
        /// This probably should move elsewhere in a later revision.
        /// </remarks>
        /// <returns></returns>
        public static AttributeSet LoadFromConfig()
        {
            try
            {
                AttributeSet attrSet = new AttributeSet();
                string configText = File.ReadAllText(Config.ConfigDir + ATTRIBUTE_FILE);
                attrSet.AttributeDefinitions = ParseAttributeDefs(configText);

                //Apply hard-coded attributes
                applyHardAttribute(attrSet, "Template");
                applyHardAttribute(attrSet, "Path");

                return attrSet;
            }
            catch(FileNotFoundException)
            {
                Logger.LogError("Could not find " + ATTRIBUTE_FILE + " in " + Config.ConfigDir);
                return null;
            }
            catch (DirectoryNotFoundException)
            {
                Logger.LogError("Could not find " + ATTRIBUTE_FILE + " in " + Config.ConfigDir);
                return null;
            }
        }
예제 #2
0
 /// <summary>
 /// Dependency injected constructor, mainly to support unit testing.
 /// </summary>
 /// <param name="paths">Paths to key items. Will not be used as heavily as in null constructor, as most config is provided.</param>
 /// <param name="attributes">A list of valid attributes to use in place of loading directly from config.</param>
 /// <param name="macroProviders">A list of macro providers to use instead of default.</param>
 public Orchestrator(
     Config.Paths paths, 
     AttributeSet attributes, 
     IList<IMacroProvider> macroProviders)
 {
     this.paths = paths;
     this.validAttributes = attributes;
     this.macroProviders = macroProviders;
 }
 private static AttributeSet getAttributeSet()
 {
     AttributeSet attrSet = new AttributeSet();
     string input = @"#A comment line
                      Title:String
                      Category:String
                      Tags:StringArray
                      Date:Date";
     attrSet.AttributeDefinitions = AttributeSet.ParseAttributeDefs(input);
     return attrSet;
 }
예제 #4
0
        public void ParseAttributeSetPositive()
        {
            string input = @"#A comment line
                             Title:String
                             Index:Number
                             Tags:StringArray
                             Date:Date";
            IList <AttributeDef> output = AttributeSet.ParseAttributeDefs(input);

            Assert.AreEqual(4, output.Count);
            Assert.AreEqual("Title", output[0].Name);
            Assert.AreEqual("Index", output[1].Name);
            Assert.AreEqual("Tags", output[2].Name);
            Assert.AreEqual("Date", output[3].Name);
            Assert.AreEqual(EAttributeType.String, output[0].DataType);
            Assert.AreEqual(EAttributeType.Number, output[1].DataType);
            Assert.AreEqual(EAttributeType.StringArray, output[2].DataType);
            Assert.AreEqual(EAttributeType.Date, output[3].DataType);
        }
예제 #5
0
 private static void applyHardAttribute(AttributeSet attrSet, string attrName)
 {
     AttributeDef existingDef = attrSet.AttributeDefinitions.FirstOrDefault(x => x.Name == attrName);
     if (existingDef != null) attrSet.AttributeDefinitions.Remove(existingDef);
     attrSet.AttributeDefinitions.Add(new AttributeDef() { Name = attrName, DataType = EAttributeType.String });
 }
예제 #6
0
        /// <summary>
        /// Sets up all known macro providers for use.
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        private static IList <IMacroProvider> getDefaultMacroProviders(Config.Paths paths, AttributeSet validAttributes)
        {
            List <IMacroProvider> macroProviders = new List <IMacroProvider>();

            if (paths == null)
            {
                return(macroProviders);
            }

            macroProviders.Add(new MarkdownMacroProvider(paths.MacrosRootDir));
            macroProviders.Add(new BasicTextMacroProvider(paths.MacrosRootDir));
            macroProviders.Add(new XslMacroProvider(paths.MacrosRootDir, validAttributes));
            return(macroProviders);
        }
예제 #7
0
 public Orchestrator(
     Config.Paths paths,
     AttributeSet attributes) : this(paths, attributes, getDefaultMacroProviders(paths, attributes))
 {
 }
예제 #8
0
 /// <summary>
 /// Creates Orchestrator using default options for configuration (loaded from file system).
 /// </summary>
 public Orchestrator()
     : this(Config.LoadPaths(), AttributeSet.LoadFromConfig())
 {
 }
예제 #9
0
 public Orchestrator(
     Config.Paths paths, 
     AttributeSet attributes)
     : this(paths, attributes, getDefaultMacroProviders(paths, attributes))
 {
 }
예제 #10
0
        /// <summary>
        /// Sets up all known macro providers for use.
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        private static IList<IMacroProvider> getDefaultMacroProviders(Config.Paths paths, AttributeSet validAttributes)
        {
            List<IMacroProvider> macroProviders = new List<IMacroProvider>();
            if (paths == null) return macroProviders;

            macroProviders.Add(new MarkdownMacroProvider(paths.MacrosRootDir));
            macroProviders.Add(new BasicTextMacroProvider(paths.MacrosRootDir));
            macroProviders.Add(new XslMacroProvider(paths.MacrosRootDir, validAttributes));
            return macroProviders;
        }