/// <summary> /// Read a contents of a File from the Path specified and return the contents as a string /// </summary> /// <param name="path">File Path as String</param> /// <returns>File Contents as String</returns> public static String readFile(String path) { String decodedString = ""; if (!File.Exists(path)) { _logger.Error(BVMessageUtil.getMessage("ERR0012") + " : File Doesn't Exist"); throw new BVSdkException("ERR0012"); } try { FileStream stream = new FileStream(path, FileMode.Open); byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { try { int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } decodedString = Encoding.UTF8.GetString(ms.ToArray()); } catch (Exception e) { _logger.Error(e.Message, e); } finally { ms.Close(); stream.Close(); } } return(decodedString); } catch (Exception ex) { _logger.Error(ex.Message, ex); return(ex.Message); } }
/// <summary> /// Get the Fragment String from the URI /// </summary> /// <param name="uri">URI as String</param> /// <returns>Fragment String</returns> public static String getFragmentString(String uri) { if (String.IsNullOrEmpty(uri)) { return(""); } Uri _uri = null; try { _uri = new Uri(uri); } catch (Exception ex) { _logger.Error(BVMessageUtil.getMessage("ERR0027"), ex); throw new BVSdkException("ERR0027"); } return(_uri.Fragment); }
/// <summary> /// Gets the message from resource file Resources.resx. /// Pass the message code including error code and you should get a message that is in the resource file. /// Gives back the same message code if it is not configured in resource bundle. /// </summary> /// <param name="code">Message Code as String</param> /// <returns>Message as String</returns> public static String getMessage(String code) { if (String.IsNullOrEmpty(code)) { _logger.Error(BVMessageUtil.getMessage("ERR0001")); throw new BVSdkException("ERR0001"); } String message = null; try { ResourceManager resxMgr = Resources.ResourceManager; if (resxMgr != null) { string msg = resxMgr.GetString(code); if (msg == null || string.IsNullOrEmpty(msg)) { message = code; } else { message = msg; } } else { message = code; } } catch (Exception ex) { _logger.Error(ex.Message, ex); message = code; } return(message); }