Example #1
0
        public string Comprimir2Base64(object[] arquivos)
        {
            MemoryStream memoryStream = new MemoryStream();

            using (Ionic.Zip.ZipOutputStream zipOutputStream = new Ionic.Zip.ZipOutputStream(memoryStream))
            {
                byte[] array = new byte[4096];
                for (int i = 0; i < arquivos.Length; i++)
                {
                    ArquivoPdf         arquivoPdf    = (ArquivoPdf)arquivos[i];
                    MemoryStream       memoryStream2 = new MemoryStream(arquivoPdf.Dados);
                    Ionic.Zip.ZipEntry zipEntry      = new Ionic.Zip.ZipEntry();
                    zipOutputStream.PutNextEntry(arquivoPdf.Nome);
                    int num;
                    do
                    {
                        num = memoryStream2.Read(array, 0, array.Length);
                        zipOutputStream.Write(array, 0, num);
                    }while (num > 0);
                }
                zipOutputStream.Close();
            }
            byte[] array2 = memoryStream.ToArray();
            return(Convert.ToBase64String(array2, 0, array2.Length));
        }
Example #2
0
        internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
        {
            // swap slashes in reference to local configuration
            string transformedFileName = entry.FileName.Replace(Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar);

            return(_Evaluate(transformedFileName));
        }
Example #3
0
        public string Comprimir(string diretorio)
        {
            string[]     files        = Directory.GetFiles(diretorio);
            MemoryStream memoryStream = new MemoryStream();
            string       result;

            using (Ionic.Zip.ZipOutputStream zipOutputStream = new Ionic.Zip.ZipOutputStream(memoryStream))
            {
                byte[]   array  = new byte[4096];
                string[] array2 = files;
                for (int i = 0; i < array2.Length; i++)
                {
                    string             path     = array2[i];
                    Ionic.Zip.ZipEntry zipEntry = new Ionic.Zip.ZipEntry();
                    zipOutputStream.PutNextEntry(Path.GetFileName(path));
                    using (FileStream fileStream = File.OpenRead(path))
                    {
                        int num;
                        do
                        {
                            num = fileStream.Read(array, 0, array.Length);
                            zipOutputStream.Write(array, 0, num);
                        }while (num > 0);
                    }
                }
                zipOutputStream.Close();
                byte[] array3 = memoryStream.ToArray();
                result = Convert.ToBase64String(array3, 0, array3.Length);
            }
            return(result);
        }
Example #4
0
        public string ComprimirArquivo(string arquivo)
        {
            MemoryStream memoryStream = new MemoryStream();
            string       result;

            using (Ionic.Zip.ZipOutputStream zipOutputStream = new Ionic.Zip.ZipOutputStream(memoryStream))
            {
                byte[]             array    = new byte[4096];
                Ionic.Zip.ZipEntry zipEntry = new Ionic.Zip.ZipEntry();
                zipOutputStream.PutNextEntry(Path.GetFileName(arquivo));
                using (FileStream fileStream = File.OpenRead(arquivo))
                {
                    int num;
                    do
                    {
                        num = fileStream.Read(array, 0, array.Length);
                        zipOutputStream.Write(array, 0, num);
                    }while (num > 0);
                }
                zipOutputStream.Close();
                byte[] array2 = memoryStream.ToArray();
                result = Convert.ToBase64String(array2, 0, array2.Length);
            }
            return(result);
        }
Example #5
0
        internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
        {
            bool result = Left.Evaluate(entry);

            switch (Conjunction)
            {
            case LogicalConjunction.AND:
                if (result)
                {
                    result = Right.Evaluate(entry);
                }
                break;

            case LogicalConjunction.OR:
                if (!result)
                {
                    result = Right.Evaluate(entry);
                }
                break;

            case LogicalConjunction.XOR:
                result ^= Right.Evaluate(entry);
                break;
            }
            return(result);
        }
