Exemple #1
0
            public static ConnectionManager MakeConnection(string hostName, int port)
            {
       
                // Create network client object
                NetworkClient nc = new NetworkClient();
                //Connect to DDD Server
                try
                {while (!nc.IsConnected())
                    {
                        Thread.Sleep(100);
                    nc.Connect(hostName, port);  
                    }
                }
                catch (SystemException e)
                {
                    //Replace with message box when move to windows
                    Console.WriteLine("Could not Connect because of " + e.Message);
                    Environment.Exit(1001);
                }
                Console.WriteLine("Made connection");



                ConnectionManager returnValue = new ConnectionManager();
                returnValue.netClient = nc;
                return returnValue;

            }
Exemple #2
0
        public static bool Connect(String hostname, int port)
        {
            if (_client == null)
                _client = new NetworkClient();
            if (_client.IsConnected())
                _client.Disconnect();

            return _client.Connect(hostname, port);
        }
Exemple #3
0
        public Form1()
        {
            netState = NetworkState.DISCONNECTED;
            clockState = ClockState.STOPPED;
            simulationTime = 0;
            updateFrequency = 1000;
            InitializeComponent();
            ofd = new OpenFileDialog();
            ofd.Filter = "XML File(*.xml)|*.xml";
            ofd2 = new OpenFileDialog();
            ofd2.Filter = "Text File(*.txt)|*.txt";
            sfd = new SaveFileDialog();

            simModel = null;
            netClient = null;
        }
Exemple #4
0
        public Form1(string simModel, string host, string port, string user)
        {
            InitializeComponent();
            userID = user;
            hostName = host;
            portNumber = port;
            simModelName = simModel;
            simModelInfo = smr.readModel(simModelName);
            AddToTextBoxText("Welcome " + userID + ".");
            server = new NetworkClient();
            server.Connect(hostName, Convert.ToInt32(portNumber));
            SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo);
            SimulationEventDistributorClient cc = new SimulationEventDistributorClient();

            dist.RegisterClient(ref cc);
            server.Subscribe("TextChat");
            isRunning = true;
            waitForEventsThread = new Thread(new ThreadStart(WaitForEvents));
            waitForEventsThread.Start();

        }
Exemple #5
0
        private void NetworkInitialize()
        {
            hostnameTextBox.Text = System.Net.Dns.GetHostName();
            hostnameTextBox.Enabled = false;
            portTextBox.Text = "9999";
            portTextBox.Enabled = false;
            connectButton.Text = "Connect";
            connectButton.Enabled = false;
            connectTextBox.Text = netState.ToString();
            netState = NetworkState.DISCONNECTED;

            if (netClient != null)
            {
                netClient.Disconnect();
                netClient = null;
            }

            netClient = new NetworkClient();

            ClockInitialize();
        }
