public IEnumerable<IProvideTeamInformation> GetAllTheTeams()
        {
            using (var reader = new FileInfo(@"data\football.dat").OpenText())
            {
                string line;

                Enumerable.Range(1, 5).Each(x => reader.ReadLine());
                while ((line = reader.ReadLine()) != null)
                {
                    if(IsValidLine(line))
                        yield return ParseLine(line);
                }
            }
        }
Ejemplo n.º 2
0
        //   [Fact()]
        public void ReadFiles()
        {
            var file = Path.GetTempFileName();
            var info = new FileInfo(file);

            File.AppendAllLines(file, Enumerable.Range(1, 100000).Select(i => $"This is line number {i}"));

            var indexer = new LineIndexer(info);
            var  items = indexer.ReadToEnd().ToArray();

            var actual = File.ReadAllLines(file).ToArray();

            var toRead = Enumerable.Range(0, 1000)
                .Select(i => items.InferPosition(i))
                .ToArray();
                ;

            var largest = toRead.Last();
            var fileLength = file.Length;

            Console.WriteLine();
            var convertedLines = info.ReadLine(toRead, (li, str) =>
            {
                return str;
            }).ToArray();

            File.Delete(file);
        }
Ejemplo n.º 3
0
        private void textBoxDir_TextChanged(object sender, EventArgs e)
        {
            imagini.Clear();
            imaginiCheie.Clear();
            listaFisiere.Clear();
            pictureBox1.Image = null;

            if (IO.Directory.Exists(textBoxDir.Text))
            {
                //Asociere director cu aliniamentul
                using (acadDoc.LockDocument())
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                        using (ResultBuffer RB = new ResultBuffer(new TypedValue(1001, "OVIDIU"), new TypedValue(1000, "POZE->" + textBoxDir.Text)))
                        {
                            //Alignment Ax = (Alignment)trans.GetObject(((Alignment)comboBoxAx.SelectedItem).Id, OpenMode.ForWrite);
                            string nume = ((Alignment)comboBoxAx.SelectedItem).Name;
                            foreach (ObjectId idAx in civDoc.GetAlignmentIds())
                            {
                                Alignment Ax = (Alignment)trans.GetObject(idAx, OpenMode.ForRead);
                                if (Ax.Name == nume)
                                {
                                    Ax.UpgradeOpen();
                                    Ax.XData = RB;
                                }
                            }
                            //Ax.UpgradeOpen();
                            //Ax.XData = RB;
                            trans.Commit();
                        }//

                //Citire imaginiCheie din fisierul CALIBRARE.TXT daca acesta exista
                if (IO.File.Exists(textBoxDir.Text + @"\CALIBRARE.TXT"))
                {
                    using (IO.StreamReader reader = new IO.FileInfo(textBoxDir.Text + @"\CALIBRARE.TXT").OpenText())
                    {
                        string linie = null;
                        while ((linie = reader.ReadLine()) != null)
                        {
                            if (linie.Contains("********"))
                            {
                                try
                                {
                                    string[] componente = linie.Remove(0, 4).Replace("********", "").Split(new string[] { "-> " }, StringSplitOptions.None);
                                    imaginiCheie.Add(int.Parse(componente[0]), componente[1]);
                                }
                                catch { }
                            }
                        }
                    }
                    WF.MessageBox.Show("Numar chei citite: " + imaginiCheie.Count.ToString() + ": " + imaginiCheie.ToString());
                }

                ActualizarePoze();
            }
            else
            {
                textBoxDir.Text = @"-";
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            // Initialise the pattern provider with a list of 4 properties.
            using (var pattern = new PatternWrapper(
                new FileInfo("..\\..\\..\\..\\..\\data\\51Degrees-LiteV3.2.dat").FullName,
                    new[] { "Id", "DeviceType", "IsMobile", "ScreenPixelsWidth", "ScreenPixelsHeight" }))
            {

                // Initialise the trie provider with a data file and a list of 4 properties.
                using (var trie = new TrieWrapper(
                    new FileInfo("..\\..\\..\\..\\..\\data\\51Degrees-LiteV3.2.trie").FullName,
                    new[] { "Id", "DeviceType", "IsMobile", "ScreenPixelsWidth", "ScreenPixelsHeight" }))
                {

                    // IMPORTANT: For a full list of properties see: https://51degrees.com/resources/property-dictionary

                    using (var reader = new FileInfo(args.Length > 0 ? args[0] : "..\\..\\..\\..\\..\\data\\20000 User Agents.csv").OpenText())
                    {
                        var start = DateTime.UtcNow;
                        Console.WriteLine("Started -> {0}", start);
                        var line = reader.ReadLine();
                        while (line != null)
                        {
                            using (var patternResults = pattern.Match(line.Trim()))
                            {
                                Output(pattern, patternResults);
                            }
                            using (var trieResults = trie.Match(line.Trim()))
                            {
                                Output(trie, trieResults);
                            }
                            line = reader.ReadLine();
                        }
                        Console.WriteLine("Elapsed Time -> {0} seconds", (DateTime.UtcNow - start).TotalSeconds);
                    }
                }
            }
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        //[Fact()]
        public void FileWhereThereIsAProblemIndexing()
        {
            var file = Path.GetTempFileName();
            var info = new FileInfo(@"U:\Downloads\InventairePerpetuel.txt");

            var indexer = new LineIndexer(info);
            var indexed = indexer.ReadToEnd().ToArray();
            var indicies = new LineIndicies(indexed, indexer.Encoding,indexer.LineFeedSize);

            //   var tail = indicies.GetTail(new ScrollRequest(1)).ToArray();
            var tail = indicies.GetTail(new ScrollRequest(1)).ToArray();

            Console.WriteLine(indicies.Lines.Last());
            var convertedLines = info.ReadLine(tail, (li, str) =>
            {
                Console.WriteLine(li.Size);
                Console.WriteLine(str.Length);
                return str;
            }, indicies.Encoding).ToArray();
        }
        public void MakeSureContentsFileIsUpdated()
        {
            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("MakeSureContentsFileIsUpdated");
            if (d.Exists)
            {
                d.Delete(true);
            }
            d.Create();
            var f = new FileInfo(Path.Combine(d.FullName, "contents.txt"));
            using (var wr = f.CreateText())
            {
                wr.WriteLine("otherdataset.data.set gwatts");
            }

            var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo);

            Assert.IsTrue(f.Exists);
            Assert.AreEqual("otherdataset.data.set gwatts", f.ReadLine(1));
            Assert.IsTrue(f.ReadLine(2).StartsWith(dsinfo.Name));
        }
        public void MakeSureContentsFileIsCreated()
        {
            var dsinfo = MakeDSInfo("ds1.1.1");
            var d = new DirectoryInfo("MakeSureContentsFileIsCreated");
            if (d.Exists)
            {
                d.Delete(true);
            }

            var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
            var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
            var r = gf.GetDS(dsinfo);

            var f = new FileInfo(Path.Combine(d.FullName, "contents.txt"));
            Assert.IsTrue(f.Exists);
            Assert.IsTrue(f.ReadLine().StartsWith(dsinfo.Name));
        }
Ejemplo n.º 8
0
 public ArrayList ReadIMUFile(string filePath, double startTow, double endTow)
 {
     ArrayList list = new ArrayList();
     try
     {
         StreamReader reader = new FileInfo(filePath).OpenText();
         double num = 0.0;
         int num2 = 0;
         int num3 = 0;
         bool flag = false;
         string str = string.Empty;
         string input = reader.ReadLine();
         while (input != null)
         {
             if (!flag && input.Contains("SW Version"))
             {
                 string pattern = "SW Version*(?<swVer>.*)";
                 Regex regex = new Regex(pattern, RegexOptions.Compiled);
                 if (regex.IsMatch(input))
                 {
                     str = regex.Match(input).Result("${swVer}");
                     flag = true;
                 }
             }
             string[] strArray = input.Split(new char[] { ',' });
             if (strArray.Length <= 20)
             {
                 goto Label_0302;
             }
             if (strArray[0] == "28")
             {
                 num3 = Convert.ToInt16(strArray[0x13]);
                 if (num2 < num3)
                 {
                     num2 = num3;
                     num = (uint) Convert.ToDouble(strArray[4]);
                 }
             }
             if (!(strArray[0] == "41") || (Convert.ToInt16(strArray[2]) <= 0))
             {
                 goto Label_0302;
             }
             PositionInfo.PositionStruct struct2 = new PositionInfo.PositionStruct();
             struct2.NavType = Convert.ToUInt16(strArray[2]);
             int num4 = 8;
             struct2.TOW = (uint) (Convert.ToDouble(strArray[num4 / 2]) / 1000.0);
             if (startTow > 0.0)
             {
                 if (struct2.TOW >= startTow)
                 {
                     if ((endTow > 0.0) && (struct2.TOW > endTow))
                     {
                         return list;
                     }
                     goto Label_0190;
                 }
                 input = reader.ReadLine();
                 continue;
             }
             if ((endTow > 0.0) && (struct2.TOW > endTow))
             {
                 return list;
             }
         Label_0190:
             struct2.RxTime_Hour = Convert.ToInt32(strArray[num4++]);
             struct2.RxTime_Minute = Convert.ToInt32(strArray[num4++]);
             struct2.RxTime_second = (ushort) (Convert.ToDouble(strArray[num4++]) / 1000.0);
             struct2.SatellitesUsed = Convert.ToUInt32(strArray[num4++]);
             struct2.Latitude = Convert.ToDouble(strArray[num4++]) / 10000000.0;
             struct2.Longitude = Convert.ToDouble(strArray[num4++]) / 10000000.0;
             struct2.Altitude = Convert.ToDouble(strArray[num4++]) / 100.0;
             struct2.Speed = Convert.ToDouble(strArray[num4 + 2]) / 100.0;
             struct2.Heading = Convert.ToDouble(strArray[num4 + 3]) / 100.0;
             struct2.NumSVInFix = Convert.ToUInt16(strArray[num4 + 0x12]);
             struct2.HDOP = Convert.ToDouble(strArray[num4 + 0x13]) / 5.0;
             if (struct2.TOW == num)
             {
                 struct2.MaxCN0 = num2;
             }
             else
             {
                 struct2.MaxCN0 = 0.0;
             }
             num2 = 0;
             num3 = 0;
             struct2.SW_Version = str;
             list.Add(struct2);
         Label_0302:
             input = reader.ReadLine();
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
     return list;
 }
        public void WriteWholeFile()
        {
            var data = new List<string[]>();
            data.Add(new string[] { "column1line1", "column2line1" });
            data.Add(new string[] { "column1line2", "column2line2" });
            csvReaderWriter.Open(TestOutputFile, CSVReaderWriter.Mode.Write);
            csvReaderWriter.WriteWholeFile(data);
            csvReaderWriter.Close();

            StreamReader reader = new FileInfo(TestOutputFile).OpenText();
            Assert.That(reader.ReadLine(), Is.EqualTo("column1line1" + "\t" + "column2line1"));
            Assert.That(reader.ReadLine(), Is.EqualTo("column1line2" + "\t" + "column2line2"));
            reader.Close();
        }
Ejemplo n.º 10
0
        public Scene(string inputFilename)
        {
            triangles = new List<Triangle>();
            quads = new List<Quad>();
            bullets = new List<Bullet>();
            hud = new HUD();

            StreamReader reader = new FileInfo(inputFilename).OpenText();
            string line;

            Dictionary<string, Vector> loadedVertices = new Dictionary<string, Vector>();
            Dictionary<string, int> loadedTextures = new Dictionary<string, int>();
            Dictionary<string, float> values = new Dictionary<string,float>();

            int texturesCount = 0;
            textures = new uint[texturesCount];

            int lineCounter = 0;

            while (true)
            {
                line = reader.ReadLine();

                if (line == null)
                    break;

                line = System.Text.RegularExpressions.Regex.Replace(line, "#.*", "", System.Text.RegularExpressions.RegexOptions.Compiled);

                lineCounter++;

                if (line == "")
                    continue;

                if (line.IndexOf("clear vertices") == 0)
                    loadedVertices = new Dictionary<string, Vector>();

                else if (line.IndexOf("start") == 0)
                {
                    #region start
                    string[] parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length != 6)
                    {
                        throw new Exception("line.split for start did not make the right length array. line " + lineCounter.ToString());
                    }

                    cameraPosition.x = GetFloat(parts[1], values);
                    cameraPosition.y = GetFloat(parts[2], values);
                    cameraPosition.z = GetFloat(parts[3], values);

                    lookAngleX = GetFloat(parts[4], values);
                    lookAngleY = GetFloat(parts[5], values);
                    #endregion
                }
                else if (line.Contains("vertex"))
                {
                    #region vertex
                    try
                    {
                        string[] parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);

                        if (parts.Length != 5)
                            throw new Exception("line.Split for Vector did not make the right length array. line " + lineCounter.ToString());

                        string name = parts[1];
                        float x = GetFloat(parts[2], values);
                        float y = GetFloat(parts[3], values);
                        float z = GetFloat(parts[4], values);

                        loadedVertices.Add(name, new Vector(x, y, z));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("error parsing input file. line " + lineCounter.ToString() + " . message: " + e.Message);
                    }
                    #endregion
                }
                else if (line.Contains("quad"))
                {
                    #region quad
                    string[] parts;
                    parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);

                    if (parts.Length > 10)
                    {
                        throw new Exception("line.split for quad was not the right length. line: " + lineCounter.ToString());
                    }

                    if (parts[5] == "color")
                    {
                        float red = GetFloat(parts[6], values);
                        float green = GetFloat(parts[7], values);
                        float blue = GetFloat(parts[8], values);

                        MyColor color = new MyColor(red, green, blue);

                        string name = parts[9];

                        Vector v1 = loadedVertices[parts[1]];
                        Vector v2 = loadedVertices[parts[2]];
                        Vector v3 = loadedVertices[parts[3]];
                        Vector v4 = loadedVertices[parts[4]];

                        Quad quad = new Quad(v1, v2, v3, v4, color, name);
                        quads.Add(quad);
                    }
                    else if (parts[5] == "tex")
                    {
                        Vector v1 = loadedVertices[parts[1]];
                        Vector v2 = loadedVertices[parts[2]];
                        Vector v3 = loadedVertices[parts[3]];
                        Vector v4 = loadedVertices[parts[4]];

                        string textureName = parts[6];
                        string name = parts[7];

                        Quad quad = new Quad(v1, v2, v3, v4, name, (uint)loadedTextures[textureName]);
                        quads.Add(quad);
                    }
                    #endregion
                }
                else if (line.Contains("triangle"))
                {
                    #region triangle
                    string[] parts;
                    try
                    {
                        parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);

                        if (parts.Length < 6)
                            throw new Exception("line.split for triangle did not make the right length array. line " + lineCounter.ToString());
                    }
                    catch (Exception e)
                    {
                        throw new Exception("error splitting triangle line in input file. line " + lineCounter.ToString() + " . message: " + e.Message);
                    }

                    try
                    {
                        if (parts[4] == "color")
                        {
                            float red = GetFloat(parts[5], values);
                            float green = GetFloat(parts[6], values);
                            float blue = GetFloat(parts[7], values);

                            MyColor color = new MyColor(red, green, blue);

                            Vector v1 = loadedVertices[parts[1]];
                            Vector v2 = loadedVertices[parts[2]];
                            Vector v3 = loadedVertices[parts[3]];

                            Triangle tri = new Triangle(v1, v2, v3, color);
                            triangles.Add(tri);
                        }
                        else if (parts[4] == "texture")
                        {
                            Vector v1 = loadedVertices[parts[1]];
                            Vector v2 = loadedVertices[parts[2]];
                            Vector v3 = loadedVertices[parts[3]];

                            string textureName = parts[5];

                            Triangle tri = new Triangle(v1, v2, v3, (uint)loadedTextures[textureName]);
                            triangles.Add(tri);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("error creating triangle in input file. line: " + lineCounter.ToString() + " . message: " + e.Message);
                    }
                    #endregion
                }
                else if (line.Contains("texture"))
                {
                    #region texture
                    string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    string file = parts[1];
                    string name = parts[2];

                    texturesCount++;
                    loadedTextures[name] = texturesCount;
                    LoadTexture(file, texturesCount);
                    #endregion
                }
                else if (line.Contains("value"))
                {
                    #region value
                    string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    string name = parts[1];
                    float value = float.Parse(parts[2]);

                    values[name] = value;
                    #endregion
                }
                else if(line.Contains("clearValues"))
                {
                    values = new Dictionary<string,float>();
                }
                else
                {
                    throw new Exception("line " + lineCounter.ToString() + " not understood");
                }

            }

            reader.Close();

            lastMouseX = Cursor.Position.X;
            lastMouseY = Cursor.Position.Y;
        }
        private void LoadPO(string file, bool ignore_revision = false)
        {
            int line = 0;
            int strings = 0;
            string Quote = "\"";
            Dictionary<string, int> line_continuations = new Dictionary<string, int>();
            Dictionary<int, string> plurals = new Dictionary<int, string>();
            string comment_running = string.Empty;

            int min = int.MaxValue;
            int max = int.MinValue;

            string[] folders = System.IO.Path.GetDirectoryName(file).Split(System.IO.Path.DirectorySeparatorChar);
            string language = folders[folders.Count() - 1];

            string header = "msgid \"\"\r\nmsgstr \"\"";
            StreamReader po = new FileInfo(file).OpenText();
            string po_line = po.ReadLine().Trim(); line += 1;

            for (int i = 0; i <= present.GetUpperBound(0); i++)
            {
                present[i] = false;
                current_text[i] = string.Empty;
            }

            Console.Write("Reading '" + file + "' ... ");

            while (po_line.StartsWith("#"))
            {
                po_line = po.ReadLine().Trim(); line += 1;
            }

            po_line += "\r\n" + po.ReadLine(); line += 1;

            if (po_line == header)
            {
                po_line = po.ReadLine(); line += 1;
                while (po_line.Length > 0)
                {
                    string name = po_line.Substring(0, po_line.IndexOf(":"));
                    string value = po_line.Substring(po_line.IndexOf(":") + 1).Trim();
                    if (name[0] == '\"') name = name.Substring(1);
                    if (value[value.Length - 1] == '\"') value = value.Substring(0, value.Length - 1);
                    if (ignore_revision == false) revision_info.Add(name, value);

                    po_line = po.ReadLine(); line += 1;
                }
                if (ignore_revision == false) revision_info.Add("Language-Name", language);

                bool need_read = false;
                int id = int.MinValue;
                int line_contd = keyword_unknown;
                int plural_case = -1;

                while (po.EndOfStream == false)
                {
                    if (need_read)
                    {
                        po_line = po.ReadLine().Trim(); line += 1;
                    }
                    else
                    {
                        need_read = true; // read on the next pass
                    }

                    if (po_line.Length == 0)
                    {
                        if (current_text[keyword_msg_context].Length > 0)
                        {
                            try
                            {
                                if (id > max) max = id;
                                if (id < min) min = id;
                                if (current_text[keyword_msg_plural] == string.Empty && plurals.Count == 0)
                                {
                                    map.Add(id, new TextResource(id, current_text[keyword_msg_id], current_text[keyword_msg_text], comment_running));
                                }
                                else
                                {
                                    map.Add(id, new TextResource(id, current_text[keyword_msg_id], current_text[keyword_msg_text], comment_running, current_text[keyword_msg_plural], plurals));
                                }
                                strings++;
                            }
                            catch (ArgumentException ex)
                            {
                                throw new FileLoadException(string.Format("Duplicate message id on line {0} in file {1}. {2}", line, file, ex));
                            }
                        }
                        comment_running = string.Empty;
                        id = int.MinValue;
                        line_contd = keyword_unknown;
                        for (int i = 0; i <= present.GetUpperBound(0); i++)
                        {
                            present[i] = false;
                            current_text[i] = string.Empty;
                        }
                        plurals = new Dictionary<int, string>();
                    }
                    else
                    {
                        if (po_line.StartsWith("#") == true)
                        {
                            if (po_line.StartsWith("#empty string") == false)
                            {
                                comment_running += po_line;
                            }
                        }
                        else
                        {
                            int token = keyword_unknown;
                            for (int i = 0; i <= po_allowed.GetUpperBound(0); i++)
                            {
                                if (po_line.StartsWith(po_allowed[i]))
                                {
                                    token = i;
                                    break;
                                }
                            }

                            switch (token)
                            {
                                case keyword_msg_context:
                                case keyword_msg_id:
                                case keyword_msg_plural:
                                case keyword_msg_text:
                                    {
                                        if (present[token] == false)
                                        {
                                            if (token != keyword_msg_context) // no line continuation for context
                                            {
                                                line_contd = token;
                                            }
                                            current_text[token] = po_line.Substring(po_allowed[token].Length);
                                            if (current_text[token].EndsWith(Quote))
                                            {
                                                current_text[token] = current_text[token].Substring(0, current_text[token].Length - 1);
                                            }
                                            else
                                            {
                                                Console.WriteLine("Warning: Line {0} does not end with a \".", line);
                                            }
                                            present[token] = true;

                                            if (token == keyword_msg_context)
                                            {
                                                string num_id = po_line.Substring((po_allowed[token]+"#").Length);
                                                if (num_id.EndsWith(Quote))
                                                {
                                                    num_id = num_id.Substring(0, num_id.Length - 1);
                                                }
                                                else
                                                {
                                                    Console.WriteLine("Warning: Line {0} does not end with a \".", line);
                                                }
                                                if (int.TryParse(num_id, out id) == false)
                                                    throw new FileLoadException(string.Format("Expecting numeric message id on line {0} in file {1}.", line, file));
                                             }
                                        }
                                        else
                                        {
                                            throw new FileLoadException(string.Format("Unexpected PO token on line {0} in file {1}.", line, file));
                                        }

                                        break;
                                    }
                                case keyword_msg_plural_string:
                                    {
                                        plural_case = -1;
                                        line_contd = token;

                                        string plural = po_line.Substring((po_allowed[token].Length));
                                        if (plural.Contains(']'))
                                        {
                                            string p = plural.Substring(0,plural.IndexOf(']')).Trim();

                                            if (int.TryParse(p, out plural_case) == true)
                                            {
                                                plural = plural.Substring(plural.IndexOf(']') + 1).Trim();
                                                if (plural.StartsWith(Quote))
                                                {

                                                    if (plurals.ContainsKey(plural_case) == false)
                                                    {
                                                        if (plural.EndsWith(Quote))
                                                        {
                                                            plural = plural.Substring(1, plural.Length - 2);
                                                        }
                                                        else
                                                        {
                                                            Console.WriteLine("Warning: Line {0} does not end with a \".", line);
                                                        }
                                                        plurals.Add(plural_case, plural);
                                                    }
                                                    else
                                                    {
                                                        throw new FileLoadException(string.Format("Duplicate plural string resource [case {0}] on line {1} in file {2}.", plural_case, line, file));
                                                    }
                                                }
                                                else
                                                {
                                                    throw new FileLoadException(string.Format("Expecting plural string resource [case {0}] on line {1} in file {2}.", plural_case, line, file));
                                                }
                                            }
                                            else
                                            {
                                                throw new FileLoadException(string.Format("Expecting numeric plural case id on line {0} in file {1}.", line, file));
                                            }
                                        }
                                        else
                                        {
                                            throw new FileLoadException(string.Format("Expecting terminating ] on line {0} in file {1}.", line, file));
                                        }

                                        break;
                                    }
                                case po_line_continuation:
                                    {
                                        if (line_contd != keyword_unknown)
                                        {
                                            if (line_continuations.ContainsKey(current_text[keyword_msg_context]) == false)
                                            {
                                                line_continuations.Add(current_text[keyword_msg_context], 1);
                                            }

                                            string text = po_line.Substring(po_allowed[token].Length);
                                            if (text.EndsWith(Quote))
                                            {
                                                text = text.Substring(0, text.Length - 1);
                                            }
                                            else
                                            {
                                                Console.WriteLine("Warning: Line {0} does not end with a \".", line);
                                            }
                                            if (line_contd == keyword_msg_plural_string)
                                            {
                                                if (plurals.ContainsKey(plural_case))
                                                {
                                                    plurals[plural_case] += text;
                                                }
                                                else
                                                {
                                                    throw new FileLoadException(string.Format("Expecting to continue a string declaration from the previous line on line {0} in file {1}", line, file));
                                                }
                                            }
                                            else
                                            {
                                                current_text[line_contd] += text;
                                            }
                                        }
                                        else
                                        {
                                            throw new FileLoadException(string.Format("Expecting to continue a string declaration from the previous line on line {0} in file {1}", line, file));
                                        }
                                        break;
                                    }
                                case keyword_unknown:
                                    {
                                        throw new FileLoadException(string.Format("Expecting PO token on line {0} in file {1}.", line, file));
                                    }
                                default:
                                    {
                                        goto case keyword_unknown;
                                    }
                            }
                        }
                    }
                }

                if (current_text[keyword_msg_context].Length > 0)
                {
                    try
                    {
                        if (id > max) max = id;
                        if (id < min) min = id;
                        if (current_text[keyword_msg_plural] == string.Empty && plurals.Count == 0)
                        {
                            map.Add(id, new TextResource(id, current_text[keyword_msg_id], current_text[keyword_msg_text], comment_running));
                        }
                        else
                        {
                            map.Add(id, new TextResource(id, current_text[keyword_msg_id], current_text[keyword_msg_text], comment_running, current_text[keyword_msg_plural], plurals));
                        }
                        strings++;
                    }
                    catch (ArgumentException ex)
                    {
                        throw new FileLoadException(string.Format("Duplicate message id on line {0} in file {1}. {2}", line, file, ex));
                    }
                }

                Console.WriteLine(strings.ToString() + " string(s) [" + min.ToString() + " thru " + max.ToString() + "]");

                foreach (string contd in line_continuations.Keys)
                {
                    Console.WriteLine(string.Format("Warning: Line continuation for context {0} in file {1}", contd, file));
                }
            }
            else
            {
                throw new FileLoadException(string.Format("Expecting message header magic on line {0} in file {1}.", line, file));
            }
        }
