Example #1
0
        public IcebergOrder(IServerFacade serverFacade,
                            string symbol,
                            string clOrdID,
                            MarketSide side,
                            decimal totalQuantity,
                            decimal clipSize,
                            decimal initialPrice,
                            decimal priceDelta)
        {
            if (totalQuantity <= 0)
                throw new ApplicationException(
                    "Iceberg Order must have a quantity greater than zero");

            if (clipSize > totalQuantity)
                throw new ApplicationException(
                    "Iceberg Order total quantity must be greater or equal to the clip size");

            Symbol = symbol;
            ClOrdID = clOrdID;
            Side = side;
            TotalQuantity = totalQuantity;
            ClipSize = clipSize;
            InitialPrice = initialPrice;
            PriceDelta = priceDelta;
            State = ActivationState.Suspended;

            _serverFacade = serverFacade;
            RemainingQuantity = totalQuantity;
            CurrentPrice = InitialPrice;
            CurrentQuantity = clipSize;
        }
Example #2
0
        public IcebergOrder(IServerFacade serverFacade,
                            string symbol,
                            string clOrdID,
                            MarketSide side,
                            decimal totalQuantity,
                            decimal clipSize,
                            decimal initialPrice,
                            decimal priceDelta)
        {
            if (totalQuantity <= 0)
            {
                throw new ApplicationException(
                          "Iceberg Order must have a quantity greater than zero");
            }

            if (clipSize > totalQuantity)
            {
                throw new ApplicationException(
                          "Iceberg Order total quantity must be greater or equal to the clip size");
            }

            Symbol        = symbol;
            ClOrdID       = clOrdID;
            Side          = side;
            TotalQuantity = totalQuantity;
            ClipSize      = clipSize;
            InitialPrice  = initialPrice;
            PriceDelta    = priceDelta;
            State         = ActivationState.Suspended;

            _serverFacade     = serverFacade;
            RemainingQuantity = totalQuantity;
            CurrentPrice      = InitialPrice;
            CurrentQuantity   = clipSize;
        }
Example #3
0
 public PacManJoined()
 {
     ServerFacade = ServerFacadeFactory.GetServerFacade();
     ServerFacade.CreateGameX("GameName");
     var pacman = ServerFacade.JoinGameX("GameName", "PacManName", PlayerRole.PacMan);
     GameInstance = ServerFacade.GetGameStateForX(pacman.PlayerId);
 }
Example #4
0
 public PacManStartedGame()
 {
     ServerFacade = ServerFacadeFactory.GetServerFacade();
     ServerFacade.CreateGameX("GameName");
     var pacman = ServerFacade.JoinGameX("GameName", "PacManName", PlayerRole.PacMan);
     ServerFacade.UpdateMyWhereabouts(new ServerPollParameters(pacman.PlayerId, 0, 0, true));
     GameInstance = ServerFacade.GetGameStateForX(pacman.PlayerId);
 }
Example #5
0
        public ConnectionViewModel(IServerFacade serverFacade, IMessageSink messageSink)
        {
            _messageSink = messageSink;

            SessionString = serverFacade.GetServerSessionID();

            serverFacade.LogonEvent += OnLogon;
            serverFacade.LogoutEvent += OnLogout;
        }
Example #6
0
        public ConnectionViewModel(IServerFacade serverFacade, IMessageSink messageSink)
        {
            _messageSink = messageSink;

            SessionString = serverFacade.GetServerSessionID();

            serverFacade.LogonEvent  += OnLogon;
            serverFacade.LogoutEvent += OnLogout;
        }
Example #7
0
        public ATOrderMediator(IATOrderRepository atOrderRepository,
                               IServerFacade serverFacade,
                               IClOrdIDGenerator clOrdIDGenerator)
        {
            _atOrderRepository = atOrderRepository;
            _serverFacade = serverFacade;
            _clOrdIDGenerator = clOrdIDGenerator;

            _serverFacade.OrderExecutionEvent += OnOrderExecutionEvent;
        }
