private void GetLoginAttemptsService()
        {
            while (true)
            {
                ITuple attempt = _loginAttempts.Get(typeof(string), typeof(string));
                Console.WriteLine("saw login request");
                var user = attempt[0] as string;
                var pass = attempt[1] as string;

                try
                {
                    SelectAccount(user); // don't remove, used to check whether account exists. Because accountExists(user) is hard
                    if (BoolFromRawPassAndUser(pass, user) && _loggedInUsers.QueryP(user) == null)
                    {
                        _loggedInUsers.Put(user);
                        _loginAttempts.Put(user, 1);
                        Console.WriteLine("server: deposited results succ");
                    }
                    else
                    {
                        _loginAttempts.Put(user, 0);
                        Console.WriteLine("server: deposited results fail");
                    }
                }
                catch (Exception)
                {
                    _loginAttempts.Put(user, 0);
                    Console.WriteLine("server: deposited results null");
                }
            }
        }
Esempio n. 2
0
        //public ITuple getRunwayClearance(string planeCredentials, string currentLocationName)
        //{
        //    return getRunwayClearance(planeCredentials, currentLocationName, 0);
        //}

        //public ITuple getRunwayClearance(string planeCredentials, string currentLocationName, int currentLocationCredential)
        //{
        //    ITuple freeRunwaySpace;
        //    Console.WriteLine(planeCredentials + " found a Control Tower and is getting clearance for accessing the runway...");
        //    if (currentLocationName == "Taxiway")
        //    {
        //        freeRunwaySpace = runwaySpace.Get("Runway Nr.", currentLocationCredential);
        //    }
        //    else
        //    {
        //        freeRunwaySpace = runwaySpace.Get("Runway Nr.", typeof(int));
        //    }
        //    Console.WriteLine(planeCredentials + " has been granted clearance to access " + freeRunwaySpace[0] + freeRunwaySpace[1]);
        //    return freeRunwaySpace;
        //}

        public ITuple getRunwayClearance(string planeCredentials)
        {
            ITuple freeRunwaySpace;

            Console.WriteLine(planeCredentials + " found a Control Tower and is getting clearance for accessing the runway...");
            freeRunwaySpace = runwaySpace.Get("Runway Nr.", typeof(int));
            return(freeRunwaySpace);
        }
Esempio n. 3
0
        public void landing()
        {
            //Establishing communication
            Console.WriteLine(credentials + " is Searching for control tower...");
            //ITuple controlTowerTupleInner = new dotSpace.Objects.Space.Tuple("Control Tower Nr.", typeof(int), typeof(ControlTower));
            //ITuple controlTowerTuple = airport.QueryP("Control Towers", controlTowerTupleInner);
            if (controlTowerSpace != null)
            {
                ITuple controlTowerTuple = controlTowerSpace.Query("Control Tower Nr.", typeof(int), typeof(ControlTower));
                //Console.WriteLine(controlTowerTuple);
                if (controlTowerTuple != null)
                {
                    //Getting landing clearance
                    ControlTower controlTower = (ControlTower)controlTowerTuple[2];
                    Console.WriteLine(credentials + " found control tower and getting landing clearance...");
                    ITuple freeRunwayLock = controlTower.getRunwayClearance();
                    if (freeRunwayLock != null)
                    {
                        //runwaySpace.Get(freeRunwayLock);
                        Console.WriteLine(credentials + " got landing clearance with ID " + freeRunwayLock[0] + freeRunwayLock[1]);

                        //Leave airspace, land in airport
                        //Thread.sleep(5000);

                        //Landing & Taxiway step
                        Console.WriteLine(credentials + " is searching for free landing taxiway...");
                        //ITuple freeTaxiWayTuple = taxiwaySpace.Query("Taxiway Nr.", controlTowerTuple[1], typeof(int), true);
                        //ITuple freeTaxiWayTuple = taxiwayLandingSpace.Get("Taxiway L", controlTowerTuple[1], typeof(int), true);
                        ITuple freeTaxiWayTuple = taxiwayLandingSpace.Get("Taxiway L", freeRunwayLock[1], typeof(int), true);
                        int    barrierLimit     = (int)freeTaxiWayTuple[2] - 1;
                        Console.WriteLine(credentials + " found free landing taxiway with barrier value " + (barrierLimit + 1) + " and getting free taxiway tuple...");
                        //taxiwaySpace.Get((string)freeTaxiWayTuple[0], freeTaxiWayTuple[1], barrierLimit);
                        Console.WriteLine(credentials + " is putting runway lock with ID " + freeRunwayLock[0] + freeRunwayLock[1]);
                        //runwaySpace.Put(freeRunwayLock);
                        controlTower.putRunway(freeRunwayLock);
                        Console.WriteLine(credentials + " is putting free landing taxiway back with new barrier " + barrierLimit);
                        taxiwayLandingSpace.Put((string)freeTaxiWayTuple[0], freeTaxiWayTuple[1], barrierLimit, (barrierLimit) > 0);
                        //System.Threading.Thread.Sleep(2500);

                        //Hanger step
                        Console.WriteLine(credentials + " is searching for same landing taxiway, to increase barrier...");
                        //ITuple usedTaxiWay = taxiwayLandingSpace.Get("Taxiway L", controlTowerTuple[1], typeof(int), typeof(bool));
                        ITuple usedTaxiWay = taxiwayLandingSpace.Get("Taxiway L", freeTaxiWayTuple[1], typeof(int), typeof(bool));
                        barrierLimit = (int)usedTaxiWay[2] + 1;
                        Console.WriteLine(credentials + " is increasing landing taxiway " + usedTaxiWay[1] + "'s barrierLimit to " + barrierLimit);
                        taxiwayLandingSpace.Put((string)freeTaxiWayTuple[0], freeTaxiWayTuple[1], barrierLimit, (barrierLimit) > 0);
                        Console.WriteLine(credentials + " has safely arrived in the hangar!");
                        // Thread kill
                        //return;
                    }
                }
            }
        }
