Пример #1
0
        public void MainSuccessScenario()
        {
            var content1 = "content1 " + Guid.NewGuid();
            var content2 = "content2 " + Guid.NewGuid();

            using (var write = new ZipFile())
            {
                write.AddFileFromString("file1.txt", "", content1);
                write.AddFileFromString("file2.txt", @"Dir1\Dir2\", content2);
                write.AddDirectoryByName("Dir2/Dir3");
                write.Save("testarc.zip");
                write.Dispose();
            }

            using (var read = new ZipFile("testarc.zip"))
            {
                Assert.AreEqual(1, read.Entries.Where(e => e.IsDirectory).Count());
                Assert.AreEqual(2, read.Entries.Where(e => !e.IsDirectory).Count());

                var ms1 = new MemoryStream();
                var ms2 = new MemoryStream();
                read.Extract(@"file1.txt", ms1);
                read.Extract(@"Dir1\Dir2\file2.txt", ms2);
                ms1.Seek(0, SeekOrigin.Begin);
                ms2.Seek(0, SeekOrigin.Begin);
                read.Dispose();

                Assert.AreEqual(content1, new StreamReader(ms1).ReadToEnd());
                Assert.AreEqual(content2, new StreamReader(ms2).ReadToEnd());
            }

            using (var write2 = new ZipFile("testarc.zip"))
            {
                write2.RemoveEntry(@"file1.txt");
                write2.Save();
                write2.Dispose();
            }

            using (var read2 = new ZipFile("testarc.zip"))
            {
                Assert.AreEqual(1, read2.Entries.Where(e => !e.IsDirectory).Count());
                Assert.AreEqual(1, read2.Entries.Where(e => e.IsDirectory).Count());
            }
        }
Пример #2
0
        public void MainSuccessScenario()
        {
            var content1 = "content1 " + Guid.NewGuid();
            var content2 = "content2 " + Guid.NewGuid();

            using (var write = new ZipFile())
            {
                write.AddFileFromString("file1.txt", "", content1);
                write.AddFileFromString("file2.txt", @"Dir1\Dir2\", content2);
                write.AddDirectoryByName("Dir2/Dir3");
                write.Save("testarc.zip");
                write.Dispose();
            }

            using(var read = new ZipFile("testarc.zip"))
            {
                Assert.AreEqual(1, read.Entries.Where(e => e.IsDirectory).Count());
                Assert.AreEqual(2, read.Entries.Where(e => !e.IsDirectory).Count());

                var ms1 = new MemoryStream();
                var ms2 = new MemoryStream();
                read.Extract(@"file1.txt", ms1);
                read.Extract(@"Dir1\Dir2\file2.txt", ms2);
                ms1.Seek(0, SeekOrigin.Begin);
                ms2.Seek(0, SeekOrigin.Begin);
                read.Dispose();

                Assert.AreEqual(content1, new StreamReader(ms1).ReadToEnd());
                Assert.AreEqual(content2, new StreamReader(ms2).ReadToEnd());
            }

            using (var write2 = new ZipFile("testarc.zip"))
            {
                write2.RemoveEntry(@"file1.txt");
                write2.Save();
                write2.Dispose();
            }

            using (var read2 = new ZipFile("testarc.zip"))
            {
                Assert.AreEqual(1, read2.Entries.Where(e => !e.IsDirectory).Count());
                Assert.AreEqual(1, read2.Entries.Where(e => e.IsDirectory).Count());
            }
        }
Пример #3
0
        public string CreatePluginFromDirectory(string sourceDirectory, string destinationFileName, bool includeAllFiles)
        {
            string response = "Unknown Error";



            if (File.Exists(destinationFileName))
            {
                FileHelper.DeleteFile(destinationFileName);
            }
            //Create plugin file
            using (var zip = new ZipFile())
            {
                var directory = new DirectoryInfo(sourceDirectory);

                //Add files in directory
                foreach (var fileToAdd in Directory.GetFiles(sourceDirectory, "*.*", SearchOption.AllDirectories))
                {
                    if (includeAllFiles || mWhatIsConsideredCode.Contains(FileManager.GetExtension(fileToAdd).ToLower()))
                    {
                        string relativeDirectory = null;

                        relativeDirectory = FileManager.MakeRelative(FileManager.GetDirectory(fileToAdd), directory.Parent.FullName);

                        if (relativeDirectory.EndsWith("/"))
                        {
                            relativeDirectory = relativeDirectory.Substring(0, relativeDirectory.Length - 1);
                        }
                        zip.AddFile(fileToAdd, relativeDirectory);
                    }
                }

                //Add compatibility file
                var time = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;


                if (zip.Entries.Any(item => item.FileName == directory.Name + "/" + "Compatibility.txt"))
                {
                    zip.RemoveEntry(directory.Name + "/" + "Compatibility.txt");
                }

                try
                {
                    zip.AddFileFromString("Compatibility.txt", directory.Name, time.ToString());
                    response = "Successfully Created";
                }
                catch (Exception)
                {
                    response = "The directory already contains a Compatibility.txt file name.  The plugin will still be created but it may not properly include compatibility information.  Consider removing this file and re-creating the plugin.";
                }
                zip.Save(destinationFileName);
            }

            return(response);
        }
Пример #4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            TreeViewNode[] checkednodes = MEGATREE.CheckedNodes;

            //Key is: subprocess ID
            //Value is: struct containing the workspaceID and the list of rolenums
            Hashtable selectedSubprocess = new Hashtable();

            foreach (TreeViewNode curnode in checkednodes)
            {
                if (curnode.ID.StartsWith("SP/"))
                {
                    if (curnode.Checked)
                    {
                        exportinfo baby = new exportinfo();
                        baby.ARRidNode   = new ArrayList();
                        baby.idWS        = -1;
                        baby.isWorkspace = false;
                        baby.strName     = curnode.Text;
                        selectedSubprocess[int.Parse(curnode.ID.Substring(3))] = baby;
                    }
                }
                string srchfor = "EntSet/ACT/";
                if (curnode.ID.StartsWith(srchfor))
                {
                    int subpr = int.Parse(curnode.ID.Substring(srchfor.Length));
                    try
                    {
                        exportinfo x = (exportinfo)(selectedSubprocess[subpr]);
                        x.idWS     = int.Parse(curnode.Value);
                        x.strName += " (ACTIVE)";
                        selectedSubprocess[subpr] = x;
                    }
                    catch (Exception eign) { }
                }
                srchfor = "EntSet/WS/";
                if (curnode.ID.StartsWith(srchfor))
                {
                    int subpr = int.Parse(curnode.ID.Substring(srchfor.Length));
                    try
                    {
                        exportinfo x = (exportinfo)(selectedSubprocess[subpr]);
                        x.idWS                    = int.Parse(curnode.Value);
                        x.strName                += " (Workspace)";
                        x.isWorkspace             = true;
                        selectedSubprocess[subpr] = x;
                    }
                    catch (Exception eign) { }
                }
                srchfor = "EntSet/ARCHIVE/";
                if (curnode.ID.StartsWith(srchfor))
                {
                    int subpr = int.Parse(curnode.ID.Substring(srchfor.Length));
                    try
                    {
                        exportinfo x = (exportinfo)(selectedSubprocess[subpr]);
                        x.idWS                    = int.Parse(curnode.Value);
                        x.strName                += " (Archive: " + curnode.Text + ")";
                        x.isWorkspace             = true;
                        selectedSubprocess[subpr] = x;
                    }
                    catch (Exception eign) { }
                }
                srchfor = "BR/";
                if (curnode.ID.StartsWith(srchfor))
                {
                    // This node represents a business role.
                    if (curnode.Checked)
                    {
                        string[] parts = curnode.ID.Split(new char[] { '/' });

                        // Special value: parts[1] == "*ALL*" means all roles is implied, we do not have an explicit list.
                        // The ARRidNode array will thus be left empty and that signals "show all roles" to the export engine.

                        {
                            int subpr   = int.Parse(parts[1]);
                            int broleID = -1; // -1 is special sentinel meaning all business roles *ALL*
                            if (parts[2] != "*ALL*")
                            {
                                broleID = int.Parse(parts[2]);
                            }

                            if (broleID >= 0)
                            {
                                try
                                {
                                    exportinfo x = (exportinfo)(selectedSubprocess[subpr]);
                                    x.ARRidNode.Add(broleID);
                                    selectedSubprocess[subpr] = x; //ESSENTIAL, or the change to the array is ignored!!
                                }
                                catch (Exception eign) { }
                            }
                        }
                    }
                }
            }


            // NOW we are ready to launch.

            // If exactly one subprocess, then we can force the IFRAME to be the receipient
            if (selectedSubprocess.Count == 1)
            {
                IEnumerator enumKeys = selectedSubprocess.Keys.GetEnumerator();
                enumKeys.MoveNext();
                int        thekey = (int)(enumKeys.Current);
                exportinfo guider = (exportinfo)(selectedSubprocess[thekey]);

                string curSubcontractorURL = GenUrl(thekey, ref guider);

                this.TheIframe.Attributes["src"] = curSubcontractorURL;
            }



            if (selectedSubprocess.Count > 1)
            {
                if (CHKforFullDetailCSV.Checked)
                {
                    // We want all the subprocesses all merged into a single CSV
                    Response.ContentType = "text/csv";
                    Response.AddHeader("Content-Disposition",
                                       "filename=export.csv;attachment");
                    IEnumerator enumKeys = selectedSubprocess.Keys.GetEnumerator();
                    while (enumKeys.MoveNext())
                    {
                        int        thekey = (int)(enumKeys.Current);
                        exportinfo guider = (exportinfo)(selectedSubprocess[thekey]);
                        string     curSubcontractorURL = GenUrl(thekey, ref guider);

                        HttpWebRequest subcontract =
                            (HttpWebRequest)WebRequest.Create(curSubcontractorURL);
                        subcontract.Method = "GET"; //experiment: may not work!!
                        HttpWebResponse thereply       = (HttpWebResponse)subcontract.GetResponse();
                        Stream          replycontent   = thereply.GetResponseStream();
                        StreamReader    SRreplycontent = new StreamReader(replycontent);

                        Response.Write(SRreplycontent.ReadToEnd());
                    }
                    Response.End();
                }
                else
                {
                    Response.ContentType = "application/zip";
                    Response.AddHeader("content-disposition", "filename=excelfilecollection.zip");

                    ZipFile zipfileOut = new ZipFile();

                    IEnumerator enumKeys = selectedSubprocess.Keys.GetEnumerator();
                    while (enumKeys.MoveNext())
                    {
                        int        thekey = (int)(enumKeys.Current);
                        exportinfo guider = (exportinfo)(selectedSubprocess[thekey]);
                        string     curSubcontractorURL = GenUrl(thekey, ref guider);

                        HttpWebRequest subcontract =
                            (HttpWebRequest)WebRequest.Create(curSubcontractorURL);
                        subcontract.Method = "GET"; //experiment: may not work!!
                        HttpWebResponse thereply       = (HttpWebResponse)subcontract.GetResponse();
                        Stream          replycontent   = thereply.GetResponseStream();
                        StreamReader    SRreplycontent = new StreamReader(replycontent);

                        zipfileOut.AddFileFromString(
                            guider.strName.Replace(':', '-').Replace('/', '-') + ".xls", "",
                            SRreplycontent.ReadToEnd());
                    }
                    zipfileOut.Save(Response.OutputStream);
                    Response.End();
                }
            }
        }
Пример #5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //Validate plugin folder
            if (!Directory.Exists(PluginFolder))
            {
                MessageBox.Show(@"Please select a valid folder to create the plugin from.");
                return;
            }

            //Prompt for save path
            if (sfdPlugin.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (File.Exists(sfdPlugin.FileName))
            {
                FileHelper.DeleteFile(sfdPlugin.FileName);
            }
            //Create plugin file
            using (var zip = new ZipFile())
            {
                var directory = new DirectoryInfo(PluginFolder);

                //Add files in directory
                foreach (var fileToAdd in Directory.GetFiles(PluginFolder, "*.*", SearchOption.AllDirectories))
                {
                    if (this.AllFilesRadioButton.Checked || mWhatIsConsideredCode.Contains(FileManager.GetExtension(fileToAdd).ToLower()))
                    {
                        string relativeDirectory = null;

                        relativeDirectory = FileManager.MakeRelative(FileManager.GetDirectory(fileToAdd), directory.Parent.FullName);

                        if (relativeDirectory.EndsWith("/"))
                        {
                            relativeDirectory = relativeDirectory.Substring(0, relativeDirectory.Length - 1);
                        }
                        zip.AddFile(fileToAdd, relativeDirectory);
                    }
                }

                //Add compatibility file
                var time = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;


                if (zip.Entries.Any(item => item.FileName == directory.Name + "/" + "Compatibility.txt"))
                {
                    zip.RemoveEntry(directory.Name + "/" + "Compatibility.txt");
                }

                try
                {
                    zip.AddFileFromString("Compatibility.txt", directory.Name, time.ToString());
                }
                catch (Exception)
                {
                    MessageBox.Show("The directory already contains a Compatibility.txt file name.  The plugin will still be created but it may not properly include compatibility information.  Consider removing this file and re-creating the plugin.");
                }
                zip.Save(sfdPlugin.FileName);
            }

            MessageBox.Show(@"Successfully created.");

            System.Diagnostics.Process.Start(FileManager.GetDirectory(sfdPlugin.FileName));

            Close();
        }