예제 #1
0
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                //basically just need to send parameter two to the contact in parameter one with sendMessage();
                //Process incomming command
                string to = "";
                if (gDebug)
                {
                    Log.Debug("Process command: " + method.MethodName);
                }
                if (gDebug)
                {
                    Log.Debug("Message: " + method.Parameter2);
                }
                OSAEObjectProperty prop = OSAEObjectPropertyManager.GetObjectPropertyValue(method.Parameter1, "JabberID");

                if (prop != null)
                {
                    to = prop.Value;
                }
                else
                {
                    to = method.Parameter1;
                }

                if (to == "")
                {
                    to = method.Parameter1;
                }

                if (gDebug)
                {
                    Log.Debug("To: " + to);
                }

                switch (method.MethodName)
                {
                case "SEND MESSAGE":
                    sendMessage(Common.PatternParse(method.Parameter2), to);
                    break;

                case "SEND QUESTION":
                    Ask_Question(to);
                    break;

                case "SEND FROM LIST":
                    string speechList = method.Parameter2.Substring(0, method.Parameter2.IndexOf(","));
                    string listItem   = method.Parameter2.Substring(method.Parameter2.IndexOf(",") + 1, method.Parameter2.Length - (method.Parameter2.IndexOf(",") + 1));
                    if (gDebug)
                    {
                        Log.Debug("List = " + speechList + "   Item=" + listItem);
                    }
                    sendMessage(Common.PatternParse(OSAEObjectPropertyManager.ObjectPropertyArrayGetRandom(speechList, listItem)), to);
                    break;
                }
            }
            catch (Exception ex)
            { Log.Error("Error in ProcessCommand!", ex); }
        }
예제 #2
0
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                //basically just need to send parameter two to the contact in parameter one with sendMessage();
                //Process incomming command
                string to = "";
                if (gDebug)
                {
                    Log.Debug("Process command: " + method.MethodName);
                }
                if (gDebug)
                {
                    Log.Debug("Message: " + method.Parameter2);
                }
                OSAEObjectProperty prop = OSAEObjectPropertyManager.GetObjectPropertyValue(method.Parameter1, "JabberID");

                if (prop != null)
                {
                    to = prop.Value;
                }
                else
                {
                    to = method.Parameter1;
                }

                if (to == "")
                {
                    to = method.Parameter1;
                }

                if (gDebug)
                {
                    Log.Debug("To: " + to);
                }

                switch (method.MethodName)
                {
                case "SEND MESSAGE":
                    sendMessage(Common.PatternParse(method.Parameter2), to);
                    break;

                case "SEND FROM LIST":
                    //Speech List here should not be hard coded, but I understand we only have 2 parameters to work with...
                    sendMessage(Common.PatternParse(OSAEObjectPropertyManager.ObjectPropertyArrayGetRandom("Speech List", method.Parameter2)), to);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error processing command ", ex);
            }
        }
예제 #3
0
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                //basically just need to send parameter two to the contact in parameter one with sendMessage();
                //Process incomming command
                string to = "";
                logging.AddToLog("Process command: " + method.MethodName, false);
                logging.AddToLog("Message: " + method.Parameter2, false);
                logging.AddToLog("To: " + method.Parameter1, false);
                OSAEObjectProperty prop = OSAEObjectPropertyManager.GetObjectPropertyValue(method.Parameter1, "JabberID");
                if (prop != null)
                {
                    to = prop.Value;
                }
                if (to == "")
                {
                    to = method.Parameter1;
                }
                else
                {
                    to = method.Parameter1;
                }

                if (to == "")
                {
                    to = method.Parameter1;
                }

                switch (method.MethodName)
                {
                case "SEND MESSAGE":
                    sendMessage(Common.PatternParse(method.Parameter2), to);
                    break;

                case "SEND FROM LIST":
                    sendMessage(Common.PatternParse(OSAEObjectPropertyManager.ObjectPropertyArrayGetRandom("Speech List", method.Parameter2)), to);
                    break;
                }
            }
            catch (Exception ex)
            {
                logging.AddToLog("Error processing command: " + ex.Message, true);
            }
        }
