public event EventHandler <DirectoryCloseEventArgs> Close; // event to notify the handler that it needs to be closed #endregion //constructor for ImageServer public ImageServer(IImageController controller, ILoggingService logging) { this.photosNumber = 0; this.m_logging = logging; this.m_controller = controller; //getting the paths to all directories that need monitoring. string[] paths = ReadAppConfig.ReadSetting("Handlers").Split(';'); for (int i = 0; i < paths.Length; i++) { if (!System.IO.Directory.Exists(paths[i])) { paths = paths.Where(w => w != paths[i]).ToArray(); } } this.handlers = new IDirectoryHandler[paths.Length]; //for each dir to monitor we need to create a handler for (int i = 0; i < paths.Length; i++) { this.handlers[i] = new DirectoyHandler(this.m_controller, this.m_logging, this.CommandRecieved); CommandRecieved += this.handlers[i].OnCommandRecieved; this.handlers[i].DirectoryClose += new EventHandler <DirectoryCloseEventArgs>(OnCloseServer); this.handlers[i].StartHandleDirectory(paths[i]); //starting the handler (not working - i beleive needs threads) this.m_logging.Log("created handler that listens to " + paths[i], MessageTypeEnum.INFO); } }
public static void LoginAPP() { var usuario = ReadAppConfig.ReadSetting("userWeb"); var password = ReadAppConfig.ReadSetting("passWordWeb"); OpenApp(); Sleep(2); SetText(".id", "user_email", usuario); SetText(".id", "user_password", password); ClickObjet(".name", "commit"); }
//argrs[0] is the dircetory to close. public string Execute(string[] args, out bool result) { this.imse.closeHandler(args[0]); string[] paths = ReadAppConfig.ReadSetting("Handlers").Split(';'); paths = paths.Where(val => val != args[0]).ToArray(); string newPaths = String.Join(";", paths); var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings"); connectionStringsSection.ConnectionStrings["Handlers"].ConnectionString = newPaths; config.Save(ConfigurationSaveMode.Modified, true); ConfigurationManager.RefreshSection("connectionStrings"); result = true; return(args[0]); }
//this function is called when the service begins. protected override void OnStart(string[] args) { eventLog1.WriteEntry("In OnStart"); //creating logging service to send messages to the log this.ils = new LoggingService(); //every time the logger receives a message MessageRecieved is invoked and onmsg function in this class is called this.ils.MessageRecieved += this.OnMsg; string outputDir = ReadAppConfig.ReadSetting("OutPutDir"); int thumbnailSize = ReadAppConfig.ReadThumbnailSize("ThumbnailSize"); if (thumbnailSize == -1) //in case of failed conversion to an int { thumbnailSize = 120; eventLog1.WriteEntry("warning: parsing failed, sets thumbnailsize to 120"); } else { eventLog1.WriteEntry("Thumbnail size has been read successfuly"); } //creating image model (thumbail size should be taken from app.config file) this.modal = new ImageServiceModal(outputDir, thumbnailSize); eventLog1.WriteEntry("output dir is: " + outputDir); //creating the controller and the server. this.controller = new ImageController(modal, ils); this.server = new ImageServer(this.controller, this.ils); this.server.Close += OnServerClose; this.controller.addServer(this.server); this.cServer = new ComunicationServer(8000, this.controller); this.ils.MessageRecieved += delegate(object sender, MessageRecievedEventArgs e) { string[] logArgs = { e.Status.ToString(), e.Message }; this.cServer.SendCommandToAllClients((int)CommandsEnum.LogCommand, logArgs); }; this.cServer.Start(); ITCPHandler tcpClientHandler = new TCPHandler(controller, ils); ITCPServer tcpServer = new TCPServer(8001, ils, tcpClientHandler); tcpServer.Start(); this.imageServer = new TCPServer(8001, ils, new TCPHandler(this.controller, ils)); this.imageServer.Start(); }
public string Execute(string[] args, out bool result) { ConfigFileData cfd = new ConfigFileData(); try { cfd.OutputDir = ReadAppConfig.ReadSetting("OutPutDir"); cfd.SourceDir = ReadAppConfig.readAppSettings("ImageServiceSource"); cfd.LogName = ReadAppConfig.readAppSettings("ImageServiceLog"); cfd.ThumnailSize = ReadAppConfig.ReadThumbnailSize("ThumbnailSize"); cfd.InputDirs = ReadAppConfig.ReadSetting("Handlers").Split(';'); result = true; return(JsonConvertor.ConvertToJson(cfd)); } catch { result = false; return("problem occured"); } }
//handles the client public void HandleTcpClient(TcpClient client, List <TcpClient> clients) { try { new Task(() => { try { while (true) { ils.Log("beginning to transfer photos...", MessageTypeEnum.INFO); NetworkStream stream = client.GetStream(); byte[] imgNameSizeBuffer = new byte[sizeof(int)]; stream.Read(imgNameSizeBuffer, 0, sizeof(int)); int nameSize = BitConverter.ToInt32(imgNameSizeBuffer, 0); if (nameSize == 0) { break; } byte[] imgNameBuffer = new byte[nameSize]; stream.Read(imgNameBuffer, 0, nameSize); string imgName = System.Text.Encoding.Default.GetString(imgNameBuffer); byte[] imgSizesizeBuffer = new byte[1]; stream.Read(imgSizesizeBuffer, 0, 1); int imgSizesize = BitConverter.ToInt32(imgSizesizeBuffer, 0); byte[] imgSizeBuffer = new byte[imgSizesize]; stream.Read(imgSizeBuffer, 0, imgSizesize); int imgSize = BitConverter.ToInt32(imgSizeBuffer, 0); byte[] imgBuffer = new byte[imgSize]; stream.Read(imgBuffer, 0, imgSize); MemoryStream ms = new MemoryStream(imgBuffer); Image image = Image.FromStream(ms); stream.WriteByte(1); stream.Flush(); string url = ReadAppConfig.ReadSetting("Handlers").Split(';')[0] + "\\" + imgName; image.Save(url); } } //removes and closes client upon exception catch (Exception e) { clients.Remove(client); //display to the logger the exception that occured ils.Log(e.ToString(), MessageTypeEnum.FAIL); client.Close(); } }).Start(); } catch (Exception ex) { ils.Log(ex.ToString(), MessageTypeEnum.FAIL); } }
public static void OpenApp() { var url = ReadAppConfig.ReadSetting("urlTest"); Driver.Navigate().GoToUrl(url); }