Example #8
0
        public ATOrderBookViewModel(IServerFacade serverFacade, ATOrderMediator orderMediator)
        {
            serverFacade.LogoutEvent += OnLogout;

            _orderMediator = orderMediator;
            _orderMediator.IcebergOrderUpdated += OnIcebergOrderUpdated;
            _orderMediator.IcebergOrderAdded += OnIcebergOrderAdded;

            IcebergOrders = new ObservableCollection<IcebergDisplay>();
        }
Example #9
0
        public ATOrderBookViewModel(IServerFacade serverFacade, ATOrderMediator orderMediator)
        {
            serverFacade.LogoutEvent += OnLogout;

            _orderMediator = orderMediator;
            _orderMediator.IcebergOrderUpdated += OnIcebergOrderUpdated;
            _orderMediator.IcebergOrderAdded   += OnIcebergOrderAdded;

            IcebergOrders = new ObservableCollection <IcebergDisplay>();
        }
Example #10
0
        public ATOrderMediator(IATOrderRepository atOrderRepository,
                               IServerFacade serverFacade,
                               IClOrdIDGenerator clOrdIDGenerator)
        {
            _atOrderRepository = atOrderRepository;
            _serverFacade      = serverFacade;
            _clOrdIDGenerator  = clOrdIDGenerator;

            _serverFacade.OrderExecutionEvent += OnOrderExecutionEvent;
        }
Example #11
0
        public ServerController(IServerFacade serverFacade)
        {
            clients   = new Dictionary <int, Socket>();
            idManager = new IDManager();
            parser    = new Parser();

            serverFacade.Disconnect += (x) => RemoveClient(x);
            listener             = new Listener(serverFacade);
            listener.Disconnect += (x) => RemoveClient(x);
            onlineUser           = new Dictionary <int, string>();
        }
Example #12
0
        public OrderBookViewModel(IServerFacade serverFacade,
                                  IClOrdIDGenerator clOrdIDGenerator,
            IMessageSink messageSink)
        {
            _clOrdIDGenerator = clOrdIDGenerator;
            _messageSink = messageSink;
            _serverFacade = serverFacade;
            OrderStack = new ObservableCollection<OrderStackRow>();

            _serverFacade.OrderExecutionEvent += HandleOrderExecutionEvent;
            _serverFacade.LogoutEvent += OnLogout;
        }
Example #13
0
        public OrderBookViewModel(IServerFacade serverFacade,
                                  IClOrdIDGenerator clOrdIDGenerator,
                                  IMessageSink messageSink)
        {
            _clOrdIDGenerator = clOrdIDGenerator;
            _messageSink      = messageSink;
            _serverFacade     = serverFacade;
            OrderStack        = new ObservableCollection <OrderStackRow>();

            _serverFacade.OrderExecutionEvent += HandleOrderExecutionEvent;
            _serverFacade.LogoutEvent         += OnLogout;
        }
Example #14
0
        public void Run(
            string configFilepath,
            IFixStrategy strategy,
            IFixMessageGenerator messageGenerator,
            IMessageSink messageSink,
            IExecIDGenerator execIDGenerator,
            IClOrdIDGenerator clOrdIDGenerator)
        {
            _server = ServerFacadeFactory.CreateFixServer(configFilepath,
                                                          strategy,
                                                          execIDGenerator,
                                                          messageGenerator,
                                                          messageSink);

            var atOrderRepository = new ATOrderRepository();
            var atOrderMediator = new ATOrderMediator(atOrderRepository,
                                                      _server,
                                                      clOrdIDGenerator);

            // Setup the data contexts for the child views in the main view
            // Ideally we'd do this in each view but due to the need to pass _app and the
            // message sink to the view models for expediency purposes we do it here
            var mainWindow = new MainWindow
            {
                ATOrderBook =
                {
                    DataContext = new ATOrderBookViewModel(_server, atOrderMediator)
                },
                OrderBook =
                {
                    DataContext = new OrderBookViewModel(_server, clOrdIDGenerator, messageSink)
                },
                ConnectionView = { DataContext = new ConnectionViewModel(_server, messageSink) }
            };

            // Set the main UI dispatcher
            SmartDispatcher.SetDispatcher(mainWindow.Dispatcher);

            // Send messages to the status bar
            messageSink.SetMessageSink(
                s =>
                {
                    var vm = (ConnectionViewModel) mainWindow.ConnectionView.DataContext;
                    SmartDispatcher.Invoke(() => vm.StatusMessage = s);
                });

            _server.Start();
            mainWindow.Show();
        }
