예제 #1
0
        private bool SendData(SocketCommand CommandObjectToSend, AsyncSkt ConnectionToUse)
        {
            // do we have a valid connection?
            if (ConnectionToUse == null)
            {
                return(false);
            }

            // do we have an object to send?
            if (CommandObjectToSend == null)
            {
                return(false);
            }

            string SerializedData = "";

            SerializedData = TcpIpCommon.SerializeCommandObject(CommandObjectToSend);

            // (bsk) add divider for splitting...
            SerializedData += "<msg>";

            try
            {
                ConnectionToUse.SendData(SerializedData);
            }
            catch (Exception ex)
            {
                //LogAccess.WriteLog("Error sending data: " + ex.ToString(), "Listener");
                //throw;
            }

            return(true);
        }
예제 #2
0
 protected void OnDataArrival(SocketCommand CommandtoRaise, string ID)
 {
     if (DataArrival != null)
     {
         DataArrival(CommandtoRaise, ID);
     }
 }
예제 #3
0
        private SocketCommand ShowUpdatePage(SocketCommand commandToProcess)
        {
            SocketCommand returnCommandObject = new SocketCommand();

            if (commandToProcess.Parameters.Count != 0)
            {
                string templateName    = GetParameter("TemplateName", commandToProcess).ToString();
                string destSceneString = GetParameter("DestScene", commandToProcess).ToString();

                CommandParameter queueCommandParameter = commandToProcess.Parameters.Find(delegate(CommandParameter foundList) { return(foundList.Name == "QueueCommand"); });

                bool   queueCommand = false;
                Output destScene    = _previewScene;

                if (queueCommandParameter != null && !string.IsNullOrEmpty(queueCommandParameter.Value.ToString()))
                {
                    queueCommand = (queueCommandParameter.Value.ToString() == "TRUE");
                }

                if (!string.IsNullOrEmpty(destSceneString))
                {
                    if (destSceneString.ToUpper() == "AIR")
                    {
                        destScene = _outputScene;
                    }
                    else
                    {
                        destScene = _previewScene;
                    }
                }

                if (templateName != null)
                {
                    //see if this is a merge data without transitions
                    if (GetParameter("MergeDataWithoutTransitions", commandToProcess) != null)
                    {
                        destScene.PageEngine.MergeDataWithoutTransitions(templateName, templateName, commandToProcess.TemplateData);
                    }
                    else
                    {
                        // check if there is data to merge...
                        if (commandToProcess.TemplateData != null)
                        {
                            destScene.PageEngine.MergeData(templateName, templateName, commandToProcess.TemplateData);
                        }

                        if (returnCommandObject.Command != CommandType.CommandFailed)
                        {
                            destScene.PageEngine.ShowPage(templateName, false);
                        }
                    }
                }
                else
                {
                    returnCommandObject = CreateCommandFailedObject("TemplateName cannot be nothing", commandToProcess.CommandID);
                }
            }

            return(returnCommandObject);
        }
예제 #4
0
        private void ProcessOnDataArrival(string incomingCommand)
        {
            // reset heartbeat
            DisableHeartbeat();
            EnableHeartbeat();

            SocketCommand commandToProcess = new SocketCommand();

            // split..?
            string[] stringSeperators = new string[] { "<msg>" };
            string[] myCommands       = incomingCommand.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries);

            foreach (string command in myCommands)
            {
                try
                {
                    commandToProcess = TcpIpCommon.DeserializeCommandObject(command);
                }
                catch (Exception ex)
                {
                    // log here?
                    Debug.Print(ex.ToString());
                    //LogAccess.WriteLog("Error processing command: " + ex.ToString(), "Talker");
                    //throw;
                }

                if (commandToProcess != null)
                {
                    //SendAcknowledgement(commandToProcess.CommandID);
                    OnDataArrival(commandToProcess, _identifier);
                }
            }
        }
예제 #5
0
        private void SendAcknowledgement(string receivedCommandID)
        {
            SocketCommand acknowledgementCommand = new SocketCommand
            {
                Command   = CommandType.ReceiptAcknowledgement,
                CommandID = receivedCommandID
            };

            //LogAccess.WriteLog("Sending Acknowledgement.", "Listener");
            SendData(acknowledgementCommand, _socketTalker);
        }