예제 #4
0
        private OSAEObjectPropertyCollection getProperties(string objName)
        {
            OSAEObject oObj = OSAEObjectManager.GetObjectByName(objName);
            OSAEObjectPropertyCollection props      = oObj.Properties;
            OSAEObjectPropertyCollection properties = new OSAEObjectPropertyCollection();

            foreach (OSAEObjectProperty prop in props)
            {
                OSAEObjectProperty p = new OSAEObjectProperty();
                p.Name        = prop.Name;
                p.Value       = prop.Value;
                p.DataType    = prop.DataType;
                p.LastUpdated = prop.LastUpdated;
                p.Id          = prop.Id;
                properties.Add(p);
            }
            return(properties);
        }
예제 #5
0
        /// <summary>
        /// OSA Plugin Interface - Commands the be processed by the plugin
        /// </summary>
        /// <param name="method">Method containging the command to run</param>
        public override void ProcessCommand(OSAEMethod method)
        {
            string methodName     = method.MethodName;
            string objectName     = method.ObjectName;
            string combinedString = objectName + "_" + methodName;

            //get the called objects properties to see if there is a computer objet defined
            OSAEObject calledObject = OSAEObjectManager.GetObjectByName(method.ObjectName);
            OSAEObjectPropertyCollection ComputerProperty  = calledObject.Properties;
            OSAEObjectCollection         eventGhostObjects = OSAEObjectManager.GetObjectsByType("Computer");
            OSAEObject computer = new OSAEObject();

            //if there are no properties defined then grab the first available Computer object
            //logging.AddToLog("The Count of the Computer Properties is : " + ComputerProperty.Count, true);
            if (ComputerProperty.Count == 0)
            {
                //get the last object in the list

                foreach (OSAEObject test in eventGhostObjects)
                {
                    computer = test;
                }

                //add log entry if mulptiple computer objects were dectected and no property was used to select which object
                if (eventGhostObjects.Count > 1)
                {
                    Log.Info("There are multiple eventghost computer objects detected.  " + computer.Name + " with an address of: " + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "IPAddress") + ":" + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "EventGhost Port") + " is being used to transmit the package.  Please add a property called 'Computer' with a value of the object name of the computer you wish to transmit the UDP packet to.");
                }
            }
            // if the object type contains a property with ID "Computer" use that property to select the appropriate object
            else
            {
                OSAEObjectProperty whichComputer = OSAEObjectPropertyManager.GetObjectPropertyValue(calledObject.Name, "Computer");
                computer = eventGhostObjects.Find(whichComputer.Value);

                //check to see if a computer object was found if none print the logged property value and select another object to use
                if (computer == null)
                {
                    foreach (OSAEObject test in eventGhostObjects)
                    {
                        computer = test;
                    }

                    if (eventGhostObjects.Count > 1)
                    {
                        Log.Info("A computer object was unable to be matched to " + whichComputer.Value + " please ensure that " + calledObject.Name + " contains a property called Computer with a value mathing the name of the appropriate computer object.");
                        Log.Info(computer.Name + " with an address of: " + computer.Address + ":" + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "EventGhost Port") + " is being used to transmit the package.");
                    }
                }
            }

            //logging.AddToLog(address, true);
            //logging.AddToLog(objectName, true);
            //logging.AddToLog(combinedString, true);

            //get the server address indicated in the address for the object passed to the method
            string ipAddress = computer.Address;

            //check to make sure computer object has address, if not assume local host
            if (ipAddress.Equals("", StringComparison.Ordinal))
            {
                ipAddress = "Localhost";
            }
            OSAEObjectProperty portAddress = OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "Port");

            //if no value for port use default value of 33333
            Log.Debug("The port being used is: " + portAddress.Value);
            int port = 0;

            //Log.Debug("The port being used is: " + portAddress.Value);

            if ((portAddress.Value).Equals("", StringComparison.Ordinal))
            {
                port = 33333;
            }
            else
            {
                port = Int32.Parse(portAddress.Value);
                Log.Debug("The port being used is: " + portAddress.Value);
            }
            //logging.AddToLog(port, true);
            //logging.AddToLog(ipAddress, true);
            IPAddress  serverAddr = IPAddress.Parse(ipAddress);
            IPEndPoint endPoint   = new IPEndPoint(serverAddr, port);

            Log.Debug("The ipEndPoint is:" + ipAddress + ":" + port);

            //send the updpacket
            UdpClient udp = new UdpClient();

            byte[] sendBytes = Encoding.ASCII.GetBytes(combinedString);
            udp.Send(sendBytes, sendBytes.Length, endPoint);


            ////if not value for port use default value of 33333
            //int port = 0;

            //if ((portAddress.Value).Equals("",StringComparison.Ordinal))
            //    port = 33333;
            //else
            //    port = Int32.Parse(portAddress.Value);

            ////logging.AddToLog(port, true);
            ////logging.AddToLog(ipAddress, true);
            //IPAddress serverAddr = IPAddress.Parse(ipAddress);
            //IPEndPoint endPoint = new IPEndPoint(serverAddr, port);

            ////send the updpacket
            //UdpClient udp = new UdpClient();
            //byte[] sendBytes = Encoding.ASCII.GetBytes(combinedString);
            //udp.Send(sendBytes, sendBytes.Length, endPoint);
        }
