Ejemplo n.º 1
0
 private static void addDocsInZip(List <ImportResult> results, ZipBuilder builder, string folder, InfoUtente infoUtente)
 {
     foreach (ImportResult temp in results)
     {
         try
         {
             List <BaseInfoDoc> infos = DocManager.GetBaseInfoForDocument(temp.DocNumber, null, null);
             BaseInfoDoc        doc   = infos[0];
             FileRequest        req   = new FileRequest();
             if (doc != null && !string.IsNullOrEmpty(doc.VersionLabel))
             {
                 logger.Debug("addDocsInZip GetBaseInfoForDocument VersionId " + doc.VersionLabel);
             }
             req.versionId    = doc.VersionId;
             req.docNumber    = doc.IdProfile;
             req.versionLabel = doc.VersionLabel;
             req.path         = doc.Path;
             req.version      = doc.VersionLabel;
             req.fileName     = doc.FileName;
             FileDocumento fileDocumento = BusinessLogic.Documenti.FileManager.getFile(req, infoUtente);
             string        extension     = fileDocumento.fullName.Substring(fileDocumento.fullName.LastIndexOf(".") + 1);
             builder.AddEntry(temp.DocNumber + "." + extension, new string[] { folder }, fileDocumento.content);
         }
         catch (Exception e)
         {
         }
     }
 }
        private int ZipDatabseFile(string srcPath, string destPath, int iSeverity)
        {
            int        iReturn         = 0;
            FileStream fileSource      = null;
            FileStream fileDestination = null;
            GZipStream CompressedZip   = null;

            byte[] bufferWrite = null;
            try
            {
                fileSource = new FileStream(srcPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                LogManager.WriteLog("Source: " + srcPath + " Dest: " + destPath, LogManager.enumLogLevel.Info);
                if (iSeverity == 9)
                {
                    var zipper = new ZipBuilder();
                    zipper.CreatePackage(destPath, srcPath);
                }
                else
                {
                    bufferWrite = new byte[fileSource.Length];
                    fileSource.Read(bufferWrite, 0, bufferWrite.Length);
                    fileDestination = new FileStream(destPath, FileMode.OpenOrCreate, FileAccess.Write);
                    CompressedZip   = new GZipStream(fileDestination, CompressionMode.Compress, true);
                    CompressedZip.Write(bufferWrite, 0, bufferWrite.Length);
                }
                iReturn = 1;
            }
            catch (OverflowException oex)
            {
                iReturn = 0;
                ExceptionManager.Publish(oex);
            }
            catch (Exception ex)
            {
                iReturn = 0;
                ExceptionManager.Publish(ex);
            }
            finally
            {
                if (fileSource != null)
                {
                    fileSource.Close();
                }
                if (CompressedZip != null)
                {
                    CompressedZip.Close();
                }
                if (fileDestination != null)
                {
                    fileDestination.Close();
                }
            }
            return(iReturn);
        }
Ejemplo n.º 3
0
            private void ExerciseZipBuilder(Differences diff)
            {
                Assert.IsNotNull(diff);

                using (var stream = new MemoryStream())
                    using (var writer = new StreamWriter(stream))
                    {
                        var builder = new ZipBuilder();
                        builder.Build(writer, diff);

                        Assert.IsTrue(writer.BaseStream.Length > 0);
                    }
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Takes the complete config file, public and private key of the user and turns them into files and zips them
        /// </summary>
        /// <returns>Credentials in a zip file</returns>
        private async Task <InMemoryFile> GetConfigAndKeysAsZip(string username)
        {
            User user = await _context.Users.FirstAsync(user => user.Username == username);

            var files = new List <InMemoryFile>
            {
                await SshConfigFile(username),
                new InMemoryFile("id_rsa_scalable_" + username + ".pub",
                                 Encoding.UTF8.GetBytes(user.UserPublicKey)),
                new InMemoryFile("id_rsa_scalable_" + username,
                                 Encoding.UTF8.GetBytes(user.UserPrivateKey))
            };

            return(await ZipBuilder.BuildZip(files, username + "_ScalableTeachingUserCredentials.zip"));
        }
Ejemplo n.º 5
0
        public static byte[] CreateZipFromReport(ResultsContainer report, InfoUtente infoUtente)
        {
            ZipBuilder          builder  = new ZipBuilder();
            List <ImportResult> grayList = report.GrayDocument.FindAll(e => !string.IsNullOrEmpty(e.DocNumber));

            addDocsInZip(grayList, builder, "Documenti grigi", infoUtente);
            List <ImportResult> inList = report.InDocument.FindAll(e => !string.IsNullOrEmpty(e.DocNumber));

            addDocsInZip(inList, builder, "Documenti in arrivo", infoUtente);
            List <ImportResult> outList = report.OutDocument.FindAll(e => !string.IsNullOrEmpty(e.DocNumber));

            addDocsInZip(outList, builder, "Documenti in partenza", infoUtente);
            List <ImportResult> ownList = report.OwnDocument.FindAll(e => !string.IsNullOrEmpty(e.DocNumber));

            addDocsInZip(ownList, builder, "Documenti interni", infoUtente);
            return(builder.GetOutput());
        }