コード例 #1
0
        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");
                }
            }
        }
コード例 #2
0
        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");
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: pSpaces/dotSpace-Examples
        static void Main(string[] args)
        {
            // Instantiate a new Fifo based space.
            ISpace ts = new SequentialSpace();

            // Insert the forks that the philosophers must share.
            ts.Put("FORK", 1);
            ts.Put("FORK", 2);
            ts.Put("FORK", 3);
            ts.Put("FORK", 4);
            ts.Put("FORK", 5);

            // Instantiate the philosopher agents.
            List <AgentBase> agents = new List <AgentBase>();

            agents.Add(new Philosopher("Alice", 1, 5, ts));
            agents.Add(new Philosopher("Charlie", 2, 5, ts));
            agents.Add(new Philosopher("Bob", 3, 5, ts));
            agents.Add(new Philosopher("Dave", 4, 5, ts));
            agents.Add(new Philosopher("Homer", 5, 5, ts));

            // Let the philosophers eat.
            agents.ForEach(a => a.Start());
            Console.Read();
        }
コード例 #4
0
 private void ReservePlayersToSpace(SequentialSpace space, int players_to_reserve)
 {
     space.Put("lobby_lock");
     for (int i = 0; i < players_to_reserve; i++)
     {
         space.Put("player", 0, "No user");
     }
 }
コード例 #5
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;
                    }
                }
            }
        }
コード例 #6
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
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Sends the given Event, which has been specified
        /// with a receiver and sender client id.
        /// The event is sent asynchronously
        /// </summary>
        public void Send(Event e)
        {
            if (e.Receiver == 0)
            {
                throw new ArgumentException("Receiver was not set for event");
            }

            outgoingEvents.Put(
                e.GetType().FullName,
                (int)e.Receiver,
                JsonConvert.SerializeObject(e)
                );
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: pSpaces/dotSpace-Examples
        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();
        }
コード例 #9
0
 public void putRunway(string planeCredentials, ITuple space)
 {
     if ((string)space[0] == "Runway Nr.")
     {
         Console.WriteLine(planeCredentials + " Unlocking Runway Nr. " + space[1] + " / putting it back");
         runwaySpace.Put(space[0], space[1]);
     }
 }
コード例 #10
0
 private void ReceiveEvents()
 {
     while (true)
     {
         { // First get is blocking, and signals that some event exists
           // which prevents busy waiting
             var eventTuple = Connection.Lobby.Space.Get("event", typeof(string), typeof(int), (int)Connection.LocalPlayer.Id, typeof(string));
             incomingEvents.Put((string)eventTuple[1], (int)eventTuple[2], (string)eventTuple[4]);
         }
         { // Second Get(All) is flushes the existing events to receive
             var remainingTuples = Connection.Lobby.Space.GetAll("event", typeof(string), typeof(int), (int)Connection.LocalPlayer.Id, typeof(string));
             foreach (var eventTuple in remainingTuples)
             {
                 incomingEvents.Put((string)eventTuple[1], (int)eventTuple[2], (string)eventTuple[4]);
             }
         }
     }
 }
コード例 #11
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();
        }
コード例 #12
0
        //Fire-and-forget method, to allow the logic to progress
        public void updateLogicalPosition(string planeCrededentials, string newLocationCredentials)
        {
            string planeNextLocationLock = planeCrededentials = newLocationCredentials + "-lock";

            if (newLocationCredentials == "Runway")
            {
                runwaySpace.Put(planeNextLocationLock);
            }
            else if (newLocationCredentials == "Taxiway")
            {
                taxiwaySpace.Put(planeNextLocationLock);
            }
        }
コード例 #13
0
        private void AddGameLobby()
        {
            space = new SequentialSpace();
            ReservePlayersToSpace(space, MAX_NUM_SUBSCRIBERS);

            space.Put("winner-lock");

            repository.AddSpace(spaceID, space);

            //Initialize streeming components
            clientScores    = new ClientScores(space);
            streemComponent = new StreemComponents(space);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: tmt96/dotSpace-objectSpace
        static void Main(string[] args)
        {
            // Instantiate a new Fifobased tuple space.
            ISpace dtu = new SequentialSpace();

            // Instantiate a new agent, assign the tuple space and start it.
            AgentBase userA = new User("A", dtu);
            AgentBase userB = new User("B", dtu);

            userA.Start();
            userB.Start();

            Console.WriteLine("Starting");
            dtu.Put(0);
        }
コード例 #15
0
 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
     }
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: pSpaces/dotSpace-Examples
        static void Main(string[] args)
        {
            // Instantiate a new Fifobased tuplespace.
            ISpace pingpongTable = new SequentialSpace();

            // Insert the ping.
            pingpongTable.Put("ping", 0);

            // Create two PingPong agents and start them.
            PingPong a1 = new PingPong("ping", "pong", pingpongTable);
            PingPong a2 = new PingPong("pong", "ping", pingpongTable);

            a1.Start();
            a2.Start();
            Console.Read();
        }
コード例 #17
0
        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);
                }
            }
        }
コード例 #18
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);
        }