Ejemplo n.º 12
0
        private void textBoxDir_TextChanged(object sender, EventArgs e)
        {
            imagini.Clear();
            imaginiCheie.Clear();
            listaFisiere.Clear();
            pictureBox1.Image = null;

            if (IO.Directory.Exists(textBoxDir.Text))
            {
                //Asociere director cu aliniamentul
                using (acadDoc.LockDocument())
                    using (Transaction trdir = db.TransactionManager.StartTransaction())
                        using (ResultBuffer RB = new ResultBuffer(new TypedValue(1001, "OVIDIU"), new TypedValue(1000, "POZE->" + textBoxDir.Text)))
                        {
                            //Alignment Ax = (Alignment)trans.GetObject(((Alignment)comboBoxAx.SelectedItem).Id, OpenMode.ForWrite);
                            string    nume = ((Alignment)comboBoxAx.SelectedItem).Name;
                            Alignment Ax   = null;
                            foreach (ObjectId idAx in civDoc.GetAlignmentIds())
                            {
                                Ax = (Alignment)trdir.GetObject(idAx, OpenMode.ForRead);
                                if (Ax.Name == nume)
                                {
                                    Ax.UpgradeOpen();
                                    Ax.XData = RB;
                                }
                            }
                            //Ax.UpgradeOpen();
                            //Ax.XData = RB;


                            //Capturare Senzor
                            CapturaSenzor();
                            //CapturaSenzor(trans, Ax);
                            //TypedValue[] TVs = new TypedValue[]
                            //{
                            //    new TypedValue(0, "SOLID"),
                            //    new TypedValue(8, "AR-MArker"),
                            //    new TypedValue(62, "3")
                            //};
                            //SelectionFilter SF = new SelectionFilter(TVs);
                            //PromptSelectionResult PSR = ed.SelectAll(SF);
                            //if (PSR.Status != PromptStatus.OK) return;
                            //SelectionSet SS = PSR.Value;
                            //foreach (SelectedObject SO in SS)
                            //{
                            //    Solid S = (Solid)trans.GetObject(SO.ObjectId, OpenMode.ForRead);
                            //    double[] Xs = { S.GetPointAt(0).X, S.GetPointAt(1).X, S.GetPointAt(2).X };
                            //    double[] Ys = { S.GetPointAt(0).Y, S.GetPointAt(1).Y, S.GetPointAt(2).Y };
                            //    double km = double.NaN;
                            //    double offset = double.NaN;
                            //    try
                            //    {
                            //        Ax.StationOffset(Xs.Average(), Ys.Average(), ref km, ref offset);
                            //    }
                            //    catch { }
                            //    if (offset != double.NaN)
                            //    {
                            //        if (Senzor == null) Senzor = S;
                            //        else
                            //        {
                            //            double[] SenzorXs = { Senzor.GetPointAt(0).X, Senzor.GetPointAt(1).X, Senzor.GetPointAt(2).X };
                            //            double[] SenzorYs = { Senzor.GetPointAt(0).Y, Senzor.GetPointAt(1).Y, Senzor.GetPointAt(2).Y };
                            //            double SenzorKm = double.NaN;
                            //            double SenzorOffset = double.NaN;
                            //            try
                            //            {
                            //                Ax.StationOffset(SenzorXs.Average(), SenzorYs.Average(), ref SenzorKm, ref SenzorOffset);
                            //                if (offset < SenzorOffset) Senzor = S;
                            //            }
                            //            catch { }
                            //        }
                            //    }
                            //}
                            //if (Senzor != null) checkBoxSincr.Checked = true; //

                            trdir.Commit();
                        }//

                //Inregistrare vedere curenta
                VTRcur = ed.GetCurrentView().Clone() as ViewTableRecord;

                //Citire imaginiCheie din fisierul CALIBRARE.TXT daca acesta exista
                if (IO.File.Exists(textBoxDir.Text + @"\CALIBRARE.TXT"))
                {
                    using (IO.StreamReader reader = new IO.FileInfo(textBoxDir.Text + @"\CALIBRARE.TXT").OpenText())
                    {
                        string linie = null;
                        while ((linie = reader.ReadLine()) != null)
                        {
                            if (linie.Contains("********"))
                            {
                                try
                                {
                                    string[] componente = linie.Remove(0, 4).Replace("********", "").Split(new string[] { "-> " }, StringSplitOptions.None);
                                    imaginiCheie.Add(int.Parse(componente[0]), componente[1]);
                                }
                                catch { }
                            }
                        }
                    }
                    //WF.MessageBox.Show("Numar chei citite: " + imaginiCheie.Count.ToString() + ": " + imaginiCheie.ToString());
                }

                ActualizarePoze();
            }
            else
            {
                textBoxDir.Text = @"-";
            }
        }
