コード例 #1
0
        public static ScriptHost.Result MonthlyFinancialEmails(string date, IDictionary <object, object> args)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            QueryParameters queryParams = QueryParameters.Create(args);

            DateTime d = DateTime.Parse(date);

            var opt = new FinancialManagerReportOptions
            {
                ClientID       = 0,
                ManagerOrgID   = 0,
                Period         = d,
                IncludeManager = queryParams.GetValue("IncludeManager", true),
                Message        = queryParams.GetValue("Message", string.Empty)
            };

            var processResult = Provider.Billing.Report.SendFinancialManagerReport(opt);
            var count         = processResult.TotalEmailsSent;

            result.Success = true;
            result.Message = string.Format("sent {0} emails", count);
            result.Data    = null;

            return(result);
        }
コード例 #2
0
        public static ScriptHost.Result ProwatchCreateUser(int id)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            var c = DataSession.Single <LNF.Impl.Repository.Data.ClientInfo>(id).CreateModel <IClient>();

            if (c == null)
            {
                result.Success = false;
                result.Message = string.Format("ClientID {0} not found", id);
            }
            else
            {
                Badge b = Provider.PhysicalAccess.GetBadge(c.ClientID).FirstOrDefault();

                if (b == null)
                {
                    Provider.PhysicalAccess.AddClient(new AddClientRequest {
                        ClientID = c.ClientID, UserName = c.UserName, FName = c.FName, LName = c.LName, MName = c.MName
                    });
                    result.Success = true;
                    result.Message = "ok";
                }
                else
                {
                    result.Success = false;
                    result.Message = string.Format("ClientID {0} already exists", id);
                }
            }

            return(result);
        }
コード例 #3
0
        public static ScriptHost.Result AccountInfo(object search)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            IEnumerable <AccountInfo> c = null;

            if (search is int)
            {
                var single = DataSession.Single <Account>(Convert.ToInt32(search));

                if (single != null)
                {
                    c = new Account[] { single }.Select(x => new AccountInfo()
                    {
                        AccountID   = x.AccountID,
                        AccountName = x.Name,
                        ShortCode   = x.ShortCode
                    });
                }
            }
            else
            {
                string         s     = search.ToString();
                List <Account> query = new List <Account>();

                query.AddRange(DataSession.Query <Account>().Where(x => x.Name.Contains(s)));
                query.AddRange(DataSession.Query <Account>().Where(x => x.ShortCode.Contains(s)));

                c = query.Select(x => new AccountInfo()
                {
                    AccountID   = x.AccountID,
                    AccountName = x.Name,
                    ShortCode   = x.ShortCode
                }).ToList();
            }

            if (c == null || c.Count() == 0)
            {
                result.Success = false;
                result.Message = string.Format("Accounts not found using {0}", search);
                result.Data    = null;
            }
            else
            {
                result.Success = true;
                result.Message = string.Format("Found {0} accounts\n", c.Count());
                result.Data    = c;
            }

            return(result);
        }
コード例 #4
0
        public static ScriptHost.Result ResetPassword(int id)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            Client c = DataSession.Single <Client>(id);

            if (c != null)
            {
                Provider.Data.Client.AuthUtility().ResetPassword(c.ClientID);
                result.Success = true;
                result.Message = string.Format("{0} password reset.", c.UserName);
            }
            else
            {
                result.Success = false;
                result.Message = string.Format("ClientID {0} not found", id);
            }

            return(result);
        }
コード例 #5
0
        public static ScriptHost.Result Execute(string cmd)
        {
            ScriptHost.Result scriptResult;

            try
            {
                scriptResult = host.Run(cmd);
            }
            catch (Exception ex)
            {
                scriptResult = new ScriptHost.Result()
                {
                    Success = false,
                    Message = ex.Message + "\nUse help() for a list of commands",
                    Data    = null
                };
            }

            return(scriptResult);
        }
コード例 #6
0
        public static ScriptHost.Result TaskCheck(string task)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            string sql;

            switch (task)
            {
            case "daily":
                sql = "SELECT 'ToolDataClean' AS 'TableName', CONVERT(nvarchar(20), MAX(ActualBeginDateTime), 120) AS 'Value' FROM sselData.dbo.ToolDataClean"
                      + " UNION SELECT 'ToolData', CONVERT(nvarchar(20), MAX(ActDate), 120) FROM sselData.dbo.ToolData"
                      + " UNION SELECT 'ToolBillingTemp', CONVERT(nvarchar(20), MAX(ActDate), 120) FROM sselData.dbo.ToolBillingTemp"
                      + " UNION SELECT 'RoomDataClean', CONVERT(nvarchar(20), MAX(EntryDT), 120) FROM sselData.dbo.RoomDataClean"
                      + " UNION SELECT 'RoomData', CONVERT(nvarchar(20), MAX(EvtDate), 120) FROM sselData.dbo.RoomData"
                      + " UNION SELECT 'RoomBillingTemp', CONVERT(nvarchar(20), MAX(Period), 120) FROM sselData.dbo.RoomBillingTemp";
                break;

            case "monthly":
                sql = "SELECT 'ToolDataClean' AS 'TableName', MAX(ActualBeginDateTime) AS 'MaxDate' FROM sselData.dbo.ToolDataClean"
                      + " UNION SELECT 'ToolData', MAX(ActDate) FROM sselData.dbo.ToolData"
                      + " UNION SELECT 'ToolBillingTemp', MAX(ActDate) FROM sselData.dbo.ToolBillingTemp"
                      + " UNION SELECT 'RoomDataClean', MAX(EntryDT) FROM sselData.dbo.RoomDataClean"
                      + " UNION SELECT 'RoomData', MAX(EvtDate) FROM sselData.dbo.RoomData"
                      + " UNION SELECT 'RoomBillingTemp', MAX(Period) FROM sselData.dbo.RoomBillingTemp";
                break;

            default:
                result.Success = false;
                result.Message = string.Format("Invalid task: {0}", task);
                result.Data    = null;
                return(result);
            }

            var query = DataSession.SqlQuery(sql).List <TaskCheck>();

            result.Success = true;
            result.Message = null;
            result.Data    = query;

            return(result);
        }
