Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts the string representation of a Guid to its Guid
        /// equivalent. A return value indicates whether the operation
        /// succeeded.
        /// </summary>
        /// <param name="value">A string containing a Guid to convert.</param>
        /// <returns>
        /// <strong>true</strong> if ip address is valid; otherwise, <strong>false</strong>.
        /// </returns>
        public static bool IsValidGuid(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 a valid guid.");
            Logger.Instance.Debug($" > Signature: ({typeof(bool)}) IsValidGuid({typeof(string)})");

            SentinelHelper.ArgumentNull(value, nameof(value));

            Logger.Instance.Debug($"   > value: {value}");

            Regex format = new Regex(GuidPattern);
            bool  match  = format.IsMatch(value);

            Logger.Instance.Debug(" > Output:");
            Logger.Instance.Debug($"   > Pattern to use: {GuidPattern}");
            Logger.Instance.Debug($"   > Value: {match}");

            return(match);
        }
Esempio n. 3
0
        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);
        }