Exemple #6
0
        public void StartListening()
        {

            while (!network.IsConnected())
            {
                Thread.Sleep(100);
            }
            subscribeToEvents();
            isActive = true;
            while (network.IsConnected())
            {// as long as there's a network we remain open to input events
                while (isActive && network.IsConnected())
                {

                    events = network.GetEvents();

                    foreach (SimulationEvent e in events)
                    {
                        switch (e.eventType)
                        {

                            case "RevealObject":
                                if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                {
                                    AttributeCollectionValue attributes = (AttributeCollectionValue)e["Attributes"];
                                    LocationValue locus = (LocationValue)attributes["Location"];
                                    ScudLauncher.AddUnit(((StringValue)e["ObjectID"]).value, locus.X, locus.Y);
                                }
                                else if (Target.IsTarget((((StringValue)e["ObjectID"]).value)))
                                {
                                    Target.AddUnit(((StringValue)e["ObjectID"]).value);
                                }

                                break;
                            case "StateChange":
                                if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                {
                                    if ("Dead" == ((StringValue)e["NewState"]).value)
                                    {
                                        if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                            if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))

                                                ScudLauncher.DropUnit(((StringValue)e["ObjectID"]).value);
                                            else if (Target.IsTarget((((StringValue)e["ObjectID"]).value)))
                                                Target.DropUnit(((StringValue)e["ObjectID"]).value);
                                    }
                                }
                                break;
                            /*        case "MoveDone":
                                        if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                            ScudLauncher.GetScudLauncher((((StringValue)e["ObjectID"]).value)).InMotion = false;
 
                                        break;*/
                            case "SimulationTimeEvent":
                                if (0 == ((IntegerValue)e["Time"]).value % 1000)// only bother with full seconds
                                {
                                    ScudLauncher.Tick(((IntegerValue)e["Time"]).value);
                                }
                                break;
                            case "ViewProMotionUpdate":
                                if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                {
                                    string objectID=((StringValue)e["ObjectID"]).value;
                                    LocationValue locVal=(LocationValue)e["Location"];
                                    Location current=new Location(locVal.X,locVal.Y);
                                     locVal=(LocationValue)e["DestinationLocation"];
                                     Location destination=new Location(locVal.X,locVal.Y);

                                     Boolean moving = (current.X != destination.X) || (current.Y != destination.Y);
                                     if (moving != ScudLauncher.IsMoving(objectID))
                                         if(!moving)
                                         {
                                             Console.WriteLine("Updating position of "+objectID+" to ("+destination.X.ToString()+","+destination.Y.ToString()+")");
                                             ScudLauncher.SetLocation(objectID, current);

                                         }
                      ScudLauncher.SetMovement(objectID, moving);
                      
                                }
                                break;


                        }
                    }

                    Thread.Sleep(100);
                }
                if (!network.IsConnected())
                    isActive = false;
            }
            Console.WriteLine("Lost connection.");
            network = null;
        }
Exemple #7
0
 /// <summary>
 /// The constructor for the DDDServerConnection object.
 /// </summary>
 /// 
 public DDDServerConnection()
 {
     m_subscibedEvents = new List<string>();
     m_eventQueue = new List<SimulationEvent>();
     m_netClient = new NetworkClient();
     m_players = new List<string>();
     lock (PublicDmViewLock)
     { m_dmViews = new Dictionary<string, DMView>(); }
     m_dddClientPath = "";
     m_dddTimeInt = 0;
     m_dddTimeString = "0:00:00";
     _eventCallbacks = new Dictionary<string, List<ProcessSimulationEvent>>();
     m_regionDefinitions = new Dictionary<string, PolygonValue>();
     m_groundTruthView = new DMView("Ground_Truth");
 }
Exemple #8
0
 private DDD_Global() {
     _nc = new Aptima.Asim.DDD.CommonComponents.NetworkTools.NetworkClient();
 }
Exemple #9
0
        /// <summary>
        /// Constructs a watcher
        /// </summary>
        /// <param name="inputDelta">Time to sleep between checking ticks</param>
        public TickWatcher(NetworkClient s, string simModel)
        {
            string simModelName = simModel;
            simModelInfo = smr.readModel(simModelName);
            server = s;
            SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo);
            SimulationEventDistributorClient cc = new SimulationEventDistributorClient();

            dist.RegisterClient(ref cc);/////////////////
            server.Subscribe("TimeTick");


        }