Esempio n. 4
0
        public void takeoff()
        {
            // Leaving hangar, entering taxiway
            Console.WriteLine(credentials + " is searching for free take-off taxiway...");
            //ITuple freeTaxiWayTuple = taxiwayTakeoffSpace.Get("Taxiway T", controlTowerTuple[1], typeof(int), true);
            ITuple freeTaxiWayTuple = taxiwayTakeoffSpace.Get("Taxiway T", typeof(int), typeof(int), true);
            int    barrierLimit     = (int)freeTaxiWayTuple[2] - 1;

            Console.WriteLine(credentials + " found free take-off taxiway with barrier value " + (barrierLimit + 1) + " and getting free taxiway tuple...");
            //System.Threading.Thread.Sleep(2500);
            Console.WriteLine(credentials + " is putting free take-off taxiway back with new barrier " + barrierLimit);
            taxiwayTakeoffSpace.Put((string)freeTaxiWayTuple[0], freeTaxiWayTuple[1], barrierLimit, barrierLimit > 0);

            // Leaving taxiway, entering runway

            //Getting takeoff clearance
            //Establishing communication
            Console.WriteLine(credentials + " is searching for control tower...");
            //ITuple controlTowerTupleInner = new dotSpace.Objects.Space.Tuple("Control Tower Nr.", typeof(int), typeof(ControlTower));
            //ITuple controlTowerTuple = airport.QueryP("Control Towers", controlTowerTupleInner);
            if (controlTowerSpace != null)
            {
                ITuple controlTowerTuple = controlTowerSpace.Query("Control Tower Nr.", typeof(int), typeof(ControlTower));
                //Console.WriteLine(controlTowerTuple);
                if (controlTowerTuple != null)
                {
                    ControlTower controlTower = (ControlTower)controlTowerTuple[2];
                    Console.WriteLine(credentials + " found control tower and getting takeoff clearance...");
                    ITuple freeRunwayLock = controlTower.getRunwayClearance();
                    if (freeRunwayLock != null)
                    {
                        //Make space on the taxiway you just left
                        Console.WriteLine(credentials + " is searching for same take-off taxiway, to increase barrier...");
                        //ITuple usedtaxiway = taxiwayTakeoffSpace.Get("Taxiway T", controlTowerTuple[1], typeof(int), typeof(bool));
                        ITuple usedtaxiway = taxiwayTakeoffSpace.Get("Taxiway T", freeTaxiWayTuple[1], typeof(int), typeof(bool));
                        barrierLimit = (int)usedtaxiway[2] + 1;
                        Console.WriteLine(credentials + " is increasing take-off taxiway " + usedtaxiway[1] + "'s barrierlimit to " + barrierLimit);
                        taxiwayTakeoffSpace.Put((string)usedtaxiway[0], usedtaxiway[1], barrierLimit, barrierLimit > 0);
                        Console.WriteLine(credentials + " has safely left the taxiway!");

                        //Leave the runway
                        //runwaySpace.Get(freeRunwayLock);
                        Console.WriteLine(credentials + " got takeoff clearance with ID " + freeRunwayLock[0] + freeRunwayLock[1] + " and left the airport!");
                        //leave airport, enter in airspace
                        //Thread.sleep(5000);
                        //runwaySpace.Put(freeRunwayLock);
                        controlTower.putRunway(freeRunwayLock);
                        //Airspace step
                    }
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please specify your name");
                return;
            }
            // Instantiate a new Fifobased tuple space.
            ISpace dtu = new SequentialSpace();

            // Insert a tuple with a message.
            dtu.Put("Hello student!");

            // Instantiate a new agent, assign the tuple space and start it.
            AgentBase student = new Student(args[0], dtu);

            student.Start();

            // Wait and retrieve the message from the agent.
            ITuple tuple = dtu.Get(typeof(string), typeof(string));

            // Print the contents to the console.
            Console.WriteLine(string.Format("{0}, you are attending course {1}", tuple[0], tuple[1]));
            Console.Read();
        }
        private void GetAccountCreationService()
        {//To create a user, put at (username, password) tuple in accountCreation and check for confirmation
            while (true)
            {
                ITuple attempt = _accountCreation.Get(typeof(string), typeof(string));

                var username = (string)attempt[0];
                var password = (string)attempt[1];

                Console.WriteLine("server: saw request for user creation. With input " + username + " " + password);
                try
                {
                    var exists = SelectAccount(username);
                    _accountCreation.Put(username, 0);
                    Console.WriteLine("server: rejected user creation");
                }
                catch (Exception)
                {
                    var newUser = new Account(username, password);
                    _userAccounts.Put(newUser);
                    _accountCreation.Put(username, 1); //lav 1 til en enum for success
                    Console.WriteLine("server: created user");
                }
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            SequentialSpace inbox = new SequentialSpace();

            inbox.Put("Hello world!");
            ITuple tuple = inbox.Get(typeof(string));

            Console.WriteLine(tuple);
            Console.Read();
        }
        private void GetConferenceListService()
        {
            while (true)
            {
                var request        = _getConferences.Get(typeof(string), typeof(string), typeof(string), typeof(int), typeof(string));
                var username       = (string)request[0];
                var conferenceName = (string)request[1];
                var ipOfConference = (string)request[2];
                var requestType    = (int)request[3];
                var pass           = (string)request[4];

                SelectAccount(username); // don't remove

                Console.WriteLine("got request to create or delete conference");
                if (!IsAuthorized(username, pass))
                {
                    Console.WriteLine("User was not authorized");
                    _getConferences.Put("Result", 0, username);
                    break;
                }
                if (requestType == 1)
                {
                    //add
                    _conferences.Put(username, conferenceName, ipOfConference);
                    List <string> confList = _conferences.QueryAll(typeof(string), typeof(string), typeof(string)).Select(t => t.Get <string>(1)).ToList();
                    _getConferences.Get(typeof(List <string>));
                    _getConferences.Put(confList);
                    Console.WriteLine("added conference " + conferenceName);
                    _getConferences.Put("Result", 1, username);
                }
                if ((int)request[3] == 0)
                {
                    //remove
                    _conferences.Get(username, conferenceName, ipOfConference);
                    List <string> confList = _conferences.QueryAll(typeof(string), typeof(string), typeof(string)).Select(t => t.Get <string>(1)).ToList();
                    _getConferences.Get(typeof(List <string>));
                    _getConferences.Put(confList);
                    Console.WriteLine("removed conference " + conferenceName);
                }
            }
        }
 public void CreateSequentialSpaceWithSequentialSpaceNameGeneratorTest()
 {
     using (var spaceRepo = new SpaceRepository())
     {
         string uri       = "tcp://127.0.0.1:5005";
         string testName  = NameHashingTool.GenerateUniqueSequentialSpaceName("ThisNameDoesNotActuallyMatter");
         ISpace testSpace = new SequentialSpace();
         spaceRepo.AddSpace(testName, testSpace);
         spaceRepo.AddGate(uri + "?CONN");
         var testElement = "This string is a test";
         testSpace.Put(testElement);
         testSpace.Get(testElement);
         Debug.Assert(!testSpace.GetAll().Any());
         // putting and getting the element should leave us with an empty space
     }
 }
        private void SendEvents()
        {
            while (true)
            {
                // Wait for send signal
                outgoingEvents.Get("send-signal");
                // Get the batch of events to send
                var eventTuples = outgoingEvents.GetAll(typeof(string), typeof(int), typeof(string));

                foreach (var eventTuple in eventTuples)
                {
                    Connection.Lobby.Space.Put("event",
                                               (string)eventTuple[0],          // Event type identifier
                                               (int)Connection.LocalPlayer.Id, // Sender (local id)
                                               (int)eventTuple[1],             // Receiver
                                               (string)eventTuple[2]           // JSON data
                                               );
                }
            }
        }
        private void GetLogoutAttemptsService()
        {
            while (true)
            {
                ITuple attempt = _loginAttempts.Get("logout", typeof(string), typeof(string));
                Console.WriteLine("saw logout request");
                var user = attempt[1] as string;
                var pass = attempt[2] as string;

                try
                {
                    if (BoolFromRawPassAndUser(pass, user) && _loggedInUsers.QueryP(user) != null)
                    {
                        _loggedInUsers.Get(user);
                        Console.WriteLine("logged out " + user);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("malformed logout request");
                }
            }
        }
Esempio n. 12
0
        private void runwayToTaxiway(string taxiway, ControlTower ct, ITuple frwT)
        {
            updateGraphics(credentials, airspaceName, "" + frwT[0] + frwT[1]);
            //runwaySpace.Get(runwayGUILock);

            Console.WriteLine(credentials + " is searching for free landing taxiway " + taxiway);
            ITuple freeTaxiWayTupleTo = taxiwaySpace.Get("Taxiway", taxiway, typeof(int), true);
            int    barrierLimitA      = (int)freeTaxiWayTupleTo[2] - 1;

            Console.WriteLine(credentials + " found free taxiway " + taxiway + " with barrier value " + (barrierLimitA + 1) + " and getting free taxiway tuple...");
            Console.WriteLine(credentials + " is putting runway lock with ID " + frwT[0] + frwT[1]);
            ct.putRunway(credentials, frwT);
            updateGraphics(credentials, "" + frwT[0] + frwT[1], "" + freeTaxiWayTupleTo[0] + freeTaxiWayTupleTo[1]);
            Console.WriteLine(credentials + " is putting free taxiway " + taxiway + " back with lower barrier " + barrierLimitA);
            taxiwaySpace.Put((string)freeTaxiWayTupleTo[0], freeTaxiWayTupleTo[1], barrierLimitA, (barrierLimitA) > 0);
            //taxiwaySpace.Get(taxiwayGUILock);
            //System.Threading.Thread.Sleep(2500);
        }
Esempio n. 13
0
        public void realisticLanding()
        {
            //Establishing communication
            Console.WriteLine(credentials + " is Searching for control tower...");
            ITuple controlTowerTuple = controlTowerSpace.Query("Control Tower Nr.", typeof(int), typeof(ControlTower));

            //Getting landing clearance
            ControlTower controlTower = (ControlTower)controlTowerTuple[2];

            Console.WriteLine(credentials + " found control tower and getting landing clearance...");


            switch (windDirection)
            {
            case "S":
                ITuple freeLandingRunwayS = runwaySpace.Get("Runway Nr.", 0);

                runwayToTaxiway("Alfa", controlTower, freeLandingRunwayS);

                taxiwayToTaxiway("Alfa", "Beta");

                taxiwayToHangar("Beta");


                break;

            case "N":
                ITuple freeLandingRunwayN = runwaySpace.Get("Runway Nr.", 0);

                runwayToTaxiway("Delta", controlTower, freeLandingRunwayN);

                taxiwayToTaxiway("Delta", "Epsilon");

                taxiwayToTaxiway("Epsilon", "Alfa");

                taxiwayToTaxiway("Alfa", "Beta");

                taxiwayToHangar("Beta");

                break;

            case "W":
                ITuple freeLandingRunwayW = runwaySpace.Get("Runway Nr.", 90);

                runwayToTaxiway("Beta", controlTower, freeLandingRunwayW);
                taxiwayToHangar("Beta");

                break;

            case "E":
                ITuple freeLandingRunwayE = runwaySpace.Get("Runway Nr.", 90);

                runwayToTaxiway("Epsilon", controlTower, freeLandingRunwayE);

                taxiwayToTaxiway("Epsilon", "Alfa");

                taxiwayToTaxiway("Alfa", "Beta");

                taxiwayToHangar("Beta");

                break;
            }
        }