예제 #6
0
        //public delegate void CommandCompleteEventHandler(PlayerCommand Command);
        //static event GFXPlayer.CommandCompleteEventHandler CommandCompleted;
        //static void OnCommandCompleted(PlayerCommand Command)
        //{
        //    //DataArrival(CommandtoRaise);
        //    if (CommandCompleted != null)
        //    {
        //        CommandCompleted(Command);
        //    }
        //}

        //private static void gfxCommandCompleted(PlayerCommand command)
        //{

        //    string filenameToSave = GetParameter("filename", _currentCommand);
        //    string templateName = GetParameter("Template", _currentCommand);

        //    if ((filenameToSave != null) & (templateName != null))
        //    {
        //        filenameToSave = FileNameGenerator(filenameToSave);
        //        _returnCommandObject = GraphicsPlayer.gfxPlayer.CaptureImage(templateName, filenameToSave);
        //    }
        // }

        private SocketCommand CreateCommandFailedObject(string messageDetail, string commandID)
        {
            SocketCommand returnCommandObject = new SocketCommand();

            returnCommandObject.Command    = CommandType.CommandFailed;
            returnCommandObject.Parameters = new List <CommandParameter>();
            returnCommandObject.Parameters.Add(new CommandParameter("exception", messageDetail));
            returnCommandObject.CommandID = commandID;

            return(returnCommandObject);
        }
예제 #7
0
        // private routines
        private void SendHeartBeat(AsyncSkt SocketToSendOn)
        {
            SocketCommand myHeartBeat = new SocketCommand()
            {
                ID        = TcpIpCommon.GetMyID(),
                Timestamp = DateTime.Now,
                Command   = CommandType.Heartbeat
            };

            //LogAccess.WriteLog("...heartbeat...", "Listener");
            SendData(myHeartBeat, SocketToSendOn);
        }
예제 #8
0
        public static SocketCommand DeserializeCommandObject(string CommandObjectString)
        {
            XmlSerializer serializer          = new XmlSerializer(typeof(SocketCommand));
            SocketCommand ObjectToReturn      = new SocketCommand();
            StringReader  StringToDeserialize = new StringReader(CommandObjectString);

            try
            {
                ObjectToReturn = (SocketCommand)serializer.Deserialize(StringToDeserialize);
                return(ObjectToReturn);
            }
            finally
            { StringToDeserialize.Close(); }
        }
예제 #9
0
        public static string SerializeCommandObject(SocketCommand CommandObject)
        {
            XmlSerializer serializer   = new XmlSerializer(typeof(SocketCommand));
            StringWriter  StringToSend = new StringWriter();

            try
            {
                serializer.Serialize(StringToSend, CommandObject);

                return(StringToSend.ToString());
            }
            finally
            { StringToSend.Close(); }
        }
예제 #10
0
        // private routines
        private void SendHeartBeat(AsyncSkt SocketToSendOn)
        {
            //disable the heartbeat so we don't get queued events
            DisableHeartbeat(); // _heartbeatTimer.Enabled = false;
            SocketCommand myHeartBeat = new SocketCommand()
            {
                ID        = TcpIpCommon.GetMyID(),
                Timestamp = DateTime.Now,
                //Command = CommandType.Heartbeat
            };

            //LogAccess.WriteLog("...heartbeat...", "Talker");
            SendData(myHeartBeat, SocketToSendOn);
            //re enable the timer so we can send future heartbeats
            EnableHeartbeat(); // _heartbeatTimer.Enabled = true;
        }
