/// <summary> /// ImageServer is the server that in charge on all the Handlers. /// </summary> /// <param name="controller"></param> /// <param name="logging"></param> public ImageServer(IImageController controller, ILoggingService logging, int port) { this.port = port; //function to remove handler this.handle += this.handling; //function to inform our list of handlers that a handler was removed: this.handle += HandlerSingleton.Instance.GetDelegate(); // intilaize Server's controller and logger. this.m_controller = controller; this.m_logging = logging; //we will do the mobile server communication as a task in order to prevent damage //to the reset of the functionality of the code. new Task(() => { MobileServer serv = new MobileServer(this, this.m_controller, this.m_logging, 8234); serv.Start(); }).Start(); this.ch = new ClientHandler(new ExecuteCommands(this.m_logging), this.handle); // get all directories path string[] paths = ConfigurationManager.AppSettings.Get("Handler").Split(';'); foreach (string path in paths) { // handler creation IDirectoryHandler directoryHandler = new DirectoyHandler(this.m_logging, this.m_controller, path); CommandRecieved += directoryHandler.OnCommandRecieved; this.server_close += directoryHandler.closeHandler; directoryHandler.StartHandleDirectory(path); //adding the handler to our dictary so we can close it when we are told to by the GUI dic.Add(path, directoryHandler); HandlerSingleton.addItem(path); this.m_logging.Log("Create handler for path - " + path, Logging.Modal.MessageTypeEnum.INFO); } //after looping through the folders: this.m_logging.Log("starting to listen", Logging.Modal.MessageTypeEnum.INFO); Start(); }
public string HandleClient(TcpClient client) { new Task(() => { using (NetworkStream stream = client.GetStream()) using (BinaryReader reader = new BinaryReader(stream)) using (BinaryWriter writer = new BinaryWriter(stream)) { m_logging.Log("handle mobile client", MessageTypeEnum.INFO); //getting the picture's name string fileName = GetName(stream); string sum = ""; sum += fileName.Split('.')[1]; sum = "." + sum; Byte[] b = new Byte[1]; b[0] = 1; //informing the client to send the next stream, which is the picture itself. stream.Write(b, 0, 1); //getting the byte stream of the picture byte[] photoArr = GetPhotoBytes(stream); //writing the bytes into a picture File.WriteAllBytes(HandlerSingleton.getList()[0] + "\\" + fileName + sum, photoArr); //informing the end of this picture information stream.Write(b, 0, 1); System.Threading.Thread.Sleep(500); } }).Start(); return(null); }