Esempio n. 1
0
        public static void InitObjects(Stream stream, bool skipHash = false)
        {
            var     parser = new IniParser.StreamIniDataParser();
            IniData data   = parser.ReadData(new StreamReader(stream));

            foreach (var section in data.Sections)
            {
                List <AttributeInfo> attributes = new List <AttributeInfo>();
                foreach (var key in section.Keys)
                {
                    AttributeTypes type;
                    if (!Enum.TryParse(key.Value, out type))
                    {
                        // unknown attribute, what to do?
                        Debug.WriteLine($"Unknown type! [{key.Value}]");
                    }

                    attributes.Add(new AttributeInfo(new NameIdentifier(key.KeyName), type));
                }
                objects.Add(new ObjectInfo(new NameIdentifier(section.SectionName), attributes));
            }
            if (skipHash != true)
            {
                hashToObject = objects.ToDictionary(x => x.Name.HashString());
            }
        }
Esempio n. 2
0
        private static string ElaboratedParsing(IniData parsedData, StreamIniDataParser parser)
        {
            StringBuilder sb = new StringBuilder();

            //Process data: print contents of the file into screen
            foreach (SectionData sectionData in parsedData.Sections)
            {
                //Print comments for current section
                foreach (string sectionComment in sectionData.Comments)
                    sb.AppendLine(parser.CommentDelimiter + sectionComment);

                //Print section's name
                sb.AppendLine(
                    parser.SectionDelimiters[0] + sectionData.SectionName + parser.SectionDelimiters[1]);

                sb.AppendLine();

                //Print section's key-value pairs with it's comments
                foreach (KeyData keyData in sectionData.Keys)
                {
                    //Print comments for current key
                    foreach (string keyComment in keyData.Comments)
                        sb.AppendLine(parser.CommentDelimiter + keyComment);

                    //Print key and value
                    sb.AppendLine(keyData.KeyName + " " + parser.KeyValueDelimiter + " " + keyData.Value);

                    sb.AppendLine();
                }

                sb.AppendLine();
            }

            return sb.ToString();
        }
        public void write_key_and_value_without_blanks()
        {
            var data = new IniData();
            data.Sections.AddSection("section1");
            data["section1"].AddKey("key1", "value1");
            data.Configuration.AssigmentSpacer = "";

            var parser = new StreamIniDataParser();
            string tempPath = System.IO.Path.GetTempFileName();
            using (var sw = new System.IO.StreamWriter(tempPath))
            {
                parser.WriteData(sw, data);
            }

            Assert.AreEqual(@"[section1]
key1=value1
", System.IO.File.ReadAllText(tempPath));
        }
Esempio n. 4
0
        public NameValuePair GetSatIniMappings(string resource)
        {
            using (var stream = GetType().Assembly.GetManifestResourceStream(resource))
            {
                using (var reader = new StreamReader(stream))
                {
                    var parser = new StreamIniDataParser();
                    IniData data = parser.ReadData(reader);

                    var satType1 = data["SATTYPE"]["1"];
                    var satType2 = data["SATTYPE"]["2"];

                    if (string.IsNullOrWhiteSpace(satType2))
                    {
                        return null;
                    }

                    var srch = "SatIp.ini.";
                    var filename = Path.GetFileName(resource);

                    return new NameValuePair
                    {
                        Name = satType1 + " " + satType2,
                        Value = satType2 + "|" + filename.Substring(filename.IndexOf(srch) + srch.Length)
                    };
                }
            }
        }
        public static void InitObjects(Stream stream)
        {
            var     parser = new IniParser.StreamIniDataParser();
            IniData data   = parser.ReadData(new StreamReader(stream));

            foreach (var section in data.Sections)
            {
                List <AttributeInfo> attributes = new List <AttributeInfo>();
                foreach (var key in section.Keys)
                {
                    AttributeTypes type;
                    switch (key.Value)
                    {
                    case "UINT8":
                        type = AttributeTypes.UINT8;
                        break;

                    case "UINT16":
                        type = AttributeTypes.UINT16;
                        break;

                    case "UINT32":
                        type = AttributeTypes.UINT32;
                        break;

                    case "INT8":
                        type = AttributeTypes.INT8;
                        break;

                    case "INT16":
                        type = AttributeTypes.INT16;
                        break;

                    case "INT32":
                        type = AttributeTypes.INT32;
                        break;

                    case "VAR":
                        type = AttributeTypes.VAR;
                        break;

                    case "BOOL":
                        type = AttributeTypes.BOOL;
                        break;

                    case "STRING":
                        type = AttributeTypes.STRING;
                        break;

                    case "POSITION":
                        type = AttributeTypes.POSITION;
                        break;

                    case "COLOR":
                        type = AttributeTypes.COLOR;
                        break;

                    default:
                        // Unknown attribute
                        continue;
                    }

                    attributes.Add(new AttributeInfo(new NameIdentifier(key.KeyName), type));
                }
                objects.Add(new ObjectInfo(new NameIdentifier(section.SectionName), attributes));
            }
            hashToObject = objects.ToDictionary(x => x.Name.HashString());
        }
Esempio n. 6
0
        public async Task<List<ChannelInfo>> Scan(TunerHostInfo info, CancellationToken cancellationToken)
        {
            var ini = info.SourceA.Split('|')[1];
            var resource = GetType().Assembly.GetManifestResourceNames().FirstOrDefault(i => i.EndsWith(ini, StringComparison.OrdinalIgnoreCase));

            _logger.Info("Opening ini file {0}", resource);
            var list = new List<ChannelInfo>();

            using (var stream = GetType().Assembly.GetManifestResourceStream(resource))
            {
                using (var reader = new StreamReader(stream))
                {
                    var parser = new StreamIniDataParser();
                    var data = parser.ReadData(reader);

                    var count = GetInt(data, "DVB", "0", 0);

                    _logger.Info("DVB Count: {0}", count);

                    var index = 1;
                    var source = "1";

                    while (index <= count)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        using (var rtspSession = new RtspSession(info.Url, _logger))
                        {
                            float percent = count == 0 ? 0 : (float)(index) / count;
                            percent = Math.Max(percent * 100, 100);

                            //SetControlPropertyThreadSafe(pgbSearchResult, "Value", (int)percent);
                            var strArray = data["DVB"][index.ToString(CultureInfo.InvariantCulture)].Split(',');

                            string tuning;
                            if (strArray[4] == "S2")
                            {
                                tuning = string.Format("src={0}&freq={1}&pol={2}&sr={3}&fec={4}&msys=dvbs2&mtype={5}&plts=on&ro=0.35&pids=0,16,17,18,20", source, strArray[0], strArray[1].ToLower(), strArray[2].ToLower(), strArray[3], strArray[5].ToLower());
                            }
                            else
                            {
                                tuning = string.Format("src={0}&freq={1}&pol={2}&sr={3}&fec={4}&msys=dvbs&mtype={5}&pids=0,16,17,18,20", source, strArray[0], strArray[1].ToLower(), strArray[2], strArray[3], strArray[5].ToLower());
                            }

                            rtspSession.Setup(tuning, "unicast");

                            rtspSession.Play(string.Empty);

                            int signallevel;
                            int signalQuality;
                            rtspSession.Describe(out signallevel, out signalQuality);

                            await Task.Delay(500).ConfigureAwait(false);
                            index++;
                        }
                    }
                }
            }

            return list;
        }