public static bool SaveReport(XLWorkbook Workbook) { if (Workbook.Worksheets.Count > 0) { Stream MyStream; SaveFileDialog SaveFileDialog1 = new SaveFileDialog(); SaveFileDialog1.Filter = "excel files (*.xlsx)|*.xlsx"; SaveFileDialog1.FilterIndex = 2; SaveFileDialog1.RestoreDirectory = true; if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { if ((MyStream = SaveFileDialog1.OpenFile()) != null) { MyStream.Close(); } Workbook.SaveAs(SaveFileDialog1.FileName); MessageBox.Show("Отчёт успешно сформирован"); } return(true); } else { MessageBox.Show("Нужно выбрать хотя бы один пункт для формирования отчёта"); return(false); } }
public override void Close() { AssertInvariants(); if (MyStream != null) { MyStream.Close(); } }
/// Function - AddToArrayListFromFile /// <summary> /// Adds from a file the names that split by "split by" in the path "path" /// </summary> /// <param name="path"> path of the c code type string.</param> /// <param name="a"> ArrayList </param> /// <param name="splitBy"> What to split by type string.</param> public static void AddToArrayListFromFile(string path, ArrayList a, string splitBy) { MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); string s = sr.ReadLine(); string [] temp = Regex.Split(s, splitBy); foreach (string i in temp) { a.Add(i); } sr.Close(); }
/// Function - findAllFunctionNames /// <summary> /// find all the function names in the code. /// </summary> /// <param name="path"> Path for the code.</param> /// <param name="pattern"> Pattern for the function.</param> public static void findAllFunctionNames(string path, Regex pattern) { string codeLine = GeneralConsts.EMPTY_STRING; MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); while (codeLine != null) { codeLine = findFunction(sr, pattern); //enter function to where i store it. //add it to where i store the function code. } sr.Close(); }
public static void findAllFunctionNames(string path, Regex pattern) { string s = ""; MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); while (s != null) { s = findFunction(sr, pattern); //enter function to where i store it. //add it to where i store the function code. } sr.Close(); }
public static void AddToHashFromFile(string path, Hashtable a, string splitBy) { MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); string temp = sr.ReadLine(); string[] tempArr = Regex.Split(temp, splitBy); ICollection keys = keywords.Keys; for (int i = 0; i < tempArr.Length; i++) { a.Add(CreateMD5(tempArr[i]), tempArr[i]); } sr.Close(); }
public static void CheckUninitializeVariableType(string path) { MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); string s; bool endLoop = false; string[] structNames; while ((s = sr.ReadLine()) != null) { if (StructPattern.IsMatch(s) || TypedefOneLine.IsMatch(s)) { AddStructNames(sr, s); } } sr.Close(); }
public void WriteFile(string WriteString) { Stream MyStream; SaveFileDialog SaveFileDialog1 = new SaveFileDialog(); SaveFileDialog1.InitialDirectory = Environment.CurrentDirectory; SaveFileDialog1.Filter = "text files (*.txt)|*.txt"; SaveFileDialog1.FilterIndex = 2; SaveFileDialog1.RestoreDirectory = true; if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { if ((MyStream = SaveFileDialog1.OpenFile()) != null) { MyStream.Close(); File.WriteAllText(SaveFileDialog1.FileName, WriteString, Encoding.UTF8); MessageBox.Show("Данные успешно записанны в файл"); } } }
/// Function - AddToHashFromFile /// <summary> /// Adds from a file splited by "splitBy" parameter to the Hashtable fromt he path. /// </summary> /// <param name="path"> The path for the file.</param> /// <param name="a"> Hashtable to store the keywords.</param> /// <param name="splitBy"> String that the file needs to split by.</param> public static void AddToHashFromFile(string path, Hashtable a, string splitBy) { MyStream sr = null; try { sr = new MyStream(path, System.Text.Encoding.UTF8); } catch (Exception e) { MainProgram.AddToLogString(path, e.ToString()); } string line = sr.ReadLine(); string[] keysArr = Regex.Split(line, splitBy); ICollection keys = a.Keys; for (int i = 0; i < keysArr.Length; i++) { a.Add(CreateMD5(keysArr[i]), keysArr[i]); } sr.Close(); }
private void GetSize() { HttpFileCollection MyFileCollection; HttpPostedFile MyFile; long FileLen = 0; Stream MyStream; MyFileCollection = Request.Files; FileLen = Request.InputStream.Length; if (FileLen > 0) { byte[] input = new byte[FileLen]; MyStream = Request.InputStream; MyStream.Position = 0; MyStream.Read(input, 0, (int)FileLen); FileStream fs = null; string token = Request.Params["token"]; string name = Request.Params["name"]; string[] names = name.Split((".").ToCharArray()); string uploadPath = HttpContext.Current.Server.MapPath("UploadImages" + "\\") + token + "." + names[names.Length - 1]; fs = new FileStream(uploadPath, FileMode.OpenOrCreate, FileAccess.Write); fs.Seek(0, SeekOrigin.End); fs.Write(input, 0, (int)FileLen); fs.Position = 0; FileLen = fs.Length; MyStream.Dispose(); MyStream.Close(); fs.Dispose(); fs.Close(); } string value = "{start:" + FileLen + ",success:'true'}"; Response.Clear(); Response.Write(value); Response.End(); //*/ }
/// Fubnction - CreateFunctionsJsonFile /// <summary> /// function is creating the json file for the "Function" GET request. /// </summary> /// <param name="path"> path of the file that is being checked.</param> /// <param name="pattern"></param> /// <param name="variables"> Dictionary that every key on him is the function LINE and every value is an arrayList /// type "ParameterType" of all of his variables. /// </param> /// <param name="final_json"> the final big json.</param> static void CreateFunctionsJsonFile(string path, Regex pattern, Dictionary <string, ArrayList> variables, Dictionary <string, Dictionary <string, Object> > final_json) { string codeLine = GeneralConsts.EMPTY_STRING; string fName; string[] temp; string returnType = GeneralConsts.EMPTY_STRING; bool exitFlag = false; string firstLineDocumentation = GeneralConsts.EMPTY_STRING; uint curPos; Object tempDict = new Dictionary <string, FunctionInfoJson>(); MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); uint documentPos = sr.Pos; while (codeLine != null) { //saves the last documentation. while (!exitFlag && !FunctionPatternInC.IsMatch(codeLine)) { if (codeLine != null) { codeLine = sr.ReadLine(); } firstLineDocumentation = GeneralConsts.EMPTY_STRING; if (codeLine == null) { exitFlag = true; break; } if (codeLine.IndexOf("//") != NOT_FOUND_STRING) { documentPos = sr.Pos; firstLineDocumentation = codeLine; } while ((codeLine.IndexOf("//") != NOT_FOUND_STRING)) { if (codeLine != null) { codeLine = sr.ReadLine(); } } if ((codeLine.IndexOf("/*") != NOT_FOUND_STRING)) { documentPos = sr.Pos; firstLineDocumentation = codeLine; while (!(codeLine.IndexOf("*/") != NOT_FOUND_STRING)) { if (codeLine != null) { codeLine = sr.ReadLine(); } } if ((codeLine.IndexOf("*/") != NOT_FOUND_STRING)) { if (codeLine != null) { codeLine = sr.ReadLine(); } } } if (codeLine == null) { exitFlag = true; } } if (codeLine == null) { exitFlag = true; } if (!exitFlag) { fName = codeLine; if (fName != null) { temp = Regex.Split(fName, @"\*|\s"); if (fName.IndexOf("static") != NOT_FOUND_STRING) { returnType = takeSecondNotNullString(temp); } else { returnType = temp[0]; } returnType = returnType.Trim(); //enter function to where i store it. Object tempStorage = new FunctionInfoJson(); GeneralCompilerFunctions.NextScopeLength(sr, ref codeLine, ref ((FunctionInfoJson)tempStorage).codeLength, true); ((FunctionInfoJson)tempStorage).content = FunctionCode(sr, ref codeLine); ((FunctionInfoJson)tempStorage).parameters = FindParameters(fName); ((FunctionInfoJson)tempStorage).returnType = returnType; ((FunctionInfoJson)tempStorage).variables = FindVariables(variables[fName]); curPos = sr.Pos; ((FunctionInfoJson)tempStorage).documentation = FindDocumentation(sr, documentPos, firstLineDocumentation, curPos); ((Dictionary <string, FunctionInfoJson>)tempDict).Add(fName, (FunctionInfoJson)tempStorage); } else { exitFlag = true; } } //add it to where i store the function code. } //Serialize. Dictionary <string, Object> tempOuterDict = new Dictionary <string, Object>(); tempOuterDict.Add("function", tempDict); final_json.Add(path, tempOuterDict); sr.Close(); }
public static DataTable ReadExcelToDataTableForFirstDateTime(HttpPostedFile httpPostedFileBase, string sheetname) { Stream MyStream; int FileLen; FileLen = httpPostedFileBase.ContentLength; // 读取文件的 byte[] //byte[] bytes = new byte[FileLen]; MyStream = httpPostedFileBase.InputStream; //MyStream.Read(bytes, 0, FileLen); IWorkbook workbook; if (httpPostedFileBase.FileName.Contains(".xlsx")) { workbook = new XSSFWorkbook(MyStream); } else { workbook = new HSSFWorkbook(MyStream); } //获取excel的第一个sheet ISheet sheet = null; if (!string.IsNullOrEmpty(sheetname)) { sheet = workbook.GetSheet(sheetname); } else { sheet = workbook.GetSheetAt(0); } DataTable table = new DataTable(); //获取sheet的首行 IRow headerRow = sheet.GetRow(0); //一行最后一个方格的编号 即总的列数 int cellCount = headerRow.LastCellNum; for (int i = headerRow.FirstCellNum; i < cellCount; i++) { DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue); table.Columns.Add(column); } //最后一列的标号 即总的行数 int rowCount = sheet.LastRowNum; for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); if (row != null) { DataRow dataRow = table.NewRow(); string RowString = ""; for (int j = row.FirstCellNum; j < cellCount; j++) { if (row.GetCell(j) != null) { if (j == 0) { try { dataRow[j] = row.GetCell(j).DateCellValue.ToString(); RowString += dataRow[j]; } catch (Exception ex) { dataRow[j] = row.GetCell(j).ToString(); RowString += row.GetCell(j).ToString(); } } else { dataRow[j] = row.GetCell(j).ToString(); RowString += row.GetCell(j).ToString(); } } } if (!string.IsNullOrEmpty(RowString)) { table.Rows.Add(dataRow); } } } workbook = null; sheet = null; MyStream.Close(); return(table); }
//path to the code; public static void PreprocessorActions(string path, int threadNumber) { bool endLoop = false; MyStream sr = null; try { sr = new MyStream(path, System.Text.Encoding.UTF8); } catch (Exception e) { Console.WriteLine("{0} Second exception caught.", e); endLoop = true; } string s; string firstNewVariableWord; string secondNewVariableWord; string[] newkeyWords; string newKeyword; char[] charsToTrim = { '\t', ' ', '*', '&' }; while (!endLoop && (s = sr.ReadLine()) != null) { if (DefineDecleration.IsMatch(s)) { firstNewVariableWord = s.Substring(s.IndexOf(' '), s.Length - s.IndexOf(' ')); firstNewVariableWord = firstNewVariableWord.Trim(); firstNewVariableWord = firstNewVariableWord.Substring(firstNewVariableWord.IndexOf(' '), firstNewVariableWord.Length - firstNewVariableWord.IndexOf(' ')); firstNewVariableWord = firstNewVariableWord.Trim(); firstNewVariableWord = firstNewVariableWord.Trim(charsToTrim); if (firstNewVariableWord.IndexOf(" ") != -1) { newkeyWords = Regex.Split(firstNewVariableWord, " "); secondNewVariableWord = newkeyWords[1]; firstNewVariableWord = newkeyWords[0]; if (CheckIfStringInHash(keywords, firstNewVariableWord) && CheckIfStringInHash(keywords, secondNewVariableWord)) { newKeyword = Regex.Split(s, " ")[1]; newKeyword = newKeyword.Trim(); if (!keywords.ContainsKey(CreateMD5(newKeyword))) { keywords.Add(CreateMD5(newKeyword), newKeyword); } } } else { if (CheckIfStringInHash(keywords, firstNewVariableWord)) { newKeyword = Regex.Split(s, " ")[1]; newKeyword = newKeyword.Trim(); if (!keywords.ContainsKey(CreateMD5(newKeyword))) { keywords.Add(CreateMD5(newKeyword), newKeyword); } } } } if (StructPattern.IsMatch(s) && threadNumber != 0) { AddStructNames(sr, s); } else if (TypedefOneLine.IsMatch(s) && threadNumber != 0) { AddStructNames(sr, s); } else if (IncludeTrianglesPattern.IsMatch(s) || IncludeRegularPattern.IsMatch(s)) { string CurrentPath; string result; if (s.IndexOf("<") != -1 && s.IndexOf(">") != -1) { result = CutBetween2Strings(s, "<", ">"); CurrentPath = librariesPath; } else { result = CutBetween2Strings(s, "\"", "\""); CurrentPath = projectPath; } Console.WriteLine(result); if (!includes.Contains(CreateMD5(result))) { includes.Add(CreateMD5(result), result); Thread thread; if (result.IndexOf("\\") != -1) { thread = new Thread(() => PreprocessorActions(result, threadNumber + 1)); } else { thread = new Thread(() => PreprocessorActions(CurrentPath + "\\" + result, threadNumber + 1)); } thread.Start(); thread.Join(); Console.WriteLine("thread " + threadNumber + "stopped"); } } } if (sr != null) { sr.Close(); } }
public static string findAllFunctionNamesAndCode(string path, Regex pattern) { string s = ""; string fName; string[] temp; string returnType = ""; bool exitFlag = false; bool found; string firstLineDocumentation = ""; uint curPos; Dictionary <string, FunctionInfoJson> tempDict = new Dictionary <string, FunctionInfoJson>(); MyStream sr = new MyStream(path, System.Text.Encoding.UTF8); uint documentPos = sr.Pos; while (s != null) { while (!exitFlag && !FunctionPatternInC.IsMatch(s)) { if (s != null) { s = sr.ReadLine(); } firstLineDocumentation = ""; if (s == null) { exitFlag = true; } if (s.IndexOf("//") != -1) { documentPos = sr.Pos; firstLineDocumentation = s; } while ((s.IndexOf("//") != -1)) { if (s != null) { s = sr.ReadLine(); } } if ((s.IndexOf("/*") != -1)) { documentPos = sr.Pos; firstLineDocumentation = s; while (!(s.IndexOf("*/") != -1)) { if (s != null) { s = sr.ReadLine(); } } if ((s.IndexOf("*/") != -1)) { if (s != null) { s = sr.ReadLine(); } } } if (s == null) { exitFlag = true; } } if (s == null) { exitFlag = true; } if (!exitFlag) { fName = s; if (fName != null) { temp = Regex.Split(fName, @"\*|\s"); if (fName.IndexOf("static") != -1) { returnType = takeSecondNotNullString(temp); } else { returnType = temp[0]; } returnType = returnType.Trim(); //enter function to where i store it. FunctionInfoJson tempStorage = new FunctionInfoJson(); tempStorage.content = FunctionCode(sr, ref s); tempStorage.parameters = findParameters2(fName); tempStorage.returnType = returnType; curPos = sr.Pos; tempStorage.documentation = findDocumentation(sr, documentPos, firstLineDocumentation, curPos); tempDict.Add(fName, tempStorage); } else { exitFlag = true; } } //add it to where i store the function code. } string finalJson = JsonConvert.SerializeObject(tempDict); sr.Close(); return(finalJson); }
//path to the code; /// Function - PreprocessorActions /// <summary> /// /// </summary> /// <param name="path"> The path for the C code.</param> /// <param name="threadNumber"> thread number is a parameter to make sure when the main file is in. /// number 0 means its the main file any other number means it is currently /// reads a file that is not the main. (Import).</param> /// <param name="keywords"> Hashtable to store the keywords.</param> /// <param name="includes"> Hashtable to store the includes.</param> /// <param name="defines"> Dictionary to store the defines . (key - new keyword, value - old Definition)</param> /// <param name="pathes"> Paths for all the places where the imports might be.</param> static void PreprocessorActions(string path, int threadNumber, Hashtable keywords, Hashtable includes, Dictionary <string, string> defines, string [] pathes) { bool endLoop = false; MyStream sr = null; //try to open the buffer. try { sr = new MyStream(path, System.Text.Encoding.UTF8); } catch (Exception e) { MainProgram.AddToLogString(path, String.Format("{0} Second exception caught.", e.ToString())); Server.ConnectionServer.CloseConnection(threadNumber, FILE_NOT_FOUND, GeneralConsts.ERROR); endLoop = true; } string codeLine; string firstNewVariableWord; string secondNewVariableWord; string[] newkeyWords; string newKeyword; string defineOriginalWord; while (!endLoop && (codeLine = sr.ReadLine()) != null) { if (DefineDecleration.IsMatch(codeLine)) { //getting both of the names in two variables. firstNewVariableWord = codeLine.Substring(codeLine.IndexOf(' '), codeLine.Length - codeLine.IndexOf(' ')); firstNewVariableWord = firstNewVariableWord.Trim(); firstNewVariableWord = firstNewVariableWord.Substring(firstNewVariableWord.IndexOf(GeneralConsts.SPACEBAR), firstNewVariableWord.Length - firstNewVariableWord.IndexOf(GeneralConsts.SPACEBAR)); firstNewVariableWord = firstNewVariableWord.Trim(CharsToTrim); //old definition. defineOriginalWord = firstNewVariableWord; if (firstNewVariableWord.IndexOf(GeneralConsts.SPACEBAR) != GeneralConsts.NOT_FOUND_STRING) { //checks if the definition exists. if (keywords.ContainsKey(CreateMD5(firstNewVariableWord))) { //new keyword //takes the part after the first space. newKeyword = Regex.Split(codeLine, GeneralConsts.SPACEBAR)[1]; newKeyword = newKeyword.Trim(); //make sure that the keyword isn't already existed. if (!keywords.ContainsKey(CreateMD5(newKeyword))) { //adds her if not keywords.Add(CreateMD5(newKeyword), newKeyword); //adds the new definition. defines.Add(newKeyword, defineOriginalWord); //types the dont mind the variable are being ingored. for an example static : so if //the type for example is static and i define a new static definition it will add it to //the ignoreVariablesType. if (ignoreVarialbesType.Contains(defineOriginalWord)) { ignoreVarialbesType.Add(newKeyword); } } } else { //splits when there are 2 types that you define for an example "unsinged int" //so what this section is doing is checking if both of the types exist. newkeyWords = Regex.Split(firstNewVariableWord, GeneralConsts.SPACEBAR); secondNewVariableWord = newkeyWords[1]; firstNewVariableWord = newkeyWords[0]; //checks both types. if (CheckIfStringInHash(keywords, firstNewVariableWord) && CheckIfStringInHash(keywords, secondNewVariableWord)) { newKeyword = Regex.Split(codeLine, GeneralConsts.SPACEBAR)[1]; newKeyword = newKeyword.Trim(); //creates the keywords if they dont exist. if (!keywords.ContainsKey(CreateMD5(newKeyword))) { keywords.Add(CreateMD5(newKeyword), newKeyword); defines.Add(newKeyword, defineOriginalWord); MainProgram.AddToLogString(path, "new Keywords :" + newkeyWords[0]); } } } } else { //if there is only one type in the old definition. if (CheckIfStringInHash(keywords, firstNewVariableWord)) { newKeyword = Regex.Split(codeLine, GeneralConsts.SPACEBAR)[1]; newKeyword = newKeyword.Trim(); if (!keywords.ContainsKey(CreateMD5(newKeyword))) { keywords.Add(CreateMD5(newKeyword), newKeyword); defines.Add(newKeyword, defineOriginalWord); MainProgram.AddToLogString(path, "new : " + newKeyword); } } } } //Handling almost the same patterns as the syntaxCheck function. if (StructPattern.IsMatch(codeLine) && threadNumber != 0) { AddStructNames(sr, codeLine, keywords); } else if (TypedefOneLine.IsMatch(codeLine) && threadNumber != 0) { AddStructNames(sr, codeLine, keywords); } //if the code line is an include it creates a thread and enters to the defines , structs and more to //the Hashtables and Dictionaries. else if (IncludeTrianglesPattern.IsMatch(codeLine) || IncludeRegularPattern.IsMatch(codeLine)) { string currentPath = GeneralConsts.EMPTY_STRING; string result; if (codeLine.IndexOf("<") != -1 && codeLine.IndexOf(">") != -1) { result = CutBetween2Strings(codeLine, "<", ">"); } else { result = CutBetween2Strings(codeLine, "\"", "\""); } MainProgram.AddToLogString(path, result); //only enters an include if it didnt already included him. if (!includes.Contains(CreateMD5(result))) { includes.Add(CreateMD5(result), result); Thread preprocessorThread; //if the include includes a path inside of it. if (result.IndexOf("\\") != -1) { //opens the thread (thread number +1). preprocessorThread = new Thread(() => PreprocessorActions(result, threadNumber + 1, keywords, includes, defines, pathes)); } //if it does not include an exact path. else { //runs on the pathes that the import files might be in. for (int i = 0; i < pathes.Length; i++) { //checks if the file exists in one of those folders. if (File.Exists(pathes[i] + "\\" + result)) { currentPath = pathes[i]; break; } } //creats a thread. preprocessorThread = new Thread(() => PreprocessorActions(currentPath + "\\" + result, threadNumber + 1, keywords, includes, defines, pathes)); } preprocessorThread.Start(); preprocessorThread.Join(GeneralConsts.TIMEOUT_JOIN); MainProgram.AddToLogString(path, "thread " + threadNumber + "stopped"); } } } if (sr != null) { sr.Close(); } }
/// <summary> /// Private method to make HttpWebRequests to the end point. /// </summary> /// <param name="endPoint"></param> /// <param name="requestMethod"></param> /// <param name="postData"></param> /// <returns></returns> private string MakeHttpWebRequest(string endPoint, HttpVerb requestMethod, string postData = null) { // https://binarythistleblog.wordpress.com/2017/10/12/posting-to-a-rest-api-with-c/ string MyReturn = string.Empty; LastHttpWebRequestStream = postData; LastHttpVerb = requestMethod; HttpWebRequest MyHttpWebRequest = HttpWebRequest.Create(endPoint) as HttpWebRequest; MyHttpWebRequest.Method = requestMethod.ToString(); if (CompressContent) { MyHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); } // HTTP Basic Authentication. MyHttpWebRequest.Headers.Add("Authorization", "Basic " + _Credentials); MyHttpWebRequest.UserAgent = USERAGENT; //NTLM authentication scheme. //MyHttpWebRequest.Credentials = new NetworkCredential(UserName, Password); //MyHttpWebRequest.Accept = "application/xml"; //MyHttpWebRequest.Accept = "application/*"; //MyHttpWebRequest.Accept = "*/*"; MyHttpWebRequest.Accept = "*.*"; //MyHttpWebRequest.ContentType = "application/xml;charset=UTF-8"; MyHttpWebRequest.ContentType = "application/xml"; MyHttpWebRequest.KeepAlive = KeepRequestAlive; if (MyHttpWebRequest.Method == HttpVerb.POST.ToString()) { // Write the POST data. if (!string.IsNullOrEmpty(postData)) { using (StreamWriter MyStreamWriter = new StreamWriter(MyHttpWebRequest.GetRequestStream())) { MyStreamWriter.Write(postData); MyStreamWriter.Close(); } } } // Get the response. try { using (HttpWebResponse exResponse = MyHttpWebRequest.GetResponse() as HttpWebResponse) { LastHttpStatusCode = exResponse.StatusCode; LastHttpStatusDescription = exResponse.StatusDescription; Stream MyStream = exResponse.GetResponseStream(); if (exResponse.ContentEncoding.ToLower().Contains("gzip")) { MyStream = new GZipStream(MyStream, CompressionMode.Decompress); } else if (exResponse.ContentEncoding.ToLower().Contains("deflate")) { MyStream = new DeflateStream(MyStream, CompressionMode.Decompress); } StreamReader MyStreamReader = new StreamReader(MyStream, Encoding.Default); MyReturn = MyStreamReader.ReadToEnd(); exResponse.Close(); MyStream.Close(); } } catch (WebException ex) { using (HttpWebResponse exResponse = ex.Response as HttpWebResponse) { LastHttpStatusCode = exResponse.StatusCode; LastHttpStatusDescription = exResponse.StatusDescription; Stream MyStream = exResponse.GetResponseStream(); if (exResponse.ContentEncoding.ToLower().Contains("gzip")) { MyStream = new GZipStream(MyStream, CompressionMode.Decompress); } else if (exResponse.ContentEncoding.ToLower().Contains("deflate")) { MyStream = new DeflateStream(MyStream, CompressionMode.Decompress); } StreamReader MyStreamReader = new StreamReader(MyStream, Encoding.Default); MyReturn = MyStreamReader.ReadToEnd(); exResponse.Close(); MyStream.Close(); } } catch (Exception ex) { // this is a JSON response. //MyReturn = "{\"errorMessages\":[\"" + ex.Message.ToString() + "\"],\"errors\":{}}"; // this is an XML response, MyReturn = $"<root><errorMessage>{ex.Message.ToString()}</errorMessages></root>"; // this is in plain text response. //MyReturn = ex.Message.ToString(); } LastHttpWebResponseStream = MyReturn; return(MyReturn); }