private void DeleteFile_execute(object obj) { try { var listPosition = (string)obj; AvailableFolders.Remove(listPosition); } catch (Exception e) { log.Add(e.ToString()); } }
public byte[] GetImage(string requestModel, AccountModelForShareson account = null, bool UseSQL = false) { byte[] result = new byte[0]; try { if (UseSQL) { if (sql.CheckIfUserIsLogedIn(account.ID, account.Email)) { ImagesConverter convert = new ImagesConverter(); var model = DeserializeImagesRequest(requestModel); if (!string.IsNullOrEmpty(model.PathToDirectory) && !string.IsNullOrEmpty(model.FileName)) { result = convert.ReturnImageWithInfoAsBytes(model.PathToDirectory, model.FileName, model.ExcludedExtensions); } return(result); } else { return(null); } } else { ImagesConverter convert = new ImagesConverter(); var model = DeserializeImagesRequest(requestModel); if (!string.IsNullOrEmpty(model.PathToDirectory) && !string.IsNullOrEmpty(model.FileName)) { result = convert.ReturnImageWithInfoAsBytes(model.PathToDirectory, model.FileName, model.ExcludedExtensions); } return(result); } } catch (Exception e) { log.Add(e.ToString()); return(null); } }
public void Receive(Socket client) { try { Socket socket = client; socket.BeginReceive(Model.buffer, 0, options.BufferSize, 0, new AsyncCallback(ReceiveCallBack), socket); } catch (Exception e) { InfoLog infoLog = new InfoLog(Settings.Default.LogsFilePath); infoLog.Add(e.ToString()); } //ProceedExecuteRequest.WaitOne(); }
public byte[] ReturnImageWithInfoAsBytes(string PathToFolder, string FileName, string[] ExcludedExtensions = null) { try { ImageConverterModel model; byte[] dataToReturn = new byte[0]; string searchingFile; if (string.IsNullOrEmpty(FileName)) { searchingFile = PathToFolder + All_Images.GetRandom(PathToFolder, ExcludedExtensions); model = GetImageInfo(searchingFile); } else { searchingFile = PathToFolder + FileName; model = GetImageInfo(searchingFile); } FileInfo info = new FileInfo(searchingFile); dataToReturn = new byte[info.Length]; if (info.Length > 0) { using (FileStream fstream = File.OpenRead(searchingFile)) { fstream.Read(dataToReturn, 0, dataToReturn.Length); } } model.Size = info.Length; model.Image = dataToReturn; var json = JsonConvert.SerializeObject(model); var jsonAsBytes = Encoding.ASCII.GetBytes(json); ImageInfo = false; return(jsonAsBytes); } catch (System.Exception e) { var json = JsonConvert.SerializeObject(model); var jsonAsBytes = Encoding.ASCII.GetBytes(json); ImageInfo = false; log.Add(e.ToString()); return(jsonAsBytes); } }