Ejemplo n.º 13
0
        private void LoadPO(string file, bool ignore_revision = false)
        {
            int line = 0;
            int strings = 0;
            string comment = string.Empty;
            string comment_running = comment;
            int min = int.MaxValue;
            int max = int.MinValue;

            string[] folders = System.IO.Path.GetDirectoryName(file).Split(System.IO.Path.DirectorySeparatorChar);
            string language = folders[folders.Count() - 1];

            string header = "msgid \"\"\r\nmsgstr \"\"";
            StreamReader po = new FileInfo(file).OpenText();
            string h = po.ReadLine().Trim(); line += 1;

            Console.Write("Reading '" + file + "' ... ");

            while (h.StartsWith("#"))
            {
                h = po.ReadLine().Trim(); line += 1;
            }

            h += "\r\n" + po.ReadLine(); line += 1;

            if (h == header)
            {
                h = po.ReadLine(); line += 1;
                while (h.Length > 0)
                {
                    string name = h.Substring(0, h.IndexOf(":"));
                    string value = h.Substring(h.IndexOf(":") + 1).Trim();
                    if (name[0] == '\"') name = name.Substring(1);
                    if (value[value.Length - 1] == '\"') value = value.Substring(0, value.Length - 1);
                    if (ignore_revision == false) revision_info.Add(name, value);
                    h = po.ReadLine(); line += 1;
                }
                if (ignore_revision == false) revision_info.Add("Language-Name", language);
                string numid = "";
                string key;
                string text;

                while (po.EndOfStream == false)
                {
                    numid = po.ReadLine().Trim(); line += 1;

                    if (numid.StartsWith("msgctxt \"#") == true)
                    {
                        comment = comment_running;
                        comment_running = string.Empty;

                        numid = numid.Substring("msgctxt \"#".Length);
                        if (numid.EndsWith("\"")) numid = numid.Substring(0, numid.Length - 1);

                        key = po.ReadLine().Trim(); line += 1;
                        if (key.StartsWith("msgid \"") == true)
                        {
                            key = key.Substring("msgid \"".Length);
                            if (key.EndsWith("\"")) key = key.Substring(0, key.Length - 1);
                        }
                        else
                            throw new FileLoadException(string.Format("Expecting textual message id on line {0} in file {1}.", line, file));

                        text = po.ReadLine().Trim(); line += 1;
                        if (text.StartsWith("msgstr \"") == true)
                        {
                            text = text.Substring("msgstr \"".Length);
                            if (text.EndsWith("\"")) text = text.Substring(0, text.Length - 1);
                        }
                        else
                            throw new FileLoadException(string.Format("Expecting resource message on line {0} in file {1}.", line, file));

                        string empty = po.ReadLine(); line += 1;

                        int id = 0;
                        if (int.TryParse(numid, out id) == false)
                            throw new FileLoadException(string.Format("Expecting numeric message id on line {0} in file {1}.", line, file));

                        try
                        {
                            if (id > max) max = id;
                            if (id < min) min = id;
                            map.Add(id, new TextResource(id, key, text, comment));
                            comment = string.Empty;
                            strings++;
                        }
                        catch (ArgumentException ex)
                        {
                            throw new FileLoadException(string.Format("Duplicate message id on line {0} in file {1}. {2}", line, file, ex));
                        }

                    }
                    else
                        if (numid.Length > 0 && numid.StartsWith("#") == false)
                        {
                            throw new FileLoadException(string.Format("Expecting numeric message id on line {0} in file {1}.", line, file));
                        }
                        else
                        {
                            if (numid.Length > 0 && numid.StartsWith("#empty string") == false)
                            {
                                comment_running += numid;
                            }
                        }
                }

                Console.WriteLine(strings.ToString() + " string(s) [" + min.ToString() + " thru " + max.ToString() + "]");
            }
            else
            {
                throw new FileLoadException(string.Format("Expecting message header magic on line {0} in file {1}.", line, file));
            }
        }