Example #6
0
 /// <summary>
 /// 压缩文件(传递参数源文件路径和压缩后的文件路径)
 /// </summary>
 /// <param name="srcPath">源文件全路径</param>
 /// <param name="destPath">保存为Zip包的目录</param>
 public static void ZipFileInfo(string srcPath, string destPath)
 {
     using (var zip = new ZipFile())
     {
         Ionic.Zip.ZipEntry zipEntry = zip.AddFile(srcPath, @"\");
         zipEntry.Comment = "Added by Cheeso's CreateZip utility.";
         zip.Comment      = $"This zip archive was created by the CreateZip example application on machine '{Dns.GetHostName()}'";
         zip.Save(destPath);
     }
 }
        /// <summary>
        /// 解压一个文件
        /// </summary>
        /// <param name="zipedFileName">压缩文件中的文件名</param>
        /// <param name="encryptKey">加密密码(优先检查), NULL表示不加密</param>
        /// <param name="licenseKeyType">授权密码类型,0表示不加密</param>
        /// <returns>解压缩的文件内容</returns>
        public byte[] ReadBytes(string zipedFileName, string encryptKey, int licenseKeyType)
        {
            if (zipObject == null)
            {
                ErrorString = "Open function must called first";
                return(null);
            }

            try
            {
                //查找指定的文件
                Ionic.Zip.ZipEntry foundEntry = zipObject[zipedFileName];
                if (foundEntry == null || foundEntry.IsDirectory)
                {
                    throw new Exception("Cannot find file");
                }

                //创建MemoryStream,用于解压文件
                byte[]       srcBytes = new byte[foundEntry.UncompressedSize];
                MemoryStream stream   = new MemoryStream(srcBytes, 0, srcBytes.Length);
                foundEntry.Extract(stream);
                stream.Close();

                //添加到压缩文件中
                byte[] decodeBytes = null;
                if (!string.IsNullOrWhiteSpace(encryptKey) || licenseKeyType > 0)
                {
                    if (!string.IsNullOrWhiteSpace(encryptKey))
                    {
                        decodeBytes = Security.DecryptData(srcBytes, encryptKey, null);
                    }
                    else
                    {
                        decodeBytes = Security.DecryptDataByLicenseKey(srcBytes, licenseKeyType);
                    }

                    if (decodeBytes == null)
                    {
                        ErrorString = Security.ErrorString;
                        return(null);
                    }
                }
                else
                {
                    decodeBytes = srcBytes;
                }

                return(srcBytes);
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(null);
            }
        }
Example #8
0
        internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
        {
            bool result = (ObjectType == 'D')
                ? entry.IsDirectory
                : !entry.IsDirectory;

            if (Operator != ComparisonOperator.EqualTo)
            {
                result = !result;
            }
            return(result);
        }
Example #9
0
 /// <summary>
 /// Gets the raw data from entry.
 /// </summary>
 /// <param name="zipEntry">The zip entry.</param>
 /// <returns>IEnumerable with the zip entry content.</returns>
 private IEnumerable <string> GetRawDataStreamFromEntry(ZipEntry zipEntry)
 {
     using (var outerStream = new StreamReader(zipEntry.OpenReader()))
         using (var innerStream = new GZipStream(outerStream.BaseStream, CompressionMode.Decompress))
             using (var outputStream = new StreamReader(innerStream))
             {
                 string line;
                 while ((line = outputStream.ReadLine()) != null)
                 {
                     yield return(line);
                 }
             }
 }
Example #10
0
 /// <summary>
 /// 压缩目录下的所有文件
 /// </summary>
 /// <param name="filePath">源文件根目录</param>
 /// <param name="savePath">保存为Zip包的目录</param>
 public static void ZipDirFileInfo(string filePath, string savePath)
 {
     using (var zip = new ZipFile())
     {
         //读取文件夹下面的所有文件
         string[] fileNames = Directory.GetFiles(filePath);
         foreach (string fileName in fileNames)
         {
             Ionic.Zip.ZipEntry zipEntry = zip.AddFile(fileName, @"\");
             zipEntry.Comment = "Added by Cheeso's CreateZip utility.";
         }
         zip.Comment = $"This zip archive was created by the CreateZip example application on machine '{Dns.GetHostName()}'";
         zip.Save(savePath);
     }
 }
Example #11
0
        private void ExtractFileToPath(Ionic.Zip.ZipFile z, string OutputPath, string FileName)
        {
            z.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Always;
            StatusFloater.Invoke(new System.Action(() => StatusFloater.lblSubStatus.Text = FileName));
            FileStream fs;

            if (!File.Exists(OutputPath + "\\" + FileName) && z.Count(ze => ze.FileName.Contains(FileName)) > 0)
            {
                fs = new FileStream(OutputPath + "\\" + FileName, FileMode.Create);
                Ionic.Zip.ZipEntry ze = z.Entries.Where(f => f.FileName.Contains(FileName)).First();
                ze.Extract(fs);
                fs.Flush(true);
                fs.Close();
            }
        }
Example #12
0
 /// <summary>
 /// Backs up all files that are .DBF
 /// </summary>
 /// <param name="sDirToBackup">The directory to backup</param>
 /// <returns>True if successful, otherwise false</returns>
 public static bool FullBackup(string sSubDir)
 {
     if (GTill.Properties.Settings.Default.bDoBackups)
     {
         if (Directory.Exists(GTill.Properties.Settings.Default.sBackupLocation))
         {
             try
             {
                 // sBackupLocation + "\\" + sBackupDir + "\\" + sSubDir + "\\" + sDirToBackup[z] + "\\" - How confusing!
                 string[] sDirToBackup     = { GTill.Properties.Settings.Default.sINGNGDir, GTill.Properties.Settings.Default.sOUTGNGDir, "..\\TILL" };
                 string[] sDestinationDirs = { "INGNG", "OUTGNG", "TILL" };
                 string   sBackupDir       = DateTime.Now.Day.ToString() + "." + DateTime.Now.Month.ToString() + "." + DateTime.Now.Year.ToString();
                 Directory.CreateDirectory(GTill.Properties.Settings.Default.sBackupLocation + "\\" + sBackupDir);
                 Directory.CreateDirectory(GTill.Properties.Settings.Default.sBackupLocation + "\\" + sBackupDir + "\\" + sSubDir);
                 for (int z = 0; z < sDirToBackup.Length; z++)
                 {
                     using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
                     {
                         //Directory.CreateDirectory(GTill.Properties.Settings.Default.sBackupLocation + "\\" + sBackupDir + "\\" + sSubDir + "\\" + sDestinationDirs[z]);
                         string[] sFiles = Directory.GetFiles(sDirToBackup[z], "*.DBF");
                         for (int i = 0; i < sFiles.Length; i++)
                         {
                             //File.Copy(sFiles[i], GTill.Properties.Settings.Default.sBackupLocation + "\\" + sBackupDir + "\\" + sSubDir + "\\" + sDestinationDirs[z] + "\\" + sFiles[i].Split('\\')[sFiles[i].Split('\\').Length - 1], true);
                             Ionic.Zip.ZipEntry ze = zip.AddFile(sFiles[i]);
                         }
                         zip.Save(GTill.Properties.Settings.Default.sBackupLocation + "\\" + sBackupDir + "\\" + sSubDir + "\\" + sDestinationDirs[z] + ".zip");
                     }
                 }
                 TextWriter tw = new StreamWriter(GTill.Properties.Settings.Default.sBackupLocation + "\\" + sBackupDir + "\\" + sSubDir + "\\backuplog.txt", true);
                 tw.WriteLine("Full backup performed - " + DateTime.Now.ToString());
                 tw.WriteLine("");
                 tw.Close();
             }
             catch (Exception e)
             {
                 GTill.ErrorHandler.LogError("Full backup failed. Error: " + e.Message);
                 return(false);
             }
         }
         else
         {
             GTill.ErrorHandler.LogError("Full backup failed. sBackupDir (Directory " + GTill.Properties.Settings.Default.sBackupLocation + ") doesn't exist. To disable backups please read the manual about changing bDoBackups to False in the configuration file.");
             return(false);
         }
         return(true);
     }
     return(true);
 }
        /// <summary>
        /// 向压缩文件中添加Byte[]
        /// </summary>
        /// <param name="srcBytes">要添加的数据</param>
        /// <param name="zipedName">目标文件名</param>
        /// <param name="encryptKey">加密密码(优先检查), NULL表示不加密</param>
        /// <param name="licenseKeyType">授权密码类型,0表示不加密</param>
        public bool AddBytes(byte[] srcBytes, string zipedName, string encryptKey, int licenseKeyType)
        {
            if (zipObject == null)
            {
                ErrorString = "Create function must called first";
                return(false);
            }
            if (srcBytes == null || string.IsNullOrWhiteSpace(zipedName))
            {
                ErrorString = "Invalid Parameters";
                return(false);
            }

            try
            {
                //添加到压缩文件中
                byte[] encodeBytes = null;
                if (!string.IsNullOrWhiteSpace(encryptKey) || licenseKeyType > 0)
                {
                    if (!string.IsNullOrWhiteSpace(encryptKey))
                    {
                        encodeBytes = Security.EncryptData(srcBytes, encryptKey);
                    }
                    else
                    {
                        encodeBytes = Security.EncryptDataByLicenseKey(srcBytes, licenseKeyType);
                    }

                    if (encodeBytes == null)
                    {
                        ErrorString = Security.ErrorString;
                        return(false);
                    }
                }
                else
                {
                    encodeBytes = srcBytes;
                }

                Ionic.Zip.ZipEntry entry = zipObject.AddEntry(zipedName, srcBytes);
                return(true);
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(false);
            }
        }
Example #14
0
        private System.Xml.XmlDocument GetContentXmlFile(Ionic.Zip.ZipFile zipFile)
        {
            // Get file(in zip archive) that contains data ("content.xml").
            Ionic.Zip.ZipEntry contentZipEntry = zipFile["content.xml"];

            // Extract that file to MemoryStream.
            System.IO.Stream contentStream = new System.IO.MemoryStream();
            contentZipEntry.Extract(contentStream);
            contentStream.Seek(0, System.IO.SeekOrigin.Begin);

            // Create XmlDocument from MemoryStream (MemoryStream contains content.xml).
            System.Xml.XmlDocument contentXml = new System.Xml.XmlDocument();
            contentXml.Load(contentStream);

            return(contentXml);
        }
Example #15
0
 /// <summary>
 /// 将一个压缩文件集合返回压缩后的字节数
 /// </summary>
 /// <param name="filesPath">源文件集合</param>
 /// <returns></returns>
 public static byte[] ZipFilesInfo(IEnumerable <string> filesPath)
 {
     using (var zipFile = new Ionic.Zip.ZipFile())
     {
         foreach (var filePath in filesPath)
         {
             Ionic.Zip.ZipEntry zipEntry = zipFile.AddFile(filePath, @"\");
         }
         zipFile.Comment =
             string.Format("This zip archive was created by the CreateZip example application on machine '{0}'",
                           Dns.GetHostName());
         using (MemoryStream memoryStream = new MemoryStream())
         {
             zipFile.Save(memoryStream);
             return(memoryStream.ToArray()); //将流内容写入字节数组
         }
     }
 }
Example #16
0
 public bool CheckPassword(Ionic.Zip.ZipEntry entry, string password)
 {
     try
     {
         using (var s = new PasswordCheckStream())
         {
             entry.ExtractWithPassword(s, password);
         }
         return(true);
     }
     catch (Ionic.Zip.BadPasswordException)
     {
         return(false);
     }
     catch (PasswordCheckStream.GoodPasswordException)
     {
         return(true);
     }
 }
Example #17
0
        public string Read(string path, string fileName, string password)
        {
            string result = "";

            try
            {
                MemoryStream ms = new MemoryStream();
                using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(path))
                {
                    Ionic.Zip.ZipEntry e = zip["" + fileName + ""];
                    e.ExtractWithPassword(ms, password);
                    StreamReader sr = new StreamReader(ms);
                    ms.Position = 0;
                    result      = sr.ReadToEnd();
                }
            }
            catch { }
            return(result);
        }
Example #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="file"></param>
 /// <param name="key"></param>
 /// <param name="compressedName"></param>
 /// <returns></returns>
 public virtual File Compress(File file, string key = null, string compressedName = null)
 {
     using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
     {
         string fileName = string.IsNullOrEmpty(compressedName) ? file.Name + "zip" : compressedName;
         using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
         {
             zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
             Ionic.Zip.ZipEntry e = zip.AddEntry(file.Name, file.Content);
             if (!string.IsNullOrEmpty(key))
             {
                 e.Password = key;
             }
             zip.Save(ms);
         }
         return(new File(fileName, ms.ToArray())
         {
             Compressed = true
         });
     }
 }
        public ZipSubfileReader_DotNetZip(string zipPath, string subPath)
        {
            var zipfile = new Ionic.Zip.ZipFile(zipPath);

            try {
                Ionic.Zip.ZipEntry entry = zipfile[subPath];
                if (entry == null)
                {
                    throw new System.IO.FileNotFoundException("Cannot find subfile");
                }

                SetWrapped(entry.OpenReader(), true);
                m_file  = zipfile;
                zipfile = null;
            } finally {
                if (zipfile != null)
                {
                    zipfile.Dispose();
                }
            }
        }
Example #20
0
        internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
        {
            DateTime x;

            switch (Which)
            {
            case WhichTime.atime:
                x = entry.AccessedTime;
                break;

            case WhichTime.mtime:
                x = entry.ModifiedTime;
                break;

            case WhichTime.ctime:
                x = entry.CreationTime;
                break;

            default: throw new ArgumentException("??time");
            }
            return(_Evaluate(x));
        }
Example #21
0
        private bool Evaluate(Ionic.Zip.ZipEntry entry)
        {
            bool result = _Criterion.Evaluate(entry);

            return(result);
        }
Example #22
0
 internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
 {
     return(_Evaluate(entry.UncompressedSize));
 }
Example #23
0
        public void SaveTemplate(bool copyContactLogoToITpipesDirectory = true)
        {
            if (string.IsNullOrEmpty(this.PathToTemplateFile) ||
                string.IsNullOrEmpty(this._pathToTemporarilyExtractedProjectMdb))
            {
                throw new Exception("Cannot save a template whose PathToTemplateFile or _pathToTemporarilyExtractedProjectMdb is null or empty");
            }

            if (File.Exists(this.PathToTemplateFile) == false ||
                File.Exists(this._pathToTemporarilyExtractedProjectMdb) == false)
            {
                throw new FileNotFoundException(string.Format("Template file or temporary file not found:\nTemplate: {0}\nTemp File: {1}", this.PathToTemplateFile, this._pathToTemporarilyExtractedProjectMdb));
            }

            using (OleDbConnection curOleConn = new OleDbConnection(this._privateOleConnString))
                using (OleDbCommand curOleCommand = curOleConn.CreateCommand()) {
                    curOleConn.Open();

                    //Need to clear out all contacts which have been removed from the contact list in the template:

                    string pkValuesInContactList = getAllPkValuesFromContactsForUseWithSqlWhereInClause(this.TemplateContacts);

                    if (pkValuesInContactList != "()")
                    {
                        curOleCommand.CommandText = "DELETE FROM `Info` WHERE [Info_ID] NOT IN " + pkValuesInContactList;
                        curOleCommand.ExecuteNonQuery();
                    }
                    else
                    {
                        curOleCommand.CommandText = "DELETE FROM `Info`";
                        curOleCommand.ExecuteNonQuery();
                    }

                    foreach (AddressBookContact curContact in this.TemplateContacts)
                    {
                        if (curContact == null || string.IsNullOrWhiteSpace(curContact.Name) || curContact.ContactHasBeenModified == false)
                        {
                            continue;
                        }

                        AddressBookContact.CopyLogoToITpipesDirectory(curContact, this.TemplateName);

                        if (curContact.SourceRecordIntPK > 0)
                        {
                            AddressBookContact.LoadCommandToUpdateExistingContactRecord(curOleCommand, curContact);
                        }

                        else
                        {
                            AddressBookContact.LoadCommandToInsertNewContactRecord(curOleCommand, curContact);
                        }

                        curOleCommand.ExecuteNonQuery();

                        if (curContact.SourceRecordIntPK < 1)
                        {
                            curOleCommand.Parameters.Clear();
                            curOleCommand.CommandText    = "SELECT TOP 1 [Info_ID] FROM Info ORDER BY [Info_ID] DESC";
                            curContact.SourceRecordIntPK = (int)curOleCommand.ExecuteScalar();
                        }
                    }
                }

            string pathToTempMdb = Path.Combine(Path.GetTempPath(), "project.mdb");

            if (File.Exists(pathToTempMdb))
            {
                File.Delete(pathToTempMdb);
            }

            File.Copy(this._pathToTemporarilyExtractedProjectMdb, pathToTempMdb);

            Ionic.Zip.ZipEntry projectMdbEntry = null;

            foreach (var curEntry in TemplateZipObject.Entries)
            {
                if (curEntry.FileName == "project.mdb")
                {
                    projectMdbEntry = curEntry;
                }
            }

            if (projectMdbEntry != null)
            {
                TemplateZipObject.RemoveEntry(projectMdbEntry);
            }

            projectMdbEntry = null;


            TemplateZipObject.Encryption = Ionic.Zip.EncryptionAlgorithm.PkzipWeak;
            TemplateZipObject.AddFile(pathToTempMdb, "\\").Password = "******";

            string tempFolderPath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(TemplateZipObject.Name);

            if (Directory.Exists(tempFolderPath) == false)
            {
                Directory.CreateDirectory(tempFolderPath);
            }

            TemplateZipObject.Save();
            TemplateZipObject.Reset(false); //If you don't reset the zip object, project.mdb becomes corrupt after the second consecutive save--not sure why.
        }
Example #24
0
        /// <summary>
        /// Gets the ticks from Kaiko file zip entry.
        /// </summary>
        /// <param name="zipEntry">The zip entry.</param>
        /// <returns></returns>
        public IEnumerable <BaseData> GetTicksFromZipEntry(ZipEntry zipEntry)
        {
            var rawData = GetRawDataStreamFromEntry(zipEntry);

            return(_tickType == TickType.Trade ? ParseKaikoTradeFile(rawData) : ParseKaikoQuoteFile(rawData));
        }
Example #25
0
        /// #NAME#: #DESCRIPTION#
        public void f_17250dd1_6cd2_4b1b_a7cd_58ec52297bb8()
        {
            //INI CODE PRCGUID: 17250dd1-6cd2-4b1b-a7cd-58ec52297bb8

            String fichero_de_salida = Input_str("Fichero de salida");

            if (fichero_de_salida != "")
            {
                // current program
                ARQODE_UI.GestorProgramas.CVentanaProgramas CVentanaProgramas = new ARQODE_UI.GestorProgramas.CVentanaProgramas(vm);
                String ns_programa = CVentanaProgramas.Namespace_programa_activo.ToString();

                // program stack for recursive exploration
                Stack <KeyValuePair <int, CProgram> > s_prog = new Stack <KeyValuePair <int, CProgram> >();

                // Progs and procs dictionarys
                Dictionary <String, JToken> exp_programs  = new Dictionary <string, JToken>();
                Dictionary <String, JToken> exp_processes = new Dictionary <String, JToken>();

                CProgram cprog = new CProgram(sys, App_globals, ns_programa);
                while ((ns_programa != "") || (s_prog.Count > 0))
                {
                    int i = 0;

                    // Restore program from stack
                    if (cprog == null)
                    {
                        KeyValuePair <int, CProgram> k_prog = s_prog.Pop();
                        i     = k_prog.Key;
                        cprog = k_prog.Value;
                    }
                    int  n_prcs     = ((JArray)cprog.Logic).Count;
                    bool force_exit = false;

                    // Save program and inner processes
                    while ((!force_exit) && (i < n_prcs))
                    {
                        TProcess proc = new TProcess(sys, App_globals, (JObject)((JArray)cprog.Logic).ElementAt(i));
                        if (!exp_programs.ContainsKey(cprog.Program_namespace))
                        {
                            // add program only once
                            exp_programs.Add(cprog.Program_namespace, cprog.get_json.DeepClone());
                        }

                        i++;
                        if (proc.Guid == "Call")
                        {
                            // Add current program to stack and atach the new one for explore recursively
                            s_prog.Push(new KeyValuePair <int, CProgram>(i, cprog));
                            cprog       = new CProgram(sys, App_globals, proc.Configuration["program"].ToString());
                            ns_programa = cprog.Program_namespace;
                            force_exit  = true;
                        }
                        else if (!exp_processes.ContainsKey(proc.Guid))
                        {
                            // add process only once
                            exp_processes.Add(proc.Guid, proc.get_json.DeepClone());
                        }
                    }
                    if ((i == n_prcs) && (!force_exit))
                    {
                        // set null program only if previous bucle ends
                        cprog       = null;
                        ns_programa = "";
                    }
                }

                #region Create zip

                Ionic.Zip.ZipFile exp_file = null;
                if (File.Exists(fichero_de_salida))
                {
                    exp_file = Ionic.Zip.ZipFile.Read(fichero_de_salida);
                }
                else
                {
                    exp_file = new Ionic.Zip.ZipFile(fichero_de_salida);
                }

                #region add programs & ns conversions to zip file

                String entry_path     = "";
                String base_file_path = "";
                JArray jConversion    = new JArray();

                if (exp_file.ContainsEntry(dEXPORTCODE.STR_IMPORT_CONVS))
                {
                    Ionic.Zip.ZipEntry ze = exp_file.Entries.Where(entry => entry.FileName == dEXPORTCODE.STR_IMPORT_CONVS).FirstOrDefault();

                    MemoryStream ms = new MemoryStream();
                    ze.Extract(ms);
                    byte[] entry_data   = ms.ToArray();
                    String file_content = System.Text.Encoding.Default.GetString(entry_data);
                    ms.Close();
                    jConversion = JArray.Parse(file_content);
                }
                foreach (String sprog in exp_programs.Keys)
                {
                    base_file_path = escape_sc(sprog);

                    // Conversions
                    String  new_ns = dPROGRAM.FOLDER + "\\Imports\\" + base_file_path;
                    JObject jconv  = new JObject(new JProperty(sprog, new_ns));
                    jConversion.Add(jconv);

                    // Add program
                    entry_path = dPROGRAM.FOLDER + "\\Imports\\" + base_file_path + ".json";
                    if (!exp_file.ContainsEntry(entry_path))
                    {
                        exp_file.AddEntry(entry_path, System.Text.UTF8Encoding.UTF8.GetBytes(exp_programs[sprog].ToString()));
                    }
                }
                if (exp_file.ContainsEntry(dEXPORTCODE.STR_IMPORT_CONVS))
                {
                    exp_file.UpdateEntry(dEXPORTCODE.STR_IMPORT_CONVS, jConversion.ToString());
                }
                else
                {
                    exp_file.AddEntry(dEXPORTCODE.STR_IMPORT_CONVS, jConversion.ToString());
                }
                #endregion

                #region Create processes file

                JSonFile jfTemplate = new JSonFile(Globals.AppDataSection(dPATH.PROCESSES), dGLOBALS.PROCESS_TEMPLATE.Replace(".json", ""));
                foreach (JToken jproc in exp_processes.Values)
                {
                    ((JArray)jfTemplate.get(dPROCESS.PROCESSES)).Add(jproc);
                }
                #endregion

                #region add processes file

                base_file_path = escape_sc(CVentanaProgramas.Namespace_programa_activo.ToString());
                entry_path     = dPROCESS.FOLDER + "\\Imports\\" + base_file_path + ".json";
                if (!exp_file.ContainsEntry(entry_path))
                {
                    exp_file.AddEntry(entry_path, System.Text.UTF8Encoding.UTF8.GetBytes(jfTemplate.jActiveObj.ToString()));
                }
                #endregion

                exp_file.Save();

                #endregion

                MessageBox.Show(String.Format("Program exported {0}", CVentanaProgramas.Namespace_programa_activo.ToString()));
            }

            //END CODE PRCGUID: 17250dd1-6cd2-4b1b-a7cd-58ec52297bb8
        }
Example #26
0
 internal abstract bool Evaluate(Ionic.Zip.ZipEntry entry);
Example #27
0
        internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
        {
            FileAttributes fileAttrs = entry.Attributes;

            return(_Evaluate(fileAttrs));
        }