Example #15
0
        public void Run(
            string configFilepath,
            IFixStrategy strategy,
            IFixMessageGenerator messageGenerator,
            IMessageSink messageSink,
            IExecIDGenerator execIDGenerator,
            IClOrdIDGenerator clOrdIDGenerator)
        {
            _server = ServerFacadeFactory.CreateFixServer(configFilepath,
                                                          strategy,
                                                          execIDGenerator,
                                                          messageGenerator,
                                                          messageSink);

            var atOrderRepository = new ATOrderRepository();
            var atOrderMediator   = new ATOrderMediator(atOrderRepository,
                                                        _server,
                                                        clOrdIDGenerator);

            // Setup the data contexts for the child views in the main view
            // Ideally we'd do this in each view but due to the need to pass _app and the
            // message sink to the view models for expediency purposes we do it here
            var mainWindow = new MainWindow
            {
                ATOrderBook =
                {
                    DataContext = new ATOrderBookViewModel(_server, atOrderMediator)
                },
                OrderBook =
                {
                    DataContext = new OrderBookViewModel(_server, clOrdIDGenerator, messageSink)
                },
                ConnectionView = { DataContext = new ConnectionViewModel(_server, messageSink) }
            };

            // Set the main UI dispatcher
            SmartDispatcher.SetDispatcher(mainWindow.Dispatcher);

            // Send messages to the status bar
            messageSink.SetMessageSink(
                s =>
            {
                var vm = (ConnectionViewModel)mainWindow.ConnectionView.DataContext;
                SmartDispatcher.Invoke(() => vm.StatusMessage = s);
            });

            _server.Start();
            mainWindow.Show();
        }
        public bool registerServer(string username, string ip_addr, int port)
        {
            ServerMetadata sm = new ServerMetadata();

            sm.Username = username;
            sm.IP_Addr  = ip_addr;
            sm.Port     = port;

            //adding the client metadata to the global hashtable so that it can be used later on
            servers_list.Add(username, sm);
            IServerFacade isf = connectToServerFacadeService(sm);

            serverFacadeList.Add(username, isf);


            Gui.updateServersTree(sm, null);

            return(true);
        }
        private IServerFacade connectToServerFacadeService(ServerMetadata sm)
        {
            String connectionString = "tcp://" + sm.IP_Addr + ":" + sm.Port + "/" + sm.Username + "/" + Common.Constants.SERVER_FACADE_SERVICE;

            IDictionary RemoteChannelProperties = new Dictionary <string, string>();

            RemoteChannelProperties["name"] = sm.Username;

            TcpChannel server_channel = new TcpChannel(RemoteChannelProperties, null, null);

            ChannelServices.RegisterChannel(server_channel, true);

            //TODO: uncomment and fix this to make it work
            IServerFacade facadeService = (IServerFacade)Activator.GetObject(
                typeof(IServerFacade),
                connectionString);

            return(facadeService);
        }
Example #18
0
        private void connectMenuItem_Click(object sender, EventArgs e)
        {
            //fetch selected username
            string username = treeView1.SelectedNode.Text;

            if (username.Equals("Servers") || username.Equals("Clients"))
            {
                return;
            }

            string parent = treeView1.SelectedNode.Parent.Text;


            if (parent.Equals("Servers"))
            {
                ServerMetadata sm  = (ServerMetadata)pms.getServersList()[username];
                IServerFacade  isf = (IServerFacade)pms.getServerFacadeList()[username];
                isf.Connect(); /*commented because Server Facade is not implemented yet*/
                //show(username + " is now connected");
                treeView1.SelectedNode.ImageIndex         = 0;
                treeView1.SelectedNode.SelectedImageIndex = 0;
            }

            else if (parent.Equals("Clients"))
            {
                ClientMetadata cm = (ClientMetadata)pms.getClientsList()[username];
                IClientFacade  fs = (IClientFacade)pms.getClientFacadeList()[username];
                fs.Connect(); //EXCEPTION UNHANDLED - WASIF CHECK THIS
                show(username + " has been connected");
                treeView1.SelectedNode.ImageIndex         = 0;
                treeView1.SelectedNode.SelectedImageIndex = 0;
            }
            else
            {
                return;
            }
        }