コード例 #7
0
        public static ScriptHost.Result SchedulerTask(string task, IClient currentUser)
        {
            ScriptHost.Result result = new ScriptHost.Result();
            var model = new ServiceModel()
            {
                Task = task, CurrentUser = currentUser
            };
            GenericResult gr = model.HandleCommand();

            if (gr.Success)
            {
                result.Success = true;
                result.Message = "ok";
            }
            else
            {
                result.Success = false;
                result.Message = "Service did not respond.";
                result.Data    = new string[] { task };
            }

            return(result);
        }
コード例 #8
0
        public static ScriptHost.Result BillingTask(string task, QueryParameters queryParams)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            DateTime sd;
            DateTime ed;
            DateTime period;

            void getDates(bool startRequired, bool endRequired, bool periodRequired)
            {
                if (startRequired && !queryParams.ContainsParameter("StartDate"))
                {
                    throw new Exception("Missing parameter: StartDate");
                }

                if (endRequired && !queryParams.ContainsParameter("EndDate"))
                {
                    throw new Exception("Missing parameter: EndDate");
                }

                if (periodRequired && !queryParams.ContainsParameter("Period"))
                {
                    throw new Exception("Missing parameter: Period");
                }

                sd     = queryParams.GetValue("StartDate", DateTime.Now);
                ed     = queryParams.GetValue("EndDate", DateTime.Now);
                period = queryParams.GetValue("Period", DateTime.Now);
            }

            var context  = "Data.Models.CommandLine.CommandLineUtility.BillingTask";
            var clientId = queryParams.GetValue("ClientID", 0);

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnSselData"].ConnectionString))
            {
                conn.Open();
                switch (task)
                {
                case "ToolDataClean":
                    getDates(true, true, false);
                    var writeToolDataCleanResult = new WriteToolDataCleanProcess(new WriteToolDataCleanConfig {
                        Connection = conn, StartDate = sd, EndDate = ed, ClientID = clientId, Context = context
                    }).Start();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = writeToolDataCleanResult.LogText;
                    break;

                case "ToolData":
                    getDates(true, true, false);
                    var writeToolDataResult = new WriteToolDataProcess(new WriteToolDataConfig {
                        Connection = conn, Period = sd, ClientID = clientId, ResourceID = queryParams.GetValue("ResourceID", 0), Context = context
                    }).Start();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = writeToolDataResult.LogText;
                    break;

                case "RoomDataClean":
                    getDates(true, true, false);
                    var writeRoomDataCleanResult = new WriteRoomDataCleanProcess(new WriteRoomDataCleanConfig {
                        Connection = conn, StartDate = sd, EndDate = ed, ClientID = clientId, Context = context
                    }).Start();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = writeRoomDataCleanResult.LogText;
                    break;

                case "RoomData":
                    getDates(true, true, false);
                    var writeRoomDataResult = new WriteRoomDataProcess(new WriteRoomDataConfig {
                        Connection = conn, Period = sd, ClientID = clientId, RoomID = queryParams.GetValue("RoomID", 0), Context = context
                    }).Start();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = writeRoomDataResult.LogText;
                    break;

                case "StoreDataClean":
                    getDates(true, true, false);
                    var writeStoreDataCleanResult = new WriteStoreDataCleanProcess(new WriteStoreDataCleanConfig {
                        Connection = conn, StartDate = sd, EndDate = ed, ClientID = clientId, Context = context
                    }).Start();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = writeStoreDataCleanResult.LogText;
                    break;

                case "StoreData":
                    getDates(true, true, false);
                    var writeStoreDataResult = new WriteStoreDataProcess(new WriteStoreDataConfig {
                        Connection = conn, Period = sd, ClientID = clientId, ItemID = queryParams.GetValue("ItemID", 0), Context = context
                    }).Start();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = writeStoreDataResult.LogText;
                    break;

                case "ToolBillingStep1":
                    getDates(false, false, true);
                    var step1 = new BillingDataProcessStep1(new Step1Config {
                        Connection = conn, Period = period, ClientID = clientId, IsTemp = queryParams.GetValue("IsTemp", false), Now = DateTime.Now, Context = context
                    });
                    var step1Result = step1.PopulateToolBilling();
                    result.Success = true;
                    result.Message = null;
                    result.Data    = step1Result.LogText;
                    break;

                default:
                    result.Success = false;
                    result.Message = "Unknown task: " + task;
                    break;
                }
                conn.Close();
            }

            return(result);
        }