예제 #6
0
        public override void ProcessCommand(OSAEMethod method)
        {
            //process command
            try
            {
                string             to         = string.Empty;
                string             parameter2 = string.Empty;
                string             subject    = string.Empty;
                string             body       = string.Empty;
                OSAEObjectProperty prop       = OSAEObjectPropertyManager.GetObjectPropertyValue(method.Parameter1, "Email Address");
                if (prop != null)
                {
                    to = prop.Value;
                }

                if (to == string.Empty)
                {
                    to = method.Parameter1;
                }

                // To
                MailMessage mailMsg = new MailMessage();
                mailMsg.To.Add(to);

                // From
                MailAddress mailAddress = new MailAddress(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "From Address").Value);
                mailMsg.From = mailAddress;

                // Subject and Body
                mailMsg.Subject = "Message from OSAE";
                mailMsg.Body    = Common.PatternParse(method.Parameter2);
                parameter2      = Common.PatternParse(method.Parameter2);

                // Make sure there is a body of text.
                if (parameter2.Equals(string.Empty))
                {
                    throw new ArgumentOutOfRangeException("Message body missing.");
                }

                // See if there is a subject.
                // Opening delimiter in first char is good indication of subject.
                if (parameter2[0] == ':')
                {
                    // Find clossing delimiter
                    int i = parameter2.IndexOf(':', 1);
                    if (i != -1)
                    {
                        subject = parameter2.Substring(1, i - 1);
                        body    = parameter2.Substring(i + 1, parameter2.Length - i - 1);
                    }
                }

                if (subject.Equals(string.Empty))
                {
                    mailMsg.Subject = "Message from OSAE";
                    mailMsg.Body    = parameter2;
                }
                else
                {
                    mailMsg.Subject = subject;
                    mailMsg.Body    = body;
                }

                // Init SmtpClient and send
                SmtpClient smtpClient = new SmtpClient(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "SMTP Server").Value, int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "SMTP Port").Value));
                if (OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "ssl").Value == "TRUE")
                {
                    smtpClient.EnableSsl = true;
                }
                else
                {
                    smtpClient.EnableSsl = false;
                }

                smtpClient.Timeout               = 10000;
                smtpClient.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials           = new NetworkCredential(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Username").Value, OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Password").Value);

                this.Log.Info("to: " + mailMsg.To);
                this.Log.Info("from: " + mailMsg.From);
                this.Log.Info("subject: " + mailMsg.Subject);
                this.Log.Info("body: " + mailMsg.Body);
                this.Log.Info("smtpServer: " + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "SMTP Server").Value);
                this.Log.Info("smtpPort: " + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "SMTP Port").Value);
                this.Log.Info("username: "******"Username").Value);
                this.Log.Info("password: "******"Password").Value);
                this.Log.Info("ssl: " + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "ssl").Value);

                smtpClient.Send(mailMsg);
            }
            catch (Exception ex)
            {
                this.Log.Error("Error Sending email", ex);
            }
        }