Exemple #10
0
        public void StartListening()
        {

            while (!network.IsConnected())
            {
                Thread.Sleep(300);
                try
                {
                    network.Connect("DGeller2", 9999);
                }
                catch (Exception e)
                {
                    Console.WriteLine(" Connection attempt failed:" + e.Message + ". Retrying ...");
                }
            }
            subscribeToEvents();
            isActive = true;
            while (network.IsConnected())
            {// as long as there's a network we remain open to input events
                while (isActive && network.IsConnected())
                {

                    events = network.GetEvents();

                    foreach (SimulationEvent e in events)
                    {
                        switch (e.eventType)
                        {

                            case "SimulationTimeEvent":
                                int currentTime = ((IntegerValue)e["Time"]).value;
                                if (0 == currentTime % 1000)// only bother with full seconds
                                    parentForm.NewTime(currentTime.ToString().PadLeft(6));

                                break;
                            case "NewObject":

                                if ((e.parameters.ContainsKey("ObjectType"))
                                    && ("Team" == ((StringValue)e.parameters["ObjectType"]).value))
                                {
                                    string teamName = ((StringValue)e["ID"]).value;

                                    parentForm.NewTeam(teamName);
                                }
                                else if ((e.parameters.ContainsKey("ObjectType"))
                                     && ("DecisionMaker" == ((StringValue)e.parameters["ObjectType"]).value))
                                {
                                    string DMName = ((StringValue)e["ID"]).value;
                                    string myTeamName = ((StringValue)((AttributeCollectionValue)e.parameters["Attributes"])["TeamMember"]).value;
                                    parentForm.NewDM(DMName, myTeamName);
                                }
                                else if ((e.parameters.ContainsKey("ObjectType"))
                           && (
                                    ("LandObject" == ((StringValue)e.parameters["ObjectType"]).value)
                         || ("SeaObject" == ((StringValue)e.parameters["ObjectType"]).value)
                             || ("AirObject" == ((StringValue)e.parameters["ObjectType"]).value)
                                    )
                                    && ((AttributeCollectionValue)e.parameters["Attributes"]).attributes.ContainsKey("OwnerID")
                                    )
                                {
                                    string assetName = ((StringValue)e["ID"]).value;
                                    string myOwnerName = ((StringValue)((AttributeCollectionValue)e.parameters["Attributes"])["OwnerID"]).value;
                                    parentForm.NewAsset(assetName, myOwnerName);
                                }
                                break;
                            case "UpdateTag":
                                string updateAsset = ((StringValue)e.parameters["UnitID"]).value;
                                string updateTag = ((StringValue)e.parameters["Tag"]).value;
                                List<string> updateDMs = ((StringListValue)e.parameters["TeamMembers"]).strings;
                                string updateMessage = "Received UpdateTag for '" + updateAsset + "' \nwith tag '" + updateTag + "'\n for '" + updateDMs[0] + "'";
                                for (int i = 1; i < updateDMs.Count; i++)
                                    updateMessage += ", '" + updateDMs[i] + "'";
                                MessageBox.Show(updateMessage);
                                break;
                            case "SystemMessage":
                                string msgRecipient = ((StringValue)e["PlayerID"]).value;
                                string msgSystemMessage = ((StringValue)e["Message"]).value;
                                string msgColor = ((IntegerValue)e["TextColor"]).value.ToString();
                                string msgStyle = ((StringValue)e["DisplayStyle"]).value;
                                string msgMessage = "Received SystemMessage for '" + msgRecipient + "' with color '"
                                     + msgColor + "' and style '" + msgStyle + "'\n'" + msgSystemMessage + "'";
                                MessageBox.Show(msgMessage);
                                break;
                            case "TransferObject":
                                string xferReceiver = ((StringValue)e["UserID"]).value;
                                string xferDonor = ((StringValue)e["DonorUserID"]).value;
                                string xferObject = ((StringValue)e["ObjectID"]).value;
                                string xferMessage = "Object '" + xferObject + "' transferred from '" + xferDonor + "' to '" + xferReceiver + '"';
                                MessageBox.Show(xferMessage);
                                break;
                            case "CreateChatRoom":
                                string chatRoomName = ((StringValue)e["RoomName"]).value;

                                List<string> chatMembers = ((StringListValue)e.parameters["MembershipList"]).strings;
                           if(0==chatMembers.Count)
                               MessageBox.Show(" Create chat room '"+chatRoomName+"' has no members.");
                           else{
                                string createChatMsg = "Create chat room '" + chatRoomName + "' with '";
                        createChatMsg+=chatMembers[0]+"' ";
                               for (int i=1;i<chatMembers.Count;i++)
                                   createChatMsg+=", '"+chatMembers[i]+"'";
                               MessageBox.Show(createChatMsg);
                               parentForm.AddChatRoom(chatRoomName);
                           }    
                                break;
                       case "CloseChatRoom":
                           string closeChatRoomName = ((StringValue)e["RoomName"]).value;
                               MessageBox.Show("Closing chat room '"+closeChatRoomName+"'.");
                               parentForm.CloseChatRoom(closeChatRoomName);                          
                              break;

                            case "TextChatRequest":
                                string textChatBody = ((StringValue)(e["ChatBody"])).value;
                                string textUserID=((StringValue)(e["UserID"])).value;
                                string textTargetUserID = ((StringValue)(e["TargetUserID"])).value;
                                string textChatMessage = "Message '" + textChatBody + "' sent from '" + textUserID + "' to '" + textTargetUserID + "'";
                                MessageBox.Show(textChatMessage);
                                break;
                            case "CreateVoiceChannel":
                                string voiceChannelName = ((StringValue)e["ChannelName"]).value;

                                List<string> channelMembers = ((StringListValue)e.parameters["MembershipList"]).strings;
                                if (0 == channelMembers.Count)
                                    MessageBox.Show(" Create voice channel '" + voiceChannelName + "' has no members.");
                                else
                                {
                                    string createVoiceMsg = "Create voice channel '" + voiceChannelName + "' with '";
                                    createVoiceMsg += channelMembers[0] + "' ";
                                    for (int i = 1; i < channelMembers.Count; i++)
                                        createVoiceMsg += ", '" + channelMembers[i] + "'";
                                    MessageBox.Show(createVoiceMsg);
                                    parentForm.AddVoiceChannel(voiceChannelName);
                                }

                                break;
                            case "CloseVoiceChannel":
                                string closeVoiceChannelName = ((StringValue)e["ChannelName"]).value;
                                MessageBox.Show("Closing voice channel '" + closeVoiceChannelName + "'.");
                                parentForm.CloseVoiceChannel(closeVoiceChannelName);
                                break;
                            case "AddToVoiceChannel":
                                string addToChannel = ((StringValue)e["ChannelName"]).value;
                                string addToDM = ((StringValue)e["NewAccessor"]).value;
                                MessageBox.Show("Adding '" + addToDM + "' to channel '" + addToChannel + "'");
                                break;
                            case "RemoveFromVoiceChannel":
                                string removeFromChannel = ((StringValue)e["ChannelName"]).value;
                                string deletedPlayer = ((StringValue)e["DeletedPlayer"]).value;
                                MessageBox.Show("Removing '" + deletedPlayer + "' from channel '" + removeFromChannel + "'");
                                break;

                        }
                    }

                    Thread.Sleep(100);
                }
                if (!network.IsConnected())
                    isActive = false;
            }
            Console.WriteLine("Lost connection.");
            network = null;
        }
