Ejemplo n.º 1
0
        public static bool cliNewEventWaiter(PlTerm clazzOrInstance, PlTerm memberSpec, PlTerm blockOn)
        {
            object getInstance;
            Type   c;

            if (!GetInstanceAndType(clazzOrInstance, out getInstance, out c))
            {
                return(false);
            }
            Type[] paramz = null;
            if (!CheckBound(memberSpec))
            {
                return(false);
            }
            EventInfo fi = findEventInfo(memberSpec, c, ref paramz, BindingFlagsALL);

            if (fi == null)
            {
                return(Error("Cant find event {0} on {1}", memberSpec, (object)c ?? clazzOrInstance));
            }
            WaitUntilDelegateList list = new WaitUntilDelegateList();

            list.WaitOns.Add(new WaitUntilDelegate(list, fi, getInstance));
            return(blockOn.FromObject(list));
        }
Ejemplo n.º 2
0
 public WaitUntilDelegate(WaitUntilDelegateList re, EventInfo info, object instance)
 {
     parent   = re;
     Event    = info;
     Instance = instance;
     SetInstanceOfDelegateType(info.EventHandlerType);
     Event.AddEventHandler(instance, Delegate);
 }
Ejemplo n.º 3
0
 public static bool cliNewEventWaiter(PlTerm clazzOrInstance, PlTerm memberSpec, PlTerm blockOn)
 {
     object getInstance;
     Type c;
     if (!GetInstanceAndType(clazzOrInstance, out getInstance, out c)) return false;
     Type[] paramz = null;
     if (!CheckBound(memberSpec)) return false;
     EventInfo fi = findEventInfo(memberSpec, c, ref paramz, BindingFlagsALL);
     if (fi == null)
     {
         return Error("Cant find event {0} on {1}", memberSpec, (object) c ?? clazzOrInstance);
     }
     WaitUntilDelegateList list = new WaitUntilDelegateList();
     list.WaitOns.Add(new WaitUntilDelegate(list, fi, getInstance));
     return blockOn.FromObject(list);
 }
Ejemplo n.º 4
0
        public static bool cliAddEventWaiter(PlTerm blockOn, PlTerm clazzOrInstance, PlTerm memberSpec, PlTerm newBlockOn)
        {
            WaitUntilDelegateList list = null;
            object getInstance1        = GetInstance(blockOn);
            var    wud = getInstance1 as WaitUntilDelegate;

            if (wud == null)
            {
                if (!(getInstance1 is WaitUntilDelegateList))
                {
                    return(Error("Not an instance of WaitUntilDelegate: " + blockOn));
                }
                list = getInstance1 as WaitUntilDelegateList;
            }
            else
            {
                list = wud.parent;
            }
            object getInstance;
            Type   c;

            if (!GetInstanceAndType(clazzOrInstance, out getInstance, out c))
            {
                return(false);
            }
            Type[] paramz = null;
            if (!CheckBound(memberSpec, blockOn))
            {
                return(false);
            }
            EventInfo fi = findEventInfo(memberSpec, c, ref paramz, BindingFlagsALL);

            if (fi == null)
            {
                return(Error("Cant find event {0} on {1}", memberSpec, (object)c ?? clazzOrInstance));
            }
            var wud2 = new WaitUntilDelegate(list, fi, getInstance);

            list.WaitOns.Add(wud2);
            return(newBlockOn.FromObject(list));
        }
Ejemplo n.º 5
0
        public static bool cliBlockUntilEvent(PlTerm blockOn, PlTerm maxTime, PlTerm testVarsCode, PlTerm exitCode)
        {
            WaitUntilDelegateList list = null;
            object getInstance1        = GetInstance(blockOn);
            var    wud = getInstance1 as WaitUntilDelegate;

            if (wud == null)
            {
                if (!(getInstance1 is WaitUntilDelegateList))
                {
                    return(Error("Not an instance of WaitUntilDelegate: " + blockOn));
                }
                list = getInstance1 as WaitUntilDelegateList;
            }
            else
            {
                list = wud.parent;
            }

            var timeSpan = TimeSpan.FromDays(3650);

            if (maxTime.IsInteger)
            {
                timeSpan = TimeSpan.FromMilliseconds(maxTime.intValue());
            }
            else if (!maxTime.IsVar)
            {
                timeSpan = (TimeSpan)CastTerm(maxTime, typeof(TimeSpan));
            }

            DateTime expireyTime = DateTime.Now.Add(timeSpan);

            while (DateTime.Now < expireyTime)
            {
                var results = list.WaitOne(timeSpan, out wud);
                if (results == null)
                {
                    return(exitCode.UnifyAtom("time_limit_exceeded"));
                }
                PlTerm  copyTo     = PlTerm.PlVar();
                PlTermV newPlTermV = new PlTermV(testVarsCode, copyTo);
                PlCall("system", "copy_term", newPlTermV);
                PlTerm   ctestVars = copyTo.Arg(0);
                PlTerm   ctestCode = copyTo.Arg(1);
                PlTerm[] terms     = ToTermArray(ctestVars);
                int      idx       = terms.Length - 1;
                int      resdex    = results.Length - 1;
                while (idx >= 0 && resdex >= 0)
                {
                    terms[idx--].FromObject(results[resdex--]);
                }
                try
                {
                    if (PlCall("user", "call", new PlTermV(ctestCode)))
                    {
                        return(UnifyToProlog(PlCall(null, "=", newPlTermV), exitCode) != 0);
                    }
                }
                finally
                {
                    list.Reset();
                }
            }
            return(exitCode.UnifyAtom("time_limit_exceeded"));
        }
Ejemplo n.º 6
0
 public WaitUntilDelegate(WaitUntilDelegateList re, EventInfo info, object instance)
 {
     parent = re;
     Event = info;
     Instance = instance;
     SetInstanceOfDelegateType(info.EventHandlerType);
     Event.AddEventHandler(instance, Delegate);
 }