Example #1
0
        /// <summary>
        /// Metoto encargado de grabar un archivo plano
        /// </summary>
        /// <param name="fullName">nombre completo donde sera almacenado el archivo</param>
        /// <param name="bytes">arreglo de bytes que se almacenaran</param>
        /// <param name="extencion">extencion de archivo a almacenar</param>
        /// <returns>retorna si fue o no capas de grabar</returns>
        public bool Write(string fullName, byte[] bytes, ExtencionFile extencion)
        {
            if (!fullName.EndsWith(extencion.ToString()))
            {
                throw new ExtencionNotSupportedException();
            }

            String str = Encoding.Default.GetString(bytes);

            if (!String.IsNullOrEmpty(str))
            {
                using (StreamWriter file = new StreamWriter(fullName))
                {
                    file.Write(str);
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="path"></param>
        /// <param name="extencion"></param>
        /// <returns>retorna el objeto de repuesta</returns>
        public T Read <T>(string fullName, ExtencionFile extencion) where T : FileResult
        {
            if (typeof(T) != typeof(FileTxtResult))
            {
                throw new CofingTypeNotSupportedException();
            }

            if (!fullName.EndsWith(extencion.ToString()))
            {
                throw new ExtencionNotSupportedException();
            }

            using (StreamReader sr = new StreamReader(fullName))
            {
                String line = sr.ReadToEnd();
                return(new FileTxtResult()
                {
                    Path = fullName, Extencion = extencion, TextValue = line
                } as T);
            }
        }
Example #3
0
 /// <summary>
 /// Metodo encargado de hacer la lectura de un arreglo bytes
 /// a partir de un ruta de archivo
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="path"></param>
 /// <param name="extencion"></param>
 /// <returns></returns>
 public byte[] ReadBytesPath(string path, ExtencionFile extencion)
 {
     byte[] arrayBytes = null;
     if (File.Exists(path) && dictionaryResolveFile.ContainsKey(extencion) && path.ToUpper().EndsWith(extencion.ToString().ToUpper()))
     {
         return(File.ReadAllBytes(path));
     }
     return(arrayBytes);
 }