/// <summary> /// Returns the specified file as a byte array. /// </summary> /// <param name="fileName">File to convert.</param> /// <returns> /// Array of byte than represent the file. /// </returns> public static byte[] AsByteArrayFromFile(string fileName) { Logger.Instance.Debug("External Call"); Logger.Instance.Info(" Returns the specified file as a byte array"); Logger.Instance.Info(" > Library: iTin.Core"); Logger.Instance.Info(" > Class: StreamHelper"); Logger.Instance.Info(" > Method: AsByteArrayFromFile(string)"); Logger.Instance.Info(" > Output: System.Byte[]"); SentinelHelper.IsTrue(string.IsNullOrEmpty(fileName)); byte[] buffer; using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { buffer = stream.AsByteArray(); } return(buffer); }
/// <summary> /// Determines whether <paramref name="value" /> is valid ip address. /// </summary> /// <param name="value">Ip address to check.</param> /// <returns> /// <strong>true</strong> if ip address is valid; otherwise, <strong>false</strong>. /// </returns> public static bool IsValidIpAddress(string value) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core.Helpers, Class: RegularExpressionHelper"); Logger.Instance.Debug(" Determines whether value parameter is valid ip address."); Logger.Instance.Debug($" > Signature: ({typeof(bool)}) IsValidIpAddress({typeof(string)})"); SentinelHelper.ArgumentNull(value, nameof(value)); SentinelHelper.IsTrue(value.Length > 15); Logger.Instance.Debug($" > value: {value}"); Regex format = new Regex(IpPattern); bool match = format.IsMatch(value); Logger.Instance.Debug(" > Output:"); Logger.Instance.Debug($" > Pattern to use: {IpPattern}"); Logger.Instance.Debug($" > Value: {match}"); return(match); }
public static MemoryStream AsMemoryStreamFromFile(string fileName) { Logger.Instance.Debug("External Call"); Logger.Instance.Info(" Convert input file to memory stream"); Logger.Instance.Info(" > Library: iTin.Core"); Logger.Instance.Info(" > Class: StreamHelper"); Logger.Instance.Info(" > Method: AsMemoryStreamFromFile(string)"); Logger.Instance.Info(" > Output: System.IO.MemoryStream"); SentinelHelper.IsTrue(string.IsNullOrEmpty(fileName)); MemoryStream ms; FileStream fs = null; MemoryStream mstemp = null; try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); try { mstemp = new MemoryStream(fs.AsByteArray()); ms = mstemp; mstemp = null; } finally { mstemp?.Dispose(); } } finally { fs?.Dispose(); } return(ms); }