Exemplo n.º 1
0
        public void CreatePacket(Packet packetDefinition, List<string> fileList, List<string> addFileList, string archFileName)
        {
            FileStream fsOut = File.Create(archFileName);

            ZipOutputStream zip = new ZipOutputStream(fsOut);
            zip.SetLevel(9);

            var fileName = Path.GetTempFileName();

            PacketDefinitionsLoader loader = new PacketDefinitionsLoader();
            packetDefinition.ChangedFiles =
                packetDefinition.ChangedFiles.Select(
                    x =>
                        FolderOffset != string.Empty
                            ? ZipEntry.CleanName(x.Replace(FolderOffset, string.Empty))
                            : ZipEntry.CleanName(Path.GetFileName(x))).ToList();

            loader.SavePacket(packetDefinition, fileName);

            PutFileToZip(fileName, _packetdefinitionXml, zip);

            try
            {
                File.Delete(fileName);
            }
            catch (Exception)
            {

            }

            foreach (var path in fileList)
            {
                string entryName = FolderOffset != string.Empty ? path.Replace(FolderOffset, string.Empty) : Path.GetFileName(path);
                entryName = ZipEntry.CleanName(entryName);
                PutFileToZip(path, entryName, zip);
            }

            foreach (var path in addFileList)
            {
                string entryName = AdditionalFilesOffset + Path.GetFileName(path);
                entryName = ZipEntry.CleanName(entryName);
                PutFileToZip(path, entryName, zip);
            }

            zip.IsStreamOwner = true;
            zip.Close();
        }
Exemplo n.º 2
0
        public void SavePacketTest()
        {
            Packet packet = new Packet();
            packet.PacketIdentification = new PacketIdentificationType();
            packet.PacketIdentification.Number = "2";
            packet.PacketIdentification.Date = DateTime.Now;
            packet.PacketIdentification.Guid = Guid.NewGuid().ToString();
            packet.PacketIdentification.ProgramGuid = Guid.NewGuid().ToString();
            packet.PacketIdentification.ProgramVersion = "5.2016.2.2";

            packet.PreviousPackets = new List<PacketIdentificationType>();
            var sss = new PacketIdentificationType
            {
                Number = "1",
                Date = DateTime.Now.AddDays(-1),
                Guid = Guid.NewGuid().ToString(),
                ProgramGuid = Guid.NewGuid().ToString(),
                ProgramVersion = "5.2016.2.2"
            };

            packet.PreviousPackets.Add(sss);

            packet.ActionsBeforeUpdate = new ActionsType();
            packet.ActionsBeforeUpdate.Runs = new List<RunAppType>();

            packet.ActionsBeforeUpdate.Runs.Add(new RunAppType() { RelPath = "asdd", Args = "asddvk", Value = "" });
            packet.ActionsBeforeUpdate.Runs.Add(new RunAppType() { RelPath = "as", Args = "asddvklklfk", Value = "94056" });

            packet.ActionsBeforeUpdate.Scripts = new List<string>();
            packet.ActionsBeforeUpdate.Scripts.Add("dfjhdgfg");
            packet.ActionsBeforeUpdate.Scripts.Add("cxvbvb");

            packet.ChangedFiles = new List<string>() {"asd", "xccc", "aaaaaa"};

            packet.ActionsAfterUpdate = new ActionsType();
            packet.ActionsAfterUpdate.Runs = new List<RunAppType>();
            packet.ActionsAfterUpdate.Runs.Add(new RunAppType() { RelPath = "asdd 2", Args = "asddvklklfk 2 ", Value = "94056" }); 
            packet.ActionsAfterUpdate.Runs.Add(new RunAppType() { RelPath = "asdd" , Args = "asddvklklfk", Value = "94056" });
            packet.UpdateMessage = string.Empty;
            PacketDefinitionsLoader definitionsLoader = new PacketDefinitionsLoader();

            var fileName = Path.GetTempFileName();
            definitionsLoader.SavePacket(packet, fileName);

        }