4 using System
.Collections
;
8 namespace Wv
.Schedulator
10 public class LogSource
: Source
14 public LogSource(Schedulator s
, string name
, string logstr
)
20 public static Source
create(Schedulator s
, string name
,
21 string prefix
, string suffix
)
23 return new LogSource(s
, name
, suffix
);
26 static string clean_filename(string s
)
31 if (Char
.IsLetterOrDigit(c
))
39 static string get_file_from_id(string id
)
43 StreamReader r
= File
.OpenText(
44 String
.Format("schedules/{0}.sched.log",
55 public static Source
create_from_file_id(Schedulator s
, string name
,
56 string prefix
, string suffix
)
58 string id
= wv
.isempty(suffix
) ? s
.name
: suffix
;
59 return new LogSource(s
, name
, get_file_from_id(id
));
65 origest
= TimeSpan
.Zero
,
66 currest
= TimeSpan
.Zero
;
70 public override void cleanup_tasks()
72 Hashtable changes
= new Hashtable();
74 string[] lines
= logstr
.Split("\n".ToCharArray());
75 foreach (string line
in lines
)
77 string[] words
= line
.Split(" ".ToCharArray());
78 if (words
.Length
< 2) continue;
79 string key
= HttpUtility
.UrlDecode(words
[0]);
80 string value = HttpUtility
.UrlDecode(words
[1]);
82 if (words
.Length
>= 3)
83 date
= DateTime
.Parse(words
[2]);
85 date
= DateTime
.Parse("1999-01-01");
88 if (changes
[key
] != null)
89 v
= (Values
)changes
[key
];
95 if (wv
.isempty(v
.origest
) && !wv
.isempty(v
.currest
))
96 v
.origest
= v
.currest
;
97 v
.currest
= StringSource
.parse_estimate(0, value);
98 if (wv
.isempty(v
.origest
))
99 v
.origest
= v
.currest
;
103 foreach (string key
in changes
.Keys
)
105 string[] words
= key
.Split("_".ToCharArray(), 3);
106 if (words
.Length
< 3) continue; // invalid
108 Task t
= s
.tasks
.FindById(words
[1] + ":" + words
[2]);
110 continue; // no longer exists, ignore
112 Values v
= (Values
)changes
[key
];
117 t
.currest
= v
.currest
;
118 t
.origest
= v
.origest
;
121 t
.elapsed
= v
.currest
;
125 t
.done
= (!wv
.isempty(t
.currest
) && t
.currest
== t
.elapsed
);
126 if (t
.done
) t
.donedate
= v
.date
;