Пример #1
0
        public Stream DownloadQuickFix(string path, bool filtroTipoArtigo = false)
        {
            var filenames = _vfs.ListFolderContent(path);

            using (var zip = new ZipCompression())
            {
                foreach (var filename in filenames)
                {
                    // HACK 1: ignore article 0
                    if (filename.Contains("-artigo0-"))
                    {
                        continue;
                    }

                    string basename = GetFilename(filename);
                    using (var file = _vfs.OpenReader(filename))
                        using (var txtFile = new StreamReader(file))
                        {
                            var text = txtFile.ReadToEnd();

                            // HACK 4: filtrar por tipo de artigo
                            if (filtroTipoArtigo && FiltrarTipoArtigo(text))
                            {
                                continue;
                            }

                            // HACK 2: convert date YYYY_MM_DD to DD/MM/YYYY
                            var newtext = QuickFix2(QuickFix(text));

                            using (var newstream = new MemoryStream())
                            {
                                using (var memwrite = new StreamWriter(newstream))
                                {
                                    memwrite.Write(newtext);
                                    memwrite.Flush();
                                    newstream.Seek(0, SeekOrigin.Begin);

                                    // HACK3: remove "article" from name
                                    string newbasename = basename
                                                         .Replace("-artigo", "")
                                                         .Replace("DO", "")
                                                         .Replace("_", "");

                                    int idxP = newbasename.IndexOf("-p");
                                    newbasename = newbasename.Substring(0, idxP);

                                    // add XML extension
                                    newbasename = newbasename + ".xml";

                                    zip.Add(newbasename, newstream);
                                }
                            }
                        }
                }

                return(zip.DownloadStream());
            }
        }
Пример #2
0
        void StartCopyBasename(string filename, string basename)
        {
            string folder = FindFolder(basename);
            string path   = $"2017/{folder}/{basename}.pdf";

            using (var srcFile = _sourceFS.OpenReader(path))
            {
                using (var dstFile = _webFS.OpenWriter(filename))
                {
                    srcFile.CopyTo(dstFile);
                }
            }
        }
Пример #3
0
 public void EnsureFile(string filename, string basename)
 {
     try
     {
         using (var file = _webFS.OpenReader(filename))
         {
             // file exists!
         }
     }
     catch (Exception ex)
     {
         // not found
         // copy the file
         StartCopyBasename(filename, basename);
     }
 }