Exemplo n.º 1
0
        private void Unmap(ParameterizedMap map)
        {
            this.datamap.Add("base", map.TryGet <BasicInformation>("base"));
            PacketEventArgs packet = map.TryGet <PacketEventArgs>("packet");

            if (packet != null)
            {
                DynamicData data = map.TryGet <DynamicData>("parameters");
                foreach (string key in data.GetDictionary().Keys)
                {
                    this.datamap.Add(key, data.GetDictionary()[key]);
                }
            }
        }
Exemplo n.º 2
0
        public static string CreateCommand(string signature, string input, IKeySym privateKey)
        {
            IParser <ParamArgs> parser = new CommandParser();
            ParamArgs           output = parser.Parse(input);

            if (output.Count == 0)
            {
                throw new OperationCanceledException("Could not parse command.");
            }

            Header header     = new Header(signature, "", output.Get <string>("Command"));
            string jsonHeader = Newtonsoft.Json.JsonConvert.SerializeObject(header);

            DynamicData detail = new DynamicData();

            foreach (string key in output.ToDictionary().Keys)
            {
                if (!key.Equals("Command"))
                {
                    detail.Add(key, output.Get <object>(key));
                }
            }
            string  jsonDetail = Newtonsoft.Json.JsonConvert.SerializeObject(detail.GetDictionary());
            Crypter crypter    = new Crypter(privateKey);

            string final = string.Format(Format, jsonHeader, jsonDetail);

            return(crypter.Encrypt(final));
        }
        protected void GetQueue(string sql, params object[] args)
        {
            IDbManager   dbManager = ObjectPool.Instance.Resolve <IDbManager>();
            IDataCommand db        = dbManager.GetDatabase(DatabaseNames.SMSGW);

            List <QueueWork> workItem = db.Query <QueueWork>(sql, args);
            MutableObservableCollection <ComposeMessageModel> buffer = new MutableObservableCollection <ComposeMessageModel>();

            if (workItem.Any())
            {
                List <DailyTrigger>         daily;
                List <WeeklyTrigger>        weekly;
                List <MonthlyTrigger>       monthly;
                CommandParser               parser;
                Dictionary <string, string> parsingCommand;
                DynamicData         parameters;
                ComposeMessageModel model;

                foreach (QueueWork item in workItem)
                {
                    model = new ComposeMessageModel();

                    parser         = new CommandParser();
                    parsingCommand = parser.Parse(item.Command);
                    parameters     = new DynamicData();
                    foreach (string key in parsingCommand.Keys)
                    {
                        if (!key.Equals("Command"))
                        {
                            parameters.Add(key, parsingCommand[key]);
                        }
                    }

                    model.Source      = item.Source;
                    model.SeqNbr      = item.SeqNbr;
                    model.Phonenumber = (string)parameters.GetDictionary()["number"];
                    model.Message     = (string)parameters.GetDictionary()["message"];
                    model.Date        = item.Created.ToString("dd/MM/yyyy");
                    model.Time        = item.Created.ToString("HH:mm");
                    model.Enabled     = item.Enabled;

                    if (item.NextExecuted.Ticks > 0)
                    {
                        model.NextExecuted = DateTime.Parse(item.NextExecuted.ToString("dd/MM/yyyy HH:mm"));
                    }

                    string triggerPrefix = string.Empty;
                    if (!string.IsNullOrEmpty(item.ScheduleID))
                    {
                        triggerPrefix = item.ScheduleID.Substring(0, 1);
                    }
                    switch (triggerPrefix)
                    {
                    case "D":
                        daily = db.Query <DailyTrigger>("GetDailyTriggerByID", new { ID = item.ScheduleID });
                        if (daily.Any())
                        {
                            model.TriggerOptions = TriggerOptions.Daily;
                            model.RecursDay      = daily[0].RecursEvery;
                        }
                        break;

                    case "W":
                        weekly = db.Query <WeeklyTrigger>("GetWeeklyTriggerByID", new { ID = item.ScheduleID });
                        if (weekly.Any())
                        {
                            model.TriggerOptions          = TriggerOptions.Weekly;
                            model.RecursWeek              = weekly[0].RecursEvery;
                            model.WeeklyOptions.Monday    = weekly[0].Monday;
                            model.WeeklyOptions.Tuesday   = weekly[0].Tuesday;
                            model.WeeklyOptions.Wednesday = weekly[0].Wednesday;
                            model.WeeklyOptions.Thursday  = weekly[0].Thursday;
                            model.WeeklyOptions.Friday    = weekly[0].Friday;
                            model.WeeklyOptions.Saturday  = weekly[0].Saturday;
                            model.WeeklyOptions.Sunday    = weekly[0].Sunday;
                        }
                        break;

                    case "M":
                        monthly = db.Query <MonthlyTrigger>("GetMonthlyTriggerByID", new { ID = item.ScheduleID });
                        if (monthly.Any())
                        {
                            model.TriggerOptions = TriggerOptions.Monthly;

                            model.Months[0].IsSelected  = monthly[0].January;
                            model.Months[1].IsSelected  = monthly[0].February;
                            model.Months[2].IsSelected  = monthly[0].March;
                            model.Months[3].IsSelected  = monthly[0].April;
                            model.Months[4].IsSelected  = monthly[0].May;
                            model.Months[5].IsSelected  = monthly[0].June;
                            model.Months[6].IsSelected  = monthly[0].July;
                            model.Months[7].IsSelected  = monthly[0].August;
                            model.Months[8].IsSelected  = monthly[0].September;
                            model.Months[9].IsSelected  = monthly[0].October;
                            model.Months[10].IsSelected = monthly[0].November;
                            model.Months[11].IsSelected = monthly[0].December;

                            string[] days = monthly[0].Days.Split(',');
                            foreach (string day in days)
                            {
                                model.Days[Convert.ToInt32(day)].IsSelected = 1;
                            }
                        }
                        break;

                    case "O":
                        model.TriggerOptions = TriggerOptions.OneTime;
                        break;
                    }
                    buffer.Add(model);
                }
            }
            Source = buffer;
        }