Example #1
0
 string Expand(string value, Log log = null)
 {
     return(MacroParser.Expand(
                Source, value, true, log,
                (s, n, c) => GetString(n, (Log)c),
                "$(", ')'));
 }
Example #2
0
        void ShouldIgnoreEmptyMacros()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={}1", inputDevice);

            Assert.Equal("http://example.com?Mac={}1", parsed);
        }
Example #3
0
        void ShouldIgnoreUnfinishedMacros4()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac=}Mac&Ip=1234", inputDevice);

            Assert.Equal("http://example.com?Mac=}Mac&Ip=1234", parsed);
        }
Example #4
0
        void ShouldIgnoreUnfinishedMacros2()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={Mac&Ip={Ip}", inputDevice);

            Assert.Equal("http://example.com?Mac={Mac&Ip=192.168.1.1", parsed);
        }
Example #5
0
        void ShouldIgnoreUnfinishedMacros()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={Mac}&Ip={Ip", inputDevice);

            Assert.Equal("http://example.com?Mac=001122334455&Ip={Ip", parsed);
        }
Example #6
0
        void ShouldNotTranslateNonMacroStrings()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={Mac}&Ip={Ip}", inputDevice);

            Assert.Equal("http://example.com?Mac=001122334455&Ip=192.168.1.1", parsed);
        }
Example #7
0
        void ShouldTranslateMacAndIpAndName()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?mac={Mac}&ip={Ip}&name={Name}", inputDevice);

            Assert.Equal("http://example.com?mac=001122334455&ip=192.168.1.1&name=server", parsed);
        }
Example #8
0
        void ShouldTranslateMac()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?mac={Mac}", inputDevice);

            Assert.Equal("http://example.com?mac=001122334455", parsed);
        }
Example #9
0
        void ShouldNotParseMissingProperties()
        {
            var parser = new MacroParser();

            var parsed = parser.Parse("http://example.com?Mac={aaa}1", inputDevice);

            Assert.Equal("http://example.com?Mac={aaa}1", parsed);
        }
Example #10
0
        protected IParseTree GetPreProcessorParseTree(string code, string fileName)
        {
            var input   = new AntlrInputStream(code);
            var lexer   = new MacroLexer(input);
            var tokens  = new CommonTokenStream(lexer);
            var parser  = new MacroParser(tokens);
            var context = parser.preprocess();

            return(context);
        }
Example #11
0
        void Update(ref StuffItem item)
        {
            if (item.Value == null)
            {
                return;
            }

            item.Value = MacroParser.Expand(Source.Unknown, item.Value, false, null, GetConstant, "$(", ')');

            if (Path.DirectorySeparatorChar == '\\' && item.Value.IsFullPath())
            {
                item.Value = item.Value.UnixToNative();
            }
        }
Example #12
0
        private string ParsePath(string path)
        {
            if (macroVariables == null)
            {
                macroVariables = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { "slot", Root }
                }
            }
            ;

            var macro = new MacroParser(macroVariables, VariableProviders.Default);

            return(Environment.ExpandEnvironmentVariables(macro.Parse(path)));
        }
    }
Example #13
0
        protected string ExpandVariables(string value)
        {
            if (value == null)
            {
                return(value);
            }

            var macros = new MacroParser(ParentTask.Variables, VariableProviders.Default);
            var val    = macros.Parse(value);

            if (val.IndexOfAny(new char[] { ' ', '\t' }) != -1)
            {
                val = $"\"{value}\"";
            }

            return(val);
        }
Example #14
0
        // Token: 0x06000880 RID: 2176 RVA: 0x0003E0E0 File Offset: 0x0003C2E0
        public static Dictionary <string, object> GetVolumeCustomProperties(int volumeId, ICollection <string> properties)
        {
            Volume volume = VolumeDAL.GetVolume(volumeId);
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (properties == null || properties.Count == 0)
            {
                properties = volume.CustomProperties.Keys;
            }
            MacroParser macroParser = new MacroParser(new Action <string, int>(BusinessLayerOrionEvent.WriteEvent))
            {
                ObjectType    = "Volume",
                ActiveObject  = volume.ID.ToString(),
                NetObjectID   = volume.ID.ToString(),
                NetObjectName = volume.FullName,
                NodeID        = volume.NodeID,
                NodeName      = NodeDAL.GetNode(volume.NodeID).Name
            };

            using (macroParser.MyDBConnection = DatabaseFunctions.CreateConnection())
            {
                foreach (string text in properties)
                {
                    string key = text.Trim();
                    if (volume.CustomProperties.ContainsKey(key))
                    {
                        object obj = volume.CustomProperties[key];
                        if (obj != null && obj.ToString().Contains("${"))
                        {
                            dictionary[key] = macroParser.ParseMacros(obj.ToString(), false);
                        }
                        else
                        {
                            dictionary[key] = obj;
                        }
                    }
                }
            }
            return(dictionary);
        }
Example #15
0
        public static Dictionary <string, object> GetVolumeCustomProperties(
            int volumeId,
            ICollection <string> properties)
        {
            Volume volume = VolumeDAL.GetVolume(volumeId);
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (properties == null || properties.Count == 0)
            {
                properties = volume.get_CustomProperties().Keys;
            }
            MacroParser macroParser1 = new MacroParser(new Action <string, int>(BusinessLayerOrionEvent.WriteEvent));

            macroParser1.set_ObjectType("Volume");
            macroParser1.set_ActiveObject(volume.get_ID().ToString());
            macroParser1.set_NetObjectID(volume.get_ID().ToString());
            macroParser1.set_NetObjectName(volume.get_FullName());
            macroParser1.set_NodeID(volume.get_NodeID());
            macroParser1.set_NodeName(NodeDAL.GetNode(volume.get_NodeID()).get_Name());
            MacroParser   macroParser2 = macroParser1;
            SqlConnection connection;

            macroParser2.set_MyDBConnection(connection = DatabaseFunctions.CreateConnection());
            using (connection)
            {
                foreach (string property in (IEnumerable <string>)properties)
                {
                    string key = property.Trim();
                    if (volume.get_CustomProperties().ContainsKey(key))
                    {
                        object customProperty = volume.get_CustomProperties()[key];
                        dictionary[key] = customProperty == null || !customProperty.ToString().Contains("${") ? customProperty : (object)macroParser2.ParseMacros(customProperty.ToString(), false);
                    }
                }
            }
            return(dictionary);
        }
Example #16
0
 public ActiveMacro(MacroNode node, string contents)
 {
     this.Node  = node;
     this.Steps = MacroParser.Parse(contents).ToList();
 }