Exemple #11
0
        static void Main(string[] args)
        {
            
            /* setup the exit handler */

            Console.TreatControlCAsInput = false;
            Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler);

            /* read in the config file */

            if (args.Length != 2)
            {
                Console.WriteLine(String.Format("Usage: {0} [CONFIG_FILE] [DDD_SIMULATION_MODEL]",Environment.CommandLine));
                Environment.Exit(1);
            }

            string configFileName = args[0];
            Console.WriteLine(String.Format("Reading config file: {0}",configFileName));

            string simModelFile = args[1];
            SimulationModelInfo simModel = null;
            SimulationModelReader smr = new SimulationModelReader();
            try
            {
                simModel = smr.readModel(simModelFile);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            ConfigFile config = new ConfigFile();
            try
            {
                config.readFile(configFileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            try
            {
                config.verifyConfig();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            /* connect to the DDD Server */

            dddNetworkClient = new NetworkClient();


            if (!dddNetworkClient.Connect(config.dddServerHostname, config.dddServerPortNumber))
            {
                Environment.Exit(1);
            }

            /* connect to the IMAP server */

            imapServer = new Chilkat.Imap();
            imapServer.Port = config.emailServerPortNumber;
            imapServer.Ssl = config.emailServerUseSSL;

            bool success;

            // Anything unlocks the component and begins a fully-functional 30-day trial.
            success = imapServer.UnlockComponent("SAptimaIMAPMAIL_yyq2ULZCFw4G");
            if (success != true)
            {
                Console.WriteLine(imapServer.LastErrorText);
                ExitApp();
            }
           

            /* loop reading from the IMAP Server until user cancels or the DDD disconnects us */
            int count = config.emailCheckFrequency;
            while (dddNetworkClient.IsConnected())
            {
                if (count == config.emailCheckFrequency)
                {
                    Console.WriteLine("Checking email");
                    // Connect to an IMAP server.
                    success = imapServer.Connect(config.emailServerHostname);
                    if (success != true)
                    {
                        Console.WriteLine(imapServer.LastErrorText);
                        ExitApp();
                    }

                    // Login
                    success = imapServer.Login(config.emailUsername, config.emailPassword);
                    if (success != true)
                    {
                        Console.WriteLine(imapServer.LastErrorText);
                        ExitApp();
                    }

                    // Select an IMAP mailbox
                    success = imapServer.SelectMailbox("Inbox");
                    if (success != true)
                    {
                        Console.WriteLine(imapServer.LastErrorText);
                        ExitApp();
                    }
                    Chilkat.MessageSet messageSet;
                    // We can choose to fetch UIDs or sequence numbers.
                    bool fetchUids;
                    fetchUids = true;
                    /* downloading new emails from IMAP server */

                    messageSet = imapServer.Search("NOT SEEN", fetchUids);
                    if (messageSet == null)
                    {
                        Console.WriteLine(imapServer.LastErrorText);
                        ExitApp();
                    }
                    // Fetch the emails into a bundle object:
                    Chilkat.EmailBundle bundle;
                    bundle = imapServer.FetchBundle(messageSet);
                    if (bundle == null)
                    {

                        Console.WriteLine(imapServer.LastErrorText);
                        ExitApp();
                    }

                    imapServer.Disconnect();
                    int i;

                    Chilkat.Email email;

                    for (i = 0; i <= bundle.MessageCount - 1; i++)
                    {
                        email = bundle.GetEmail(i);

                        SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, "ExternalEmailReceived");
                        ((StringValue)ev["FromAddress"]).value = email.FromAddress;
  
                        for (int k = 0; k < email.NumTo; k++)
                        {
                            ((StringListValue)ev["ToAddresses"]).strings.Add(email.GetToAddr(k));
                            //Console.WriteLine("To:" + email.GetToAddr(k));
                        }
                        //Console.WriteLine("Wall clock time:" + email.LocalDate.ToString());
                        ((StringValue)ev["WallClockTime"]).value = email.LocalDate.ToString();
                        //Console.WriteLine("Subject:" + email.Subject);
                        ((StringValue)ev["Subject"]).value = email.Subject;

                        //Console.WriteLine("Body:" + email.Body);
                        ((StringValue)ev["Body"]).value = email.Body;
                        //Console.WriteLine("NumAttachments:" + email.NumAttachments.ToString());
                        string attachName;
                        string attachDir;
                        string dirPath;
                        for (int j = 0; j < email.NumAttachments; j++)
                        {
                            attachName = email.GetAttachmentFilename(j);
                            //Console.WriteLine("filename=" + email.GetAttachmentFilename(j));
                            attachDir = String.Format("Attachments{0}", email.LocalDate.ToString("yyyyMMddHHmmss"));
                            
                            dirPath = String.Format("{0}\\{1}", config.attachmentBaseDirectory, UniqueDirName(config.attachmentBaseDirectory, attachDir));
                            Directory.CreateDirectory(dirPath);
                            attachName = String.Format("{0}\\{1}", dirPath, email.GetAttachmentFilename(j));
                            ((StringListValue)ev["Attachments"]).strings.Add(attachName);
                            email.SaveAttachedFile(j, dirPath);
                        }

                        dddNetworkClient.PutEvent(ev);
                        Console.WriteLine(SimulationEventFactory.XMLSerialize(ev));
                    }
                    count = 0;
                }
                
                Thread.Sleep(1000);
                count++;
            }

            ExitApp();
        }