| 1 | #include "StdAfx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <map>
|
|---|
| 4 | #include <list>
|
|---|
| 5 |
|
|---|
| 6 | #include <boost/bind.hpp>
|
|---|
| 7 | #include <boost/assign.hpp>
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | #include <parsers/where.hpp>
|
|---|
| 11 | #include <parsers/filter/where_filter.hpp>
|
|---|
| 12 | #include <parsers/filter/where_filter_impl.hpp>
|
|---|
| 13 |
|
|---|
| 14 | #include <parsers/where/unary_fun.hpp>
|
|---|
| 15 | #include <parsers/where/list_value.hpp>
|
|---|
| 16 | #include <parsers/where/binary_op.hpp>
|
|---|
| 17 | #include <parsers/where/unary_op.hpp>
|
|---|
| 18 | #include <parsers/where/variable.hpp>
|
|---|
| 19 |
|
|---|
| 20 | #include <strEx.h>
|
|---|
| 21 | #include "filter.hpp"
|
|---|
| 22 |
|
|---|
| 23 | #define DATE_FORMAT _T("%#c")
|
|---|
| 24 | using namespace boost::assign;
|
|---|
| 25 | using namespace parsers::where;
|
|---|
| 26 |
|
|---|
| 27 | tasksched_filter::filter_obj_handler::filter_obj_handler() {
|
|---|
| 28 | insert(types)
|
|---|
| 29 | (_T("title"), (type_string))
|
|---|
| 30 | // (_T("account"), (type_string))
|
|---|
| 31 | // (_T("application"), (type_string))
|
|---|
| 32 | // (_T("comment"), (type_string))
|
|---|
| 33 | // (_T("creator"), (type_string))
|
|---|
| 34 | // (_T("parameters"), (type_string))
|
|---|
| 35 | // (_T("working_directory"), (type_string))
|
|---|
| 36 | // (_T("error_retry_count"), (type_int))
|
|---|
| 37 | // (_T("error_retry_interval"), (type_int))
|
|---|
| 38 | // (_T("idle_wait"), (type_int))
|
|---|
| 39 | (_T("exit_code"), (type_int))
|
|---|
| 40 | // (_T("flags"), (type_int))
|
|---|
| 41 | // (_T("max_run_time"), (type_int))
|
|---|
| 42 | // (_T("priority"), (type_int))
|
|---|
| 43 | (_T("status"), (type_custom_hresult))
|
|---|
| 44 | (_T("most_recent_run_time"), (type_date));
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | bool tasksched_filter::filter_obj_handler::has_variable(std::wstring key) {
|
|---|
| 48 | return types.find(key) != types.end();
|
|---|
| 49 | }
|
|---|
| 50 | parsers::where::value_type tasksched_filter::filter_obj_handler::get_type(std::wstring key) {
|
|---|
| 51 | types_type::const_iterator cit = types.find(key);
|
|---|
| 52 | if (cit == types.end())
|
|---|
| 53 | return parsers::where::type_invalid;
|
|---|
| 54 | return cit->second;
|
|---|
| 55 | }
|
|---|
| 56 | bool tasksched_filter::filter_obj_handler::can_convert(parsers::where::value_type from, parsers::where::value_type to) {
|
|---|
| 57 | if ((from == parsers::where::type_string)&&(to == type_custom_hresult))
|
|---|
| 58 | return true;
|
|---|
| 59 | if ((from == parsers::where::type_int)&&(to == type_custom_hresult))
|
|---|
| 60 | return true;
|
|---|
| 61 | return false;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | tasksched_filter::filter_obj_handler::base_handler::bound_string_type tasksched_filter::filter_obj_handler::bind_simple_string(std::wstring key) {
|
|---|
| 65 | base_handler::bound_string_type ret;
|
|---|
| 66 | if (key == _T("title"))
|
|---|
| 67 | ret = &object_type::get_title;
|
|---|
| 68 | // else if (key == _T("account"))
|
|---|
| 69 | // ret = &object_type::get_account_name;
|
|---|
| 70 | // else if (key == _T("application"))
|
|---|
| 71 | // ret = &object_type::get_application_name;
|
|---|
| 72 | // else if (key == _T("comment"))
|
|---|
| 73 | // ret = &object_type::get_comment;
|
|---|
| 74 | // else if (key == _T("creator"))
|
|---|
| 75 | // ret = &object_type::get_creator;
|
|---|
| 76 | // else if (key == _T("parameters"))
|
|---|
| 77 | // ret = &object_type::get_parameters;
|
|---|
| 78 | // else if (key == _T("working_directory"))
|
|---|
| 79 | // ret = &object_type::get_working_directory;
|
|---|
| 80 | // else
|
|---|
| 81 | NSC_DEBUG_MSG_STD(_T("Failed to bind (string): ") + key);
|
|---|
| 82 | return ret;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | tasksched_filter::filter_obj_handler::base_handler::bound_int_type tasksched_filter::filter_obj_handler::bind_simple_int(std::wstring key) {
|
|---|
| 87 | base_handler::bound_int_type ret;
|
|---|
| 88 | // if (key == _T("error_retry_count"))
|
|---|
| 89 | // ret = &object_type::get_error_retry_count;
|
|---|
| 90 | // else if (key == _T("error_retry_interval"))
|
|---|
| 91 | // ret = &object_type::get_error_retry_interval;
|
|---|
| 92 | // // else if (key == _T("idle_wait"))
|
|---|
| 93 | // // ret = &object_type::get_idle_wait;
|
|---|
| 94 | if (key == _T("exit_code"))
|
|---|
| 95 | ret = &object_type::get_exit_code;
|
|---|
| 96 | // else if (key == _T("flags"))
|
|---|
| 97 | // ret = &object_type::get_flags;
|
|---|
| 98 | // else if (key == _T("max_run_time"))
|
|---|
| 99 | // ret = &object_type::get_max_run_time;
|
|---|
| 100 | // else if (key == _T("priority"))
|
|---|
| 101 | // ret = &object_type::get_priority;
|
|---|
| 102 | else if (key == _T("status"))
|
|---|
| 103 | ret = &object_type::get_status;
|
|---|
| 104 | else if (key == _T("most_recent_run_time"))
|
|---|
| 105 | ret = &object_type::get_most_recent_run_time;
|
|---|
| 106 | else
|
|---|
| 107 | NSC_DEBUG_MSG_STD(_T("Failed to bind (int): ") + key);
|
|---|
| 108 | return ret;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | bool tasksched_filter::filter_obj_handler::has_function(parsers::where::value_type to, std::wstring name, expression_ast_type *subject) {
|
|---|
| 112 | if (to == type_custom_hresult)
|
|---|
| 113 | return true;
|
|---|
| 114 | return false;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | long tasksched_filter::filter_obj::convert_status(std::wstring status) {
|
|---|
| 118 | if (status == _T("ready"))
|
|---|
| 119 | return 3;
|
|---|
| 120 | if (status == _T("running"))
|
|---|
| 121 | return 4;
|
|---|
| 122 | if (status == _T("unknown"))
|
|---|
| 123 | return 0;
|
|---|
| 124 | if (status == _T("disabled"))
|
|---|
| 125 | return 1;
|
|---|
| 126 | if (status == _T("queued"))
|
|---|
| 127 | return 2;
|
|---|
| 128 | return strEx::stoi(status);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | std::wstring tasksched_filter::filter_obj::convert_status(long status) {
|
|---|
| 132 | std::wstring ret;
|
|---|
| 133 | if (status == 3)
|
|---|
| 134 | return _T("ready");
|
|---|
| 135 | if (status == 4)
|
|---|
| 136 | return _T("running");
|
|---|
| 137 | if (status == 0)
|
|---|
| 138 | return _T("unknown");
|
|---|
| 139 | if (status == 1)
|
|---|
| 140 | return _T("disabled");
|
|---|
| 141 | if (status == 2)
|
|---|
| 142 | return _T("queued");
|
|---|
| 143 | return strEx::itos(status);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | tasksched_filter::filter_obj_handler::base_handler::bound_function_type tasksched_filter::filter_obj_handler::bind_simple_function(parsers::where::value_type to, std::wstring name, expression_ast_type *subject) {
|
|---|
| 147 | base_handler::bound_function_type ret;
|
|---|
| 148 | if (to == type_custom_hresult)
|
|---|
| 149 | ret = &object_type::fun_convert_status;
|
|---|
| 150 | else
|
|---|
| 151 | NSC_DEBUG_MSG_STD(_T("Failed to bind (function): ") + name);
|
|---|
| 152 | return ret;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 160 |
|
|---|
| 161 | #define DEFINE_GET_EX(type, variable, helper, func) type tasksched_filter::filter_obj::get_ ## variable() { return helper.fetch(this, &IRegisteredTask::func, variable); }
|
|---|
| 162 |
|
|---|
| 163 | #define DEFINE_GET_STRING(variable, helper, func) DEFINE_GET_EX(std::wstring, variable, helper, func)
|
|---|
| 164 | #define DEFINE_GET_DWORD(variable, helper, func) DEFINE_GET_EX(unsigned long, variable, helper, func)
|
|---|
| 165 | #define DEFINE_GET_WORD(variable, helper, func) DEFINE_GET_EX(unsigned short, variable, helper, func)
|
|---|
| 166 | #define DEFINE_GET_DATE(variable, helper, func) DEFINE_GET_EX(tasksched_filter::filter_obj::task_sched_date, variable, helper, func)
|
|---|
| 167 | #define DEFINE_GET_HRESULT(variable, helper, func) DEFINE_GET_EX(long, variable, helper, func)
|
|---|
| 168 |
|
|---|
| 169 | DEFINE_GET_STRING(title, string_fetcher, get_Name);
|
|---|
| 170 | DEFINE_GET_HRESULT(exit_code, hresult_fetcher, get_LastTaskResult);
|
|---|
| 171 | DEFINE_GET_WORD(status, state_fetcher, get_State);
|
|---|
| 172 | DEFINE_GET_DATE(most_recent_run_time, date_fetcher, get_LastRunTime);
|
|---|
| 173 |
|
|---|
| 174 | tasksched_filter::filter_obj::expression_ast_type tasksched_filter::filter_obj::fun_convert_status(parsers::where::value_type target_type, parsers::where::filter_handler handler, expression_ast_type const& subject) {
|
|---|
| 175 | return expression_ast_type(parsers::where::int_value(convert_status(subject.get_string(handler))));
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | std::wstring tasksched_filter::filter_obj::render(std::wstring format, std::wstring datesyntax) {
|
|---|
| 180 | strEx::replace(format, _T("%title%"), get_title());
|
|---|
| 181 | // strEx::replace(format, _T("%account%"), get_account_name());
|
|---|
| 182 | // strEx::replace(format, _T("%application%"), get_application_name());
|
|---|
| 183 | // strEx::replace(format, _T("%comment%"), get_comment());
|
|---|
| 184 | // strEx::replace(format, _T("%creator%"), get_creator());
|
|---|
| 185 | // strEx::replace(format, _T("%parameters%"), get_parameters());
|
|---|
| 186 | // strEx::replace(format, _T("%working_directory%"), get_working_directory());
|
|---|
| 187 | //
|
|---|
| 188 | strEx::replace(format, _T("%exit_code%"), strEx::itos(get_exit_code()));
|
|---|
| 189 | // strEx::replace(format, _T("%error_retry_count%"), strEx::itos(get_error_retry_count()));
|
|---|
| 190 | // strEx::replace(format, _T("%error_retry_interval%"), strEx::itos(get_error_retry_interval()));
|
|---|
| 191 | // strEx::replace(format, _T("%flags%"), strEx::itos(get_flags()));
|
|---|
| 192 | // //strEx::replace(format, _T("%idle_wait%"), strEx::itos(get_idle_wait()));
|
|---|
| 193 | // strEx::replace(format, _T("%max_run_time%"), strEx::itos(get_max_run_time()));
|
|---|
| 194 | // strEx::replace(format, _T("%priority%"), strEx::itos(get_priority()));
|
|---|
| 195 | strEx::replace(format, _T("%status%"), convert_status(get_status()));
|
|---|
| 196 | //
|
|---|
| 197 | // // strEx::replace(format, _T("%next_run%"), strEx::format_date(get_next_run()));
|
|---|
| 198 | if (get_most_recent_run_time()) {
|
|---|
| 199 | task_sched_date date = get_most_recent_run_time();
|
|---|
| 200 | unsigned long long t = date;
|
|---|
| 201 | if (t == 0 || date.never_) {
|
|---|
| 202 | strEx::replace(format, _T("%most_recent_run_time%"), _T("never"));
|
|---|
| 203 | strEx::replace(format, _T("%most_recent_run_time-raw%"), _T("never"));
|
|---|
| 204 | } else {
|
|---|
| 205 | strEx::replace(format, _T("%most_recent_run_time%"), strEx::format_date(t, datesyntax));
|
|---|
| 206 | strEx::replace(format, _T("%most_recent_run_time-raw%"), strEx::itos(t));
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | strEx::replace(format, _T("\n"), _T(""));
|
|---|
| 211 | return format;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 215 |
|
|---|
| 216 | tasksched_filter::filter_engine tasksched_filter::factories::create_engine(tasksched_filter::filter_argument arg) {
|
|---|
| 217 | return filter_engine(new filter_engine_type(arg));
|
|---|
| 218 | }
|
|---|
| 219 | tasksched_filter::filter_argument tasksched_filter::factories::create_argument(std::wstring syntax, std::wstring datesyntax) {
|
|---|
| 220 | return filter_argument(new tasksched_filter::filter_argument_type(tasksched_filter::filter_argument_type::error_type(new where_filter::nsc_error_handler()), syntax, datesyntax));
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | tasksched_filter::filter_result tasksched_filter::factories::create_result(tasksched_filter::filter_argument arg) {
|
|---|
| 224 | return filter_result(new where_filter::simple_count_result<filter_obj>(arg));
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|