Beispiel #1
0
        /// <summary>
        /// converts DMS3 formated data for 'dayflag.exe' prorgram into SeriesList
        /// each series is named  instant_cbtt_pcode,
        /// for example  instant_jck_fb
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static SeriesList HydrometDMS3DataToSeriesList(TextFile tf)
        {
            var rval = new SeriesList();

            for (int i = 1; i < tf.Length; i++) // skip first row (header)
            {
                var      strDate = tf[i].Substring(0, 14);
                DateTime t;
                if (!DateTime.TryParseExact(strDate, "yyyyMMMdd HHmm", new CultureInfo("en-US"), System.Globalization.DateTimeStyles.None, out t))
                {
                    Console.WriteLine("Bad Date, Skipping line: " + tf[i]);
                    continue;
                }
                string cbtt        = tf[i].Substring(15, 8).Trim();
                string pcode       = tf[i].Substring(24, 9).Trim();
                string strValue    = tf[i].Substring(34, 10);
                string strFlagCode = tf[i].Substring(56, 3);
                double val         = 0;

                if (!double.TryParse(strValue, out val))
                {
                    Console.WriteLine("Error parsing double " + strValue);
                    continue;
                }

                string name = "instant_" + cbtt + "_" + pcode;
                name = name.ToLower();
                var    idx = rval.IndexOfTableName(name);
                Series s;
                if (idx >= 0)
                {
                    s = rval[idx];
                }
                else
                {
                    s                 = new Series();
                    s.SiteID          = cbtt;
                    s.Parameter       = pcode;
                    s.Name            = cbtt + "_" + pcode;
                    s.Name            = s.Name.ToLower();
                    s.Table.TableName = name;
                    rval.Add(s);
                }

                string flag = DayFiles.FlagFromCode(strFlagCode);
                if (s.IndexOf(t) < 0)
                {
                    s.Add(t, val, flag);
                }
                else
                {
                    Logger.WriteLine(s.SiteID + ":" + s.Parameter + "skipped duplicate datetime " + t.ToString());
                }
            }

            return(rval);
        }
Beispiel #2
0
        public static void WriteToHydrometFile(Series s, string cbtt, string pcode, string user, string filename, bool append = false)
        {
            if (s.Count == 0)
            {
                return;
            }

            bool oldFile = File.Exists(filename);

            StreamWriter output = new StreamWriter(filename, append);

            Console.WriteLine("Writing " + cbtt + "/" + pcode + " to " + filename + " " + s.Count + " records");
            if (!oldFile)
            {
                output.WriteLine("yyyyMMMdd hhmm cbtt     PC        NewValue   OldValue   Flag User:"******"m");
                    pt.Value = missing;
                }

                string str = pt.DateTime.ToString("yyyyMMMdd HHmm").ToUpper()
                             + " " + cbtt.ToUpper().PadRight(8)
                             + " " + pcode.ToUpper().Trim().PadRight(9)
                             + " " + FormatValue(pt.Value)
                             + " " + missing.ToString("F2").PadRight(10)
                             + " " + flagCode.ToString().PadRight(3);
                output.WriteLine(str);
            }


            output.Close();
        }
        public static string RunArchiver(string user, string password, string[] cbtt,
                                         string pcode, DateTime t1, DateTime t2, bool previewOnly)
        {
            string   tmpFile = FileUtility.GetTempFileName(".txt"); // create script.
            TextFile tf      = new TextFile(tmpFile);

            for (int i = 0; i < cbtt.Length; i++)
            {
                if (cbtt[i].Trim() == "" || Regex.IsMatch(cbtt[i], "[^a-zA-z0-9]"))
                {
                    return("Error: invalid cbtt");
                }
                if (Regex.IsMatch(pcode, "[^a-zA-z0-9\\.]"))
                {
                    return("Error: invalid character in pcode");
                }

                if (pcode.Trim() == "")
                {
                    return("Error: empty pcode not allowed!  ");
                }


                if (t2 < t1)
                {
                    return("Error: Invalid Dates -- ending date is less than the beginning date");
                }


                tf.Add("$! -- Archiver script --- ");
                AddVmsScriptHeader(user, tf);

                /*
                 * interpret/nodebug acm 2010Jun14 mck fb
                 * interpret/nodebug acm 2010Jun15 mck fb
                 *
                 * */
                DateTime t = t1.Date;
                if (pcode == "ALL")
                {
                    pcode = "";
                }



                while (t <= t2.Date)
                {
                    tf.Add(DayFiles.ArchiveCommand(cbtt[i], pcode, t));
                    t = t.AddDays(1);
                }
                //tf.Add("$ Mail/subject=\"Archiver data has run for cbtt=[" + cbtt + "]  \" run_archiver.com ktarbet");
            }

            if (previewOnly)
            {
                return(String.Join("\n", tf.FileData));
            }
            else
            {
                tf.SaveAsVms(tf.FileName);
                string t              = DateTime.Now.ToString(timeFormat).ToLower();
                string remoteFile     = "huser1:[edits]run_archiver_" + user + t + ".com";
                string unixRemoteFile = VmsToUnixPath(remoteFile);
                string rval           = SendFileAndRunCommand(user, password, tmpFile, unixRemoteFile, "@" + remoteFile);
                return(rval);
            }
        }