예제 #11
0
        private object GetParameter(string parameterName, SocketCommand commandToSearch)
        {
            try
            {
                CommandParameter outputFormatParameter = commandToSearch.Parameters.Find(delegate(CommandParameter foundList) { return(foundList.Name == parameterName); });
                if (outputFormatParameter != null)
                {
                    return(outputFormatParameter.Value);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }
예제 #12
0
        private void ProcessOnDataArrival(string incomingCommand)
        {
            SocketCommand incomingCommandObject = new SocketCommand();

            // split..?
            string[] stringSeperators = new string[] { "<msg>" };
            string[] myCommands       = incomingCommand.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries);

            //LogAccess.WriteLog("Data arrival event", "Listener");
            foreach (string command in myCommands)
            {
                if (tracing)
                {
                    // we need to log the command with a timestamp
                    //TcpIpCommon.WriteToTraceLogSimple(command.ToString());
                }

                try
                {
                    incomingCommandObject = TcpIpCommon.DeserializeCommandObject(command);
                }
                catch (Exception ex)
                {
                    // log here?
                    //Debug.Print(ex.ToString());
                    //LogAccess.WriteLog(ex.ToString());
                    //LogAccess.WriteLog("Bad Command received: " + command.ToString(), "Listener");
                    incomingCommandObject = null;
                    //throw;
                }

                if (incomingCommandObject != null)
                {
                    SendAcknowledgement(incomingCommandObject.CommandID);
                    OnDataArrival(incomingCommandObject, _identifier);
                }
            }
        }
예제 #13
0
        public bool Talk(SocketCommand CommandToSend)
        {
            //disable the heartbeat so we don't get a heartbeat while trying to send a command
            DisableHeartbeat(); // _heartbeatTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
            // update ID, timestamp
            CommandToSend.ID        = TcpIpCommon.GetMyID();
            CommandToSend.Timestamp = DateTime.Now;

            try
            {
                SendData(CommandToSend, _socketTalker);
                return(true);
            }
            catch (Exception ex)
            {
                //LogAccess.WriteLog(ex.ToString(), "Talker");
                return(false);
            }
            finally
            {
                //re enable the timer so we can send future heartbeats
                EnableHeartbeat(); // _heartbeatTimer.Change(_heartbeatInterval,_heartbeatInterval);
            }
        }
예제 #14
0
 //added by wknight to allow tcplistener to send back command success or failure from
 //the listener
 public bool SendData(SocketCommand CommandObjectToSend)
 {
     return(SendData(CommandObjectToSend, _socketTalker));
 }
예제 #15
0
        public SocketCommand ProcessCommand(SocketCommand commandToProcess)
        {
            _currentCommand      = commandToProcess;
            _returnCommandObject = new SocketCommand();

            // extract command from command object
            switch (commandToProcess.Command)
            {
            case CommandType.Initialize:
            {
                VX_DISPLAY_TYPES displayType = VX_DISPLAY_TYPES.VX_DISPLAY_VGA;
                VX_FORMAT_TYPES  formatType  = VX_FORMAT_TYPES.VX_FORMAT_720P;

                if (commandToProcess.Parameters.Count != 0)
                {
                    CommandParameter displayTypeParameter = commandToProcess.Parameters.Find(delegate(CommandParameter foundList) { return(foundList.Name == "DisplayType"); });
                    if (displayTypeParameter != null)
                    {
                        displayType = (VX_DISPLAY_TYPES)displayTypeParameter.Value;
                    }

                    CommandParameter formatTypeParameter = commandToProcess.Parameters.Find(delegate(CommandParameter foundList) { return(foundList.Name == "FormatType"); });
                    if (formatTypeParameter != null)
                    {
                        formatType = (VX_FORMAT_TYPES)formatTypeParameter.Value;
                    }
                }

                CommandParameter workingDirectory = commandToProcess.Parameters.Find(delegate(CommandParameter foundList) { return(foundList.Name == "WorkingDirectory"); });

                _previewScene.WorkingDirectory = workingDirectory.Value.ToString();
                _outputScene.WorkingDirectory  = workingDirectory.Value.ToString();

                _previewScene.InitializeScene(VX_DISPLAY_TYPES.VX_DISPLAY_VGA, formatType);
                _outputScene.InitializeScene(displayType, formatType);

                _returnCommandObject = null;

                break;
            }

            //#region "LoadTemplate"
            ////
            //// LoadTemplate
            ////
            //case CommandType.LoadTemplate:
            //    {
            //        if (commandToProcess.Parameters.Count != 0)
            //        {
            //            //string templateName = GetParameter("TemplateName", commandToProcess);
            //            string templateDirectory = GetParameter("TemplateDirectory", commandToProcess);

            //            //if ((!string.IsNullOrEmpty(templateDirectory)) && (templateDirectory != _workingDirectory))
            //            //{
            //            //    templateName = templateDirectory + "\\" + templateName;
            //            //}

            //            string templateName = GetTemplateName(commandToProcess);

            //            if (!string.IsNullOrEmpty(templateName))
            //            {
            //                _returnCommandObject = GraphicsPlayer.gfxPlayer.LoadTemplate(templateName);
            //            }
            //            else
            //            {
            //                _returnCommandObject = CreateCommandFailedObject("TemplateName cannot be nothing",
            //                                                                commandToProcess.CommandID);
            //            }
            //            //CommandParameter outputFormatParameter = CommandToProcess.Parameters.Find(delegate(CommandParameter foundList) { return foundList.Name == "TemplateName"; });
            //            //if (outputFormatParameter != null) { outputFormat = outputFormatParameter.Value; }
            //        }
            //        break;

            //    }
            //#endregion

            // didn't really see a difference between ShowPage and UpdatePage commands; combining for now
            case CommandType.ShowPage:
            case CommandType.UpdatePage:
            {
                _returnCommandObject = ShowUpdatePage(commandToProcess);
                break;
            }

            case CommandType.HidePage:
            {
                if (commandToProcess.Parameters.Count != 0)
                {
                    string templateName       = GetParameter("TemplateName", commandToProcess).ToString();
                    string queueCommandString = GetParameter("QueueCommand", commandToProcess).ToString();
                    string destSceneString    = GetParameter("DestScene", commandToProcess).ToString();
                    bool   queueCommand       = false;
                    Output destScene          = _previewScene;

                    if (!string.IsNullOrEmpty(queueCommandString))
                    {
                        queueCommand = (queueCommandString == "TRUE");
                    }

                    if (!string.IsNullOrEmpty(destSceneString))
                    {
                        if (destSceneString.ToUpper() == "AIR")
                        {
                            destScene = _outputScene;
                        }
                        else
                        {
                            destScene = _previewScene;
                        }
                    }

                    if (!string.IsNullOrEmpty(queueCommandString))
                    {
                        queueCommand = (queueCommandString == "TRUE");
                    }

                    if (templateName != null)
                    {
                        try
                        {
                            destScene.PageEngine.HidePage(templateName, queueCommand);
                        }
                        catch
                        {
                            //for some reason HidePage was throwing an exception when a page wasn't visible...eventually figure out what the deal is
                        }
                    }
                    else
                    {
                        _returnCommandObject = CreateCommandFailedObject("TemplateName cannot be nothing",
                                                                         commandToProcess.CommandID);
                    }
                }
                break;
            }

            case CommandType.SetCalibrationFile:
            {
                _outputScene.CalibrationFile  = GetParameter("CalibrationFile", commandToProcess).ToString();
                _previewScene.CalibrationFile = GetParameter("CalibrationFile", commandToProcess).ToString();
                break;
            }

            case CommandType.SetTelemetryFile:
            {
                _outputScene.TelemetryFile  = GetParameter("TelemetryFile", commandToProcess).ToString();
                _previewScene.TelemetryFile = GetParameter("TelemetryFile", commandToProcess).ToString();
                break;
            }

            default:
            {
                _currentCommand = null;
                return(null);
            }
            }

            if (_returnCommandObject != null)
            {
                _returnCommandObject.CommandID = commandToProcess.CommandID;

                _currentCommand = null;

                if (_returnCommandObject.Command == CommandType.CommandFailed)
                {
                    //LogAccess.WriteLog("Command Failed. Reason = " + GetParameter("exception", _returnCommandObject), "CommandProcessor");
                }
            }

            //LogAccess.WriteLog("> Done Processing " + commandToProcess.Command, "CommandProcessor");
            return(_returnCommandObject);
        }