-
Notifications
You must be signed in to change notification settings - Fork 2
/
HydrometEditsVMS.cs
683 lines (567 loc) · 26.2 KB
/
HydrometEditsVMS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
using System;
using Reclamation.Core;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Configuration;
using HydrometTools.ssh;
namespace Reclamation.TimeSeries.Hydromet
{
static class HydrometEditsVMS
{
static string timeFormat = "MMMdyyyy_HH_mm_ss";
public static string HydrometHostAddress
{
get
{
HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences();
if (svr == HydrometHost.PN || svr == HydrometHost.PNLinux)
return ConfigurationManager.AppSettings["BoiseHydrometAddress"];
else
if (svr == HydrometHost.Yakima)
return ConfigurationManager.AppSettings["YakimaHydrometAddress"];
else if (svr == HydrometHost.GreatPlains)
return ConfigurationManager.AppSettings["BillingsHydrometAddress"];
throw new NotImplementedException(svr.ToString());
}
}
/// <summary>
/// Runs multiple Archive commands in a single batch
/// </summary>
/// <param name="user"></param>
/// <param name="password"></param>
/// <param name="commands"></param>
/// <returns></returns>
public static string RunArchiveCommands(string user, string password, string[] commands)
{
//interpret/nodebug acm 2010Jun14 mck fb
string rval = "";
var tmpFile = FileUtility.GetTempFileName(".txt");
TextFile tf = new TextFile(tmpFile);
AddVmsScriptHeader(user, tf);
foreach (var item in commands)
{
tf.Add(item);
rval += "\n" + item;
}
tf.SaveAsVms(tf.FileName);
string t = DateTime.Now.ToString(timeFormat).ToLower();
string remoteFile = "huser1:[edits]run_archiver_" + user + t + ".com";
string unixRemoteFile = VmsToUnixPath(remoteFile);
rval += "\n" + SendFileAndRunCommand(user, password, tmpFile, unixRemoteFile, "@" + remoteFile);
return rval;
}
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;
}
}
public static string RunRawData(string user, string password, string cbtt, DateTime t1, DateTime t2)
{
if (cbtt.Trim() == "" || Regex.IsMatch(cbtt, "[^a-zA-z0-9]"))
{
return "Error: invalid cbtt";
}
if (t2 <= t1)
{
return "Error: Invalid Dates -- ending date must be greater than beginning";
}
string tmpFile = FileUtility.GetTempFileName(".com"); // create script.
TextFile tf = new TextFile(tmpFile);
CreateRawDataCommands(user, cbtt, t1, t2, tf);
//PNHYD0$ mail/subject="karl test" get_all_gstable.com ktarbet
// tf.Add("$ Mail/subject=\"Raw data has run for cbtt=["+cbtt + "] \" run_rawdata.com ktarbet");
tf.SaveAsVms(tf.FileName);
string t = DateTime.Now.ToString(timeFormat).ToLower();
string remoteFile = "huser1:[edits]run_rawdata_" + user + t + ".com";
string unixRemoteFile = VmsToUnixPath(remoteFile);
string rval = SendFileAndRunCommand(user, password, tmpFile, unixRemoteFile, "@" + remoteFile);
return rval;
}
private static void CreateRawDataCommands(string user, string cbtt, DateTime t1, DateTime t2, TextFile tf)
{
/*
day=2010Jun14
g/00:00,23:59/route=huser1:[jdoty]route.dat/brief mck
day=2010Jun15
g/a/route=huser1:[jdoty]route.dat/brief mck
day=2010Jun16
*/
bool singleDay = t1.Date == t2.Date;
tf.Add("$! -- rawdata script --- ");
AddVmsScriptHeader(user, tf);
tf.Add("$ rawdata");
tf.Add("day=" + t1.ToString("yyyyMMMdd"));
if (singleDay)
{
tf.Add("g/" + t1.ToString("HH") + ":" + t1.ToString("mm") + ","
+ t2.ToString("HH") + ":" + t2.ToString("mm") + "/route=huser1:[edits]route.dat/brief " + cbtt);
}
else // multi day
{
tf.Add("g/" + t1.ToString("HH") + ":" + t1.ToString("mm") + ",23:59/route=huser1:[edits]route.dat/brief " + cbtt);
DateTime t = t1.Date.AddDays(1);
while (t <= t2.Date)
{
tf.Add("day=" + t.ToString("yyyyMMMdd"));
if (t.Date == t2.Date)
{// final value. look at hour and minute.
tf.Add("g/00:00," + t2.ToString("HH") + ":" + t2.ToString("mm") + "/route=huser1:[edits]route.dat/brief " + cbtt);
}
else
{
tf.Add("g/all/route=huser1:[edits]route.dat/brief " + cbtt);
}
t = t.Date.AddDays(1);
}
}
tf.Add("$ Exit");
}
public static string RunRatingTableMath(string user, string password, string cbtt, string pcodeIn,
string pcodeOut, DateTime t1, DateTime t2, bool ace = false)
{
if (cbtt.Trim() == "" || Regex.IsMatch(cbtt, "[^a-zA-z0-9]")
|| pcodeIn.Trim() == "" || Regex.IsMatch(pcodeIn, "[^a-zA-z0-9]")
|| pcodeOut.Trim() == "" || Regex.IsMatch(pcodeOut, "[^a-zA-z0-9]"))
{
return "Error: invalid cbtt or pcode";
}
if (t2 <= t1)
{
return "Error: Invalid Dates (%rating) -- ending date must be greater than beginning";
}
string tmpFile_dfp = FileUtility.GetTempFileName(".dfp"); // create script.
string tmpFile_com = FileUtility.GetTempFileName(".com");
TextFile tf_dfp = new TextFile(tmpFile_dfp);
TextFile tf_com = new TextFile(tmpFile_com);
CreateRatingMathCommands(user, cbtt, pcodeIn, pcodeOut, t1, t2, tf_dfp, ace);
string t = DateTime.Now.ToString(timeFormat).ToLower();
string remoteFile_dfp = "huser1:[edits]math_cmds_" + user + t + ".dfp";
string remoteFile_com = "huser1:[edits]run_math_" + user + t + ".com";
string unixRemoteFile_dfp = VmsToUnixPath(remoteFile_dfp);
string unixRemoteFile_com = VmsToUnixPath(remoteFile_com);
tf_com.Add("$! -- Archiver script --- ");
AddVmsScriptHeader(user, tf_com);
tf_com.Add("$day");
tf_com.Add("@" + remoteFile_dfp);
tf_dfp.SaveAsVms(tf_dfp.FileName);
tf_com.SaveAsVms(tf_com.FileName);
if (!SendFile(user, password, tmpFile_dfp, unixRemoteFile_dfp))
{
return "Error sending file to server '" + remoteFile_com + "'";
}
string rval = SendFileAndRunCommand(user, password, tmpFile_com, unixRemoteFile_com, "@" + remoteFile_com);
return rval;
}
/// <summary>
/// Allow users to compute daily ratings. Computes ratings from daily gage heights and forebay elevations.
/// </summary>
/// <param name="user"></param>
/// <param name="password"></param>
/// <param name="cbtt"></param>
/// <param name="pcodeIn"></param>
/// <param name="pcodeOut"></param>
/// <param name="t1"></param>
/// <param name="t2"></param>
/// <param name="ace"></param>
/// <returns></returns>
public static string RunRatingTableMathArchives(string user, string password, string cbtt, string pcodeIn,
string pcodeOut, DateTime t1, DateTime t2, bool ace = false)
{
if (cbtt.Trim() == "" || Regex.IsMatch(cbtt, "[^a-zA-z0-9]")
|| pcodeIn.Trim() == "" || Regex.IsMatch(pcodeIn, "[^a-zA-z0-9]")
|| pcodeOut.Trim() == "" || Regex.IsMatch(pcodeOut, "[^a-zA-z0-9]"))
{
return "Error: invalid cbtt or pcode";
}
if (t2 <= t1)
{
return "Error: Invalid Dates (%rating) -- ending date must be greater than beginning";
}
if (ace)
{
pcodeOut = "ACE";
}
string tmpFile_com = FileUtility.GetTempFileName(".com");
TextFile tf_com = new TextFile(tmpFile_com);
string t = DateTime.Now.ToString(timeFormat).ToLower();
string remoteFile_com = "huser1:[edits]run_daily_rating" + user + t + ".com";
string unixRemoteFile_com = VmsToUnixPath(remoteFile_com);
tf_com.Add("$! -- Rating_Daily script --- ");
AddVmsScriptHeader(user, tf_com);
tf_com.Add("$INTERPRET DLY_RATING/NODEBUG " + t1.ToString("yyyyMMMdd") + " " + t2.ToString("yyyyMMMdd") + " " + cbtt.Trim().ToUpper() + " " + pcodeIn.ToUpper() + " " + pcodeOut.ToUpper());
tf_com.SaveAsVms(tf_com.FileName);
if (!SendFile(user, password, tf_com.FileName, unixRemoteFile_com))
{
return "Error sending file to server '" + remoteFile_com + "'";
}
string rval = SendFileAndRunCommand(user, password, tmpFile_com, unixRemoteFile_com, "@" + remoteFile_com);
return rval;
}
/// <summary>
/// Lets users run the "FIXINFLO" procedure directly from HydrometTools.
/// This is a procedure that calculates the inflow for some GP's more complicated reservoirs, and it is not run by the archiver.
/// </summary>
/// <param name="user"></param>
/// <param name="password"></param>
/// <param name="cbtt"></param>
/// <param name="t1"></param>
/// <param name="t2"></param>
/// <returns></returns>
public static string RunGPFixInflowProc(string user, string password, string cbtt,
DateTime t1, DateTime t2)
{
if (cbtt.Trim() == "" || Regex.IsMatch(cbtt, "[^a-zA-z0-9]"))
{
return "Error: invalid cbtt or pcode";
}
if (t2 <= t1)
{
return "Error: Invalid Dates (@fixinflo) -- ending date must be greater than beginning";
}
string tmpFile_com = FileUtility.GetTempFileName(".com");
TextFile tf_com = new TextFile(tmpFile_com);
string t = DateTime.Now.ToString(timeFormat).ToLower();
string remoteFile_com = "huser1:[edits]run_math_" + user + t + ".com";
string unixRemoteFile_com = VmsToUnixPath(remoteFile_com);
tf_com.Add("$! -- Fixinflo script --- ");
AddVmsScriptHeader(user, tf_com);
tf_com.Add("INTERPRET FIXINFLO/NODEBUG " + t1.ToString("yyyyMMMdd") + " " + cbtt.Trim() + " " + t2.ToString("yyyyMMMdd"));
tf_com.SaveAsVms(tf_com.FileName);
if (!SendFile(user, password, tf_com.FileName, unixRemoteFile_com))
{
return "Error sending file to server '" + remoteFile_com + "'";
}
string rval = SendFileAndRunCommand(user, password, tmpFile_com, unixRemoteFile_com, "@" + remoteFile_com);
return rval;
}
private static void AddVmsScriptHeader(string user, TextFile tf)
{
string un = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
tf.Add("$! generated by HydrometTools " + DateTime.Now.ToString());
tf.Add("$! username: " + un + " " + user);
tf.Add("$! ----------------------------------");
tf.Add("$interpret:== $SUTRON$:[rtcm]rtcm");
HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences();
if (svr == HydrometHost.PN || svr == HydrometHost.Yakima || svr == HydrometHost.PNLinux)
{
tf.Add("$set process/priv=syslck");
}
tf.Add("$DAY:== $SUTRON$:[DAYFILE]DAYFILE");
}
private static void CreateRatingMathCommands(string user, string cbtt, string pcodeIn,
string pcodeOut, DateTime t1, DateTime t2, TextFile tf, bool ace)
{
/*
day= 2010Jun14
g/00:00, 23:59/fb,af mck
math/fb,af
mck/af:=%rating(mck/fb)
exit
update
clear
day= 2010Jun15
g/a/fb,af mck
math/fb,af
mck/af:=%rating(mck/fb)
exit
update
clear
*
*
* === GP Region has different column names (instead of AF using ACE in rating table)
day= 2010Jun15
g/a/fb,af gibr
math/fb,af
gibr/ace:=%rating(gibr/fb)
gibr/af :=gibr/ace
remove gibr/ace
exit
update
clear
*
*/
bool singleDay = t1.Date == t2.Date;
tf.Add("day=" + t1.ToString("yyyyMMMdd"));
if (singleDay)
{
tf.Add("FORMAT=NULL");
tf.Add("g/" + t1.ToString("HH") + ":" + t1.ToString("mm") + ","
+ t2.ToString("HH") + ":" + t2.ToString("mm") + "/" + pcodeIn + "," + pcodeOut + " " + cbtt);
tf.Add("math/" + pcodeIn + "," + pcodeOut);
RatingEquation(cbtt, pcodeIn, pcodeOut, tf, ace);
tf.Add("exit");
tf.Add("update");
tf.Add("clear");
}
else // multi day
{
tf.Add("FORMAT=NULL");
tf.Add("g/" + t1.ToString("HH") + ":" + t1.ToString("mm") + ",23:59/" + pcodeIn + "," + pcodeOut + " " + cbtt);
tf.Add("math/" + pcodeIn + "," + pcodeOut);
RatingEquation(cbtt, pcodeIn, pcodeOut, tf, ace);
//tf.Add(cbtt + "/" + pcodeOut + ":=%rating(" + cbtt + "/" + pcodeIn + ")");
tf.Add("exit");
tf.Add("update");
tf.Add("clear");
DateTime t = t1.Date.AddDays(1);
while (t <= t2.Date)
{
tf.Add("day=" + t.ToString("yyyyMMMdd"));
if (t.Date == t2.Date)
{// final value. look at hour and minute.
tf.Add("g/00:00," + t2.ToString("HH") + ":" + t2.ToString("mm") + "/" + pcodeIn + "," + pcodeOut + " " + cbtt);
}
else
{
tf.Add("g/a/" + pcodeIn + "," + pcodeOut + " " + cbtt);
}
tf.Add("math/" + pcodeIn + "," + pcodeOut);
RatingEquation(cbtt, pcodeIn, pcodeOut, tf, ace);
tf.Add("exit");
tf.Add("update");
tf.Add("clear");
t = t.Date.AddDays(1);
}
}
}
private static void RatingEquation(string cbtt, string pcodeIn, string pcodeOut, TextFile tf, bool ace)
{
if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains
&& pcodeIn.ToLower().Trim() == "fb" && ace)
{
tf.Add(cbtt + "/" + "ace" + ":=%rating(" + cbtt + "/" + pcodeIn + ")");
tf.Add(cbtt + "/" + pcodeOut + ":=" + cbtt + "/ace");
tf.Add("remove " + cbtt + "/ace");
}
else
{
tf.Add(cbtt + "/" + pcodeOut + ":=%rating(" + cbtt + "/" + pcodeIn + ")");
}
}
public static string SaveDailyData(string user, string password, string localFile,
string remoteFile, bool overwrite = false, bool checkDayfileBuffer = true, bool interactive = true)
{
string rmtFile = VmsToUnixPath(remoteFile);
if (overwrite)
return SendFileAndRunCommand(user, password, localFile, rmtFile, "Arcimport " + remoteFile + " overwrite", checkDayfileBuffer, interactive);
else
return SendFileAndRunCommand(user, password, localFile, rmtFile, "Arcimport " + remoteFile, checkDayfileBuffer, interactive);
}
public static string SaveInstantData(string user, string password, string localFile, string remoteFile, bool interactive = true)
{
string rmtFile = VmsToUnixPath(remoteFile);
return SendFileAndRunCommand(user, password, localFile, rmtFile, "dayflag " + remoteFile, true, interactive);
}
public static string RunMpollImport(string user, string password, string localFile, string remoteFile)
{
string rmtFile = VmsToUnixPath(remoteFile);
return SendFileAndRunCommand(user, password, localFile, rmtFile, "mpimport " + remoteFile, false);
}
public static string SendFileAndRunCommand(string user, string password, string localFile,
string remoteFile, string command = "", bool checkDayfileBuffer = true, bool interactive = true)
{
try
{
// wait for any pending procesing.
bool ready = true; // no pending jobs
if (checkDayfileBuffer)
ready = EmptyBuffer(user, password, interactive);
if (ready && SendFile(user, password, localFile, remoteFile))
{
Logger.WriteLine("file copy was sucessful ", "ui");
if (command != "")
{
Logger.WriteLine("Running command '" + command + "'", "ui");
string rval = Utility.RunCommand(HydrometHostAddress, user, password, @"\$", command);
return rval;
}
Logger.WriteLine("done.", "ui");
return "";
}
else
{
return "Error copying file to server. Check permissions and path to server " + remoteFile;
}
}
catch (Exception ex)
{
if (interactive)
System.Windows.Forms.MessageBox.Show(ex.Message);
Logger.WriteLine(ex.Message);
return ex.Message;
}
//Logger.WriteLine("Completed ", "ui");
//return "";
}
/// <summary>
/// check the sutron buffer for pending jobs
/// that may interfere with work. Wait a few seconds if needed
/// </summary>
/// <param name="user"></param>
/// <param name="password"></param>
/// <returns></returns>
private static bool EmptyBuffer(string user, string password, bool interactive = true)
{
string s = "";
for (int i = 0; i < 500; i++)
{
Logger.WriteLine("Checking if server buffer is busy " + i.ToString());
Application.DoEvents();
s = Utility.RunCommand(HydrometHostAddress, user, password, @"\$", "dir DMSSYS:[DMS_V4.DMS402.mbxbuf]*.buf");
if (s.IndexOf("%DIRECT-W-NOFILES, no files found") >= 0)
return true;
Logger.WriteLine("result of shobuf = '" + s + "'");
Logger.WriteLine("Server is busy: Waiting for 10 seconds");
HydrometTools.ssh.Utility.Close(); // hope to fix false busy bug.. (lost connection)
System.Threading.Thread.Sleep(10000);
if (interactive)
{
var result = MessageBox.Show("Click yes continue waiting?", "The server is too busy to perform the command", MessageBoxButtons.YesNo);
if (result == DialogResult.No)
{
//return false;
throw new Exception("Command canceled ");
}
}
}
if (interactive)
System.Windows.Forms.MessageBox.Show("ERROR: Buffer is busy please try later. " + s);
Logger.WriteLine("Error: giving up because after 500 tries the server is still busy");
return false;
}
private static bool SendFile(string user, string password, string localFile, string remoteFile)
{
try
{
Logger.WriteLine("copying " + localFile + " to " + remoteFile, "ui");
SecureCopy.CopyTo(user, HydrometHostAddress, password, localFile, remoteFile);
return true;
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message, "ui");
System.Windows.Forms.MessageBox.Show(ex.Message);
return false;
}
}
public static string VmsToUnixPath(string remoteFile)
{
// convert huser2:[ktarbet.tmp]edits.txt
// to /huser2/ktarbet/tmp/edits.txt
var m = Regex.Match(remoteFile, @"(?<path>.+\:\[.{1,256}\])(?<filename>.{1,50})");
if (m.Success)
{
string path = m.Groups["path"].Value;
string filename = m.Groups["filename"].Value;
path = "/" + path.Replace(":[", "/");
path = path.Replace("]", "/");
path = path.Replace(".", "/");
return path + "" + filename;
}
return remoteFile;
}
/// <summary>
/// Inserts a constant value many times into dayfiles
/// </summary>
/// <param name="user"></param>
/// <param name="password"></param>
/// <param name="t1">starting date/time</param>
/// <param name="t2">ending date/time</param>
/// <param name="value">value to insert</param>
/// <param name="increment">minutes between values</param>
/// <returns></returns>
public static string InsertDayFileValue(string user, string password, DateTime t1,
DateTime t2, string cbtt, string pcode, double value, int increment)
{
DateTime t = t1;
if (t2 < t1)
return "Error dates out of order";
TimeSpan ts = new TimeSpan(t2.Ticks - t1.Ticks);
if (ts.Days > 365)
{
if (System.Windows.Forms.MessageBox.Show("Warning. A large amount of data will be inserted. Is this OK?", "Continue?", System.Windows.Forms.MessageBoxButtons.OKCancel)
!= System.Windows.Forms.DialogResult.OK)
{
return "inserting data was canceled";
}
}
string fn = FileUtility.GetTempFileName(".txt");
StreamWriter output = new StreamWriter(fn);
output.WriteLine("yyyyMMMdd hhmm cbtt PC NewValue OldValue Flag User:" + user);
do
{
string flagCode = "-03";// manually entered data
double missing = 998877.0;
string str = t.ToString("yyyyMMMdd HHmm").ToUpper()
+ " " + cbtt.ToUpper().PadRight(8)
+ " " + pcode.ToUpper().Trim().PadRight(9)
+ " " + value.ToString("F2").PadRight(10)
+ " " + missing.ToString("F2").PadRight(10)
+ " " + flagCode.ToString().PadRight(3);
output.WriteLine(str);
t = t.AddMinutes(increment);
} while (t <= t2);
output.Close();
string remoteFilename = HydrometDataUtility.CreateRemoteFileName(user, TimeInterval.Irregular);
return SaveInstantData(user, password, fn, remoteFilename);
}
public static string UpdateShift(string user, string password, string cbtt,
string pcode, double shift)
{
string command = "input_shift " + cbtt + " " + pcode + " " + shift.ToString("F2");
Logger.WriteLine("Running command '" + command + "'", "ui");
string rval = Utility.RunCommand(HydrometHostAddress, user, password, @"\$", command);
return rval;
}
}
}