Beispiel #1
0
    public bool PPGEvent(Context in_ctxt)
    {
        try
        {
            PPGEventContext ppgctxt = (PPGEventContext)in_ctxt;
            siPPGEventID    eventID = ppgctxt.EventID;

            if (eventID == siPPGEventID.siParameterChange)
            {
                // The Source of the event is the parameter itself
                Parameter changed = (Parameter)ppgctxt.Source;
                if ("ProcessReqTimer" == changed.ScriptName)
                {
                    int        interval = (int)changed.GetValue2(null);
                    TimerEvent evTimer  = (TimerEvent)GetXSI().EventInfos["sIBL_GUI_XSI_Server_ProcessRequestsTimerEvent"];
                    evTimer.Reset(interval, 0);
                }
                else if ("EnableRequests" == changed.ScriptName)
                {
                    bool      bValue  = (bool)changed.GetValue2(null);
                    EventInfo evTimer = GetXSI().EventInfos["sIBL_GUI_XSI_Server_ProcessRequestsTimerEvent"];
                    evTimer.Mute = bValue == false;
                }
            }
            else if (eventID == siPPGEventID.siButtonClicked)
            {
                String buttonPressed = (String)ppgctxt.GetAttribute("Button");

                if (buttonPressed == "GetHostAddress")
                {
                    // Set host param with this host address
                    IPHostEntry hostEntry   = Dns.GetHostEntry(Dns.GetHostName());
                    IPAddress[] ipAddresses = hostEntry.AddressList;

                    Property  prop = (Property)ppgctxt.Source;
                    Parameter adr  = prop.Parameters["Address"];
                    adr.PutValue2(null, ipAddresses[0].ToString());
                }
                else if (buttonPressed == "GetLocalHostAddress")
                {
                    // Set host param with this host address
                    Property  prop = (Property)ppgctxt.Source;
                    Parameter adr  = prop.Parameters["Address"];
                    adr.PutValue2(null, "127.0.0.1");
                }
                else if (buttonPressed == "LogRequests")
                {
                    Info("Logging all requests ...");
                    ClientRequests requests = new ClientRequests();
                    requests.Log();
                }
                else if (buttonPressed == "ClearRequests")
                {
                    Info("Removing all requests ...");
                    ClientRequests requests = new ClientRequests();
                    requests.Clear();
                }
                else if (buttonPressed == "StartServer" || buttonPressed == "StopServer")
                {
                    TimerEvent evTimer = (TimerEvent)GetXSI().EventInfos["sIBL_GUI_XSI_Server_ProcessRequestsTimerEvent"];
                    if (buttonPressed == "StartServer")
                    {
                        // Start server
                        Info("sIBL_GUI_XSI_Server | Server Started!");
                        Property prop = (Property)ppgctxt.Source;
                        sIBL_GUI_XSI_Server.Start((String)prop.Parameters["Address"].GetValue2(null),
                                                  (int)prop.Parameters["Port"].GetValue2(null),
                                                  (int)prop.Parameters["MaxCnx"].GetValue2(null));
                        evTimer.Mute = false;
                    }
                    else if (buttonPressed == "StopServer")
                    {
                        Info("sIBL_GUI_XSI_Server | Server Stopped!");
                        sIBL_GUI_XSI_Server.Stop();
                        evTimer.Mute = true;
                    }
                }
            }
        }
        catch (Exception e)
        {
            Error(e.ToString());
        }

        return(true);
    }