Ejemplo n.º 1
0
        public static Dictionary <string, object> GetRuleAndAction(int actionId)
        {
            Map map = Maps.Instance.GetMap();

            ConfigAccess configAccess = new ConfigAccess();
            DataRow      row          = configAccess.GetRow("Rule", "ID", actionId.ToString(), map.GetConfigDatabase().ConnectionString);

            if (row == null)
            {
                throw new ActionNotFoundException(actionId);
            }
            int viewId = System.Convert.ToInt32(row["Rules"]);

            string name = row["Name"].ToString();

            View view = null;

            view = (View)map.Database.Views.Values.Where(v => v.ID == viewId).FirstOrDefault();
            if (view == null)
            {
                throw new ActionNotFoundException(actionId, viewId);
            }

            Rule rule = view.Rules[name];

            return(new Dictionary <string, object>()
            {
                { "view", view }, { "rule", rule }
            });
        }
Ejemplo n.º 2
0
        protected override IHttpActionResult ValidateInputForPost(Durados.Web.Mvc.View view, Dictionary <string, object> values)
        {
            if (IsOverTheLimit(view))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "You have exceeded the limit of maximum crons allowed")));
            }


            if (values.ContainsKey(NAME))
            {
                string name = values[NAME].ToString();
                if (Map.Database.Crons.Values.Where(c => c.Name == name).FirstOrDefault() != null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Conflict, string.Format(Messages.CronWithNameAlreadyExists, name))));
                }
            }

            if (!values.ContainsKey(CRON_TYPE))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "Missing CronType")));
            }

            string cronType = values[CRON_TYPE].ToString();

            if (cronType != CronType.External.ToString() && !values.ContainsKey(EntityId))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "Missing EntityId")));
            }

            int entityId = -1;

            if (!int.TryParse(values[EntityId].ToString(), out entityId))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "EntityId must be a number")));
            }

            if (cronType == CronType.Query.ToString())
            {
                if (Map.Database.Queries.Values.Where(q => q.ID == entityId).FirstOrDefault() == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Query not found for id " + entityId)));
                }
            }

            if (cronType == CronType.Action.ToString())
            {
                ConfigAccess configAccess = new ConfigAccess();
                DataRow      row          = configAccess.GetRow("Rule", "ID", entityId.ToString(), map.GetConfigDatabase().ConnectionString);

                if (row == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Action not found for id " + entityId)));
                }
            }


            if (values.ContainsKey(DATABASE))
            {
                values[DATABASE] = 0;
            }
            else
            {
                values.Add(DATABASE, 0);
            }

            return(null);
        }