Exemple #1
0
 /// <summary>
 /// Send a Command but does not wait for it to succeed and come back
 /// </summary>
 /// <param name="cmd"></param>
 public void SendCommandAsync(Commands.BaseCommand cmd)
 {
     cmd.Send(this);
     foreach (CommunicationEndpoint mycomm in knownEndpoints)
     {
         if (mycomm.Connected())
         {
             if (mycomm.commType == CommunicationEndpoint.Communicationtype.Command)
             {
                 mycomm.SendCommand(cmd);
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Sends a Command and waits until it comes back with the Results
        /// </summary>
        /// <param name="cmd">An Command object to be sent, containing code and values</param>
        /// <returns>The resulting Command object which came back</returns>
        public Commands.BaseCommand SendCommand(Commands.BaseCommand cmd)
        {
            //Sende Kommando an alle Endpunkte
            bool sent = false;

            cmd.Send(this);
            foreach (CommunicationEndpoint mycomm in knownEndpoints)
            {
                if (mycomm.Connected())
                {
                    if (mycomm.commType == CommunicationEndpoint.Communicationtype.Command)
                    {
                        sent = true;
                        mycomm.SendCommand(cmd);
                    }
                }
            }
            if (!sent)
            {
                return(cmd);
            }
            // Warte auf ankunft des Ergebnisses
            bool CommandRecieved = false;

            do
            {
                lock (SynclockCommands)
                {
                    if (SyncCommands.ContainsKey(cmd.guid))
                    {
                        CommandRecieved = true;
                    }
                }
                Thread.Sleep(5);
            } while (!CommandRecieved);

            ///Remove recieved Command from store
            lock (SynclockCommands)
            {
                Commands.BaseCommand recievedCmd = SyncCommands[cmd.guid];
                SyncCommands.Remove(cmd.guid);
                return(recievedCmd);
            }
        }