Exemplo n.º 1
0
 /// <summary>
 /// ImageController constructor from IImageServiceModal (that actually handles the image).
 /// </summary>
 /// <param name="modal"> IImageServiceModal the handles pictures </param>
 public ImageController(IImageServiceModal modal, ILoggingService loggingService)
 {
     imageModal = modal;                    // Storing the Modal Of The System
     commands   = new Dictionary <int, ICommand>()
     {
     };
     commands[0] = new NewFileCommand(modal);
     commands[1] = new GetConfigCommand();
     commands[2] = new LogCommand(loggingService);
 }
Exemplo n.º 2
0
        /// <summary>
        /// method for setting the directoryHandlers manager
        /// </summary>
        /// <param name="dhManager">the directoryHandlers manager</param>
        public void SetDHManager(IDirectoryHandlersManager dhManager)
        {
            this.directoryHandlersManager = dhManager;
            CloseDHandlerCommand command1 = this.commands[CommandEnum.CloseCommand] as CloseDHandlerCommand;

            command1?.SetDirectoryHandlersManager(this.directoryHandlersManager);
            GetConfigCommand command2 = this.commands[CommandEnum.GetConfigCommand] as GetConfigCommand;

            command2?.SetDirectoryHandlersManager(this.directoryHandlersManager);
            PhotoTransferCommand command3 = this.commands[CommandEnum.PhotoTransferCommand] as PhotoTransferCommand;

            command3?.SetDirectoryHandlersManager(this.directoryHandlersManager);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Contructs a new image controller object.
        /// </summary>
        /// <param name="modal">The image service modal the controller will controll.</param>
        public ImageController(IImageServiceModal modal)
        {
            MyModal           = modal;          // Storing the Modal Of The System
            CommandDictionary = new Dictionary <int, ICommand>();
            NewFileCommand   file   = new NewFileCommand(MyModal);
            LogCommand       logger = new LogCommand();
            CloseCommand     close  = new CloseCommand();
            GetConfigCommand conf   = new GetConfigCommand();
            GetStatsCommand  stats  = new GetStatsCommand();

            //link new file command with stats command
            file.InformNewFile += stats.PhotoAdded;
            close.InformClose  += conf.HandlerRemoved;
            //close.inform_close += logger.OnLogChange; //TODO: check this
            file.InformNewFile += logger.OnLogChange;
            CommandDictionary.Add((int)CommandEnum.NewFileCommand, file);
            CommandDictionary.Add((int)CommandEnum.LogCommand, logger);
            CommandDictionary.Add((int)CommandEnum.CloseCommand, close);
            CommandDictionary.Add((int)CommandEnum.GetConfigCommand, conf);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Function that connect the server to clients.
        /// </summary>
        public void ConnectServer()
        {
            Thread.Sleep(100);
            IPEndPoint  ep       = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888);
            TcpListener listener = new TcpListener(ep);

            //first of all start the listener for searching connections.
            listener.Start();
            Console.Write("Waiting for connection...");
            HandleLogs handleLogs = new HandleLogs();

            //thread for alwayes search for cnnections.
            Task ta = new Task(() =>
            {
                while (true)
                {
                    try
                    {
                        TcpClient client = listener.AcceptTcpClient();
                        //this.client = client;
                        Console.WriteLine("Connection accepted.");
                        m_logging.Log("Connection to server accepted", MessageTypeEnum.INFO);

                        mutex3.WaitOne();
                        NetworkStream ns = client.GetStream();
                        byte[] bytes     = new byte[1024];

                        //this.ns = client.GetStream();
                        int bytesRead = ns.Read(bytes, 0, bytes.Length);
                        string r      = Encoding.ASCII.GetString(bytes, 0, bytesRead);
                        mutex3.ReleaseMutex();

                        Task task2 = new Task(() =>
                        {
                            if (client.Connected)
                            {
                                if (r == "GetConfigCommand")
                                {
                                    ICommand command = new GetConfigCommand(this, client, m_controller);
                                    bool success;
                                    command.Execute(null, out success);

                                    //HandleSettings h = new HandleSettings(this, client, m_controller);
                                }
                                else if (r == "LogCommand")
                                {
                                    ICommand command = new LogCommand(handleLogs, this, m_logging, client);
                                    bool success;
                                    command.Execute(null, out success);

                                    //handleLogs.SetAllProt(this, m_logging , client);
                                }
                            }
                        }); task2.Start();

                        /*
                         * need to take care the close
                         * when the client close the screen we should out this while !
                         *
                         * */
                    }
                    catch (Exception e)
                    {
                        break;
                    }
                }
            });

            ta.Start();
            tcpListener = listener;
        }