/// <summary> /// Check client-server connection. /// </summary> /// <param name="channel">Channel to check his cnnection.</param> private void SetServiceStatus(WebChannel channel) { if (channel.IsConnected()) { Active = "Active"; } else { Active = "Not Active"; } }
/// <summary> /// Remove handler on server side. /// </summary> /// <param name="handler">Handler to remove.</param> /// <param name="channel">Web channel for requests.</param> public void RemoveHandler(string handler, WebChannel channel) { if (handler != null && handler != "") { if (channel.IsConnected()) { CommandMessage req = new CommandMessage((int)CommandEnum.CloseCommand, new string[] { handler }); channel.Write(req); CommandMessage answer = channel.Read(); DirectoryHandlers.Remove(handler); } } }
/// <summary> /// Set all students. /// </summary> /// <param name="channel">Web channel for requesting config data.</param> private void SetStudents(WebChannel channel) { Students = new List <Student>(); if (channel.IsConnected()) { string rootPath = HttpContext.Current.Server.MapPath(@"\students.txt"); string[] lines = File.ReadAllLines(rootPath); foreach (string line in lines) { // Every line is deserialized by json. Student student = JsonConvert.DeserializeObject <Student>(line); Students.Add(student); } } }
/// <summary> /// Set number of photos in OutputDir. /// </summary> /// <param name="channel">Web channel for request.</param> private void SetNumberOfPhotos(WebChannel channel) { NumberOfPhotos = ""; if (channel.IsConnected()) { try { // Get all physical path of thumbnails directory. String rootPath = HttpContext.Current.Server.MapPath(@"\OutputDir\Thumbnails"); // Get number of thumbnails. NumberOfPhotos = Directory.GetFiles(rootPath, "*", SearchOption.AllDirectories).Length.ToString(); } catch (Exception e) { Console.WriteLine(e.Message); } } }
/// <summary> /// Set config data via server request. /// </summary> /// <param name="channel">Web channel for requests.</param> public void SetConfigData(WebChannel channel) { DirectoryHandlers = new List <string>(); OutputDir = SourceName = LogName = ThumbnailSize = ""; if (channel.IsConnected()) { CommandMessage req = new CommandMessage((int)CommandEnum.GetConfigCommand); channel.Write(req); CommandMessage answer = channel.Read(); OutputDir = answer.Args[0]; SourceName = answer.Args[1]; LogName = answer.Args[2]; ThumbnailSize = answer.Args[3]; for (int i = 4; i < answer.Args.Length; i++) { DirectoryHandlers.Add(answer.Args[i]); } } }
/// <summary> /// Set logs via server request. /// </summary> /// <param name="channel">Web channel for request.</param> public void SetLogs(WebChannel channel) { ServiceLogs = new List <Log>(); if (channel.IsConnected()) { CommandMessage req = new CommandMessage((int)CommandEnum.LogCommand); channel.Write(req); CommandMessage answer = channel.Read(); // Iterate over every two arguments. First for message and second for type. for (int i = 0; i < answer.Args.Length; i += 2) { string m = answer.Args[i]; string t = MessageRecievedEventArgs.GetTypeEnum(Int32.Parse(answer.Args[i + 1])).ToString(); Log log = new Log(t, m); // Adds a single log to an observables logs list. ServiceLogs.Add(log); } } }
/// <summary> /// Remove image and thumbnail from pc. /// </summary> /// <param name="iPath"> Image path. </param> /// <param name="tPath"> Thumbnail path. </param> /// <param name="channel">Web channel.</param> public void RemoveImage(string iPath, string tPath, WebChannel channel) { if (channel.IsConnected()) { // Get full path to image. string imagePath = HttpContext.Current.Server.MapPath(iPath); // Get full path to thumbnail. string thumbnailPath = HttpContext.Current.Server.MapPath(tPath); try { File.Delete(imagePath); File.Delete(thumbnailPath); } catch (Exception e) { Console.WriteLine(e.Message); } } }
/// <summary> /// Set all OutputDir photos. /// </summary> /// <param name="channel"> Web channel for requests. </param> public void SetServicePhotos(WebChannel channel) { ThumbnailPhotos = new List <Photo>(); if (channel.IsConnected()) { try { // Get full physical path of outputdir. string outputDirPath = HttpContext.Current.Server.MapPath(@"\OutputDir"); // Concat 'thumbnails'. string thumbnailsPath = outputDirPath + @"\Thumbnails"; // Start crawling all the photos. StartCrawlingAllPhotos(thumbnailsPath); } catch (Exception e) { Console.WriteLine(e.Message); } } }