Exemple #1
0
        public static void magix_execute_close(object sender, ActiveEventArgs e)
        {
            Node ip = Ip(e.Params);

            if (ShouldInspect(ip))
            {
                AppendInspectFromResource(
                    ip["inspect"],
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.close-dox].value");
                AppendCodeFromResource(
                    ip,
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.close-sample]");
                return;
            }

            if (!ip.ContainsValue("name"))
            {
                throw new ArgumentException("[close] needs a [name]");
            }

            Node   dp          = Dp(e.Params);
            string activeEvent = Expressions.GetExpressionValue <string>(ip["name"].Get <string>(), dp, ip, false);

            if (!ip.Contains("persist") || ip["persist"].Get <bool>())
            {
                DataBaseRemoval.Remove(activeEvent, "magix.execute.open", e.Params);
            }

            ActiveEvents.Instance.RemoveRemotable(activeEvent);
        }
Exemple #2
0
        public static void magix_execute_override(object sender, ActiveEventArgs e)
        {
            Node ip = Ip(e.Params);

            if (ShouldInspect(ip))
            {
                AppendInspectFromResource(
                    ip["inspect"],
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.override-dox].value");
                AppendCodeFromResource(
                    ip,
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.override-sample]");
                return;
            }

            if (!ip.ContainsValue("name"))
            {
                throw new ArgumentException("missing [name] parameter in [override]");
            }
            string activeEvent = ip["name"].Get <string>();

            if (ip.Contains("with"))
            {
                string newActiveEvent = ip["with"].Get <string>();
                if (newActiveEvent == null)
                {
                    throw new ArgumentException("you cannot [override] an active event with a null string");
                }

                if (!ip.Contains("persist") || ip["persist"].Get <bool>())
                {
                    DataBaseRemoval.Remove(activeEvent, "magix.execute.override", e.Params);

                    Node saveNode = new Node("magix.data.save");
                    saveNode["id"].Value             = Guid.NewGuid().ToString();
                    saveNode["value"]["event"].Value = activeEvent;
                    saveNode["value"]["type"].Value  = "magix.execute.override";
                    saveNode["value"]["with"].Value  = newActiveEvent;

                    BypassExecuteActiveEvent(saveNode, e.Params);
                }
                ActiveEvents.Instance.CreateEventMapping(activeEvent, newActiveEvent);
            }
            else
            {
                if (!ip.Contains("persist") || ip["persist"].Get <bool>())
                {
                    DataBaseRemoval.Remove(activeEvent, "magix.execute.override", e.Params);
                }

                ActiveEvents.Instance.RemoveMapping(activeEvent);
            }
        }
Exemple #3
0
        /*
         * creates an active event
         */
        private static void CreateActiveEvent(Node ip, string activeEvent, Node pars)
        {
            Node dp = Dp(pars);

            bool remotable = ip.Contains("remotable") && ip["remotable"].Get <bool>();

            string inspect = Expressions.GetFormattedExpression("inspect", pars, "");

            if (!ip.Contains("persist") || ip["persist"].Get <bool>())
            {
                // removing any previous similar events
                DataBaseRemoval.Remove(activeEvent, "magix.execute.event", pars);

                Node saveNode = new Node("magix.data.save");
                saveNode["id"].Value                 = Guid.NewGuid().ToString().Replace("-", "");
                saveNode["value"]["event"].Value     = activeEvent;
                saveNode["value"]["type"].Value      = "magix.execute.event";
                saveNode["value"]["remotable"].Value = remotable;
                if (ip.Contains("inspect"))
                {
                    saveNode["value"]["inspect"].Value = inspect;
                }
                saveNode["value"]["code"].AddRange(ip["code"].Clone());

                BypassExecuteActiveEvent(saveNode, pars);
            }

            ActiveEvents.Instance.CreateEventMapping(
                activeEvent,
                "magix.execute._active-event-2-code-callback");

            if (ip.Contains("remotable"))
            {
                if (remotable)
                {
                    ActiveEvents.Instance.MakeRemotable(activeEvent);
                }
                else
                {
                    ActiveEvents.Instance.RemoveRemotable(activeEvent);
                }
            }

            _events[activeEvent].Clear();
            _events[activeEvent].AddRange(ip["code"].Clone());

            _inspect[activeEvent].Clear();
            if (ip.Contains("inspect"))
            {
                _inspect[activeEvent].Value = inspect;
            }
        }