Example #19
0
        private void readEventFileAndDispatchEvents()
        {
            string line = string.Empty;

            System.IO.StreamReader sr = new
                                        System.IO.StreamReader(openFileDialog1.FileName);
            while ((line = sr.ReadLine()) != null)
            {
                show(line);
                string              opcode = line.Split(' ')[0];
                string              username;
                IClientFacade       icf;
                IServerFacade       sf;
                List <CalendarSlot> clientCalendar;
                //TODO: fetch initiator from Users list

                switch (opcode)
                {
                case "disconnect":
                    username = line.Split(' ')[1];

                    if (username.StartsWith("central"))
                    {
                        ServerMetadata sm  = (ServerMetadata)pms.getServersList()[username];
                        IServerFacade  isf = (IServerFacade)pms.getServerFacadeList()[username];
                        while (isf == null)
                        {
                            show("Trying to disconnect server: " + username);
                            isf = (IServerFacade)pms.getServerFacadeList()[username];
                            Thread.Sleep(100);
                        }

                        try
                        {
                            isf.Disconnect();
                            changeIconToDisconnected(username, null);
                        }
                        catch (Exception ioe)
                        {
                            MessageBox.Show(ioe.ToString());
                        }
                    }
                    else
                    {
                        icf = (IClientFacade)pms.getClientFacadeList()[username];
                        while (icf == null)
                        {
                            show("Trying to disconnect client: " + username);
                            icf = (IClientFacade)pms.getClientFacadeList()[username];
                            Thread.Sleep(1000);
                        }

                        try
                        {
                            icf.Disconnect();
                        }
                        catch (Exception ee)
                        {
                            show("Exception: " + ee.Message);
                        }

                        changeIconToDisconnected(username, null);
                    }
                    break;


                case "connect":

                    username = line.Split(' ')[1].Trim();
                    string ip   = line.Split(' ')[2].Split(':')[0].Trim();
                    int    port = Convert.ToInt32(line.Split(' ')[2].Split(':')[1]);

                    icf = (IClientFacade)pms.getClientFacadeList()[username];
                    sf  = (IServerFacade)pms.getServerFacadeList()[username];

                    if (icf != null)     //means the client has already been created
                    {
                        show("Trying to reconnect to client: " + username);
                        icf.Connect();
                        changeIconToConnected(username, null);
                    }

                    else if (sf != null)
                    {
                        show("Reconnecting to server: " + username);
                        sf.Connect();
                        changeIconToConnected(username, null);
                    }
                    else     //means a new process needs to be started
                    {
                        if (username.StartsWith("central"))
                        {
                            string           path      = server_dir;
                            ProcessStartInfo startInfo = new ProcessStartInfo();


                            startInfo.FileName    = path + "Server.exe";
                            startInfo.Arguments   = username + " " + port;
                            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                            Process process = new Process();
                            process.StartInfo = startInfo;
                            process.Start();
                            processes.Add(process);


                            //TODO: save the PIDS of all processes and kill them on exit

                            //if server  is online, we move on to the next event. If not, we wait until the server is online
                            IServerFacade isf = (IServerFacade)pms.getServerFacadeList()[username];
                            while (isf == null)
                            {
                                Thread.Sleep(500);
                                isf = (IServerFacade)pms.getServerFacadeList()[username];
                            }
                        }
                        else     //means its a client
                        {
                            string           path      = client_dir;
                            ProcessStartInfo startInfo = new ProcessStartInfo();

                            startInfo.FileName    = path + "Client.exe";
                            startInfo.Arguments   = username + " " + port;
                            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                            Process process = new Process();
                            process.StartInfo = startInfo;
                            process.Start();
                            processes.Add(process);

                            //if client  is online, we move on to the next event. If not, we wait until the client is online
                            IClientFacade cf = (IClientFacade)pms.getClientFacadeList()[username];
                            while (cf == null)
                            {
                                Thread.Sleep(500);
                                cf = (IClientFacade)pms.getClientFacadeList()[username];
                            }
                        }
                    }

                    break;

                case "readCalendar":
                    username = line.Split(' ')[1].Trim();
                    icf      = (IClientFacade)pms.getClientFacadeList()[username];
                    try
                    {
                        clientCalendar = icf.ReadCalendar();
                        show("Calendar for " + username + ":");
                        foreach (CalendarSlot slot in clientCalendar)
                        {
                            show(slot);
                        }
                    }
                    catch (Exception ee)
                    {
                        show("Exception: " + ee.Message);
                    }
                    break;

                case "reservation":
                    //reservation {GroupMeeting; user1, user2; 13, 25 }
                    string        data      = line.Split('{')[1].Split('}')[0].Trim();
                    string        desc      = data.Split(';')[0].Trim();
                    string        initiator = data.Split(';')[1].Split(',')[0].Trim();
                    List <string> usersList = data.Split(';')[1].Trim().Split(',').Select(s => s.Trim()).ToList <string>();
                    List <int>    slotsList = data.Split(';')[2].Trim().Split(',').Select(s => s.Trim()).ToList <string>().ConvertAll <int>(Convert.ToInt32);

                    ReservationRequest rr = new ReservationRequest();
                    rr.Description = desc;
                    rr.Users       = usersList;
                    rr.Slots       = slotsList;
                    icf            = (IClientFacade)pms.getClientFacadeList()[initiator];
                    while (icf == null)
                    {
                        show("Trying to reconnect to initiator: " + initiator);
                        icf = (IClientFacade)pms.getClientFacadeList()[initiator];
                        Thread.Sleep(100);
                    }

                    try
                    {
                        icf.CreateReservation(rr);
                    }
                    catch (Exception e)
                    {
                        show("Error on create reservation: " + e.Message);
                    }

                    Thread.Sleep(1000);
                    break;

                case "wait":
                    int seconds = Convert.ToInt32(line.Split(' ')[1].Trim());
                    show("Sleeping for " + seconds + " second(s)");
                    Thread.Sleep(seconds * 1000);
                    break;

                case "shutdown":
                    show("Shutting down all processes in 2 seconds");
                    Thread.Sleep(2000);


                    //killing all clients
                    foreach (Process pp in processes)
                    {
                        string userName = pp.StartInfo.Arguments.Split(' ')[0].Trim();

                        if (!userName.StartsWith("central"))
                        {
                            ((IClientFacade)pms.getClientFacadeList()[userName]).Disconnect();
                            pp.Kill();
                            removeNodeFromTreeView(userName, null);
                            show("Killed " + pp.StartInfo.Arguments);
                        }
                    }

                    //killing all servers
                    foreach (Process p in processes)
                    {
                        string userName = p.StartInfo.Arguments.Split(' ')[0].Trim();

                        if (userName.StartsWith("central"))
                        {
                            try
                            {
                                ((IServerFacade)pms.getServerFacadeList()[userName]).Disconnect();
                            }
                            catch (Exception ee)
                            {
                                show(ee.Message);
                            }
                            p.Kill();
                            removeNodeFromTreeView(userName, null);
                            show("Killed " + p.StartInfo.Arguments);
                        }
                    }

                    //cleaning up
                    pms.cleanUp();

                    //RemotingServices.Unmarshal(objRef);
                    //objRef = null;
                    //pms = null;

                    processes.Clear();

                    //unregistering channels
                    UnregisterChannels();

                    show(" ");
                    show("----------------------SHUTDOWN COMPLETE--------------------");
                    show(" ");
                    break;
                }
            }

            sr.Close();
        }
Example #20
0
 public GameStarted()
 {
     ServerFacade = ServerFacadeFactory.GetServerFacade();
     GameInstance = ServerFacade.CreateGame("GameName");
 }
Example #21
0
 public Client(IServerFacade serverFacade)
 {
     ServerFacade = serverFacade;
 }
Example #22
0
 public GameCreated()
 {
     ServerFacade = ServerFacadeFactory.GetServerFacade();
     ServerFacade.CreateGameX("GameName");
     GameInstance = ServerFacade.GetGameStateAsObvserverX("GameName");
 }
Example #23
0
 public Listener(IServerFacade serverFacade)
 {
     this.serverFacade = serverFacade;
     parser            = new Parser();
 }