Beispiel #1
0
        public void TestCreateTextFileHome()
        {
            // this test does not really challange the delay caused by massive parallel change operations in Dropbox
            var tf = new TextFile("~/TestTextFileHome.txt");

            tf.Append("Hallo");
            tf.Append("World");
            tf[6]   = "Seventh line"; // should not throw an exception but extend the size of the collection
            tf[999] = "Line 1000";
            tf.Save(backup: true);
            Assert.True(File.Exists(tf.FullName));
            tf.rm();
            Assert.False(File.Exists(tf.FullName), "File is supposed to have vanished by now - not in dropbox => no delay.");
        }
Beispiel #2
0
        public void TestRaiFileEnsure()
        {   // this test does not really challange the delay caused by massive parallel change operations in Dropbox
            var f0 = new RaiFile($"{TestDir}/Data/EnsureTests/kill.txt");

            f0.mkdir();
            var f = new TextFile($"{TestDir}/Data/EnsureTests/kill.txt");

            for (int i = 0; i < 10000; i++)
            {
                f.Append("Test line " + i.ToString());
            }
            f.Save();
            var f2      = new RaiFile($"{TestDir}/Data/EnsureTests/kill2.txt");
            var start   = DateTimeOffset.UtcNow;
            var result1 = f2.cp(f);

            Assert.True(File.Exists(f2.FullName), "File is supposed to have materialized by now.");
            var cpDuration = DateTimeOffset.UtcNow - start;
            var f3         = new TmpFile();
            var result2    = f3.mv(f2);

            Assert.True(File.Exists(f3.FullName), "File is supposed to have materialized by now.");
            Assert.False(File.Exists(f2.FullName), "File is supposed to have vanished by now.");
            Assert.Equal(0, result1 + result2);
        }
Beispiel #3
0
        public void TestTextFile()
        {
            var f = new TextFile($"{TestDir}/Data/temp/kill/308024_11.text");

            f.mkdir();  // <= doesn't seem to work
            f.Append("1: first line");
            f.Save();
            f.Insert(0, "2: second line");
            f.Insert(1, "3: third line");
            f.Save();
            f.Sort();
            f.Save(true);
        }
Beispiel #4
0
        private void ReadHistoricalFilesFromWeb(DateTime t1, DateTime t2)
        {
            int      wy = DateTime.Now.WaterYear();
            TextFile tf = new TextFile(new string[] { });

            if (!InCurrentWaterYear(t1, t2))
            {
                //string filename = Path.Combine(dir, siteName + "_all.txt");
                var data = Web.GetPage(url + state + "/" + siteName + "_all.txt", true);
                tf.Append(data);
            }

            var lines = Web.GetPage(url + state + "/" + siteName + "_" + wy + ".tab", true);

            tf.Append(lines);

            int errorCount = 0;

            if (tf.Length == 0)
            {
                return;
            }
            string a   = tf[0];
            int    idx = a.LastIndexOf("-");

            Name = a.Substring(0, idx);
            a    = a.Substring(idx + 1);
            string[] cols = TextFile.Split(a);

            int idxData = Array.IndexOf(cols, columnName);

            if (idxData < 0)
            {
                Console.WriteLine("Can't find column '" + columnName + "'");
                return;
            }


            for (int i = 1; i < tf.Length; i++)
            {
                string[] tokens = tf[i].Split('\t');//.Split(i);

                if (idxData >= tokens.Length)
                {
                    continue;
                }

                if (!Regex.IsMatch(tokens[0], "[0-9]{6}"))
                {
                    errorCount++;
                    if (errorCount < 100)
                    {
                        Console.WriteLine("skipping:'" + tf[i] + "'");
                    }
                    continue;
                }
                DateTime t = ParseDate(tokens[0]);

                if (columnName.Trim().ToLower() != "prcp")
                {
                    t = t.AddDays(-1);
                }
                if (t < t1 || t >= t2)
                {
                    continue;
                }


                double num = 0;
                if (!Double.TryParse(tokens[idxData], out num))
                {
                    errorCount++;
                    if (errorCount < 100)
                    {
                        Console.WriteLine("Error parsing '" + tokens[idxData] + "'");
                        Console.WriteLine("from line " + tf[i]);
                    }
                    AddMissing(t);
                    continue;
                }
                Add(t, num);
            }
        }