Exemple #4
0
        /*
         * removes an active event
         */
        private static void RemoveActiveEvent(Node ip, string activeEvent, Node pars)
        {
            if (!ip.Contains("persist") || ip["persist"].Get <bool>())
            {
                DataBaseRemoval.Remove(activeEvent, "magix.execute.event", pars);
            }

            ActiveEvents.Instance.RemoveMapping(activeEvent);
            ActiveEvents.Instance.RemoveRemotable(activeEvent);

            _events[activeEvent].UnTie();
            _inspect[activeEvent].UnTie();
        }
Exemple #5
0
        public static void magix_execute_open(object sender, ActiveEventArgs e)
        {
            Node ip = Ip(e.Params);

            if (ShouldInspect(ip))
            {
                AppendInspectFromResource(
                    ip["inspect"],
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.open-dox].value");
                AppendCodeFromResource(
                    ip,
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.open-sample]");
                return;
            }

            if (!ip.ContainsValue("name"))
            {
                throw new ArgumentException("[open] needs a [name] parameter");
            }

            Node   dp          = Dp(e.Params);
            string activeEvent = Expressions.GetExpressionValue <string>(ip["name"].Get <string>(), dp, ip, false);

            if (!ip.Contains("persist") || ip["persist"].Get <bool>())
            {
                DataBaseRemoval.Remove(activeEvent, "magix.execute.open", e.Params);

                Node saveNode = new Node("magix.data.save");
                saveNode["id"].Value             = Guid.NewGuid();
                saveNode["value"]["event"].Value = activeEvent;
                saveNode["value"]["type"].Value  = "magix.execute.open";

                BypassExecuteActiveEvent(saveNode, e.Params);
            }
            ActiveEvents.Instance.MakeRemotable(activeEvent);
        }
Exemple #6
0
        public static void magix_execute_tunnel(object sender, ActiveEventArgs e)
        {
            Node ip = Ip(e.Params);

            if (ShouldInspect(ip))
            {
                AppendInspectFromResource(
                    ip["inspect"],
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.tunnel-dox].value");
                AppendCodeFromResource(
                    ip,
                    "Magix.execute",
                    "Magix.execute.hyperlisp.inspect.hl",
                    "[magix.execute.tunnel-sample]");
                return;
            }

            if (!ip.ContainsValue("name"))
            {
                throw new ArgumentException(
                          @"[tunnel] needs [name], being active event name, to know which event to override to go externally");
            }

            Node dp = Dp(e.Params);

            string activeEvent = Expressions.GetExpressionValue <string>(ip["name"].Get <string>(), dp, ip, false);
            string url         = ip.Contains("url") ? Expressions.GetExpressionValue <string>(ip["url"].Get <string>(), dp, ip, false) : null;

            if (string.IsNullOrEmpty(url))
            {
                if (!ip.Contains("persist") || ip["persist"].Get <bool>())
                {
                    DataBaseRemoval.Remove(activeEvent, "magix.execute.tunnel", e.Params);
                }

                ActiveEvents.Instance.RemoveRemoteOverride(activeEvent);

                string originalName    = "";
                string origActiveEvent = ActiveEvents.Instance.GetEventMappingValue(activeEvent, ref originalName);
                if (origActiveEvent == "magix.execute._mumbo-jumbo")
                {
                    ActiveEvents.Instance.RemoveMapping(activeEvent);
                }
            }
            else
            {
                if (!ip.Contains("persist") || ip["persist"].Get <bool>())
                {
                    DataBaseRemoval.Remove(activeEvent, "magix.execute.tunnel", e.Params);

                    Node saveNode = new Node("magix.data.save");
                    saveNode["id"].Value             = Guid.NewGuid();
                    saveNode["value"]["event"].Value = activeEvent;
                    saveNode["value"]["type"].Value  = "magix.execute.tunnel";
                    saveNode["value"]["url"].Value   = url;
                    BypassExecuteActiveEvent(saveNode, e.Params);
                }
                ActiveEvents.Instance.OverrideRemotely(activeEvent, url);
                if (!ActiveEvents.Instance.IsOverride(activeEvent))
                {
                    // to make sure the local system actually has an active event with that name
                    ActiveEvents.Instance.CreateEventMapping(
                        activeEvent,
                        "magix.execute._mumbo-jumbo");
                }
            }
        }