Exemple #1
0
        private static async Task ProcessContactsFile(CallInvoker invoker)
        {
            try
            {
                if (string.IsNullOrEmpty(_contactsFilename))
                {
                    return;
                }

                await using var file = File.OpenRead(_contactsFilename);
                var    stream = new StreamReader(file);
                string line;
                if ((line = stream.ReadLine()) != null)
                {
                    ZMIParser.TryParseAttributeLine(line, out var attribute, out var value);

                    if (attribute.Name == "contacts" && value.AttributeType.IsCompatible(ContactSetAttribute))
                    {
                        await SetContacts(invoker, (ValueSet)value);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e);
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            var pathToConfig = args.Length > 0 ? args[0] : DEFAULT_CONFIG_FILE;

            if (!File.Exists(pathToConfig))
            {
                Console.Error.WriteLine($"Could not find config file in path: {pathToConfig}");
                System.Environment.Exit(1);
            }

            using (var file = File.OpenRead(pathToConfig))
            {
                if (!ZMIParser.TryParseZMI(new StreamReader(file), ref _root))
                {
                    Console.Error.WriteLine($"Could not parse ZMI from file: {pathToConfig}");
                    System.Environment.Exit(1);
                }
            }

            var    scanner = Console.In;
            string line;

            while ((line = scanner.ReadLine()) != null)
            {
                var inputLine = line.Split(':');
                if (inputLine.Length > 2)
                {
                    Console.Error.WriteLine($"Wrong input");
                    continue;
                }

                var query = inputLine.Length == 2 ? inputLine[1] : inputLine[0];
                Interpreter.ExecuteQueries(_root, query.TrimEnd(';'), long.MaxValue, true);
            }
        }
Exemple #3
0
        private static bool TryParseConfig(string pathToConfig, out ZMI zmi)
        {
            zmi = null;

            if (!File.Exists(pathToConfig))
            {
                Console.Error.WriteLine($"Could not find config file in path: {pathToConfig}");
                return(false);
            }

            using var file = File.OpenRead(pathToConfig);
            if (ZMIParser.TryParseZMI(new StreamReader(file), ref zmi))
            {
                return(true);
            }

            Console.Error.WriteLine($"Could not parse ZMI from file: {pathToConfig}");
            return(false);
        }
Exemple #4
0
        private static async Task ProcessFile(CallInvoker invoker, string pathName, string fileName)
        {
            var commandOut = $"./fetch.sh > {fileName}".Bash();

            await using var file = File.OpenRead(fileName);
            var    stream = new StreamReader(file);
            string line;

            while ((line = stream.ReadLine()) != null)
            {
                if (line.StartsWith("/"))
                {
                    continue;
                }

                ZMIParser.TryParseAttributeLine(line, out var attribute, out var value);
                await SetAttribute(invoker, pathName, attribute, value);
            }
        }