+ private void Zipup()
+ {
+ if (filesToZip.Count == 0)
+ {
+ System.Console.WriteLine("Nothing to do.");
+ return;
+ }
+
+ using (var raw = File.Open(_outputFileName, FileMode.Create, FileAccess.ReadWrite ))
+ {
+ using (var output= new ZipOutputStream(raw))
+ {
+ output.Password = "VerySecret!";
+ output.Encryption = EncryptionAlgorithm.WinZipAes256;
+
+ foreach (string inputFileName in filesToZip)
+ {
+ System.Console.WriteLine("file: {0}", inputFileName);
+
+ output.PutNextEntry(inputFileName);
+ using (var input = File.Open(inputFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Write ))
+ {
+ byte[] buffer= new byte[2048];
+ int n;
+ while ((n= input.Read(buffer,0,buffer.Length)) > 0)
+ {
+ output.Write(buffer,0,n);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+
+ Private Sub Zipup()
+ Dim outputFileName As String = "XmlData.zip"
+ Dim filesToZip As String() = Directory.GetFiles(".", "*.xml")
+ If (filesToZip.Length = 0) Then
+ Console.WriteLine("Nothing to do.")
+ Else
+ Using raw As FileStream = File.Open(outputFileName, FileMode.Create, FileAccess.ReadWrite)
+ Using output As ZipOutputStream = New ZipOutputStream(raw)
+ output.Password = "VerySecret!"
+ output.Encryption = EncryptionAlgorithm.WinZipAes256
+ Dim inputFileName As String
+ For Each inputFileName In filesToZip
+ Console.WriteLine("file: {0}", inputFileName)
+ output.PutNextEntry(inputFileName)
+ Using input As FileStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
+ Dim n As Integer
+ Dim buffer As Byte() = New Byte(2048) {}
+ Do While (n = input.Read(buffer, 0, buffer.Length) > 0)
+ output.Write(buffer, 0, n)
+ Loop
+ End Using
+ Next
+ End Using
+ End Using
+ End If
+ End Sub
+
+
+ private void Zipup()
+ {
+ if (filesToZip.Count == 0)
+ {
+ System.Console.WriteLine("Nothing to do.");
+ return;
+ }
+
+ using (var output= new ZipOutputStream(outputFileName))
+ {
+ output.Password = "VerySecret!";
+ output.Encryption = EncryptionAlgorithm.WinZipAes256;
+
+ foreach (string inputFileName in filesToZip)
+ {
+ System.Console.WriteLine("file: {0}", inputFileName);
+
+ output.PutNextEntry(inputFileName);
+ using (var input = File.Open(inputFileName, FileMode.Open, FileAccess.Read,
+ FileShare.Read | FileShare.Write ))
+ {
+ byte[] buffer= new byte[2048];
+ int n;
+ while ((n= input.Read(buffer,0,buffer.Length)) > 0)
+ {
+ output.Write(buffer,0,n);
+ }
+ }
+ }
+ }
+ }
+
+
+
+ Private Sub Zipup()
+ Dim outputFileName As String = "XmlData.zip"
+ Dim filesToZip As String() = Directory.GetFiles(".", "*.xml")
+ If (filesToZip.Length = 0) Then
+ Console.WriteLine("Nothing to do.")
+ Else
+ Using output As ZipOutputStream = New ZipOutputStream(outputFileName)
+ output.Password = "VerySecret!"
+ output.Encryption = EncryptionAlgorithm.WinZipAes256
+ Dim inputFileName As String
+ For Each inputFileName In filesToZip
+ Console.WriteLine("file: {0}", inputFileName)
+ output.PutNextEntry(inputFileName)
+ Using input As FileStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
+ Dim n As Integer
+ Dim buffer As Byte() = New Byte(2048) {}
+ Do While (n = input.Read(buffer, 0, buffer.Length) > 0)
+ output.Write(buffer, 0, n)
+ Loop
+ End Using
+ Next
+ End Using
+ End If
+ End Sub
+
+
+ private void Zipup()
+ {
+ using (FileStream fs raw = File.Open(_outputFileName, FileMode.Create, FileAccess.ReadWrite ))
+ {
+ using (var output= new ZipOutputStream(fs))
+ {
+ output.Password = "VerySecret!";
+ output.Encryption = EncryptionAlgorithm.WinZipAes256;
+ output.PutNextEntry("entry1.txt");
+ byte[] buffer= System.Text.Encoding.ASCII.GetBytes("This is the content for entry #1.");
+ output.Write(buffer,0,buffer.Length);
+ output.PutNextEntry("entry2.txt"); // this will be zero length
+ output.PutNextEntry("entry3.txt");
+ buffer= System.Text.Encoding.ASCII.GetBytes("This is the content for entry #3.");
+ output.Write(buffer,0,buffer.Length);
+ }
+ }
+ }
+
+
+ private void Unzip()
+ {
+ byte[] buffer= new byte[2048];
+ int n;
+ using (var raw = File.Open(inputFileName, FileMode.Open, FileAccess.Read))
+ {
+ using (var input= new ZipInputStream(raw))
+ {
+ ZipEntry e;
+ while (( e = input.GetNextEntry()) != null)
+ {
+ if (e.IsDirectory) continue;
+ string outputPath = Path.Combine(extractDir, e.FileName);
+ using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite))
+ {
+ while ((n= input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ output.Write(buffer,0,n);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+
+ Private Sub UnZip()
+ Dim inputFileName As String = "MyArchive.zip"
+ Dim extractDir As String = "extract"
+ Dim buffer As Byte() = New Byte(2048) {}
+ Using raw As FileStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read)
+ Using input As ZipInputStream = New ZipInputStream(raw)
+ Dim e As ZipEntry
+ Do While (Not e = input.GetNextEntry Is Nothing)
+ If Not e.IsDirectory Then
+ Using output As FileStream = File.Open(Path.Combine(extractDir, e.FileName), _
+ FileMode.Create, FileAccess.ReadWrite)
+ Dim n As Integer
+ Do While (n = input.Read(buffer, 0, buffer.Length) > 0)
+ output.Write(buffer, 0, n)
+ Loop
+ End Using
+ End If
+ Loop
+ End Using
+ End Using
+ End Sub
+
+
+ private void Unzip()
+ {
+ byte[] buffer= new byte[2048];
+ int n;
+ using (var input= new ZipInputStream(inputFileName))
+ {
+ ZipEntry e;
+ while (( e = input.GetNextEntry()) != null)
+ {
+ if (e.IsDirectory) continue;
+ string outputPath = Path.Combine(extractDir, e.FileName);
+ using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite))
+ {
+ while ((n= input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ output.Write(buffer,0,n);
+ }
+ }
+ }
+ }
+ }
+
+
+
+ Private Sub UnZip()
+ Dim inputFileName As String = "MyArchive.zip"
+ Dim extractDir As String = "extract"
+ Dim buffer As Byte() = New Byte(2048) {}
+ Using input As ZipInputStream = New ZipInputStream(inputFileName)
+ Dim e As ZipEntry
+ Do While (Not e = input.GetNextEntry Is Nothing)
+ If Not e.IsDirectory Then
+ Using output As FileStream = File.Open(Path.Combine(extractDir, e.FileName), _
+ FileMode.Create, FileAccess.ReadWrite)
+ Dim n As Integer
+ Do While (n = input.Read(buffer, 0, buffer.Length) > 0)
+ output.Write(buffer, 0, n)
+ Loop
+ End Using
+ End If
+ Loop
+ End Using
+ End Sub
+
+
+ byte[] buffer= new byte[2048];
+ int n;
+ using (var raw = File.Open(_inputFileName, FileMode.Open, FileAccess.Read ))
+ {
+ using (var input= new ZipInputStream(raw))
+ {
+ ZipEntry e;
+ while (( e = input.GetNextEntry()) != null)
+ {
+ input.Password = PasswordForEntry(e.FileName);
+ if (e.IsDirectory) continue;
+ string outputPath = Path.Combine(_extractDir, e.FileName);
+ using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite))
+ {
+ while ((n= input.Read(buffer,0,buffer.Length)) > 0)
+ {
+ output.Write(buffer,0,n);
+ }
+ }
+ }
+ }
+ }
+
+
+
+ var cipher = new ZipCrypto();
+ cipher.InitCipher(Password);
+ // Decrypt the header. This has a side effect of "further initializing the
+ // encryption keys" in the traditional zip encryption.
+ byte[] DecryptedMessage = cipher.DecryptMessage(EncryptedMessage);
+
+
+ Step 1 - Initializing the encryption keys
+ -----------------------------------------
+ Start with these keys:
+ Key(0) := 305419896 (0x12345678)
+ Key(1) := 591751049 (0x23456789)
+ Key(2) := 878082192 (0x34567890)
+
+ Then, initialize the keys with a password:
+
+ loop for i from 0 to length(password)-1
+ update_keys(password(i))
+ end loop
+
+ Where update_keys() is defined as:
+
+ update_keys(char):
+ Key(0) := crc32(key(0),char)
+ Key(1) := Key(1) + (Key(0) bitwiseAND 000000ffH)
+ Key(1) := Key(1) * 134775813 + 1
+ Key(2) := crc32(key(2),key(1) rightshift 24)
+ end update_keys
+
+ Where crc32(old_crc,char) is a routine that given a CRC value and a
+ character, returns an updated CRC value after applying the CRC-32
+ algorithm described elsewhere in this document.
+
+
+
+
+ private void WriteEntry (String filename, Stream output)
+ {
+ DataSet ds1 = ObtainDataSet();
+ ds1.WriteXml(output);
+ }
+
+ private void Run()
+ {
+ using (var zip = new ZipFile())
+ {
+ zip.AddEntry(zipEntryName, WriteEntry);
+ zip.Save(zipFileName);
+ }
+ }
+
+
+
+ Private Sub WriteEntry (ByVal filename As String, ByVal output As Stream)
+ DataSet ds1 = ObtainDataSet()
+ ds1.WriteXml(stream)
+ End Sub
+
+ Public Sub Run()
+ Using zip = New ZipFile
+ zip.AddEntry(zipEntryName, New WriteDelegate(AddressOf WriteEntry))
+ zip.Save(zipFileName)
+ End Using
+ End Sub
+
+
+ using (ZipFile zip = ZipFile.Read("PackedDocuments.zip"))
+ {
+ foreach (string s1 in zip.EntryFilenames)
+ {
+ if (s1.EndsWith(".txt"))
+ {
+ zip[s1].Extract("textfiles");
+ }
+ }
+ }
+
+
+ Using zip As ZipFile = ZipFile.Read("PackedDocuments.zip")
+ Dim s1 As String
+ For Each s1 In zip.EntryFilenames
+ If s1.EndsWith(".txt") Then
+ zip(s1).Extract("textfiles")
+ End If
+ Next
+ End Using
+
+
+ String sZipPath = "Airborne.zip";
+ String sFilePath = "Readme.txt";
+ String sRootFolder = "Digado";
+ using (ZipFile zip = ZipFile.Read(sZipPath))
+ {
+ if (zip.EntryFileNames.Contains(sFilePath))
+ {
+ // use the string indexer on the zip file
+ zip[sFileName].Extract(sRootFolder,
+ ExtractExistingFileAction.OverwriteSilently);
+ }
+ }
+
+
+
+ Dim sZipPath as String = "Airborne.zip"
+ Dim sFilePath As String = "Readme.txt"
+ Dim sRootFolder As String = "Digado"
+ Using zip As ZipFile = ZipFile.Read(sZipPath)
+ If zip.EntryFileNames.Contains(sFilePath)
+ ' use the string indexer on the zip file
+ zip(sFilePath).Extract(sRootFolder, _
+ ExtractExistingFileAction.OverwriteSilently)
+ End If
+ End Using
+
+
+ using (var zip = ZipFile.Read(FilePath))
+ {
+ foreach (ZipEntry e in zip)
+ {
+ if (e.UsesEncryption)
+ e.ExtractWithPassword("Secret!");
+ else
+ e.Extract();
+ }
+ }
+
+
+ Using zip As ZipFile = ZipFile.Read(FilePath)
+ Dim e As ZipEntry
+ For Each e In zip
+ If (e.UsesEncryption)
+ e.ExtractWithPassword("Secret!")
+ Else
+ e.Extract
+ End If
+ Next
+ End Using
+
+
+ using (ZipFile zip = new ZipFile(ZipFileToRead))
+ {
+ ZipEntry e1= zip["Elevation.mp3"];
+ using (Ionic.Zlib.CrcCalculatorStream s = e1.OpenReader())
+ {
+ byte[] buffer = new byte[4096];
+ int n, totalBytesRead= 0;
+ do {
+ n = s.Read(buffer,0, buffer.Length);
+ totalBytesRead+=n;
+ } while (n>0);
+ if (s.Crc32 != e1.Crc32)
+ throw new Exception(string.Format("The Zip Entry failed the CRC Check. (0x{0:X8}!=0x{1:X8})", s.Crc32, e1.Crc32));
+ if (totalBytesRead != e1.UncompressedSize)
+ throw new Exception(string.Format("We read an unexpected number of bytes. ({0}!={1})", totalBytesRead, e1.UncompressedSize));
+ }
+ }
+
+
+ Using zip As New ZipFile(ZipFileToRead)
+ Dim e1 As ZipEntry = zip.Item("Elevation.mp3")
+ Using s As Ionic.Zlib.CrcCalculatorStream = e1.OpenReader
+ Dim n As Integer
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim totalBytesRead As Integer = 0
+ Do
+ n = s.Read(buffer, 0, buffer.Length)
+ totalBytesRead = (totalBytesRead + n)
+ Loop While (n > 0)
+ If (s.Crc32 <> e1.Crc32) Then
+ Throw New Exception(String.Format("The Zip Entry failed the CRC Check. (0x{0:X8}!=0x{1:X8})", s.Crc32, e1.Crc32))
+ End If
+ If (totalBytesRead <> e1.UncompressedSize) Then
+ Throw New Exception(String.Format("We read an unexpected number of bytes. ({0}!={1})", totalBytesRead, e1.UncompressedSize))
+ End If
+ End Using
+ End Using
+
+
+ using (ZipFile zip = new ZipFile(ZipFileToCreate))
+ {
+ ZipEntry e1= zip.AddFile(@"notes\Readme.txt");
+ ZipEntry e2= zip.AddFile(@"music\StopThisTrain.mp3");
+ e2.CompressionMethod = CompressionMethod.None;
+ zip.Save();
+ }
+
+
+
+ Using zip As New ZipFile(ZipFileToCreate)
+ zip.AddFile("notes\Readme.txt")
+ Dim e2 as ZipEntry = zip.AddFile("music\StopThisTrain.mp3")
+ e2.CompressionMethod = CompressionMethod.None
+ zip.Save
+ End Using
+
+
+ // Create a zip archive with AES Encryption.
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddFile("ReadMe.txt")
+ ZipEntry e1= zip.AddFile("2008-Regional-Sales-Report.pdf");
+ e1.Encryption= EncryptionAlgorithm.WinZipAes256;
+ e1.Password= "Top.Secret.No.Peeking!";
+ zip.Save("EncryptedArchive.zip");
+ }
+
+ // Extract a zip archive that uses AES Encryption.
+ // You do not need to specify the algorithm during extraction.
+ using (ZipFile zip = ZipFile.Read("EncryptedArchive.zip"))
+ {
+ // Specify the password that is used during extraction, for
+ // all entries that require a password:
+ zip.Password= "Top.Secret.No.Peeking!";
+ zip.ExtractAll("extractDirectory");
+ }
+
+
+
+ ' Create a zip that uses Encryption.
+ Using zip As New ZipFile()
+ zip.AddFile("ReadMe.txt")
+ Dim e1 as ZipEntry
+ e1= zip.AddFile("2008-Regional-Sales-Report.pdf")
+ e1.Encryption= EncryptionAlgorithm.WinZipAes256
+ e1.Password= "Top.Secret.No.Peeking!"
+ zip.Save("EncryptedArchive.zip")
+ End Using
+
+ ' Extract a zip archive that uses AES Encryption.
+ ' You do not need to specify the algorithm during extraction.
+ Using (zip as ZipFile = ZipFile.Read("EncryptedArchive.zip"))
+ ' Specify the password that is used during extraction, for
+ ' all entries that require a password:
+ zip.Password= "Top.Secret.No.Peeking!"
+ zip.ExtractAll("extractDirectory")
+ End Using
+
+
+
+ // create a file with encryption
+ using (ZipFile zip = new ZipFile())
+ {
+ ZipEntry entry;
+ entry= zip.AddFile("Declaration.txt");
+ entry.Password= "123456!";
+ entry = zip.AddFile("Report.xls");
+ entry.Password= "1Secret!";
+ zip.Save("EncryptedArchive.zip");
+ }
+
+ // extract entries that use encryption
+ using (ZipFile zip = ZipFile.Read("EncryptedArchive.zip"))
+ {
+ ZipEntry entry;
+ entry = zip["Declaration.txt"];
+ entry.Password = "123456!";
+ entry.Extract("extractDir");
+ entry = zip["Report.xls"];
+ entry.Password = "1Secret!";
+ entry.Extract("extractDir");
+ }
+
+
+
+
+ Using zip As New ZipFile
+ Dim entry as ZipEntry
+ entry= zip.AddFile("Declaration.txt")
+ entry.Password= "123456!"
+ entry = zip.AddFile("Report.xls")
+ entry.Password= "1Secret!"
+ zip.Save("EncryptedArchive.zip")
+ End Using
+
+
+ ' extract entries that use encryption
+ Using (zip as ZipFile = ZipFile.Read("EncryptedArchive.zip"))
+ Dim entry as ZipEntry
+ entry = zip("Declaration.txt")
+ entry.Password = "123456!"
+ entry.Extract("extractDir")
+ entry = zip("Report.xls")
+ entry.Password = "1Secret!"
+ entry.Extract("extractDir")
+ End Using
+
+
+
+
+ public static void ExtractProgress(object sender, ExtractProgressEventArgs e)
+ {
+ if (e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry)
+ Console.WriteLine("extract {0} ", e.CurrentEntry.FileName);
+
+ else if (e.EventType == ZipProgressEventType.Extracting_ExtractEntryWouldOverwrite)
+ {
+ ZipEntry entry = e.CurrentEntry;
+ string response = null;
+ // Ask the user if he wants overwrite the file
+ do
+ {
+ Console.Write("Overwrite {0} in {1} ? (y/n/C) ", entry.FileName, e.ExtractLocation);
+ response = Console.ReadLine();
+ Console.WriteLine();
+
+ } while (response != null && response[0]!='Y' &&
+ response[0]!='N' && response[0]!='C');
+
+ if (response[0]=='C')
+ e.Cancel = true;
+ else if (response[0]=='Y')
+ entry.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
+ else
+ entry.ExtractExistingFile= ExtractExistingFileAction.DoNotOverwrite;
+ }
+ }
+
+
+ using (var zip = new ZipFile())
+ {
+ zip.AlternateEnoding = System.Text.Encoding.GetEncoding("ibm861");
+ zip.AlternateEnodingUsage = ZipOption.Always;
+ zip.AddFileS(arrayOfFiles);
+ zip.Save("Myarchive-Encoded-in-IBM861.zip");
+ }
+
+
+ using (var zip = new ZipFile())
+ {
+ var e = zip.UpdateFile("Descriptions.mme", "");
+ e.IsText = true;
+ zip.Save(zipPath);
+ }
+
+
+
+ Using zip As New ZipFile
+ Dim e2 as ZipEntry = zip.AddFile("Descriptions.mme", "")
+ e.IsText= True
+ zip.Save(zipPath)
+ End Using
+
+
+ String[] itemnames= {
+ "c:\\fixedContent\\Readme.txt",
+ "MyProposal.docx",
+ "c:\\SupportFiles", // a directory
+ "images\\Image1.jpg"
+ };
+
+ try
+ {
+ using (ZipFile zip = new ZipFile())
+ {
+ for (int i = 1; i < itemnames.Length; i++)
+ {
+ // will add Files or Dirs, recurses and flattens subdirectories
+ zip.AddItem(itemnames[i],"flat");
+ }
+ zip.Save(ZipToCreate);
+ }
+ }
+ catch (System.Exception ex1)
+ {
+ System.Console.Error.WriteLine("exception: {0}", ex1);
+ }
+
+
+
+ Dim itemnames As String() = _
+ New String() { "c:\fixedContent\Readme.txt", _
+ "MyProposal.docx", _
+ "SupportFiles", _
+ "images\Image1.jpg" }
+ Try
+ Using zip As New ZipFile
+ Dim i As Integer
+ For i = 1 To itemnames.Length - 1
+ ' will add Files or Dirs, recursing and flattening subdirectories.
+ zip.AddItem(itemnames(i), "flat")
+ Next i
+ zip.Save(ZipToCreate)
+ End Using
+ Catch ex1 As Exception
+ Console.Error.WriteLine("exception: {0}", ex1.ToString())
+ End Try
+
+
+ try
+ {
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddFile("c:\\photos\\personal\\7440-N49th.png");
+ zip.AddFile("c:\\Desktop\\2008-Regional-Sales-Report.pdf");
+ zip.AddFile("ReadMe.txt");
+
+ zip.Save("Package.zip");
+ }
+ }
+ catch (System.Exception ex1)
+ {
+ System.Console.Error.WriteLine("exception: " + ex1);
+ }
+
+
+
+ Try
+ Using zip As ZipFile = New ZipFile
+ zip.AddFile("c:\photos\personal\7440-N49th.png")
+ zip.AddFile("c:\Desktop\2008-Regional-Sales-Report.pdf")
+ zip.AddFile("ReadMe.txt")
+ zip.Save("Package.zip")
+ End Using
+ Catch ex1 As Exception
+ Console.Error.WriteLine("exception: {0}", ex1.ToString)
+ End Try
+
+
+ try
+ {
+ using (ZipFile zip = new ZipFile())
+ {
+ // the following entry will be inserted at the root in the archive.
+ zip.AddFile("c:\\datafiles\\ReadMe.txt", "");
+ // this image file will be inserted into the "images" directory in the archive.
+ zip.AddFile("c:\\photos\\personal\\7440-N49th.png", "images");
+ // the following will result in a password-protected file called
+ // files\\docs\\2008-Regional-Sales-Report.pdf in the archive.
+ zip.Password = "EncryptMe!";
+ zip.AddFile("c:\\Desktop\\2008-Regional-Sales-Report.pdf", "files\\docs");
+ zip.Save("Archive.zip");
+ }
+ }
+ catch (System.Exception ex1)
+ {
+ System.Console.Error.WriteLine("exception: {0}", ex1);
+ }
+
+
+
+ Try
+ Using zip As ZipFile = New ZipFile
+ ' the following entry will be inserted at the root in the archive.
+ zip.AddFile("c:\datafiles\ReadMe.txt", "")
+ ' this image file will be inserted into the "images" directory in the archive.
+ zip.AddFile("c:\photos\personal\7440-N49th.png", "images")
+ ' the following will result in a password-protected file called
+ ' files\\docs\\2008-Regional-Sales-Report.pdf in the archive.
+ zip.Password = "EncryptMe!"
+ zip.AddFile("c:\Desktop\2008-Regional-Sales-Report.pdf", "files\documents")
+ zip.Save("Archive.zip")
+ End Using
+ Catch ex1 As Exception
+ Console.Error.WriteLine("exception: {0}", ex1)
+ End Try
+
+
+ String ZipFileToCreate = "archive1.zip";
+ String DirectoryToZip = "c:\\reports";
+ using (ZipFile zip = new ZipFile())
+ {
+ // Store all files found in the top level directory, into the zip archive.
+ String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip);
+ zip.AddFiles(filenames);
+ zip.Save(ZipFileToCreate);
+ }
+
+
+
+ Dim ZipFileToCreate As String = "archive1.zip"
+ Dim DirectoryToZip As String = "c:\reports"
+ Using zip As ZipFile = New ZipFile
+ ' Store all files found in the top level directory, into the zip archive.
+ Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
+ zip.AddFiles(filenames)
+ zip.Save(ZipFileToCreate)
+ End Using
+
+
+ using (ZipFile zip1 = new ZipFile())
+ {
+ // UpdateFile might more accurately be called "AddOrUpdateFile"
+ zip1.UpdateFile("MyDocuments\\Readme.txt");
+ zip1.UpdateFile("CustomerList.csv");
+ zip1.Comment = "This zip archive has been created.";
+ zip1.Save("Content.zip");
+ }
+
+ using (ZipFile zip2 = ZipFile.Read("Content.zip"))
+ {
+ zip2.UpdateFile("Updates\\Readme.txt");
+ zip2.Comment = "This zip archive has been updated: The Readme.txt file has been changed.";
+ zip2.Save();
+ }
+
+
+
+ Using zip1 As New ZipFile
+ ' UpdateFile might more accurately be called "AddOrUpdateFile"
+ zip1.UpdateFile("MyDocuments\Readme.txt")
+ zip1.UpdateFile("CustomerList.csv")
+ zip1.Comment = "This zip archive has been created."
+ zip1.Save("Content.zip")
+ End Using
+
+ Using zip2 As ZipFile = ZipFile.Read("Content.zip")
+ zip2.UpdateFile("Updates\Readme.txt")
+ zip2.Comment = "This zip archive has been updated: The Readme.txt file has been changed."
+ zip2.Save
+ End Using
+
+
+ string Content = "This string will be the content of the Readme.txt file in the zip archive.";
+ using (ZipFile zip1 = new ZipFile())
+ {
+ zip1.AddFile("MyDocuments\\Resume.doc", "files");
+ zip1.AddEntry("Readme.txt", Content);
+ zip1.Comment = "This zip file was created at " + System.DateTime.Now.ToString("G");
+ zip1.Save("Content.zip");
+ }
+
+
+
+ Public Sub Run()
+ Dim Content As String = "This string will be the content of the Readme.txt file in the zip archive."
+ Using zip1 As ZipFile = New ZipFile
+ zip1.AddEntry("Readme.txt", Content)
+ zip1.AddFile("MyDocuments\Resume.doc", "files")
+ zip1.Comment = ("This zip file was created at " & DateTime.Now.ToString("G"))
+ zip1.Save("Content.zip")
+ End Using
+ End Sub
+
+
+ String zipToCreate = "Content.zip";
+ String fileNameInArchive = "Content-From-Stream.bin";
+ using (System.IO.Stream streamToRead = MyStreamOpener())
+ {
+ using (ZipFile zip = new ZipFile())
+ {
+ ZipEntry entry= zip.AddEntry(fileNameInArchive, streamToRead);
+ zip.AddFile("Readme.txt");
+ zip.Save(zipToCreate); // the stream is read implicitly here
+ }
+ }
+
+
+
+ Dim zipToCreate As String = "Content.zip"
+ Dim fileNameInArchive As String = "Content-From-Stream.bin"
+ Using streamToRead as System.IO.Stream = MyStreamOpener()
+ Using zip As ZipFile = New ZipFile()
+ Dim entry as ZipEntry = zip.AddEntry(fileNameInArchive, streamToRead)
+ zip.AddFile("Readme.txt")
+ zip.Save(zipToCreate) '' the stream is read implicitly, here
+ End Using
+ End Using
+
+
+ var c1= new System.Data.SqlClient.SqlConnection(connstring1);
+ var da = new System.Data.SqlClient.SqlDataAdapter()
+ {
+ SelectCommand= new System.Data.SqlClient.SqlCommand(strSelect, c1)
+ };
+
+ DataSet ds1 = new DataSet();
+ da.Fill(ds1, "Invoices");
+
+ using(Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
+ {
+ zip.AddEntry(zipEntryName, (name,stream) => ds1.WriteXml(stream) );
+ zip.Save(zipFileName);
+ }
+
+
+ using (var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ))
+ {
+ using(Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
+ {
+ zip.AddEntry(zipEntryName, (name,output) =>
+ {
+ byte[] buffer = new byte[BufferSize];
+ int n;
+ while ((n = input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ // could transform the data here...
+ output.Write(buffer, 0, n);
+ // could update a progress bar here
+ }
+ });
+
+ zip.Save(zipFileName);
+ }
+ }
+
+
+ Private Sub WriteEntry (ByVal name As String, ByVal output As Stream)
+ Using input As FileStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
+ Dim n As Integer = -1
+ Dim buffer As Byte() = New Byte(BufferSize){}
+ Do While n <> 0
+ n = input.Read(buffer, 0, buffer.Length)
+ output.Write(buffer, 0, n)
+ Loop
+ End Using
+ End Sub
+
+ Public Sub Run()
+ Using zip = New ZipFile
+ zip.AddEntry(zipEntryName, New WriteDelegate(AddressOf WriteEntry))
+ zip.Save(zipFileName)
+ End Using
+ End Sub
+
+
+ using(Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
+ {
+ zip.AddEntry(zipEntryName,
+ (name) => File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ),
+ (name, stream) => stream.Close()
+ );
+
+ zip.Save(zipFileName);
+ }
+
+
+
+
+ Function MyStreamOpener(ByVal entryName As String) As Stream
+ '' This simply opens a file. You probably want to do somethinig
+ '' more involved here: open a stream to read from a database,
+ '' open a stream on an HTTP connection, and so on.
+ Return File.OpenRead(entryName)
+ End Function
+
+ Sub MyStreamCloser(entryName As String, stream As Stream)
+ stream.Close()
+ End Sub
+
+ Public Sub Run()
+ Dim dirToZip As String = "fodder"
+ Dim zipFileToCreate As String = "Archive.zip"
+ Dim opener As OpenDelegate = AddressOf MyStreamOpener
+ Dim closer As CloseDelegate = AddressOf MyStreamCloser
+ Dim numFilestoAdd As Int32 = 4
+ Using zip As ZipFile = New ZipFile
+ Dim i As Integer
+ For i = 0 To numFilesToAdd - 1
+ zip.AddEntry(String.Format("content-{0:000}.txt"), opener, closer)
+ Next i
+ zip.Save(zipFileToCreate)
+ End Using
+ End Sub
+
+
+
+ public void ZipUp(string targetZip, string directory)
+ {
+ using (var zip = new ZipFile())
+ {
+ zip.AddDirectory(directory, System.IO.Path.GetFileName(directory));
+ zip.Save(targetZip);
+ }
+ }
+
+
+ String ZipFileToCreate = "archive1.zip";
+ String DirectoryToZip = "c:\\reports";
+ using (ZipFile zip = new ZipFile())
+ {
+ // Store all files found in the top level directory, into the zip archive.
+ String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip);
+ zip.AddFiles(filenames, "files");
+ zip.Save(ZipFileToCreate);
+ }
+
+
+
+ Dim ZipFileToCreate As String = "archive1.zip"
+ Dim DirectoryToZip As String = "c:\reports"
+ Using zip As ZipFile = New ZipFile()
+ Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
+ zip.AddFiles(filenames, "files")
+ zip.Save(ZipFileToCreate)
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ // Store all files found in the top level directory, into the zip archive.
+ // note: this code does not recurse subdirectories!
+ String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip);
+ zip.AddFiles(filenames, "files");
+ zip.Save("Backup.zip");
+ }
+
+
+
+ Using zip As New ZipFile
+ ' Store all files found in the top level directory, into the zip archive.
+ ' note: this code does not recurse subdirectories!
+ Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
+ zip.AddFiles(filenames, "files")
+ zip.Save("Backup.zip")
+ End Using
+
+
+ using (ZipFile zip = new ZipFile("Backup.zip", Console.Out))
+ {
+ // Store all files found in the top level directory, into the zip archive.
+ // note: this code does not recurse subdirectories!
+ // Status messages will be written to Console.Out
+ String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip);
+ zip.AddFiles(filenames);
+ zip.Save();
+ }
+
+
+
+ Using zip As New ZipFile("Backup.zip", Console.Out)
+ ' Store all files found in the top level directory, into the zip archive.
+ ' note: this code does not recurse subdirectories!
+ ' Status messages will be written to Console.Out
+ Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
+ zip.AddFiles(filenames)
+ zip.Save()
+ End Using
+
+
+ String ZipFileToRead = "ArchiveToModify.zip";
+ System.DateTime Threshold = new System.DateTime(2007,12,31);
+ using (ZipFile zip = ZipFile.Read(ZipFileToRead))
+ {
+ var EntriesToRemove = new System.Collections.Generic.List<ZipEntry>();
+ foreach (ZipEntry e in zip)
+ {
+ if (e.LastModified < Threshold)
+ {
+ // We cannot remove the entry from the list, within the context of
+ // an enumeration of said list.
+ // So we add the doomed entry to a list to be removed later.
+ EntriesToRemove.Add(e);
+ }
+ }
+
+ // actually remove the doomed entries.
+ foreach (ZipEntry zombie in EntriesToRemove)
+ zip.RemoveEntry(zombie);
+
+ zip.Comment= String.Format("This zip archive was updated at {0}.",
+ System.DateTime.Now.ToString("G"));
+
+ // save with a different name
+ zip.Save("Archive-Updated.zip");
+ }
+
+
+
+ Dim ZipFileToRead As String = "ArchiveToModify.zip"
+ Dim Threshold As New DateTime(2007, 12, 31)
+ Using zip As ZipFile = ZipFile.Read(ZipFileToRead)
+ Dim EntriesToRemove As New System.Collections.Generic.List(Of ZipEntry)
+ Dim e As ZipEntry
+ For Each e In zip
+ If (e.LastModified < Threshold) Then
+ ' We cannot remove the entry from the list, within the context of
+ ' an enumeration of said list.
+ ' So we add the doomed entry to a list to be removed later.
+ EntriesToRemove.Add(e)
+ End If
+ Next
+
+ ' actually remove the doomed entries.
+ Dim zombie As ZipEntry
+ For Each zombie In EntriesToRemove
+ zip.RemoveEntry(zombie)
+ Next
+ zip.Comment = String.Format("This zip archive was updated at {0}.", DateTime.Now.ToString("G"))
+ 'save as a different name
+ zip.Save("Archive-Updated.zip")
+ End Using
+
+
+ String zipFileToRead= "PackedDocuments.zip";
+ string candidate = "DatedMaterial.xps";
+ using (ZipFile zip = ZipFile.Read(zipFileToRead))
+ {
+ if (zip.EntryFilenames.Contains(candidate))
+ {
+ zip.RemoveEntry(candidate);
+ zip.Comment= String.Format("The file '{0}' has been removed from this archive.",
+ Candidate);
+ zip.Save();
+ }
+ }
+
+
+ Dim zipFileToRead As String = "PackedDocuments.zip"
+ Dim candidate As String = "DatedMaterial.xps"
+ Using zip As ZipFile = ZipFile.Read(zipFileToRead)
+ If zip.EntryFilenames.Contains(candidate) Then
+ zip.RemoveEntry(candidate)
+ zip.Comment = String.Format("The file '{0}' has been removed from this archive.", Candidate)
+ zip.Save
+ End If
+ End Using
+
+
+ using (ZipFile zip = ZipFile.Read(zipfile))
+ {
+ foreach (ZipEntry e in zip)
+ {
+ if (WantThisEntry(e.FileName))
+ zip.Extract(e.FileName, Console.OpenStandardOutput());
+ }
+ } // Dispose() is called implicitly here.
+
+
+
+ Using zip As ZipFile = ZipFile.Read(zipfile)
+ Dim e As ZipEntry
+ For Each e In zip
+ If WantThisEntry(e.FileName) Then
+ zip.Extract(e.FileName, Console.OpenStandardOutput())
+ End If
+ Next
+ End Using ' Dispose is implicity called here
+
+
+ String TargetDirectory= "unpack";
+ using(ZipFile zip= ZipFile.Read(ZipFileToExtract))
+ {
+ zip.ExtractExistingFile= ExtractExistingFileAction.OverwriteSilently;
+ zip.ExtractAll(TargetDirectory);
+ }
+
+
+
+ Dim TargetDirectory As String = "unpack"
+ Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
+ zip.ExtractExistingFile= ExtractExistingFileAction.OverwriteSilently
+ zip.ExtractAll(TargetDirectory)
+ End Using
+
+
+ String TargetDirectory= "c:\\unpack";
+ using(ZipFile zip= ZipFile.Read(ZipFileToExtract))
+ {
+ zip.ExtractAll(TargetDirectory, ExtractExistingFileAction.DontOverwrite);
+ }
+
+
+
+ Dim TargetDirectory As String = "c:\unpack"
+ Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
+ zip.ExtractAll(TargetDirectory, ExtractExistingFileAction.DontOverwrite)
+ End Using
+
+
+ string zipToExtract = "MyArchive.zip";
+ string extractDirectory = "extract";
+ var options = new ReadOptions
+ {
+ StatusMessageWriter = System.Console.Out,
+ Encoding = System.Text.Encoding.GetEncoding(950)
+ };
+ using (ZipFile zip = ZipFile.Read(zipToExtract, options))
+ {
+ foreach (ZipEntry e in zip)
+ {
+ e.Extract(extractDirectory);
+ }
+ }
+
+
+
+
+ Dim zipToExtract as String = "MyArchive.zip"
+ Dim extractDirectory as String = "extract"
+ Dim options as New ReadOptions
+ options.Encoding = System.Text.Encoding.GetEncoding(950)
+ options.StatusMessageWriter = System.Console.Out
+ Using zip As ZipFile = ZipFile.Read(zipToExtract, options)
+ Dim e As ZipEntry
+ For Each e In zip
+ e.Extract(extractDirectory)
+ Next
+ End Using
+
+
+ var options = new ReadOptions
+ {
+ StatusMessageWriter = new System.IO.StringWriter()
+ };
+ using (ZipFile zip = ZipFile.Read("PackedDocuments.zip", options))
+ {
+ var Threshold = new DateTime(2007,7,4);
+ // We cannot remove the entry from the list, within the context of
+ // an enumeration of said list.
+ // So we add the doomed entry to a list to be removed later.
+ // pass 1: mark the entries for removal
+ var MarkedEntries = new System.Collections.Generic.List<ZipEntry>();
+ foreach (ZipEntry e in zip)
+ {
+ if (e.LastModified < Threshold)
+ MarkedEntries.Add(e);
+ }
+ // pass 2: actually remove the entry.
+ foreach (ZipEntry zombie in MarkedEntries)
+ zip.RemoveEntry(zombie);
+ zip.Comment = "This archive has been updated.";
+ zip.Save();
+ }
+ // can now use contents of sw, eg store in an audit log
+
+
+
+ Dim options as New ReadOptions
+ options.StatusMessageWriter = New System.IO.StringWriter
+ Using zip As ZipFile = ZipFile.Read("PackedDocuments.zip", options)
+ Dim Threshold As New DateTime(2007, 7, 4)
+ ' We cannot remove the entry from the list, within the context of
+ ' an enumeration of said list.
+ ' So we add the doomed entry to a list to be removed later.
+ ' pass 1: mark the entries for removal
+ Dim MarkedEntries As New System.Collections.Generic.List(Of ZipEntry)
+ Dim e As ZipEntry
+ For Each e In zip
+ If (e.LastModified < Threshold) Then
+ MarkedEntries.Add(e)
+ End If
+ Next
+ ' pass 2: actually remove the entry.
+ Dim zombie As ZipEntry
+ For Each zombie In MarkedEntries
+ zip.RemoveEntry(zombie)
+ Next
+ zip.Comment = "This archive has been updated."
+ zip.Save
+ End Using
+ ' can now use contents of sw, eg store in an audit log
+
+
+ using (ZipFile zip = ZipFile.Read(InputStream))
+ {
+ zip.Extract("NameOfEntryInArchive.doc", OutputStream);
+ }
+
+
+
+ Using zip as ZipFile = ZipFile.Read(InputStream)
+ zip.Extract("NameOfEntryInArchive.doc", OutputStream)
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddDirectory(@"c:\reports\January");
+ zip.Save("January.zip");
+ }
+
+
+
+ Using zip As New ZipFile()
+ zip.AddDirectory("c:\reports\January")
+ zip.Save("January.zip")
+ End Using
+
+
+
+ using (ZipFile zip = ZipFile.Read("ExistingArchive.zip"))
+ {
+ zip.AddFile("NewData.csv");
+ zip.Save("UpdatedArchive.zip");
+ }
+
+
+
+ Using zip As ZipFile = ZipFile.Read("ExistingArchive.zip")
+ zip.AddFile("NewData.csv")
+ zip.Save("UpdatedArchive.zip")
+ End Using
+
+
+
+ using (var zip = new Ionic.Zip.ZipFile())
+ {
+ zip.CompressionLevel= Ionic.Zlib.CompressionLevel.BestCompression;
+ zip.Password = "VerySecret.";
+ zip.Encryption = EncryptionAlgorithm.WinZipAes128;
+ zip.AddFile(sourceFileName);
+ MemoryStream output = new MemoryStream();
+ zip.Save(output);
+
+ byte[] zipbytes = output.ToArray();
+ }
+
+
+ using (var fs = new FileSteeam(filename, FileMode.Open))
+ {
+ using (var zip = Ionic.Zip.ZipFile.Read(inputStream))
+ {
+ zip.AddEntry("Name1.txt", "this is the content");
+ zip.Save(inputStream); // NO NO NO!!
+ }
+ }
+
+
+
+ using (var zip = Ionic.Zip.ZipFile.Read(filename))
+ {
+ zip.AddEntry("Name1.txt", "this is the content");
+ zip.Save(); // YES!
+ }
+
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ // To just match on filename wildcards,
+ // use the shorthand form of the selectionCriteria string.
+ zip.AddSelectedFiles("*.csv");
+ zip.Save(PathToZipArchive);
+ }
+
+
+ Using zip As ZipFile = New ZipFile()
+ zip.AddSelectedFiles("*.csv")
+ zip.Save(PathToZipArchive)
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ // Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.xml and size > 1024kb", true);
+ zip.Save(PathToZipArchive);
+ }
+
+
+ Using zip As ZipFile = New ZipFile()
+ ' Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.xml and size > 1024kb", true)
+ zip.Save(PathToZipArchive)
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ // Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.xml and size > 1024kb", "d:\\rawdata");
+ zip.Save(PathToZipArchive);
+ }
+
+
+
+ Using zip As ZipFile = New ZipFile()
+ ' Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.xml and size > 1024kb", "d:\rawdata)
+ zip.Save(PathToZipArchive)
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ // Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.csv and mtime > 2009-02-14", "files", true);
+ zip.Save(PathToZipArchive);
+ }
+
+
+ Using zip As ZipFile = New ZipFile()
+ ' Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.csv and mtime > 2009-02-14", "files", true)
+ zip.Save(PathToZipArchive)
+ End Using
+
+
+ Using Zip As ZipFile = New ZipFile(zipfile)
+ Zip.AddSelectedFfiles("name != 'excludethis\*.*'", datapath, True)
+ Zip.Save()
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ // Use a compound expression in the selectionCriteria string.
+ zip.AddSelectedFiles("name = *.psd and mtime > 2009-02-14", "photos", "content");
+ zip.Save(PathToZipArchive);
+ }
+
+
+ Using zip As ZipFile = New ZipFile
+ zip.AddSelectedFiles("name = *.psd and mtime > 2009-02-14", "photos", "content")
+ zip.Save(PathToZipArchive)
+ End Using
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddSelectedFiles("name != *.pst", SourceDirectory, "backup", true);
+ zip.Save(PathToZipArchive);
+ }
+
+
+ Using zip As ZipFile = New ZipFile
+ zip.AddSelectedFiles("name != *.pst", SourceDirectory, "backup", true)
+ zip.Save(PathToZipArchive)
+ End Using
+
+
+ using (ZipFile zip1 = ZipFile.Read(ZipFileName))
+ {
+ var PhotoShopFiles = zip1.SelectEntries("*.psd");
+ foreach (ZipEntry psd in PhotoShopFiles)
+ {
+ psd.Extract();
+ }
+ }
+
+
+ Using zip1 As ZipFile = ZipFile.Read(ZipFileName)
+ Dim PhotoShopFiles as ICollection(Of ZipEntry)
+ PhotoShopFiles = zip1.SelectEntries("*.psd")
+ Dim psd As ZipEntry
+ For Each psd In PhotoShopFiles
+ psd.Extract
+ Next
+ End Using
+
+
+ using (ZipFile zip1 = ZipFile.Read(ZipFileName))
+ {
+ var UpdatedPhotoShopFiles = zip1.SelectEntries("*.psd", "UpdatedFiles");
+ foreach (ZipEntry e in UpdatedPhotoShopFiles)
+ {
+ // prompt for extract here
+ if (WantExtract(e.FileName))
+ e.Extract();
+ }
+ }
+
+
+ Using zip1 As ZipFile = ZipFile.Read(ZipFileName)
+ Dim UpdatedPhotoShopFiles As ICollection(Of ZipEntry) = zip1.SelectEntries("*.psd", "UpdatedFiles")
+ Dim e As ZipEntry
+ For Each e In UpdatedPhotoShopFiles
+ ' prompt for extract here
+ If Me.WantExtract(e.FileName) Then
+ e.Extract
+ End If
+ Next
+ End Using
+
+
+ using (ZipFile zip1 = ZipFile.Read(ZipFileName))
+ {
+ // remove all entries from prior to Jan 1, 2008
+ zip1.RemoveEntries("mtime < 2008-01-01");
+ // don't forget to save the archive!
+ zip1.Save();
+ }
+
+
+ Using zip As ZipFile = ZipFile.Read(ZipFileName)
+ ' remove all entries from prior to Jan 1, 2008
+ zip1.RemoveEntries("mtime < 2008-01-01")
+ ' do not forget to save the archive!
+ zip1.Save
+ End Using
+
+
+ using (ZipFile zip1 = ZipFile.Read(ZipFileName))
+ {
+ // remove all entries from prior to Jan 1, 2008
+ zip1.RemoveEntries("mtime < 2008-01-01", "documents");
+ // a call to ZipFile.Save will make the modifications permanent
+ zip1.Save();
+ }
+
+
+ Using zip As ZipFile = ZipFile.Read(ZipFileName)
+ ' remove all entries from prior to Jan 1, 2008
+ zip1.RemoveEntries("mtime < 2008-01-01", "documents")
+ ' a call to ZipFile.Save will make the modifications permanent
+ zip1.Save
+ End Using
+
+
+ using (ZipFile zip = ZipFile.Read(zipArchiveName))
+ {
+ zip.ExtractSelectedEntries("name = *.xml and mtime > 2009-01-15");
+ }
+
+
+ using (ZipFile zip = ZipFile.Read(zipArchiveName))
+ {
+ zip.ExtractSelectedEntries("name = *.xml and mtime > 2009-01-15",
+ ExtractExistingFileAction.OverwriteSilently);
+ }
+
+
+ using (ZipFile zip = ZipFile.Read(zipArchiveName))
+ {
+ zip.ExtractSelectedEntries("name = *.xml and mtime > 2009-01-15","unpack");
+ }
+
+
+ using (ZipFile zip = ZipFile.Read(zipArchiveName))
+ {
+ zip.ExtractSelectedEntries("name = *.xml or size > 100000",
+ null,
+ "unpack",
+ ExtractExistingFileAction.DontOverwrite);
+ }
+
+
+ string DirectoryPath = "c:\\Documents\\Project7";
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath));
+ zip.Comment = "This will be embedded into a self-extracting console-based exe";
+ zip.SaveSelfExtractor("archive.exe", SelfExtractorFlavor.ConsoleApplication);
+ }
+
+
+ Dim DirectoryPath As String = "c:\Documents\Project7"
+ Using zip As New ZipFile()
+ zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath))
+ zip.Comment = "This will be embedded into a self-extracting console-based exe"
+ zip.SaveSelfExtractor("archive.exe", SelfExtractorFlavor.ConsoleApplication)
+ End Using
+
+
+ string DirectoryPath = "c:\\Documents\\Project7";
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath));
+ zip.Comment = "This will be embedded into a self-extracting WinForms-based exe";
+ var options = new SelfExtractorOptions
+ {
+ Flavor = SelfExtractorFlavor.WinFormsApplication,
+ DefaultExtractDirectory = "%USERPROFILE%\\ExtractHere",
+ PostExtractCommandLine = ExeToRunAfterExtract,
+ SfxExeWindowTitle = "My Custom Window Title",
+ RemoveUnpackedFilesAfterExecute = true
+ };
+ zip.SaveSelfExtractor("archive.exe", options);
+ }
+
+
+ Dim DirectoryPath As String = "c:\Documents\Project7"
+ Using zip As New ZipFile()
+ zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath))
+ zip.Comment = "This will be embedded into a self-extracting console-based exe"
+ Dim options As New SelfExtractorOptions()
+ options.Flavor = SelfExtractorFlavor.WinFormsApplication
+ options.DefaultExtractDirectory = "%USERPROFILE%\\ExtractHere"
+ options.PostExtractCommandLine = ExeToRunAfterExtract
+ options.SfxExeWindowTitle = "My Custom Window Title"
+ options.RemoveUnpackedFilesAfterExecute = True
+ zip.SaveSelfExtractor("archive.exe", options)
+ End Using
+
+
+ using (ZipFile zip = ZipFile.Read(zipfile))
+ {
+ bool header = true;
+ foreach (ZipEntry e in zip)
+ {
+ if (header)
+ {
+ System.Console.WriteLine("Zipfile: {0}", zip.Name);
+ System.Console.WriteLine("Version Needed: 0x{0:X2}", e.VersionNeeded);
+ System.Console.WriteLine("BitField: 0x{0:X2}", e.BitField);
+ System.Console.WriteLine("Compression Method: 0x{0:X2}", e.CompressionMethod);
+ System.Console.WriteLine("\n{1,-22} {2,-6} {3,4} {4,-8} {0}",
+ "Filename", "Modified", "Size", "Ratio", "Packed");
+ System.Console.WriteLine(new System.String('-', 72));
+ header = false;
+ }
+
+ System.Console.WriteLine("{1,-22} {2,-6} {3,4:F0}% {4,-8} {0}",
+ e.FileName,
+ e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
+ e.UncompressedSize,
+ e.CompressionRatio,
+ e.CompressedSize);
+
+ e.Extract();
+ }
+ }
+
+
+
+ Dim ZipFileToExtract As String = "c:\foo.zip"
+ Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
+ Dim header As Boolean = True
+ Dim e As ZipEntry
+ For Each e In zip
+ If header Then
+ Console.WriteLine("Zipfile: {0}", zip.Name)
+ Console.WriteLine("Version Needed: 0x{0:X2}", e.VersionNeeded)
+ Console.WriteLine("BitField: 0x{0:X2}", e.BitField)
+ Console.WriteLine("Compression Method: 0x{0:X2}", e.CompressionMethod)
+ Console.WriteLine(ChrW(10) & "{1,-22} {2,-6} {3,4} {4,-8} {0}", _
+ "Filename", "Modified", "Size", "Ratio", "Packed" )
+ Console.WriteLine(New String("-"c, 72))
+ header = False
+ End If
+ Console.WriteLine("{1,-22} {2,-6} {3,4:F0}% {4,-8} {0}", _
+ e.FileName, _
+ e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"), _
+ e.UncompressedSize, _
+ e.CompressionRatio, _
+ e.CompressedSize )
+ e.Extract
+ Next
+ End Using
+
+
+ using (var zip = new ZipFile())
+ {
+ zip.FullScan = true;
+ zip.Initialize(zipFileName);
+ zip.Save(newName);
+ }
+
+
+
+ Using zip As New ZipFile
+ zip.FullScan = True
+ zip.Initialize(zipFileName)
+ zip.Save(newName)
+ End Using
+
+
+ using (var zip = new ZipFile())
+ {
+ zip.AddFiles(filesToAdd);
+ zip.SortEntriesBeforeSaving = true;
+ zip.Save(name);
+ }
+
+
+
+ Using zip As New ZipFile
+ zip.AddFiles(filesToAdd)
+ zip.SortEntriesBeforeSaving = True
+ zip.Save(name)
+ End Using
+
+
+ using (var zip = new ZipFile())
+ {
+ zip.AddDirectoryWillTraverseReparsePoints = false;
+ zip.AddDirectory(dirToZip,"fodder");
+ zip.Save(zipFileToCreate);
+ }
+
+
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.SaveProgress += this.zip1_SaveProgress;
+ zip.AddDirectory(directoryToZip, "");
+ zip.UseZip64WhenSaving = Zip64Option.Always;
+ zip.BufferSize = 65536*8; // 65536 * 8 = 512k
+ zip.Save(ZipFileToCreate);
+ }
+
+
+ using (var zip = new ZipFile())
+ {
+ // produce a zip file the Mac will like
+ zip.EmitTimesInWindowsFormatWhenSaving = false;
+ zip.EmitTimesInUnixFormatWhenSaving = true;
+ zip.AddDirectory(directoryToZip, "files");
+ zip.Save(outputFile);
+ }
+
+
+
+ Using zip As New ZipFile
+ '' produce a zip file the Mac will like
+ zip.EmitTimesInWindowsFormatWhenSaving = False
+ zip.EmitTimesInUnixFormatWhenSaving = True
+ zip.AddDirectory(directoryToZip, "files")
+ zip.Save(outputFile)
+ End Using
+
+
+ using (var zip = ZipFile.Read(zipFileName, System.Text.Encoding.GetEncoding("big5")))
+ {
+ // retrieve and extract an entry using a name encoded with CP950
+ zip[MyDesiredEntry].Extract("unpack");
+ }
+
+
+
+ Using zip As ZipFile = ZipFile.Read(ZipToExtract, System.Text.Encoding.GetEncoding("big5"))
+ ' retrieve and extract an entry using a name encoded with CP950
+ zip(MyDesiredEntry).Extract("unpack")
+ End Using
+
+
+ using (ZipFile zip= ZipFile.Read(FilePath))
+ {
+ zip.StatusMessageTextWriter= System.Console.Out;
+ // messages are sent to the console during extraction
+ zip.ExtractAll();
+ }
+
+
+
+ Using zip As ZipFile = ZipFile.Read(FilePath)
+ zip.StatusMessageTextWriter= System.Console.Out
+ 'Status Messages will be sent to the console during extraction
+ zip.ExtractAll()
+ End Using
+
+
+
+ var sw = new System.IO.StringWriter();
+ using (ZipFile zip= ZipFile.Read(FilePath))
+ {
+ zip.StatusMessageTextWriter= sw;
+ zip.ExtractAll();
+ }
+ Console.WriteLine("{0}", sw.ToString());
+
+
+
+ Dim sw as New System.IO.StringWriter
+ Using zip As ZipFile = ZipFile.Read(FilePath)
+ zip.StatusMessageTextWriter= sw
+ zip.ExtractAll()
+ End Using
+ 'Status Messages are now available in sw
+
+
+
+ // create a file with encryption
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddFile("ReadMe.txt");
+ zip.Password= "!Secret1";
+ zip.AddFile("MapToTheSite-7440-N49th.png");
+ zip.AddFile("2008-Regional-Sales-Report.pdf");
+ zip.Save("EncryptedArchive.zip");
+ }
+
+ // extract entries that use encryption
+ using (ZipFile zip = ZipFile.Read("EncryptedArchive.zip"))
+ {
+ zip.Password= "!Secret1";
+ zip.ExtractAll("extractDir");
+ }
+
+
+
+
+ Using zip As New ZipFile
+ zip.AddFile("ReadMe.txt")
+ zip.Password = "123456!"
+ zip.AddFile("MapToTheSite-7440-N49th.png")
+ zip.Password= "!Secret1";
+ zip.AddFile("2008-Regional-Sales-Report.pdf")
+ zip.Save("EncryptedArchive.zip")
+ End Using
+
+
+ ' extract entries that use encryption
+ Using (zip as ZipFile = ZipFile.Read("EncryptedArchive.zip"))
+ zip.Password= "!Secret1"
+ zip.ExtractAll("extractDir")
+ End Using
+
+
+
+
+ Public Sub SaveZipFile()
+ Dim SourceFolder As String = "fodder"
+ Dim DestFile As String = "eHandler.zip"
+ Dim sw as New StringWriter
+ Using zipArchive As ZipFile = New ZipFile
+ ' Tell DotNetZip to skip any files for which it encounters an error
+ zipArchive.ZipErrorAction = ZipErrorAction.Skip
+ zipArchive.StatusMessageTextWriter = sw
+ zipArchive.AddDirectory(SourceFolder)
+ zipArchive.Save(DestFile)
+ End Using
+ ' examine sw here to see any messages
+ End Sub
+
+
+
+ // Create a zip archive with AES Encryption.
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddFile("ReadMe.txt");
+ zip.Encryption= EncryptionAlgorithm.WinZipAes256;
+ zip.Password= "Top.Secret.No.Peeking!";
+ zip.AddFile("7440-N49th.png");
+ zip.AddFile("2008-Regional-Sales-Report.pdf");
+ zip.Save("EncryptedArchive.zip");
+ }
+
+ // Extract a zip archive that uses AES Encryption.
+ // You do not need to specify the algorithm during extraction.
+ using (ZipFile zip = ZipFile.Read("EncryptedArchive.zip"))
+ {
+ zip.Password= "Top.Secret.No.Peeking!";
+ zip.ExtractAll("extractDirectory");
+ }
+
+
+
+ ' Create a zip that uses Encryption.
+ Using zip As New ZipFile()
+ zip.Encryption= EncryptionAlgorithm.WinZipAes256
+ zip.Password= "Top.Secret.No.Peeking!"
+ zip.AddFile("ReadMe.txt")
+ zip.AddFile("7440-N49th.png")
+ zip.AddFile("2008-Regional-Sales-Report.pdf")
+ zip.Save("EncryptedArchive.zip")
+ End Using
+
+ ' Extract a zip archive that uses AES Encryption.
+ ' You do not need to specify the algorithm during extraction.
+ Using (zip as ZipFile = ZipFile.Read("EncryptedArchive.zip"))
+ zip.Password= "Top.Secret.No.Peeking!"
+ zip.ExtractAll("extractDirectory")
+ End Using
+
+
+
+ using (ZipFile zip = ZipFile.Read("PackedDocuments.zip"))
+ {
+ foreach (string s1 in zip.EntryFilenames)
+ {
+ if (s1.EndsWith(".txt"))
+ zip[s1].Extract("textfiles");
+ }
+ }
+
+
+ Using zip As ZipFile = ZipFile.Read("PackedDocuments.zip")
+ Dim s1 As String
+ For Each s1 In zip.EntryFilenames
+ If s1.EndsWith(".txt") Then
+ zip(s1).Extract("textfiles")
+ End If
+ Next
+ End Using
+
+
+ String zipFileToRead= "PackedDocuments.zip";
+ string candidate = "DatedMaterial.xps";
+ using (ZipFile zip = new ZipFile(zipFileToRead))
+ {
+ if (zip.EntryFilenames.Contains(candidate))
+ Console.WriteLine("The file '{0}' exists in the zip archive '{1}'",
+ candidate,
+ zipFileName);
+ else
+ Console.WriteLine("The file, '{0}', does not exist in the zip archive '{1}'",
+ candidate,
+ zipFileName);
+ Console.WriteLine();
+ }
+
+
+ Dim zipFileToRead As String = "PackedDocuments.zip"
+ Dim candidate As String = "DatedMaterial.xps"
+ Using zip As ZipFile.Read(ZipFileToRead)
+ If zip.EntryFilenames.Contains(candidate) Then
+ Console.WriteLine("The file '{0}' exists in the zip archive '{1}'", _
+ candidate, _
+ zipFileName)
+ Else
+ Console.WriteLine("The file, '{0}', does not exist in the zip archive '{1}'", _
+ candidate, _
+ zipFileName)
+ End If
+ Console.WriteLine
+ End Using
+
+
+ using (ZipFile zip = ZipFile.Read(zipFile))
+ {
+ foreach (ZipEntry entry in zip.EntriesSorted)
+ {
+ ListViewItem item = new ListViewItem(n.ToString());
+ n++;
+ string[] subitems = new string[] {
+ entry.FileName.Replace("/","\\"),
+ entry.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
+ entry.UncompressedSize.ToString(),
+ String.Format("{0,5:F0}%", entry.CompressionRatio),
+ entry.CompressedSize.ToString(),
+ (entry.UsesEncryption) ? "Y" : "N",
+ String.Format("{0:X8}", entry.Crc)};
+
+ foreach (String s in subitems)
+ {
+ ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem();
+ subitem.Text = s;
+ item.SubItems.Add(subitem);
+ }
+
+ this.listView1.Items.Add(item);
+ }
+ }
+
+
+ progressBar1.Value = 0;
+ progressBar1.Max = listbox1.Items.Count;
+ using (ZipFile zip = new ZipFile())
+ {
+ // listbox1 contains a list of filenames
+ zip.AddFiles(listbox1.Items);
+
+ // do the progress bar:
+ zip.SaveProgress += (sender, e) => {
+ if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry) {
+ progressBar1.PerformStep();
+ }
+ };
+
+ zip.Save(fs);
+ }
+
+
+ static bool justHadByteUpdate= false;
+ public static void SaveProgress(object sender, SaveProgressEventArgs e)
+ {
+ if (e.EventType == ZipProgressEventType.Saving_Started)
+ Console.WriteLine("Saving: {0}", e.ArchiveName);
+
+ else if (e.EventType == ZipProgressEventType.Saving_Completed)
+ {
+ justHadByteUpdate= false;
+ Console.WriteLine();
+ Console.WriteLine("Done: {0}", e.ArchiveName);
+ }
+
+ else if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry)
+ {
+ if (justHadByteUpdate)
+ Console.WriteLine();
+ Console.WriteLine(" Writing: {0} ({1}/{2})",
+ e.CurrentEntry.FileName, e.EntriesSaved, e.EntriesTotal);
+ justHadByteUpdate= false;
+ }
+
+ else if (e.EventType == ZipProgressEventType.Saving_EntryBytesRead)
+ {
+ if (justHadByteUpdate)
+ Console.SetCursorPosition(0, Console.CursorTop);
+ Console.Write(" {0}/{1} ({2:N0}%)", e.BytesTransferred, e.TotalBytesToTransfer,
+ e.BytesTransferred / (0.01 * e.TotalBytesToTransfer ));
+ justHadByteUpdate= true;
+ }
+ }
+
+ public static ZipUp(string targetZip, string directory)
+ {
+ using (var zip = new ZipFile()) {
+ zip.SaveProgress += SaveProgress;
+ zip.AddDirectory(directory);
+ zip.Save(targetZip);
+ }
+ }
+
+
+
+
+ Public Sub ZipUp(ByVal targetZip As String, ByVal directory As String)
+ Using zip As ZipFile = New ZipFile
+ AddHandler zip.SaveProgress, AddressOf MySaveProgress
+ zip.AddDirectory(directory)
+ zip.Save(targetZip)
+ End Using
+ End Sub
+
+ Private Shared justHadByteUpdate As Boolean = False
+
+ Public Shared Sub MySaveProgress(ByVal sender As Object, ByVal e As SaveProgressEventArgs)
+ If (e.EventType Is ZipProgressEventType.Saving_Started) Then
+ Console.WriteLine("Saving: {0}", e.ArchiveName)
+
+ ElseIf (e.EventType Is ZipProgressEventType.Saving_Completed) Then
+ justHadByteUpdate = False
+ Console.WriteLine
+ Console.WriteLine("Done: {0}", e.ArchiveName)
+
+ ElseIf (e.EventType Is ZipProgressEventType.Saving_BeforeWriteEntry) Then
+ If justHadByteUpdate Then
+ Console.WriteLine
+ End If
+ Console.WriteLine(" Writing: {0} ({1}/{2})", e.CurrentEntry.FileName, e.EntriesSaved, e.EntriesTotal)
+ justHadByteUpdate = False
+
+ ElseIf (e.EventType Is ZipProgressEventType.Saving_EntryBytesRead) Then
+ If justHadByteUpdate Then
+ Console.SetCursorPosition(0, Console.CursorTop)
+ End If
+ Console.Write(" {0}/{1} ({2:N0}%)", e.BytesTransferred, _
+ e.TotalBytesToTransfer, _
+ (CDbl(e.BytesTransferred) / (0.01 * e.TotalBytesToTransfer)))
+ justHadByteUpdate = True
+ End If
+ End Sub
+
+
+ delegate void SaveEntryProgress(SaveProgressEventArgs e);
+ delegate void ButtonClick(object sender, EventArgs e);
+
+ public class WorkerOptions
+ {
+ public string ZipName;
+ public string Folder;
+ public string Encoding;
+ public string Comment;
+ public int ZipFlavor;
+ public Zip64Option Zip64;
+ }
+
+ private int _progress2MaxFactor;
+ private bool _saveCanceled;
+ private long _totalBytesBeforeCompress;
+ private long _totalBytesAfterCompress;
+ private Thread _workerThread;
+
+
+ private void btnZipup_Click(object sender, EventArgs e)
+ {
+ KickoffZipup();
+ }
+
+ private void btnCancel_Click(object sender, EventArgs e)
+ {
+ if (this.lblStatus.InvokeRequired)
+ {
+ this.lblStatus.Invoke(new ButtonClick(this.btnCancel_Click), new object[] { sender, e });
+ }
+ else
+ {
+ _saveCanceled = true;
+ lblStatus.Text = "Canceled...";
+ ResetState();
+ }
+ }
+
+ private void KickoffZipup()
+ {
+ _folderName = tbDirName.Text;
+
+ if (_folderName == null || _folderName == "") return;
+ if (this.tbZipName.Text == null || this.tbZipName.Text == "") return;
+
+ // check for existence of the zip file:
+ if (System.IO.File.Exists(this.tbZipName.Text))
+ {
+ var dlgResult = MessageBox.Show(String.Format("The file you have specified ({0}) already exists." +
+ " Do you want to overwrite this file?", this.tbZipName.Text),
+ "Confirmation is Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ if (dlgResult != DialogResult.Yes) return;
+ System.IO.File.Delete(this.tbZipName.Text);
+ }
+
+ _saveCanceled = false;
+ _nFilesCompleted = 0;
+ _totalBytesAfterCompress = 0;
+ _totalBytesBeforeCompress = 0;
+ this.btnOk.Enabled = false;
+ this.btnOk.Text = "Zipping...";
+ this.btnCancel.Enabled = true;
+ lblStatus.Text = "Zipping...";
+
+ var options = new WorkerOptions
+ {
+ ZipName = this.tbZipName.Text,
+ Folder = _folderName,
+ Encoding = "ibm437"
+ };
+
+ if (this.comboBox1.SelectedIndex != 0)
+ {
+ options.Encoding = this.comboBox1.SelectedItem.ToString();
+ }
+
+ if (this.radioFlavorSfxCmd.Checked)
+ options.ZipFlavor = 2;
+ else if (this.radioFlavorSfxGui.Checked)
+ options.ZipFlavor = 1;
+ else options.ZipFlavor = 0;
+
+ if (this.radioZip64AsNecessary.Checked)
+ options.Zip64 = Zip64Option.AsNecessary;
+ else if (this.radioZip64Always.Checked)
+ options.Zip64 = Zip64Option.Always;
+ else options.Zip64 = Zip64Option.Never;
+
+ options.Comment = String.Format("Encoding:{0} || Flavor:{1} || ZIP64:{2}\r\nCreated at {3} || {4}\r\n",
+ options.Encoding,
+ FlavorToString(options.ZipFlavor),
+ options.Zip64.ToString(),
+ System.DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"),
+ this.Text);
+
+ if (this.tbComment.Text != TB_COMMENT_NOTE)
+ options.Comment += this.tbComment.Text;
+
+ _workerThread = new Thread(this.DoSave);
+ _workerThread.Name = "Zip Saver thread";
+ _workerThread.Start(options);
+ this.Cursor = Cursors.WaitCursor;
+ }
+
+
+ private void DoSave(Object p)
+ {
+ WorkerOptions options = p as WorkerOptions;
+ try
+ {
+ using (var zip1 = new ZipFile())
+ {
+ zip1.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(options.Encoding);
+ zip1.Comment = options.Comment;
+ zip1.AddDirectory(options.Folder);
+ _entriesToZip = zip1.EntryFileNames.Count;
+ SetProgressBars();
+ zip1.SaveProgress += this.zip1_SaveProgress;
+
+ zip1.UseZip64WhenSaving = options.Zip64;
+
+ if (options.ZipFlavor == 1)
+ zip1.SaveSelfExtractor(options.ZipName, SelfExtractorFlavor.WinFormsApplication);
+ else if (options.ZipFlavor == 2)
+ zip1.SaveSelfExtractor(options.ZipName, SelfExtractorFlavor.ConsoleApplication);
+ else
+ zip1.Save(options.ZipName);
+ }
+ }
+ catch (System.Exception exc1)
+ {
+ MessageBox.Show(String.Format("Exception while zipping: {0}", exc1.Message));
+ btnCancel_Click(null, null);
+ }
+ }
+
+
+
+ void zip1_SaveProgress(object sender, SaveProgressEventArgs e)
+ {
+ switch (e.EventType)
+ {
+ case ZipProgressEventType.Saving_AfterWriteEntry:
+ StepArchiveProgress(e);
+ break;
+ case ZipProgressEventType.Saving_EntryBytesRead:
+ StepEntryProgress(e);
+ break;
+ case ZipProgressEventType.Saving_Completed:
+ SaveCompleted();
+ break;
+ case ZipProgressEventType.Saving_AfterSaveTempArchive:
+ // this event only occurs when saving an SFX file
+ TempArchiveSaved();
+ break;
+ }
+ if (_saveCanceled)
+ e.Cancel = true;
+ }
+
+
+
+ private void StepArchiveProgress(SaveProgressEventArgs e)
+ {
+ if (this.progressBar1.InvokeRequired)
+ {
+ this.progressBar1.Invoke(new SaveEntryProgress(this.StepArchiveProgress), new object[] { e });
+ }
+ else
+ {
+ if (!_saveCanceled)
+ {
+ _nFilesCompleted++;
+ this.progressBar1.PerformStep();
+ _totalBytesAfterCompress += e.CurrentEntry.CompressedSize;
+ _totalBytesBeforeCompress += e.CurrentEntry.UncompressedSize;
+
+ // reset the progress bar for the entry:
+ this.progressBar2.Value = this.progressBar2.Maximum = 1;
+
+ this.Update();
+ }
+ }
+ }
+
+
+ private void StepEntryProgress(SaveProgressEventArgs e)
+ {
+ if (this.progressBar2.InvokeRequired)
+ {
+ this.progressBar2.Invoke(new SaveEntryProgress(this.StepEntryProgress), new object[] { e });
+ }
+ else
+ {
+ if (!_saveCanceled)
+ {
+ if (this.progressBar2.Maximum == 1)
+ {
+ // reset
+ Int64 max = e.TotalBytesToTransfer;
+ _progress2MaxFactor = 0;
+ while (max > System.Int32.MaxValue)
+ {
+ max /= 2;
+ _progress2MaxFactor++;
+ }
+ this.progressBar2.Maximum = (int)max;
+ lblStatus.Text = String.Format("{0} of {1} files...({2})",
+ _nFilesCompleted + 1, _entriesToZip, e.CurrentEntry.FileName);
+ }
+
+ int xferred = e.BytesTransferred >> _progress2MaxFactor;
+
+ this.progressBar2.Value = (xferred >= this.progressBar2.Maximum)
+ ? this.progressBar2.Maximum
+ : xferred;
+
+ this.Update();
+ }
+ }
+ }
+
+ private void SaveCompleted()
+ {
+ if (this.lblStatus.InvokeRequired)
+ {
+ this.lblStatus.Invoke(new MethodInvoker(this.SaveCompleted));
+ }
+ else
+ {
+ lblStatus.Text = String.Format("Done, Compressed {0} files, {1:N0}% of original.",
+ _nFilesCompleted, (100.00 * _totalBytesAfterCompress) / _totalBytesBeforeCompress);
+ ResetState();
+ }
+ }
+
+ private void ResetState()
+ {
+ this.btnCancel.Enabled = false;
+ this.btnOk.Enabled = true;
+ this.btnOk.Text = "Zip it!";
+ this.progressBar1.Value = 0;
+ this.progressBar2.Value = 0;
+ this.Cursor = Cursors.Default;
+ if (!_workerThread.IsAlive)
+ _workerThread.Join();
+ }
+
+
+
+ private static bool justHadByteUpdate = false;
+ public static void ExtractProgress(object sender, ExtractProgressEventArgs e)
+ {
+ if(e.EventType == ZipProgressEventType.Extracting_EntryBytesWritten)
+ {
+ if (justHadByteUpdate)
+ Console.SetCursorPosition(0, Console.CursorTop);
+
+ Console.Write(" {0}/{1} ({2:N0}%)", e.BytesTransferred, e.TotalBytesToTransfer,
+ e.BytesTransferred / (0.01 * e.TotalBytesToTransfer ));
+ justHadByteUpdate = true;
+ }
+ else if(e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry)
+ {
+ if (justHadByteUpdate)
+ Console.WriteLine();
+ Console.WriteLine("Extracting: {0}", e.CurrentEntry.FileName);
+ justHadByteUpdate= false;
+ }
+ }
+
+ public static ExtractZip(string zipToExtract, string directory)
+ {
+ string TargetDirectory= "extract";
+ using (var zip = ZipFile.Read(zipToExtract)) {
+ zip.ExtractProgress += ExtractProgress;
+ foreach (var e in zip1)
+ {
+ e.Extract(TargetDirectory, true);
+ }
+ }
+ }
+
+
+
+ Public Shared Sub Main(ByVal args As String())
+ Dim ZipToUnpack As String = "C1P3SML.zip"
+ Dim TargetDir As String = "ExtractTest_Extract"
+ Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)
+ Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
+ AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
+ Dim e As ZipEntry
+ For Each e In zip1
+ e.Extract(TargetDir, True)
+ Next
+ End Using
+ End Sub
+
+ Private Shared justHadByteUpdate As Boolean = False
+
+ Public Shared Sub MyExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
+ If (e.EventType = ZipProgressEventType.Extracting_EntryBytesWritten) Then
+ If ExtractTest.justHadByteUpdate Then
+ Console.SetCursorPosition(0, Console.CursorTop)
+ End If
+ Console.Write(" {0}/{1} ({2:N0}%)", e.BytesTransferred, e.TotalBytesToTransfer, (CDbl(e.BytesTransferred) / (0.01 * e.TotalBytesToTransfer)))
+ ExtractTest.justHadByteUpdate = True
+ ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractEntry) Then
+ If ExtractTest.justHadByteUpdate Then
+ Console.WriteLine
+ End If
+ Console.WriteLine("Extracting: {0}", e.CurrentEntry.FileName)
+ ExtractTest.justHadByteUpdate = False
+ End If
+ End Sub
+
+
+
+ int _numEntriesToAdd= 0;
+ int _numEntriesAdded= 0;
+ void AddProgressHandler(object sender, AddProgressEventArgs e)
+ {
+ switch (e.EventType)
+ {
+ case ZipProgressEventType.Adding_Started:
+ Console.WriteLine("Adding files to the zip...");
+ break;
+ case ZipProgressEventType.Adding_AfterAddEntry:
+ _numEntriesAdded++;
+ Console.WriteLine(String.Format("Adding file {0}/{1} :: {2}",
+ _numEntriesAdded, _numEntriesToAdd, e.CurrentEntry.FileName));
+ break;
+ case ZipProgressEventType.Adding_Completed:
+ Console.WriteLine("Added all files");
+ break;
+ }
+ }
+
+ void CreateTheZip()
+ {
+ using (ZipFile zip = new ZipFile())
+ {
+ zip.AddProgress += AddProgressHandler;
+ zip.AddDirectory(System.IO.Path.GetFileName(DirToZip));
+ zip.Save(ZipFileToCreate);
+ }
+ }
+
+
+
+
+
+ Private Sub AddProgressHandler(ByVal sender As Object, ByVal e As AddProgressEventArgs)
+ Select Case e.EventType
+ Case ZipProgressEventType.Adding_Started
+ Console.WriteLine("Adding files to the zip...")
+ Exit Select
+ Case ZipProgressEventType.Adding_AfterAddEntry
+ Console.WriteLine(String.Format("Adding file {0}", e.CurrentEntry.FileName))
+ Exit Select
+ Case ZipProgressEventType.Adding_Completed
+ Console.WriteLine("Added all files")
+ Exit Select
+ End Select
+ End Sub
+
+ Sub CreateTheZip()
+ Using zip as ZipFile = New ZipFile
+ AddHandler zip.AddProgress, AddressOf AddProgressHandler
+ zip.AddDirectory(System.IO.Path.GetFileName(DirToZip))
+ zip.Save(ZipFileToCreate);
+ End Using
+ End Sub
+
+
+
+
+
+ public static void MyZipError(object sender, ZipErrorEventArgs e)
+ {
+ Console.WriteLine("Error saving {0}...", e.FileName);
+ Console.WriteLine(" Exception: {0}", e.exception);
+ ZipEntry entry = e.CurrentEntry;
+ string response = null;
+ // Ask the user whether he wants to skip this error or not
+ do
+ {
+ Console.Write("Retry, Skip, Throw, or Cancel ? (R/S/T/C) ");
+ response = Console.ReadLine();
+ Console.WriteLine();
+
+ } while (response != null &&
+ response[0]!='S' && response[0]!='s' &&
+ response[0]!='R' && response[0]!='r' &&
+ response[0]!='T' && response[0]!='t' &&
+ response[0]!='C' && response[0]!='c');
+
+ e.Cancel = (response[0]=='C' || response[0]=='c');
+
+ if (response[0]=='S' || response[0]=='s')
+ entry.ZipErrorAction = ZipErrorAction.Skip;
+ else if (response[0]=='R' || response[0]=='r')
+ entry.ZipErrorAction = ZipErrorAction.Retry;
+ else if (response[0]=='T' || response[0]=='t')
+ entry.ZipErrorAction = ZipErrorAction.Throw;
+ }
+
+ public void SaveTheFile()
+ {
+ string directoryToZip = "fodder";
+ string directoryInArchive = "files";
+ string zipFileToCreate = "Archive.zip";
+ using (var zip = new ZipFile())
+ {
+ // set the event handler before adding any entries
+ zip.ZipError += MyZipError;
+ zip.AddDirectory(directoryToZip, directoryInArchive);
+ zip.Save(zipFileToCreate);
+ }
+ }
+
+
+
+ Private Sub MyZipError(ByVal sender As Object, ByVal e As Ionic.Zip.ZipErrorEventArgs)
+ ' At this point, the application could prompt the user for an action to take.
+ ' But in this case, this application will simply automatically skip the file, in case of error.
+ Console.WriteLine("Zip Error, entry {0}", e.CurrentEntry.FileName)
+ Console.WriteLine(" Exception: {0}", e.exception)
+ ' set the desired ZipErrorAction on the CurrentEntry to communicate that to DotNetZip
+ e.CurrentEntry.ZipErrorAction = Zip.ZipErrorAction.Skip
+ End Sub
+
+ Public Sub SaveTheFile()
+ Dim directoryToZip As String = "fodder"
+ Dim directoryInArchive As String = "files"
+ Dim zipFileToCreate as String = "Archive.zip"
+ Using zipArchive As ZipFile = New ZipFile
+ ' set the event handler before adding any entries
+ AddHandler zipArchive.ZipError, AddressOf MyZipError
+ zipArchive.AddDirectory(directoryToZip, directoryInArchive)
+ zipArchive.Save(zipFileToCreate)
+ End Using
+ End Sub
+
+
+ + This is the version using unrolled loops. +
+
+ var fname = "logfile.log.bz2";
+ using (var fs = File.OpenRead(fname))
+ {
+ using (var decompressor = new Ionic.BZip2.BZip2InputStream(fs))
+ {
+ var outFname = fname + ".decompressed";
+ using (var output = File.Create(outFname))
+ {
+ byte[] buffer = new byte[2048];
+ int n;
+ while ((n = decompressor.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ output.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ var fname = "logfile.log";
+ using (var fs = File.OpenRead(fname))
+ {
+ var outFname = fname + ".bz2";
+ using (var output = File.Create(outFname))
+ {
+ using (var compressor = new Ionic.BZip2.BZip2OutputStream(output))
+ {
+ byte[] buffer = new byte[2048];
+ int n;
+ while ((n = fs.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ var fname = "logfile.log";
+ using (var fs = File.OpenRead(fname))
+ {
+ var outFname = fname + ".bz2";
+ using (var output = File.Create(outFname))
+ {
+ using (var compressor = new Ionic.BZip2.ParallelBZip2OutputStream(output))
+ {
+ byte[] buffer = new byte[2048];
+ int n;
+ while ((n = fs.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
+ {
+ using (Stream compressor = new DeflateStream(raw, CompressionMode.Compress))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(fileToCompress & ".deflated")
+ Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
+ {
+ using (Stream compressor = new DeflateStream(raw,
+ CompressionMode.Compress,
+ CompressionLevel.BestCompression))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n= -1;
+ while (n != 0)
+ {
+ if (n > 0)
+ compressor.Write(buffer, 0, n);
+ n= input.Read(buffer, 0, buffer.Length);
+ }
+ }
+ }
+ }
+
+
+
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(fileToCompress & ".deflated")
+ Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ using (var output = System.IO.File.Create(fileToCompress + ".deflated"))
+ {
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (Stream compressor = new DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n= -1;
+ while (n != 0)
+ {
+ if (n > 0)
+ compressor.Write(buffer, 0, n);
+ n= input.Read(buffer, 0, buffer.Length);
+ }
+ }
+ }
+ // can write additional data to the output stream here
+ }
+
+
+
+ Using output As FileStream = File.Create(fileToCompress & ".deflated")
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using compressor As Stream = New DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ ' can write additional data to the output stream here.
+ End Using
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(outputFile))
+ {
+ using (Stream compressor = new GZipStream(raw, CompressionMode.Compress))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ Dim outputFile As String = (fileToCompress & ".compressed")
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(outputFile)
+ Using compressor As Stream = New GZipStream(raw, CompressionMode.Compress)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ private void GunZipFile(string filename)
+ {
+ if (!filename.EndsWith(".gz))
+ throw new ArgumentException("filename");
+ var DecompressedFile = filename.Substring(0,filename.Length-3);
+ byte[] working = new byte[WORKING_BUFFER_SIZE];
+ int n= 1;
+ using (System.IO.Stream input = System.IO.File.OpenRead(filename))
+ {
+ using (Stream decompressor= new Ionic.Zlib.GZipStream(input, CompressionMode.Decompress, true))
+ {
+ using (var output = System.IO.File.Create(DecompressedFile))
+ {
+ while (n !=0)
+ {
+ n= decompressor.Read(working, 0, working.Length);
+ if (n > 0)
+ {
+ output.Write(working, 0, n);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+
+ Private Sub GunZipFile(ByVal filename as String)
+ If Not (filename.EndsWith(".gz)) Then
+ Throw New ArgumentException("filename")
+ End If
+ Dim DecompressedFile as String = filename.Substring(0,filename.Length-3)
+ Dim working(WORKING_BUFFER_SIZE) as Byte
+ Dim n As Integer = 1
+ Using input As Stream = File.OpenRead(filename)
+ Using decompressor As Stream = new Ionic.Zlib.GZipStream(input, CompressionMode.Decompress, True)
+ Using output As Stream = File.Create(UncompressedFile)
+ Do
+ n= decompressor.Read(working, 0, working.Length)
+ If n > 0 Then
+ output.Write(working, 0, n)
+ End IF
+ Loop While (n > 0)
+ End Using
+ End Using
+ End Using
+ End Sub
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(fileToCompress + ".gz"))
+ {
+ using (Stream compressor = new GZipStream(raw,
+ CompressionMode.Compress,
+ CompressionLevel.BestCompression))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(fileToCompress & ".gz")
+ Using compressor As Stream = New GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(outputFile))
+ {
+ using (Stream compressor = new GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, true))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ Dim outputFile As String = (fileToCompress & ".compressed")
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(outputFile)
+ Using compressor As Stream = New GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, True)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ byte[] working = new byte[WORKING_BUFFER_SIZE];
+ using (System.IO.Stream input = System.IO.File.OpenRead(_CompressedFile))
+ {
+ using (Stream decompressor= new Ionic.Zlib.GZipStream(input, CompressionMode.Decompress, true))
+ {
+ using (var output = System.IO.File.Create(_DecompressedFile))
+ {
+ int n;
+ while ((n= decompressor.Read(working, 0, working.Length)) !=0)
+ {
+ output.Write(working, 0, n);
+ }
+ }
+ }
+ }
+
+
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n= -1;
+ String outputFile = fileToCompress + ".compressed";
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(outputFile))
+ {
+ using (Stream compressor = new ParallelDeflateOutputStream(raw))
+ {
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Dim outputFile As String = (fileToCompress & ".compressed")
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(outputFile)
+ Using compressor As Stream = New ParallelDeflateOutputStream(raw)
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ ParallelDeflateOutputStream deflater = null;
+ foreach (var inputFile in listOfFiles)
+ {
+ string outputFile = inputFile + ".compressed";
+ using (System.IO.Stream input = System.IO.File.OpenRead(inputFile))
+ {
+ using (var outStream = System.IO.File.Create(outputFile))
+ {
+ if (deflater == null)
+ deflater = new ParallelDeflateOutputStream(outStream,
+ CompressionLevel.Best,
+ CompressionStrategy.Default,
+ true);
+ deflater.Reset(outStream);
+
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ deflater.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ var adler = Adler.Adler32(0, null, 0, 0);
+ adler = Adler.Adler32(adler, buffer, index, length);
+
+
+ private void InflateBuffer()
+ {
+ int bufferSize = 1024;
+ byte[] buffer = new byte[bufferSize];
+ ZlibCodec decompressor = new ZlibCodec();
+
+ Console.WriteLine("\n============================================");
+ Console.WriteLine("Size of Buffer to Inflate: {0} bytes.", CompressedBytes.Length);
+ MemoryStream ms = new MemoryStream(DecompressedBytes);
+
+ int rc = decompressor.InitializeInflate();
+
+ decompressor.InputBuffer = CompressedBytes;
+ decompressor.NextIn = 0;
+ decompressor.AvailableBytesIn = CompressedBytes.Length;
+
+ decompressor.OutputBuffer = buffer;
+
+ // pass 1: inflate
+ do
+ {
+ decompressor.NextOut = 0;
+ decompressor.AvailableBytesOut = buffer.Length;
+ rc = decompressor.Inflate(FlushType.None);
+
+ if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
+ throw new Exception("inflating: " + decompressor.Message);
+
+ ms.Write(decompressor.OutputBuffer, 0, buffer.Length - decompressor.AvailableBytesOut);
+ }
+ while (decompressor.AvailableBytesIn > 0 || decompressor.AvailableBytesOut == 0);
+
+ // pass 2: finish and flush
+ do
+ {
+ decompressor.NextOut = 0;
+ decompressor.AvailableBytesOut = buffer.Length;
+ rc = decompressor.Inflate(FlushType.Finish);
+
+ if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK)
+ throw new Exception("inflating: " + decompressor.Message);
+
+ if (buffer.Length - decompressor.AvailableBytesOut > 0)
+ ms.Write(buffer, 0, buffer.Length - decompressor.AvailableBytesOut);
+ }
+ while (decompressor.AvailableBytesIn > 0 || decompressor.AvailableBytesOut == 0);
+
+ decompressor.EndInflate();
+ }
+
+
+
+ int bufferSize = 40000;
+ byte[] CompressedBytes = new byte[bufferSize];
+ byte[] DecompressedBytes = new byte[bufferSize];
+
+ ZlibCodec compressor = new ZlibCodec();
+
+ compressor.InitializeDeflate(CompressionLevel.Default);
+
+ compressor.InputBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToCompress);
+ compressor.NextIn = 0;
+ compressor.AvailableBytesIn = compressor.InputBuffer.Length;
+
+ compressor.OutputBuffer = CompressedBytes;
+ compressor.NextOut = 0;
+ compressor.AvailableBytesOut = CompressedBytes.Length;
+
+ while (compressor.TotalBytesIn != TextToCompress.Length && compressor.TotalBytesOut < bufferSize)
+ {
+ compressor.Deflate(FlushType.None);
+ }
+
+ while (true)
+ {
+ int rc= compressor.Deflate(FlushType.Finish);
+ if (rc == ZlibConstants.Z_STREAM_END) break;
+ }
+
+ compressor.EndDeflate();
+
+
+
+ private void DeflateBuffer(CompressionLevel level)
+ {
+ int bufferSize = 1024;
+ byte[] buffer = new byte[bufferSize];
+ ZlibCodec compressor = new ZlibCodec();
+
+ Console.WriteLine("\n============================================");
+ Console.WriteLine("Size of Buffer to Deflate: {0} bytes.", UncompressedBytes.Length);
+ MemoryStream ms = new MemoryStream();
+
+ int rc = compressor.InitializeDeflate(level);
+
+ compressor.InputBuffer = UncompressedBytes;
+ compressor.NextIn = 0;
+ compressor.AvailableBytesIn = UncompressedBytes.Length;
+
+ compressor.OutputBuffer = buffer;
+
+ // pass 1: deflate
+ do
+ {
+ compressor.NextOut = 0;
+ compressor.AvailableBytesOut = buffer.Length;
+ rc = compressor.Deflate(FlushType.None);
+
+ if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
+ throw new Exception("deflating: " + compressor.Message);
+
+ ms.Write(compressor.OutputBuffer, 0, buffer.Length - compressor.AvailableBytesOut);
+ }
+ while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0);
+
+ // pass 2: finish and flush
+ do
+ {
+ compressor.NextOut = 0;
+ compressor.AvailableBytesOut = buffer.Length;
+ rc = compressor.Deflate(FlushType.Finish);
+
+ if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK)
+ throw new Exception("deflating: " + compressor.Message);
+
+ if (buffer.Length - compressor.AvailableBytesOut > 0)
+ ms.Write(buffer, 0, buffer.Length - compressor.AvailableBytesOut);
+ }
+ while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0);
+
+ compressor.EndDeflate();
+
+ ms.Seek(0, SeekOrigin.Begin);
+ CompressedBytes = new byte[compressor.TotalBytesOut];
+ ms.Read(CompressedBytes, 0, CompressedBytes.Length);
+ }
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(fileToCompress + ".zlib"))
+ {
+ using (Stream compressor = new ZlibStream(raw, CompressionMode.Compress))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(fileToCompress & ".zlib")
+ Using compressor As Stream = New ZlibStream(raw, CompressionMode.Compress)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (var raw = System.IO.File.Create(fileToCompress + ".zlib"))
+ {
+ using (Stream compressor = new ZlibStream(raw,
+ CompressionMode.Compress,
+ CompressionLevel.BestCompression))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ }
+
+
+
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using raw As FileStream = File.Create(fileToCompress & ".zlib")
+ Using compressor As Stream = New ZlibStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ End Using
+
+
+ using (var output = System.IO.File.Create(fileToCompress + ".zlib"))
+ {
+ using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ {
+ using (Stream compressor = new ZlibStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
+ {
+ byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ int n;
+ while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ compressor.Write(buffer, 0, n);
+ }
+ }
+ }
+ // can write additional data to the output stream here
+ }
+
+
+ Using output As FileStream = File.Create(fileToCompress & ".zlib")
+ Using input As Stream = File.OpenRead(fileToCompress)
+ Using compressor As Stream = New ZlibStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
+ Dim buffer As Byte() = New Byte(4096) {}
+ Dim n As Integer = -1
+ Do While (n <> 0)
+ If (n > 0) Then
+ compressor.Write(buffer, 0, n)
+ End If
+ n = input.Read(buffer, 0, buffer.Length)
+ Loop
+ End Using
+ End Using
+ ' can write additional data to the output stream here.
+ End Using
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+ Dim MyBrush As New SolidBrush(Color.Blue)
+
+ Sub New()
+ IsPaintingOnSeparateThread = True
+ End Sub
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50))
+ End Sub
+
+ Public Overrides Sub Dispose(ByVal disposing As Boolean)
+ MyBrush.Dispose()
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Blue);
+
+ MyControl()
+ {
+ IsPaintingOnSeparateThread = true;
+ }
+
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50));
+ }
+
+ public override void Dispose(bool disposing)
+ {
+ MyBrush.Dispose();
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ ' Cause an error by using a null pen
+ e.Graphics.DrawRectangle(Nothing, Rectangle.Empty)
+ End Sub
+
+ Protected Overrides Sub OnPaintException(ByVal e As ExceptionEventArgs)
+ Throw e.Exception
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ // Cause an error by using a null pen
+ e.Graphics.DrawRectangle(null, Rectangle.Empty);
+ }
+
+ protected override void OnPaintException(ExceptionEventArgs e)
+ {
+ throw e.Exception;
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits Control
+ Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
+ Dim MyBrush As New SolidBrush(Color.Blue)
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50))
+ MyBrush.Dispose();
+ End Sub
+ End Class
+
+
+ public class MyControl : Control
+ {
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Blue);
+ e.Graphics.FillRectangle(MyBrush, new Rectangle(50, 50, 50, 50));
+ MyBrush.Dispose();
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ Dim MyBrush As New SolidBrush(Color.Blue)
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50))
+ MyBrush.Dispose();
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Blue);
+ e.Graphics.FillRectangle(MyBrush, new Rectangle(50, 50, 50, 50));
+ MyBrush.Dispose();
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ Dim MyBrush As New SolidBrush(Color.Blue)
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50))
+ End Sub
+
+ ' Notice: MyBrush is never disposed. A memory leak
+ ' will occur!
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Blue);
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50));
+ }
+
+ // Notice: MyBrush is never disposed. A memory leak
+ // will occur!
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+ ' 1. GDI objects are created outside of the OnPaintOffScreen
+ ' methods whenever possible.
+ Dim MyBrush As New SolidBrush(Color.Blue)
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ ' 2. The paint method is as lightweight as possible,
+ ' improving rendering performance
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50))
+ End Sub
+
+ Public Overrides Sub Dispose(ByVal disposing As Boolean)
+ ' 3. Any GDI+ objects are disposed of properly
+ MyBrush.Dispose()
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ // 1. GDI objects are created outside of the OnPaintOffScreen
+ // methods whenever possible.
+ SolidBrush MyBrush = new SolidBrush(Color.Blue);
+
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ // 2. The paint method is as lightweight as possible,
+ // improving rendering performance
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50));
+ }
+
+ public override void Dispose(bool disposing)
+ {
+ // 3. Any GDI+ objects are disposed of properly
+ MyBrush.Dispose();
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+
+ Sub New()
+ ' Receive notifications of paint problems
+ AddHandler ExceptionOccurred, AddressOf HandleExceptions
+ End Sub
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ ' Try to paint with a null Pen
+ e.Graphics.DrawRectangle(Nothing, Rectangle.Empty)
+ End Sub
+
+ Private Sub HandleExceptions(ByVal sender As Object, ByVal e As ExceptionEventArgs)
+ ' Write the error to the Debug window
+ Debug.WriteLine(e.Exception.ToString())
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ MyControl()
+ {
+ // Receive notifications of paint problems
+ ExceptionOccurred += new ExceptionEventHandler(HandleExceptions);
+ }
+
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ // Try to paint with a null Pen.
+ e.Graphics.DrawRectangle(null, Rectangle.Empty);
+ }
+
+ private sub HandleExceptions(object sender, ExceptionEventArgs e)
+ {
+ // Write the error to the Console
+ Console.WriteLine(e.Exception.ToString());
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+
+ Sub New()
+ ' Enable multithreading
+ IsPaintingOnSeparateThread = True
+ End Sub
+
+ ' This method is now called from another thread
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ Dim MyBrush As New SolidBrush(Color.Blue)
+ e.Graphics.FillRectangle(MyBrush, New Rectangle(50, 50, 50, 50))
+ MyBrush.Dispose()
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ MyControl()
+ {
+ // Enable multithreading
+ IsPaintingOnSeparateThread = true;
+ }
+
+ // This method is now called from another thread
+ protected overrides void OnPaintOffScreen(PaintEventArgs e)
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Blue);
+ e.Graphics.FillRectangle(MyBrush, new Rectangle(50, 50, 50, 50));
+ MyBrush.Dispose();
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+
+ Sub New()
+ ' Enable multithreading
+ IsPaintingOnSeparateThread = True
+ ' Set a low thread priority
+ ThreadPriority = ThreadPriority.Lowest
+ End Sub
+
+ ' This method is now called from another thread
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ ' ...etc.
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ MyControl()
+ {
+ // Enable multithreading
+ IsPaintingOnSeparateThread = true;
+ // Set a low thread priority
+ ThreadPriority = ThreadPriority.Lowest;
+ }
+
+ // This method is now called from another thread
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ // ...etc.
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+ Dim AnimatedRectangle As Rectangle
+
+ Sub New()
+ ' Set a 60 frames per second target
+ TargetFramesPerSecond = 60
+ End Sub
+
+ Protected Overrides Sub OnTargetFrameRateChanged()
+ ' Change the timer to fire 60 times per second
+ MyTimer.Interval = 1000 / TargetFramesPerSecond
+ End Sub
+
+ Private Sub MyTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
+ ' Change the location of an animated thing
+ AnimatedRectangle = New Rectangle((AnimatedRectangle.X + 1) Mod Width,
+ (AnimatedRectangle.Y + 1) Mod Height,
+ 50, 50)
+ ' And cause the control to repaint
+ InvokeRepaint()
+ End Sub
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ Dim MyBrush As New SolidBrush(Color.Green)
+ e.Graphics.FillRectangle(MyBrush, AnimatedRectangle)
+ MyBrush.Dispose()
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ Rectangle AnimatedRectangle;
+
+ MyControl()
+ {
+ // Set a 60 frames per second target
+ TargetFramesPerSecond = 60;
+ }
+
+ protected override void OnTargetFrameRateChanged()
+ {
+ // Change the timer to fire 60 times per second
+ MyTimer.Interval = 1000 / TargetFramesPerSecond
+ }
+
+ private void MyTimer_Tick(object sender, EventArgs e)
+ {
+ // Change the location of an animated thing
+ AnimatedRectangle = New Rectangle((AnimatedRectangle.X + 1) ^ Width,
+ (AnimatedRectangle.Y + 1) ^ Height,
+ 50, 50);
+ // And cause the control to repaint
+ InvokeRepaint();
+ }
+
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Green);
+ e.Graphics.FillRectangle(MyBrush, AnimatedRectangle);
+ MyBrush.Dispose();
+ }
+ }
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ ' Center a rectangle in the middle of the control
+ Dim MyShape As New Rectangle(Center.X - 25, Center.Y - 25, 50, 50)
+ ' Now paint it
+ Dim MyBrush As New SolidBrush(Color.Green)
+ e.Graphics.FillRectangle(MyBrush, MyShape)
+ MyBrush.Dispose()
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ // Center a rectangle in the middle of the control
+ Rectangle MyShape = new Rectangle(Center.X - 25, Center.Y - 25, 50, 50);
+ // Now paint it
+ SolidBrush MyBrush = new SolidBrush(Color.Green);
+ e.Graphics.FillRectangle(MyBrush, MyShape);
+ MyBrush.Dispose();
+ }
+ }
+
+
+ ' Create a New color interpolator
+ Dim Interpolator As New ColorInterpolator(Color.Blue, Color.Red, 10)
+ ' Output Each calculated color
+ Dim i As Integer
+ For i = 0 To 9
+ ' Get the Next color In the sequence
+ Dim NewColor As Color = Interpolator(i)
+ ' Output RGB values of this color
+ Debug.Write(NewColor.R.ToString() + ",")
+ Debug.Write(NewColor.G.ToString() + ",")
+ Debug.WriteLine(NewColor.B.ToString())
+ Next i
+
+
+ // Create a new color interpolator
+ ColorInterpolator Interpolator = new ColorInterpolator(Color.Blue, Color.Red, 10);
+ // Output each calculated color
+ for (int i = 0; i < 10; i++)
+ {
+ // Get the next color in the sequence
+ Color NewColor = Interpolator[i];
+ // Output RGB values of this color
+ Console.Write(NewColor.R.ToString() + ",");
+ Console.Write(NewColor.G.ToString() + ",");
+ Console.WriteLine(NewColor.B.ToString());
+ }
+
+
+ ' Create a New color interpolator
+ Dim Interpolator As New ColorInterpolator(Color.Blue, Color.Red, 10)
+ ' Access the sixth item
+ Color CalculatedColor = Interpolator(5);
+
+
+ // Create a New color interpolator
+ ColorInterpolator Interpolator = new ColorInterpolator(Color.Blue, Color.Red, 10);
+ // Access the sixth item
+ Color CalculatedColor = Interpolator[5];
+
+
+ Public Class MyControl
+ Inherits DoubleBufferedControl
+
+ Sub New()
+ IsPaintingOnSeparateThread = True
+ End Sub
+
+ Protected Overrides Sub OnPaintOffScreen(ByVal e As CancelablePaintEventArgs)
+ ' Should painting be cancelled?
+ If IsPaintingAborted
+ ' Yes. Abort all painting
+ e.IsCanceled = True
+ Exit Sub
+ End If
+
+ ' Otherwise, A big paint operation begins
+ Dim Count As Integer
+ For Count = 1 To 20000
+ Dim MyBrush As New SolidBrush(Color.Green)
+ e.Graphics.DrawRectangle(MyBrush, New Rectangle(Count, Count, 5, 5))
+ MyBrush.Dispose()
+ Next Count
+ End Sub
+ End Class
+
+
+ public class MyControl : DoubleBufferedControl
+ {
+ MyControl()
+ {
+ IsPaintingOnSeparateThread = true;
+ }
+
+ protected override void OnPaintOffScreen(PaintEventArgs e)
+ {
+ // Should painting be cancelled?
+ if (IsPaintingAborted)
+ {
+ // Yes. Abort all painting
+ e.IsCanceled = true;
+ return;
+ }
+
+ // Otherwise, A big paint operation begins
+ for (int Count = 1; Count <= 20000; Count++)
+ {
+ SolidBrush MyBrush = new SolidBrush(Color.Green);
+ e.Graphics.DrawRectangle(MyBrush, new Rectangle(Count, Count, 5, 5));
+ MyBrush.Dispose();
+ }
+ }
+ }
+
+
+ Dim MyAngle As New Angle(90)
+
+
+ Angle MyAngle = new Angle(90);
+
+
+ Angle MyAngle = new Angle(90);
+
+
+ Dim MyAngle1 As New Angle(105, 30, 21.4)
+
+
+ Angle MyAngle = new Angle(105, 30, 21.4);
+
+
+ Angle MyAngle = new Angle(105, 30, 21.4);
+
+
+ Dim MyAngle As Angle = Angle.Minimum
+
+
+ Angle MyAngle = Angle.Minimum;
+
+
+ Angle MyAngle = Angle.Minimum;
+
+
+ Dim MyAngle As Angle = Angle.Maximum
+
+
+ Angle MyAngle = Angle.Maximum;
+
+
+ Dim MyAngle As New Angle(90)
+
+
+ Angle MyAngle = new Angle(90);
+
+
+ Dim MyAngle As New Angle(34, 12, 29.2)
+
+
+ Angle MyAngle = new Angle(34, 12, 29.2);
+
+
+ Dim MyAngle As New Angle(12, 42.345)
+
+
+ Angle MyAngle = new Angle(12, 42.345);
+
+
+ Dim MyAngle As New Angle("123°45'67.8""")
+
+
+ Angle MyAngle = new Angle("123°45'67.8\"");
+
+
+ Dim Angle1 As New Angle(45)
+ Dim Angle2 As Angle = Angle1.Mirror()
+ Debug.WriteLine(Angle2.ToString())
+ ' Output: 225
+
+
+ Angle Angle1 = new Angle(45);
+ Angle Angle2 = Angle1.Mirror();
+ Console.WriteLine(Angle2.ToString());
+ // Output: 225
+
+
+ Dim MyAngle As New Angle(720)
+ MyAngle = MyAngle.Normalize()
+
+
+ Angle MyAngle = new Angle(720);
+ MyAngle = MyAngle.Normalize();
+
+
+ Dim MyValue As New Angle(725)
+ MyValue = MyValue.Normalize()
+
+
+ Angle MyValue = new Angle(725);
+ MyValue = MyValue.Normalize();
+
+
+ Dim MyAngle As New Angle(90)
+ Dim MyRadians As Radian = MyAngle.ToRadians()
+
+
+ Angle MyAngle = new Angle(90);
+ Radian MyRadians = MyAngle.ToRadians();
+
+
+ Dim MyAngle As New Angle(45, 16.772)
+ Debug.WriteLine(MyAngle.ToString("h°m.mm"))
+ ' Output: 45°16.78
+
+
+ Dim MyAngle As New Angle(45, 16.772);
+ Debug.WriteLine(MyAngle.ToString("h°m.mm"));
+ // Output: 45°16.78
+
+
+ Dim MyAngle As New Angle(90)
+ Debug.WriteLine(MyAngle.ToString)
+ ' Output: "90°"
+
+
+ Angle MyAngle = new Angle(90);
+ Debug.WriteLine(MyAngle.ToString());
+ // Output: "90°"
+
+
+ Dim MyRadian As Radian = Angle.ToRadians(90)
+
+
+ Radian MyRadian = Angle.ToRadians(90);
+
+
+ ' Create a new angle equal to one radian
+ Dim MyRadians As New Radian(1)
+ Dim MyAngle As Angle = Angle.FromRadians(MyRadians)
+ Debug.WriteLine(MyAngle.ToString())
+ ' Output: 57°
+
+
+ // Create a new angle equal to one radian
+ Radian MyRadians = new Radian(1);
+ Angle MyAngle = Angle.FromRadians(MyRadians);
+ Console.WriteLine(MyAngle.ToString());
+ // Output: 57°
+
+
+ ' Correct use of Increment
+ Dim Angle1 As New Angle(89)
+ Angle1 = Angle1.Increment()
+ ' Incorrect use of Increment
+ Dim Angle1 = New Angle(89)
+ Angle1.Increment()
+ ' Notice: Angle1 will still be 89°!
+
+
+ // Correct use of Increment
+ Angle Angle1 = new Angle(89);
+ Angle1 = Angle1.Increment();
+ // Incorrect use of Increment
+ Angle Angle1 = new Angle(89);
+ Angle1.Increment();
+ // Notice: Angle1 will still be 89°!
+
+
+ Dim Angle1 As New Angle(45)
+ Angle1 = Angle1.Add(45)
+
+
+ Angle Angle1 = new Angle(45);
+ Angle1 = Angle1.Add(45);
+
+
+ ' Correct use of Decrement
+ Dim Angle1 As New Angle(91)
+ Angle1 = Angle1.Decrement()
+ ' Incorrect use of Decrement
+ Dim Angle1 = New Angle(91)
+ Angle1.Increment()
+ ' NOTE: Angle1 will still be 91°!
+
+
+ // Correct use of Decrement
+ Angle Angle1 = new Angle(91);
+ Angle1 = Angle1.Decrement();
+ // Incorrect use of Decrement
+ Angle Angle1 = new Angle(91);
+ Angle1.Decrement();
+ // NOTE: Angle1 will still be 91°!
+
+
+ Dim Angle1 As New Angle(90)
+ Angle1 = Angle1.Subtract(30)
+
+
+ Angle Angle1 = new Angle(90);
+ Angle1 = Angle1.Subtract(30);
+
+
+ Dim Angle1 As New Angle(30)
+ Angle1 = Angle1.Multiply(3)
+
+
+ Angle Angle1 = new Angle(30);
+ Angle1 = Angle1.Multiply(3);
+
+
+ Dim Angle1 As New Angle(90)
+ Angle1 = Angle1.Divide(3)
+
+
+ Angle Angle1 = new Angle(90);
+ Angle1 = Angle1.Divide(3);
+
+
+ Dim NewAngle As Angle = Angle.Parse("123.45°")
+
+
+ Angle NewAngle = Angle.Parse("123.45°");
+
+
+ Dim MyValue As Double = Latitude.ToDecimalDegrees(10, 30, 0)
+
+
+ double MyValue = Latitude.ToDecimalDegrees(10, 30, 0);
+
+
+ ' Equals will return False
+ Dim Angle1 As New Angle(90.15);
+ Dim Angle2 As New Angle(90.12);
+ If Angle1.Equals(Angle2, 2) Then
+ Debug.WriteLine("The values are the same to two digits of precision.");
+ ' Equals will return True
+ Dim Angle1 As New Angle(90.15);
+ Dim Angle2 As New Angle(90.12);
+ If Angle1.Equals(Angle2, 1) Then
+ Debug.WriteLine("The values are the same to one digit of precision.");
+
+
+ // Equals will return False
+ Angle Angle1 = new Angle(90.15);
+ Angle Angle2 = new Angle(90.12);
+ if (Angle1.Equals(Angle2, 2))
+ Console.WriteLine("The values are the same to two digits of precision.");
+ // Equals will return True
+ Angle Angle1 = new Angle(90.15);
+ Angle Angle2 = new Angle(90.12);
+ if (Angle1.Equals(Angle2, 1))
+ Console.WriteLine("The values are the same to one digits of precision.");
+
+
+ ' Equals will return False
+ Dim Angle1 As New Angle(90.15);
+ Dim Angle2 As New Angle(90.12);
+ If Angle1.Equals(Angle2, 2) Then
+ Debug.WriteLine("The values are the same to two digits of precision.");
+ ' Equals will return True
+ Dim Angle1 As New Angle(90.15);
+ Dim Angle2 As New Angle(90.12);
+ If Angle1.Equals(Angle2, 1) Then
+ Debug.WriteLine("The values are the same to one digit of precision.");
+
+
+ // Equals will return False
+ Angle Angle1 = new Angle(90.15);
+ Angle Angle2 = new Angle(90.12);
+ if (Angle1.Equals(Angle2, 2))
+ Console.WriteLine("The values are the same to two digits of precision.");
+ // Equals will return True
+ Angle Angle1 = new Angle(90.15);
+ Angle Angle2 = new Angle(90.12);
+ if (Angle1.Equals(Angle2, 1))
+ Console.WriteLine("The values are the same to one digits of precision.");
+
+
+ Dim MyAngle As New Angle(45, 16.772)
+ Debug.WriteLine(MyAngle.ToString("h°m.mm", CultureInfo.CurrentCulture))
+ ' Output: 45°16.78
+
+
+ Dim MyAngle As New Angle(45, 16.772);
+ Debug.WriteLine(MyAngle.ToString("h°m.mm", CultureInfo.CurrentCulture));
+ // Output: 45°16.78
+
+
+ ' Create an angle of 20°30'
+ Dim MyAngle As New Angle(20, 30)
+ ' Setting the DecimalMinutes recalculated other properties
+ Debug.WriteLine(MyAngle.DecimalDegrees)
+ ' Output: "20.5" the same as 20°30'
+
+
+ // Create an angle of 20°30'
+ Angle MyAngle = New Angle(20, 30);
+ // Setting the DecimalMinutes recalculated other properties
+ Console.WriteLine(MyAngle.DecimalDegrees)
+ // Output: "20.5" the same as 20°30'
+
+
+ ' Create an angle of 20°10'30"
+ Dim MyAngle As New Angle(20, 10, 30)
+ ' The DecimalMinutes property is automatically calculated
+ Debug.WriteLine(MyAngle.DecimalMinutes)
+ ' Output: "10.5"
+
+
+ // Create an angle of 20°10'30"
+ Angle MyAngle = new Angle(20, 10, 30);
+ // The DecimalMinutes property is automatically calculated
+ Console.WriteLine(MyAngle.DecimalMinutes)
+ // Output: "10.5"
+
+
+ Dim MyAngle As New Angle(60.5)
+ Debug.WriteLine(MyAngle.Hours)
+ ' Output: 60
+
+
+ Angle MyAngle = new Angle(60.5);
+ Console.WriteLine(MyAngle.Hours);
+ // Output: 60
+
+
+ Dim MyAngle As New Angle(45.5)
+ Debug.WriteLine(MyAngle.Minutes)
+ ' Output: 30
+
+
+ Angle MyAngle = new Angle(45.5);
+ Console.WriteLine(MyAngle.Minutes);
+ // Output: 30
+
+
+ Dim MyAngle As New Angle(45, 10.5)
+ Debug.WriteLine(MyAngle.Seconds)
+ ' Output: 30
+
+
+ Dim MyAngle As New Angle(45, 10.5);
+ Console.WriteLine(MyAngle.Seconds);
+ // Output: 30
+
+
+ ' Declare a Area of 50 meters
+ Dim Area1 As New Area(50, AreaUnit.SquareMeters)
+ ' Convert it into acres
+ Dim Area2 As Area = Area2.ToAcres()
+
+
+ // Declare a Area of 50 meters
+ Area Area1 = new Area(50, AreaUnit.SquareMeters);
+ // Convert it into acres
+ Area Area2 = Area2.ToAcres();
+
+
+ Dim MyArea As New Area(50, AreaUnit.SquareKilometers)
+
+
+ Area MyArea = new Area(50, AreaUnit.SquareKilometers);
+
+
+ Dim MyArea As Area
+ ' Create a Area of 50 square kilometers
+ MyArea = New Area("50 sq. km")
+ ' Create a Area of 14, 387 miles, then convert it into square inches
+ MyArea = New Area("14, 387 sq. statute miles").ToSquareInches()
+ ' Create a Area of 50 square feet
+ MyArea = New Area(" 50 sq ' ")
+
+
+ Area MyArea;
+ ' Create a Area of 50 square kilometers
+ MyArea = new Area("50 sq. km");
+ ' Create a Area of 14, 387 miles, then convert it into square inches
+ MyArea = new Area("14, 387 sq. statute miles").ToSquareInches();
+ ' Create a Area of 50 square feet
+ MyArea = new Area(" 50 sq ' ");
+
+
+ Dim MyArea As Area
+ ' Create a Area of 50 square kilometers
+ MyArea = New Area("50 sq. km", CultureInfo.CurrentCulture)
+ ' Create a Area of 14, 387 miles, then convert it into square inches
+ MyArea = New Area("14, 387 sq. statute miles", CultureInfo.CurrentCulture).ToSquareInches()
+ ' Create a Area of 50 square feet
+ MyArea = New Area(" 50 sq ' ", CultureInfo.CurrentCulture)
+
+
+ Area MyArea;
+ ' Create a Area of 50 square kilometers
+ MyArea = new Area("50 sq. km", CultureInfo.CurrentCulture);
+ ' Create a Area of 14, 387 miles, then convert it into square inches
+ MyArea = new Area("14, 387 sq. statute miles", CultureInfo.CurrentCulture).ToSquareInches();
+ ' Create a Area of 50 square feet
+ MyArea = new Area(" 50 sq ' ", CultureInfo.CurrentCulture);
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareInches)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareKilometers)
+ ' Convert the Area measurements to square feet and output the result
+ Debug.WriteLine(Area1.ToSquareFeet().ToString())
+ Debug.WriteLine(Area2.ToSquareFeet().ToString())
+ Debug.WriteLine(Area3.ToSquareFeet().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareInches);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareKilometers);
+ // Convert the Area measurements to square feet and output the result
+ Console.WriteLine(Area1.ToSquareFeet().ToString());
+ Console.WriteLine(Area2.ToSquareFeet().ToString());
+ Console.WriteLine(Area3.ToSquareFeet().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareKilometers)
+ ' Convert the Area measurements to square inches and output the result
+ Debug.WriteLine(Area1.ToSquareInches().ToString())
+ Debug.WriteLine(Area2.ToSquareInches().ToString())
+ Debug.WriteLine(Area3.ToSquareInches().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareKilometers);
+ // Convert the Area measurements to square inches and output the result
+ Console.WriteLine(Area1.ToSquareInches().ToString());
+ Console.WriteLine(Area2.ToSquareInches().ToString());
+ Console.WriteLine(Area3.ToSquareInches().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareInches)
+ ' Convert the Area measurements to square kilometers and output the result
+ Debug.WriteLine(Area1.ToSquareKilometers().ToString())
+ Debug.WriteLine(Area2.ToSquareKilometers().ToString())
+ Debug.WriteLine(Area3.ToSquareKilometers().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareInches);
+ // Convert the Area measurements to square kilometers and output the result
+ Console.WriteLine(Area1.ToSquareKilometers().ToString());
+ Console.WriteLine(Area2.ToSquareKilometers().ToString());
+ Console.WriteLine(Area3.ToSquareKilometers().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareInches)
+ ' Convert the Area measurements to square meters and output the result
+ Debug.WriteLine(Area1.ToSquareMeters().ToString())
+ Debug.WriteLine(Area2.ToSquareMeters().ToString())
+ Debug.WriteLine(Area3.ToSquareMeters().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareInches);
+ // Convert the Area measurements to square meters and output the result
+ Console.WriteLine(Area1.ToSquareMeters().ToString());
+ Console.WriteLine(Area2.ToSquareMeters().ToString());
+ Console.WriteLine(Area3.ToSquareMeters().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareInches)
+ ' Convert the Area measurements to square nautical miles and output the result
+ Debug.WriteLine(Area1.ToSquareNauticalMiles().ToString())
+ Debug.WriteLine(Area2.ToSquareNauticalMiles().ToString())
+ Debug.WriteLine(Area3.ToSquareNauticalMiles().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareInches);
+ // Convert the Area measurements to square nautical miles and output the result
+ Console.WriteLine(Area1.ToSquareNauticalMiles().ToString());
+ Console.WriteLine(Area2.ToSquareNauticalMiles().ToString());
+ Console.WriteLine(Area3.ToSquareNauticalMiles().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareInches)
+ ' Convert the Area measurements to square statute miles and output the result
+ Debug.WriteLine(Area1.ToSquareStatuteMiles().ToString())
+ Debug.WriteLine(Area2.ToSquareStatuteMiles().ToString())
+ Debug.WriteLine(Area3.ToSquareStatuteMiles().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareInches);
+ // Convert the Area measurements to square statute miles and output the result
+ Console.WriteLine(Area1.ToSquareStatuteMiles().ToString());
+ Console.WriteLine(Area2.ToSquareStatuteMiles().ToString());
+ Console.WriteLine(Area3.ToSquareStatuteMiles().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareInches)
+ ' Convert the Area measurements to acres and output the result
+ Debug.WriteLine(Area1.ToAcres().ToString())
+ Debug.WriteLine(Area2.ToAcres().ToString())
+ Debug.WriteLine(Area3.ToAcres().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareInches);
+ // Convert the Area measurements to acres and output the result
+ Console.WriteLine(Area1.ToAcres().ToString());
+ Console.WriteLine(Area2.ToAcres().ToString());
+ Console.WriteLine(Area3.ToAcres().ToString());
+
+
+ ' Create Areas of different unit types
+ Dim Area1 As New Area(10, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(20, AreaUnit.SquareStatuteMiles)
+ Dim Area3 As New Area(50, AreaUnit.SquareInches)
+ ' Convert the Area measurements to square centimeters and output the result
+ Debug.WriteLine(Area1.ToSquareCentimeters().ToString())
+ Debug.WriteLine(Area2.ToSquareCentimeters().ToString())
+ Debug.WriteLine(Area3.ToSquareCentimeters().ToString())
+
+
+ // Create Areas of different unit types
+ Area Area1 = new Area(10, AreaUnit.SquareFeet);
+ Area Area2 = new Area(20, AreaUnit.SquareStatuteMiles);
+ Area Area3 = new Area(50, AreaUnit.SquareInches);
+ // Convert the Area measurements to square centimeters and output the result
+ Console.WriteLine(Area1.ToSquareCentimeters().ToString());
+ Console.WriteLine(Area2.ToSquareCentimeters().ToString());
+ Console.WriteLine(Area3.ToSquareCentimeters().ToString());
+
+
+ Dim Area1 As New Area(27878400, AreaUnit.SquareFeet)
+ Dim Area2 As Area = Area1.ToImperialUnitType()
+ Debug.WriteLine(Area2.ToString())
+ ' Output: 1 square statute mile
+
+
+ Area Area1 = new Area(27878400, AreaUnit.SquareFeet);
+ Area Area2 = Area1.ToImperialUnitType();
+ Console.WriteLine(Area2.ToString());
+ // Output: 1 square statute mile
+
+
+ Dim Area1 As New Area(0.0001, AreaUnit.SquareKilometers)
+ Dim Area2 As Area = Area1.ToMetricUnitType()
+ Debug.WriteLine(Area2.ToString())
+ ' Output: 1 square meter
+
+
+ Area Area1 = new Area(0.0001, AreaUnit.SquareKilometers);
+ Area Area2 = Area1.ToMetricUnitType();
+ Console.WriteLine(Area2.ToString());
+ // Output: 1 square meter
+
+
+ Dim Area1 As New Area(27878400, AreaUnit.SquareFeet)
+ Dim Area2 As Area = Area1.ToUnitType(AreaUnit.SquareStatuteMiles)
+ Debug.WriteLine(Area2.ToString())
+ ' Output: 1 square statute mile
+
+
+ Area Area1 As New Area(27878400, AreaUnit.SquareFeet);
+ Area Area2 As Area = Area1.ToUnitType(AreaUnit.SquareStatuteMiles);
+ Console.WriteLine(Area2.ToString());
+ // Output: 1 square statute mile
+
+
+ ' Declare a area of 75 square statute miles
+ Dim MyArea As New Area(75, AreaUnit.SquareStatuteMiles)
+ ' Output the result using the default format
+ Debug.WriteLine(MyArea.ToString("v.v uuu"))
+ ' Output: 75.0 square statute miles
+
+
+ // Declare a area of 75 square statute miles
+ Area MyArea As New Area(75, AreaUnit.SquareStatuteMiles);
+ // Output the result using the default format
+ Console.WriteLine(MyArea.ToString("v.v uuu"));
+ // Output: 75.0 square statute miles
+
+
+ Dim Area1 As New Area(1, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(144, AreaUnit.SquareInches)
+ Dim Area3 As Area = Area1.Add(Area2)
+ Debug.WriteLine(Area3.ToString())
+ ' Output: 2 square feet
+
+
+ Area Area1 = new Area(1, AreaUnit.SquareFeet);
+ Area Area2 = new Area(144, AreaUnit.SquareInches);
+ Area Area3 = Area1.Add(Area2);
+ Console.WriteLine(Area3.ToString());
+ // Output: 2 square feet
+
+
+ Dim Area1 As New Area(1, AreaUnit.SquareFeet)
+ Dim Area2 As New Area(144, AreaUnit.SquareInches)
+ Dim Area3 As Area = Area1.Subtract(Area2)
+ Debug.WriteLine(Area3.ToString())
+ ' Output: 0 square feet
+
+
+ Area Area1 = new Area(1, AreaUnit.SquareFeet);
+ Area Area2 = new Area(144, AreaUnit.SquareInches);
+ Area Area3 = Area1.Subtract(Area2);
+ Console.WriteLine(Area3.ToString());
+ // Output: 0 square feet
+
+
+ Dim Area1 As New Area(50, AreaUnit.SquareInches)
+ Dim Area2 As New Area(2, AreaUnit.SquareInches)
+ Dim Area3 As Area = Area1.Multiply(Area2)
+ Debug.WriteLine(Area3.ToString())
+ ' Output: 100 square inches
+
+
+ Area Area1 = new Area(50, AreaUnit.SquareInches);
+ Area Area2 = new Area(2, AreaUnit.SquareInches);
+ Area Area3 = Area1.Multiply(Area2);
+ Console.WriteLine(Area3.ToString());
+ // Output: 100 square inches
+
+
+ Dim Area1 As New Area(100, AreaUnit.SquareInches)
+ Dim Area2 As New Area(2, AreaUnit.SquareInches)
+ Dim Area3 As Area = Area1.Divide(Area2)
+ Debug.WriteLine(Area3.ToString())
+ ' Output: 50 square inches
+
+
+ Area Area1 = new Area(100, AreaUnit.SquareInches);
+ Area Area2 = new Area(2, AreaUnit.SquareInches);
+ Area Area3 = Area1.Divide(Area2);
+ Debug.WriteLine(Area3.ToString());
+ // Output: 50 square inches
+
+
+ ' Correct use of Increment
+ Dim Area1 As New Area(1, AreaUnit.SquareMeters)
+ Area1 = Area1.Increment()
+ ' Incorrect use of Increment
+ Dim Area1 As New Area(1, AreaUnit.SquareMeters)
+ Area1.Increment()
+ ' NOTE: Area1 will still be 1 square meter, not 2!
+
+
+ // Correct use of Increment
+ Area Area1 = new Area(1, AreaUnit.SquareMeters);
+ Area1 = Area1.Increment();
+ // Incorrect use of Increment
+ Area Area1 = new Area(1, AreaUnit.SquareMeters);
+ Area1.Increment();
+ // NOTE: Area1 will still be 1 square meter, not 2!
+
+
+ ' Correct use of Increment
+ Dim Area1 As New Area(1, AreaUnit.SquareMeters)
+ Area1 = Area1.Increment()
+ ' Incorrect use of Increment
+ Dim Area1 As New Area(1, AreaUnit.SquareMeters)
+ Area1.Increment()
+ ' NOTE: Area1 will still be 1 square meter, not 0!
+
+
+ // Correct use of Increment
+ Area Area1 = new Area(1, AreaUnit.SquareMeters);
+ Area1 = Area1.Decrement();
+ // Incorrect use of Increment
+ Area Area1 = new Area(1, AreaUnit.SquareMeters);
+ Area1.Decrement();
+ // NOTE: Area1 will still be 1 square meter, not 0!
+
+
+ Dim NewArea As Area
+ ' Create a Area of 50 kilometers
+ NewArea = Area.Parse("50 km")
+ ' Create a Area of 14, 387 miles, then convert it into square inches
+ NewArea = Area.Parse("14, 387 statute miles").ToSquareInches()
+ ' Parse an untrimmed measurement into 50 feet
+ NewArea = Area.Parse(" 50 ' ")
+
+
+ Area NewArea;
+ // Create a Area of 50 kilometers
+ NewArea = Area.Parse("50 km");
+ // Create a Area of 14, 387 miles, then convert it into square inches
+ NewArea = Area.Parse("14, 387 statute miles").ToInches();
+ // Parse an untrimmed measurement into 50 feet
+ NewArea = Area.Parse(" 50 ' ");
+
+
+ Dim NewArea As Area
+ ' Create a Area of 50 kilometers
+ NewArea = Area.Parse("50 km", CultureInfo.CurrentCulture)
+ ' Create a Area of 14, 387 miles, then convert it into inches
+ NewArea = Area.Parse("14, 387 statute miles", CultureInfo.CurrentCulture).ToSquareInches()
+ ' Parse an untrimmed measurement into 50 feet
+ NewArea = Area.Parse(" 50 ' ", CultureInfo.CurrentCulture)
+
+
+ Area NewArea;
+ // Create a Area of 50 kilometers
+ NewArea = Area.Parse("50 km", CultureInfo.CurrentCulture);
+ // Create a Area of 14, 387 miles, then convert it into square inches
+ NewArea = Area.Parse("14, 387 statute miles", CultureInfo.CurrentCulture).ToInches();
+ // Parse an untrimmed measurement into 50 feet
+ NewArea = Area.Parse(" 50 ' ", CultureInfo.CurrentCulture);
+
+
+ ' Declare a area of 75 square statute miles
+ Dim MyArea As New Area(75, AreaUnit.SquareStatuteMiles)
+ ' Output the result using the default format
+ Debug.WriteLine(MyArea.ToString())
+ ' Output: 75 sq. statute miles
+
+
+ // Declare a area of 75 square statute miles
+ Area MyArea = nre Area(75, AreaUnit.SquareStatuteMiles);
+ // Output the result using the default format
+ Console.WriteLine(MyArea.ToString());
+ // Output: 75 sq. statute miles
+
+
+ ' Declare a area of 75 square statute miles
+ Dim MyArea As New Area(75, AreaUnit.SquareStatuteMiles)
+ ' Output the result using the default format
+ Debug.WriteLine(MyArea.ToString("v.v uuu", CultureInfo.CurrentCulture))
+ ' Output: 75.0 square statute miles
+
+
+ // Declare a area of 75 square statute miles
+ Area MyArea As New Area(75, AreaUnit.SquareStatuteMiles);
+ // Output the result using the default format
+ Console.WriteLine(MyArea.ToString("v.v uuu", CultureInfo.CurrentCulture));
+ // Output: 75.0 square statute miles
+
+
+ Dim Area1 As New Area(1, AreaUnit.SquareKilometers)
+
+
+ Area Area1 = new Area(1, AreaUnit.SquareKilometers);
+
+
+ Dim MyAzimuth As New Azimuth(45)
+
+
+ Azimuth MyAzimuth = new Azimuth(45);
+
+
+ Dim MyAzimuth As New Azimuth(45, 30, 15)
+
+
+ Azimuth MyAzimuth = new Azimuth(45, 30, 15);
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.NorthNorthwest
+
+
+ Azimuth MyAzimuth = Azimuth.NorthNorthwest;
+
+
+ Dim MyAzimuth As New Azimuth(90)
+
+
+ Azimuth MyAzimuth = new Azimuth(90);
+
+
+ Dim MyAzimuth As New Azimuth(34, 12, 29.2)
+
+
+ Azimuth MyAzimuth = new Azimuth(34, 12, 29.2);
+
+
+ Dim MyAzimuth As New Azimuth(12, 42.345)
+
+
+ Azimuth MyAzimuth = new Azimuth(12, 42.345);
+
+
+ Dim MyAzimuth As New Azimuth("123°45'67.8""")
+
+
+ Azimuth MyAzimuth = new Azimuth("123°45'67.8\"");
+
+
+ Dim NewAzimuth As New Azimuth("NW")
+
+
+ Azimuth NewAzimuth = new Azimuth("NW");
+
+
+ Dim NewAzimuth As New Azimuth("NW", CultureInfo.CurrentCulture)
+
+
+ Azimuth NewAzimuth = new Azimuth("NW", CultureInfo.CurrentCulture);
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.Minimum
+
+
+ Azimuth MyAzimuth = Azimuth.Minimum;
+
+
+ Azimuth MyAzimuth = Azimuth.Minimum;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.Maximum
+
+
+ Azimuth MyAzimuth = Azimuth.Maximum;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.North
+
+
+ Azimuth MyAzimuth = Azimuth.North;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.NorthNortheast
+
+
+ Azimuth MyAzimuth = Azimuth.NorthNortheast;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.Northeast
+
+
+ Azimuth MyAzimuth = Azimuth.Northeast;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.EastNortheast
+
+
+ Azimuth MyAzimuth = Azimuth.EastNortheast;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.East
+
+
+ Azimuth MyAzimuth = Azimuth.East;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.EastSoutheast
+
+
+ Azimuth MyAzimuth = Azimuth.EastSoutheast;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.Southeast
+
+
+ Azimuth MyAzimuth = Azimuth.Southeast;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.SouthSoutheast
+
+
+ Azimuth MyAzimuth = Azimuth.SouthSoutheast;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.South
+
+
+ Azimuth MyAzimuth = Azimuth.South;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.SouthSouthwest
+
+
+ Azimuth MyAzimuth = Azimuth.SouthSouthwest;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.Southwest
+
+
+ Azimuth MyAzimuth = Azimuth.Southwest;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.WestSouthwest
+
+
+ Azimuth MyAzimuth = Azimuth.WestSouthwest;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.West
+
+
+ Azimuth MyAzimuth = Azimuth.West;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.WestNorthwest
+
+
+ Azimuth MyAzimuth = Azimuth.WestNorthwest;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.Northwest
+
+
+ Azimuth MyAzimuth = Azimuth.Northwest;
+
+
+ Dim MyAzimuth As Azimuth = Azimuth.NorthNorthwest
+
+
+ Azimuth MyAzimuth = Azimuth.NorthNorthwest;
+
+
+ Dim MyAzimuth As New Azimuth(720)
+ MyAzimuth = MyAzimuth.Normalize()
+
+
+ Azimuth MyAzimuth = new Azimuth(720);
+ MyAzimuth = MyAzimuth.Normalize();
+
+
+ Dim MyValue As New Azimuth(725)
+ MyValue = MyValue.Normalize()
+
+
+ Azimuth MyValue = new Azimuth(725);
+ MyValue = MyValue.Normalize();
+
+
+ Dim MyAzimuth As New Azimuth(90.946)
+ Debug.WriteLine(MyAzimuth.ToString("d.dd (cc)"))
+ ' Output: 90.95 (East)
+
+
+ Azimuth MyAzimuth = new Azimuth(90.946);
+ Console.WriteLine(MyAzimuth.ToString("d.dd (cc)"));
+ // Output: 90.95 (East)
+
+
+ Dim Azimuth1 As New Azimuth(45)
+ Dim Azimuth2 As Azimuth = Azimuth1.Mirror()
+ Debug.WriteLine(Azimuth2.ToString())
+ ' Output: 225
+
+
+ Azimuth Azimuth1 = new Azimuth(45);
+ Azimuth Azimuth2 = Azimuth1.Mirror();
+ Console.WriteLine(Azimuth2.ToString());
+ // Output: 225
+
+
+ Dim MyAzimuth As New Azimuth(90)
+ Dim MyRadians As Radian = MyAzimuth.ToRadians()
+
+
+ Azimuth MyAzimuth = new Azimuth(90);
+ Radian MyRadians = MyAzimuth.ToRadians();
+
+
+ Dim MyAzimuth As New Azimuth(90)
+ Debug.WriteLine(MyAzimuth.ToString)
+ ' Output: "90°"
+
+
+ Azimuth MyAzimuth = new Azimuth(90);
+ Debug.WriteLine(MyAzimuth.ToString());
+ // Output: "90°"
+
+
+ Dim MyValue As Double = Latitude.ToDecimalDegrees(10, 30, 0)
+
+
+ double MyValue = Latitude.ToDecimalDegrees(10, 30, 0);
+
+
+ Dim NewAzimuth As Azimuth = Azimuth.Parse("123.45°")
+
+
+ Azimuth NewAzimuth = Azimuth.Parse("123.45°");
+
+
+ Dim NewAzimuth As Azimuth = Azimuth.Parse("NW", CultureInfo.CurrentCulture)
+
+
+ Azimuth NewAzimuth = Azimuth.Parse("NW", CultureInfo.CurrentCulture);
+
+
+ Dim MyRadian As Radian = Azimuth.ToRadians(90)
+
+
+ Radian MyRadian = Azimuth.ToRadians(90);
+
+
+ ' Create a new angle equal to one radian
+ Dim MyRadians As New Radian(1)
+ Dim MyAzimuth As Azimuth = Azimuth.FromRadians(MyRadians)
+ Debug.WriteLine(MyAzimuth.ToString())
+ ' Output: 57°
+
+
+ // Create a new angle equal to one radian
+ Radian MyRadians = new Radian(1);
+ Azimuth MyAzimuth = Azimuth.FromRadians(MyRadians);
+ Console.WriteLine(MyAzimuth.ToString());
+ // Output: 57°
+
+
+ ' Correct use of Increment
+ Dim Azimuth1 As New Azimuth(89)
+ Azimuth1 = Azimuth1.Increment()
+ ' Incorrect use of Increment
+ Dim Azimuth1 = New Azimuth(89)
+ Azimuth1.Increment()
+ ' NOTE: Azimuth1 will still be 89°!
+
+
+ // Correct use of Increment
+ Azimuth Azimuth1 = new Azimuth(89);
+ Azimuth1 = Azimuth1.Increment();
+ // Incorrect use of Increment
+ Azimuth Azimuth1 = new Azimuth(89);
+ Azimuth1.Increment();
+ // NOTE: Azimuth1 will still be 89°!
+
+
+ Dim Azimuth1 As New Azimuth(45)
+ Azimuth1 = Azimuth1.Add(45)
+
+
+ Azimuth Azimuth1 = new Azimuth(45);
+ Azimuth1 = Azimuth1.Add(45);
+
+
+ ' Correct use of Decrement
+ Dim Azimuth1 As New Azimuth(91)
+ Azimuth1 = Azimuth1.Decrement()
+ ' Incorrect use of Decrement
+ Dim Azimuth1 = New Azimuth(91)
+ Azimuth1.Increment()
+ ' NOTE: Azimuth1 will still be 91°!
+
+
+ // Correct use of Decrement
+ Azimuth Azimuth1 = new Azimuth(91);
+ Azimuth1 = Azimuth1.Decrement();
+ // Incorrect use of Decrement
+ Azimuth Azimuth1 = new Azimuth(91);
+ Azimuth1.Decrement();
+ // NOTE: Azimuth1 will still be 91°!
+
+
+ Dim Azimuth1 As New Azimuth(90)
+ Azimuth1 = Azimuth1.Subtract(30)
+
+
+ Azimuth Azimuth1 = new Azimuth(90);
+ Azimuth1 = Azimuth1.Subtract(30);
+
+
+ Dim Azimuth1 As New Azimuth(30)
+ Azimuth1 = Azimuth1.Multiply(3)
+
+
+ Azimuth Azimuth1 = new Azimuth(30);
+ Azimuth1 = Azimuth1.Multiply(3);
+
+
+ Dim Azimuth1 As New Azimuth(90)
+ Azimuth1 = Azimuth1.Divide(3)
+
+
+ Azimuth Azimuth1 = new Azimuth(90);
+ Azimuth1 = Azimuth1.Divide(3);
+
+
+ ' Equals will return False
+ Dim Azimuth1 As New Azimuth(90.15);
+ Dim Azimuth2 As New Azimuth(90.12);
+ If Azimuth1.Equals(Azimuth2, 2) Then
+ Debug.WriteLine("The values are the same to two digits of precision.");
+ ' Equals will return True
+ Dim Azimuth1 As New Azimuth(90.15);
+ Dim Azimuth2 As New Azimuth(90.12);
+ If Azimuth1.Equals(Azimuth2, 1) Then
+ Debug.WriteLine("The values are the same to one digit of precision.");
+
+
+ // Equals will return False
+ Azimuth Azimuth1 = new Azimuth(90.15);
+ Azimuth Azimuth2 = new Azimuth(90.12);
+ if (Azimuth1.Equals(Azimuth2, 2))
+ Console.WriteLine("The values are the same to two digits of precision.");
+ // Equals will return True
+ Azimuth Azimuth1 = new Azimuth(90.15);
+ Azimuth Azimuth2 = new Azimuth(90.12);
+ if (Azimuth1.Equals(Azimuth2, 1))
+ Console.WriteLine("The values are the same to one digits of precision.");
+
+
+ Dim MyAzimuth As New Azimuth(90.946)
+ Debug.WriteLine(MyAzimuth.ToString("d.dd (cc)", CultureInfo.CurrentCulture))
+ ' Output: 90.95 (East)
+
+
+ Azimuth MyAzimuth = new Azimuth(90.946);
+ Console.WriteLine(MyAzimuth.ToString("d.dd (cc)", CultureInfo.CurrentCulture));
+ // Output: 90.95 (East)
+
+
+ ' Create an angle of 20°30'
+ Dim MyAzimuth As New Azimuth(20, 30)
+ ' Setting the DecimalMinutes recalculated other properties
+ Debug.WriteLine(MyAzimuth.DecimalDegrees)
+ ' Output: "20.5" the same as 20°30'
+
+
+ // Create an angle of 20°30'
+ Azimuth MyAzimuth = New Azimuth(20, 30);
+ // Setting the DecimalMinutes recalculated other properties
+ Console.WriteLine(MyAzimuth.DecimalDegrees)
+ // Output: "20.5" the same as 20°30'
+
+
+ ' Create an angle of 20°10'30"
+ Dim MyAzimuth As New Azimuth(20, 10, 30)
+ ' The DecimalMinutes property is automatically calculated
+ Debug.WriteLine(MyAzimuth.DecimalMinutes)
+ ' Output: "10.5"
+
+
+ // Create an angle of 20°10'30"
+ Azimuth MyAzimuth = new Azimuth(20, 10, 30);
+ // The DecimalMinutes property is automatically calculated
+ Console.WriteLine(MyAzimuth.DecimalMinutes)
+ // Output: "10.5"
+
+
+ Dim MyAzimuth As New Azimuth(60.5)
+ Debug.WriteLine(MyAzimuth.Hours)
+ ' Output: 60
+
+
+ Azimuth MyAzimuth = new Azimuth(60.5);
+ Console.WriteLine(MyAzimuth.Hours);
+ // Output: 60
+
+
+ Dim MyAzimuth As New Azimuth(45.5)
+ Debug.WriteLine(MyAzimuth.Minutes)
+ ' Output: 30
+
+
+ Azimuth MyAzimuth = new Azimuth(45.5);
+ Console.WriteLine(MyAzimuth.Minutes);
+ // Output: 30
+
+
+ Dim MyAzimuth As New Azimuth(45, 10.5)
+ Debug.WriteLine(MyAzimuth.Seconds)
+ ' Output: 30
+
+
+ Dim MyAzimuth As New Azimuth(45, 10.5);
+ Console.WriteLine(MyAzimuth.Seconds);
+ // Output: 30
+
+
+ Dim MyAzimuth As New Azimuth(272)
+ Debug.WriteLine(MyAzimuth.Direction.ToString())
+ ' Output: West
+
+
+ Azimuth MyAzimuth = new Azimuth(272);
+ Console.WriteLine(MyAzimuth.Direction.ToString());
+ // Output: West
+
+
+ Dim MyAzimuth As New Azimuth(272)
+ Debug.WriteLine(MyAzimuth.Direction.ToString())
+ ' Output: West
+
+
+ Azimuth MyAzimuth = new Azimuth(272);
+ Console.WriteLine(MyAzimuth.Direction.ToString());
+ // Output: West
+
+
+ ' Declare a new event
+ Dim MyDilutionOfPrecisionEvent As EventHandler
+ ' Create a DilutionOfPrecision of 30 horizontal
+ Dim MyDilutionOfPrecision As New DilutionOfPrecision(DilutionOfPrecisionType.Horizontal, 30.0)
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyDilutionOfPrecisionEvent(Me, New DilutionOfPrecisionEventArgs(MyDilutionOfPrecision))
+ End Sub
+
+
+ // Declare a new event
+ EventHandler MyDilutionOfPrecisionEvent;
+ // Create a DilutionOfPrecision of 30 horizontal
+ DilutionOfPrecision MyDilutionOfPrecision = new DilutionOfPrecision(DilutionOfPrecisionType.Horizontal, 30.0);
+ void Main()
+ {
+ // Raise our custom event
+ MyDilutionOfPrecisionEvent(this, New DilutionOfPrecisionEventArgs(MyDilutionOfPrecision));
+ }
+
+
+ ' Declare a new receiver
+ Private WithEvents MyReceiver As New Receiver()
+ ' Raised when the fix quality has changed
+ Private Sub OnFixQualityChanged(ByVal sender As Object, ByVal e As FixQualityEventArgs)
+ ' What is the new fix quality°
+ Select Case e.FixQuality
+ Case FixQuality.NoFix
+ ' No fix is obtained
+ Debug.WriteLine("No fix is currently obtained.")
+ Case FixQuality.GpsFix
+ ' A fix is present
+ Debug.WriteLine("A fix has been obtained using only GPS satellites.")
+ Case FixQuality.DifferentialGpsFix
+ ' A differential fix is present
+ Debug.WriteLine("A fix has been obtained using GPS satellites and correction information from DGPS/WAAS ground stations.")
+ Case FixQuality.Estimated
+ ' A fix is being estimated (not an actual fix)
+ Debug.WriteLine("A fix is currently being estimated. ")
+ End Select
+ End Sub
+
+
+ // Declare a new receiver
+ Receiver MyReceiver = new Receiver();
+ // Raised when the fix quality has changed
+ void OnFixQualityChanged(Object sender, FixQualityEventArgs e)
+ {
+ // What is the new fix quality°
+ switch (e.FixQuality)
+ {
+ case FixQuality.NoFix:
+ // No fix is obtained
+ Debug.WriteLine("No fix is currently obtained.");
+ case FixQuality.GpsFix:
+ // A fix is present
+ Debug.WriteLine("A fix has been obtained using only GPS satellites.");
+ case FixQuality.DifferentialGpsFix:
+ // A differential fix is present
+ Debug.WriteLine("A fix has been obtained using GPS satellites and correction information from DGPS/WAAS ground stations.");
+ case FixQuality.Estimated:
+ // A fix is being estimated (not an actual fix)
+ Debug.WriteLine("A fix is currently being estimated. ");
+ }
+ }
+
+
+ Private WithEvents MyReceiver As New Receiver()
+ ' Raised whenever the fix method has changed
+ Private Sub OnFixMethodChanged(ByVal sender As Object, ByVal e As FixMethodEventArgs)
+ ' What is the new fix method°
+ Select Case e.FixMethod
+ Case FixMethod.NoFix
+ ' We have neither position or altitude
+ Debug.WriteLine("Your position is: Not Yet Available")
+ Debug.WriteLine("Your altitude is: Not Yet Available")
+ Case FixMethod.Fix2D
+ ' We have a position but no altitude
+ Debug.WriteLine("Your position is: " & MyReceiver.Position.ToString)
+ Debug.WriteLine("Your altitude is: Not Yet Available")
+ Case FixMethod.Fix3D
+ ' We have both position and altitude
+ Debug.WriteLine("Your position is: " & MyReceiver.Position.ToString)
+ Debug.WriteLine("Your altitude is: " & MyReceiver.Altitude.ToString)
+ End Select
+ End Sub
+
+
+ // Declare a new receiver
+ Private WithEvents MyReceiver As New Receiver()
+ // Raised whenever the fix method has changed
+ void OnFixMethodChanged(Object sender, FixMethodEventArgs e)
+ {
+ // What is the new fix method°
+ switch (e.FixMethod)
+ {
+ case FixMethod.NoFix:
+ // We have neither position or altitude
+ Debug.WriteLine("Your position is: Not Yet Available");
+ Debug.WriteLine("Your altitude is: Not Yet Available");
+ case FixMethod.Fix2D:
+ // We have a position but no altitude
+ Debug.WriteLine("Your position is: " & MyReceiver.Position.ToString());
+ Debug.WriteLine("Your altitude is: Not Yet Available");
+ case FixMethod.Fix3D:
+ // We have both position and altitude
+ Debug.WriteLine("Your position is: " & MyReceiver.Position.ToString());
+ Debug.WriteLine("Your altitude is: " & MyReceiver.Altitude.ToString());
+ }
+ }
+
+
+ ' Declare a new receiver
+ Private WithEvents MyReceiver As New Receiver()
+ Sub Main()
+ ' Start listening for messages
+ MyReceiver.Start
+ End Sub
+ Sub OnFixLikelihoodChanged(ByVal sender As Object, ByVal e As FixLikelihoodEventArgs) Handles MyReceiver.FixLikelihoodChanged
+ ' Do we have a fix currently°
+ If MyReceiver.IsFixObtained Then
+ ' Yes. What's the likelihood that the fix will be sustained°
+ Select Case MyReceiver.FixLikelihood
+ Case FixLikelihood.Unlikely
+ Debug.WriteLine("The current fix is about to be lost!")
+ Case FixLikelihood.Possible
+ Debug.WriteLine("The current fix is unstable. Find a more open view of the sky soon.")
+ Case FixLikelihood.Likely
+ Debug.WriteLine("The current fix is nearly stable.")
+ Case FixLikelihood.Certain
+ Debug.WriteLine("The current fix is stable.")
+ End Select
+ Else
+ ' No. What's the likelihood that a fix will be obtained°
+ Select Case MyReceiver.FixLikelihood
+ Case FixLikelihood.Unlikely
+ Debug.WriteLine("A fix is not possible. Find a more open view of the sky.")
+ Case FixLikelihood.Possible
+ Debug.WriteLine("A fix is possible, but satellite signals are still mostly obscured.")
+ Case FixLikelihood.Likely
+ Debug.WriteLine("A fix should occur within the next several seconds.")
+ Case FixLikelihood.Certain
+ Debug.WriteLine("A fix will occur in a few seconds.")
+ End Select
+ End If
+ End Sub
+
+
+ ' Declare a new receiver
+ Private Receiver MyReceiver = new Receiver();
+ void Main()
+ {
+ // Start listening for messages
+ MyReceiver.Start();
+ }
+ void OnFixLikelihoodChanged(Object sender, FixLikelihoodEventArgs e)
+ {
+ // Do we have a fix currently°
+ if (MyReceiver.IsFixObtained)
+ {
+ // Yes. What's the likelihood that the fix will be sustained°
+ switch (MyReceiver.FixLikelihood)
+ {
+ case FixLikelihood.Unlikely:
+ Debug.WriteLine("The current fix is about to be lost!");
+ break;
+ case FixLikelihood.Possible:
+ Debug.WriteLine("The current fix is unstable. Find a more open view of the sky soon.");
+ break;
+ case FixLikelihood.Likely:
+ Debug.WriteLine("The current fix is nearly stable.");
+ break;
+ case FixLikelihood.Certain:
+ Debug.WriteLine("The current fix is stable.");
+ break;
+ }
+ }
+ else
+ {
+ // No. What's the likelihood that a fix will be obtained°
+ switch (MyReceiver.FixLikelihood)
+ {
+ case FixLikelihood.Unlikely:
+ Debug.WriteLine("A fix is not possible. Find a more open view of the sky.");
+ break;
+ case FixLikelihood.Possible:
+ Debug.WriteLine("A fix is possible, but satellite signals are still mostly obscured.");
+ break;
+ case FixLikelihood.Likely:
+ Debug.WriteLine("A fix should occur within the next several seconds.");
+ break;
+ case FixLikelihood.Certain:
+ Debug.WriteLine("A fix will occur in a few seconds.");
+ break;
+ }
+ }
+ }
+
+
+ ' Declare a new event
+ Dim MyFixMethodEvent As EventHandler
+ ' Create a FixMethod signifying a 3-D fix (both position and altitude)
+ Dim MyFixMethod As FixMethod = FixMethod.Fix3D
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyFixMethodEvent(Me, New FixMethodEventArgs(MyFixMethod))
+ End Sub
+
+
+ // Declare a new event
+ EventHandler MyFixMethodEvent;
+ // Create a FixMethod signifying a 3-D fix (both position and altitude)
+ FixMethod MyFixMethod = FixMethod.Fix3D;
+ void Main()
+ {
+ // Raise our custom event
+ MyFixMethodEvent(this, New FixMethodEventArgs(MyFixMethod));
+ }
+
+
+ ' Declare a new event
+ Dim MyFixLikelihoodEvent As FixLikelihoodEventHandler
+ ' Create a FixLikelihood signifying a 3-D fix (both position and altitude)
+ Dim MyFixLikelihood As FixLikelihood = FixLikelihood.Fix3D
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyFixLikelihoodEvent(Me, New FixLikelihoodEventArgs(MyFixLikelihood))
+ End Sub
+
+
+ // Declare a new event
+ FixLikelihoodEventHandler MyFixLikelihoodEvent;
+ // Create a FixLikelihood signifying a 3-D fix (both position and altitude)
+ FixLikelihood MyFixLikelihood = FixLikelihood.Fix3D;
+ void Main()
+ {
+ // Raise our custom event
+ MyFixLikelihoodEvent(this, New FixLikelihoodEventArgs(MyFixLikelihood));
+ }
+
+
+ ' Declare a new event
+ Dim MyFixModeEvent As EventHandler
+ ' Create a FixMode signifying that the fix method is being chosen automatically
+ Dim MyFixMode As FixMode = FixMode.Automatic
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyFixModeEvent(Me, New FixModeEventArgs(MyFixMode))
+ End Sub
+
+
+ // Declare a new event
+ EventHandler MyFixModeEvent;
+ // Create a FixMode signifying that the fix method is being chosen automatically
+ FixMode MyFixMode = FixMode.Automatic;
+ void Main()
+ {
+ // Raise our custom event
+ MyFixModeEvent(this, New FixModeEventArgs(MyFixMode));
+ }
+
+
+ ' Declare a new event
+ Dim MyFixQualityEvent As EventHandler
+ ' Create a FixQuality signifying that a differential GPS fix is obtained
+ Dim MyFixQuality As FixQuality = FixQuality.DifferentialGpsFix
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyFixQualityEvent(Me, New FixQualityEventArgs(MyFixQuality))
+ End Sub
+
+
+ // Declare a new event
+ EventHandler MyFixQualityEvent;
+ // Create a FixQuality signifying that a differential GPS fix is obtained
+ FixQuality MyFixQuality = FixQuality.DifferentialGpsFix;
+ void Main()
+ {
+ // Raise our custom event
+ MyFixQualityEvent(this, New FixQualityEventArgs(MyFixQuality));
+ }
+
+
+ ' Declare a new event
+ Dim MySentenceEvent As SentenceEventHandler
+ ' Create an NMEA $GPGLL sentence
+ Dim MySentence As String = "$GPGLL, 4122, N, 14628, W, 104243.00, A, D*7E"
+
+ Sub Main()
+ ' Raise our custom event, also indicating that the sentence was completely recognized
+ RaiseEvent MySentenceEvent(Me, New SentenceEventArgs(MySentence, SentenceType.Recognized))
+ End Sub
+
+
+ // Declare a new event
+ SentenceEventHandler MySentenceEvent;
+ // Create an NMEA $GPGLL sentence
+ string MySentence = "$GPGLL, 4122, N, 14628, W, 104243.00, A, D*7E"
+
+ void Main()
+ {
+ // Raise our custom event, also indicating that the sentence was completely recognized
+ MySentenceEvent(this, New SentenceEventArgs(MySentence, SentenceType.Recognized));
+ }
+
+ 
+ ' Start a new receiver
+ Dim MyReceiver As New Receiver()
+ ' Declare a new event
+ Dim MySatelliteEvent As EventHandler
+ ' Get a handle on the first satellite in the receiver's collection
+ Dim MySatellite As Satellite = MyReceiver.Satellites(0)
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MySatelliteEvent(Me, New SatelliteEventArgs(MySatellite))
+ End Sub
+
+
+ // Start a new receiver
+ Receiver MyReceiver = new Receiver();
+ // Declare a new event
+ EventHandler MySatelliteEvent;
+ // Create an Satellite of 90°
+ Satellite MySatellite = new Satellite(90);
+ void Main()
+ {
+ // Raise our custom event
+ MySatelliteEvent(this, New SatelliteEventArgs(MySatellite));
+ }
+
+
+ Dim NorthwestCorner As New Position("39N 105W")
+ Dim RectangleSize As New GeographicSize(2, 5)
+ Dim Rectangle As New GeographicRectangle(NorthwestCorner, RectangleSize)
+
+
+ Position NorthwestCorner = new Position("39N, 105W");
+ GeographicSize RectangleSize = new GeographicSize(2, 5);
+ GeographicRectangle Rectangle = new GeographicRectangle(NorthwestCorner, RectangleSize);
+
+
+ Dim NorthwestCorner As New Position("39N 105W")
+ Dim RectangleWidth As Distance = Distance.FromKilometers(1)
+ Dim RectangleHeight As Distance = Distance.FromKilometers(1)
+ Dim Rectangle As New GeographicRectangle(NorthwestCorner, RectangleWidth, RectangleHeight)
+
+
+ Position NorthwestCorner = new Position("39N 105W");
+ Distance RectangleWidth = Distance.FromKilometers(1);
+ Distance RectangleHeight = Distance.FromKilometers(1);
+ GeographicRectangle Rectangle = new GeographicRectangle(NorthwestCorner, RectangleWidth, RectangleHeight);
+
+
+ Dim NorthwestCorner As New Position("39N 105W")
+ Dim SoutheastCorner As New Position("37N 100W")
+ Dim Rectangle As New GeographicRectangle(NorthwestCorner, SoutheastCorner)
+
+
+ Position NorthwestCorner = new Position("39N 105W");
+ Position SoutheastCorner = new Position("37N 100W");
+ GeographicRectangle Rectangle = new GeographicRectangle(NorthwestCorner, SoutheastCorner);
+
+
+ Dim Rectangle As New GeographicRectangle("39N, 105W, 37N, 100W")
+
+
+ GeographicRectangle Rectangle = new GeographicRectangle("39N, 105W, 37N, 100W");
+
+
+ Dim Rectangle As New GeographicRectangle("39N, 105W, 37N, 100W", CultureInfo.CurrentCulture)
+
+
+ GeographicRectangle Rectangle = new GeographicRectangle("39N, 105W, 37N, 100W", CultureInfo.CurrentCulture);
+
+
+ Dim Left As New Longitude(-105)
+ Dim Top As New Latitude(39)
+ Dim Right As New Longitude(-100)
+ Dim Top As New Latitude(37)
+ Dim Rectangle As New GeographicRectangle(Left, Top, Right, Bottom)
+
+
+ Longitude Left = new Longitude(-105);
+ Latitude Top = new Latitude(39);
+ Longitude Right = new Longitude(-100);
+ Latitude Top = new Latitude(37);
+ GeographicRectangle Rectangle = new GeographicRectangle(Left, Top, Right, Bottom);
+
+
+ Dim Left As New Longitude(-105)
+ Dim Top As New Latitude(39)
+ Dim Right As New Longitude(-100)
+ Dim Top As New Latitude(37)
+ Dim Rectangle As New GeographicRectangle(Left, Top, Right, Bottom)
+
+
+ Latitude Top = new Latitude(39);
+ Longitude Left = new Longitude(-105);
+ Latitude Bottom = new Latitude(37);
+ Longitude Right = new Longitude(-100);
+ GeographicRectangle Rectangle = new GeographicRectangle(Top, Left, Bottom, Right);
+
+
+ Dim Rectangle As New GeographicRectangle("30N, 105W, 1°, 5°")
+ Rectangle = Rectangle.Translate(Azimuth.Northeast, New Distance(50, DistanceUnit.Kilometers))
+
+
+ GeographicRectangle Rectangle = new GeographicRectangle("30N, 105W, 1°, 5°");
+ Rectangle = Rectangle.Translate(Azimuth.Northeast, New Distance(50, DistanceUnit.Kilometers));
+
+
+ Dim Rectangle As New GeographicRectangle("30N, 105W, 1°, 5°")
+ Rectangle = Rectangle.Translate(new Angle(45), New Distance(50, DistanceUnit.Kilometers))
+
+
+ GeographicRectangle Rectangle = new GeographicRectangle("30N, 105W, 1°, 5°");
+ Rectangle = Rectangle.Translate(new Angle(45), New Distance(50, DistanceUnit.Kilometers));
+
+
+ Dim Rectangle As New GeographicRectangle("30N, 105W, 1°, 5°")
+ Rectangle = Rectangle.Translate(45, New Distance(50, DistanceUnit.Kilometers))
+
+
+ GeographicRectangle Rectangle = new GeographicRectangle("30N, 105W, 1°, 5°");
+ Rectangle = Rectangle.Translate(45, New Distance(50, DistanceUnit.Kilometers));
+
+
+ // Create a percentage of 25%
+ Percent twentyFivePercent = new Percent(0.25f);
+
+
+ ' Create a percentage of 25%
+ Dim TwentyFivePercent As New Percent(0.25)
+
+
+ // Create a percentage of 25%
+ Percent twentyFivePercent = New Percent("25.4%", CultureInfo.InvariantCulture);
+
+
+ ' Create a percentage of 25%
+ Dim TwentyFivePercent As New Percent("25.5%", CultureInfo.InvariantCulture)
+
+
+ ' Get information about the NAD1983 datum
+ Dim MyDatum As Datum = Geodesy.GetDatum(DatumType.NorthAmerican1983)
+ ' Get the ellipsoid associated with this datum
+ Dim MyEllipsoid As Ellipsoid = MyDatum.Ellipsoid
+ ' Write the semi-major axis of the ellipsoid
+ Debug.WriteLine(MyEllipsoid.SemiMajorAxis.ToString())
+
+
+ // Get information about the NAD1983 datum
+ Datum MyDatum = Geodesy.GetDatum(DatumType.NorthAmerican1983);
+ // Get the ellipsoid associated with this datum
+ Ellipsoid MyEllipsoid = MyDatum.Ellipsoid;
+ // Write the semi-major axis of the ellipsoid
+ Debug.WriteLine(MyEllipsoid.SemiMajorAxis.ToString());
+
+
+ Dim MyDistance As New Distance(50, DistanceUnit.Kilometers)
+
+
+ Distance MyDistance = new Distance(50, DistanceUnit.Kilometers);
+
+
+ Dim MyDistance As Distance
+ ' Create a distance of 50 kilometers
+ MyDistance = New Distance("50 km")
+ ' Create a distance of 14, 387 miles, then convert it into inches
+ MyDistance = New Distance("14, 387 statute miles").ToInches
+ ' Parse an untrimmed measurement into 50 feet
+ MyDistance = New Distance(" 50 ' ")
+
+
+ Distance MyDistance;
+ // Create a distance of 50 kilometers
+ MyDistance = new Distance("50 km");
+ // Create a distance of 14, 387 miles, then convert it into inches
+ MyDistance = new Distance("14, 387 statute miles").ToInches;
+ // Parse an untrimmed measurement into 50 feet
+ MyDistance = new Distance(" 50 ' ");
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Inches)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Kilometers)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToFeet.ToString)
+ Debug.WriteLine(Distance2.ToFeet.ToString)
+ Debug.WriteLine(Distance3.ToFeet.ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Inches);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Kilometers);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToFeet().ToString());
+ Debug.WriteLine(Distance2.ToFeet().ToString());
+ Debug.WriteLine(Distance3.ToFeet().ToString());
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Feet)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Kilometers)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToInches.ToString)
+ Debug.WriteLine(Distance2.ToInches.ToString)
+ Debug.WriteLine(Distance3.ToInches.ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Feet);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Kilometers);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToInches().ToString());
+ Debug.WriteLine(Distance2.ToInches().ToString());
+ Debug.WriteLine(Distance3.ToInches().ToString());
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Feet)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Inches)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToKilometers.ToString)
+ Debug.WriteLine(Distance2.ToKilometers.ToString)
+ Debug.WriteLine(Distance3.ToKilometers.ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Feet);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Inches);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToKilometers().ToString());
+ Debug.WriteLine(Distance2.ToKilometers().ToString());
+ Debug.WriteLine(Distance3.ToKilometers().ToString());
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Feet)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Inches)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToMeters().ToString)
+ Debug.WriteLine(Distance2.ToMeters().ToString)
+ Debug.WriteLine(Distance3.ToMeters().ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Feet);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Inches);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToMeters().ToString());
+ Debug.WriteLine(Distance2.ToMeters().ToString());
+ Debug.WriteLine(Distance3.ToMeters().ToString());
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Feet)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Inches)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToMeters().ToString)
+ Debug.WriteLine(Distance2.ToMeters().ToString)
+ Debug.WriteLine(Distance3.ToMeters().ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Feet);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Inches);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToMeters().ToString());
+ Debug.WriteLine(Distance2.ToMeters().ToString());
+ Debug.WriteLine(Distance3.ToMeters().ToString());
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Feet)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Inches)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToNauticalMiles.ToString)
+ Debug.WriteLine(Distance2.ToNauticalMiles.ToString)
+ Debug.WriteLine(Distance3.ToNauticalMiles.ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Feet);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Inches);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToNauticalMiles().ToString());
+ Debug.WriteLine(Distance2.ToNauticalMiles().ToString());
+ Debug.WriteLine(Distance3.ToNauticalMiles().ToString());
+
+
+ ' Create distances of different unit types
+ Dim Distance1 As New Distance(10, DistanceUnit.Feet)
+ Dim Distance2 As New Distance(20, DistanceUnit.StatuteMiles)
+ Dim Distance3 As New Distance(50, DistanceUnit.Inches)
+ ' Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToStatuteMiles.ToString)
+ Debug.WriteLine(Distance2.ToStatuteMiles.ToString)
+ Debug.WriteLine(Distance3.ToStatuteMiles.ToString)
+
+
+ // Create distances of different unit types
+ Distance Distance1 = new Distance(10, DistanceUnit.Feet);
+ Distance Distance2 = new Distance(20, DistanceUnit.StatuteMiles);
+ Distance Distance3 = new Distance(50, DistanceUnit.Inches);
+ // Convert the distance measurements to feet and output the result
+ Debug.WriteLine(Distance1.ToStatuteMiles().ToString());
+ Debug.WriteLine(Distance2.ToStatuteMiles().ToString());
+ Debug.WriteLine(Distance3.ToStatuteMiles().ToString());
+
+ | ##0.## uu | +## uuuu | +# u | +### | +
+ ' Declare a distance of 75 miles
+ Dim MyDistance As New Distance(75, DistanceUnit.StatuteMiles)
+ ' Set the text box to the distance, formatted as a string
+ MyTextBox.Text = MyDistance.ToString("## uuu")
+
+
+ // Declare a distance of 75 miles
+ Distance MyDistance = new Distance(75, DistanceUnit.StatuteMiles);
+ // Set the text box to the distance, formatted as a string
+ MyTextBox.Text = MyDistance.ToString("## uuu");
+
+
+ ' Declare a distance of 75 miles
+ Dim MyDistance As New Distance(75, DistanceUnit.StatuteMiles)
+ ' Set the text box to the distance, formatted as a string
+ MyTextBox.Text = MyDistance.ToString
+
+
+ // Declare a distance of 75 miles
+ Distance MyDistance = new Distance(75, DistanceUnit.StatuteMiles);
+ // Set the text box to the distance, formatted as a string
+ MyTextBox.Text = MyDistance.ToString();
+
+
+ Dim NewDistance As Distance
+ ' Create a distance of 50 kilometers
+ NewDistance = Distance.Parse("50 km")
+ ' Create a distance of 14, 387 miles, then convert it into inches
+ NewDistance = Distance.Parse("14, 387 statute miles").ToInches
+ ' Parse an untrimmed measurement into 50 feet
+ NewDistance = Distance.Parse(" 50 ' ")
+
+
+ Distance NewDistance;
+ // Create a distance of 50 kilometers
+ NewDistance = Distance.Parse("50 km");
+ // Create a distance of 14, 387 miles, then convert it into inches
+ NewDistance = Distance.Parse("14, 387 statute miles").ToInches;
+ // Parse an untrimmed measurement into 50 feet
+ NewDistance = Distance.Parse(" 50 ' ");
+
+ | ##0.## uu | +## uuuu | +# u | +### | +
+ ' Declare a distance of 75 miles
+ Dim MyDistance As New Distance(75, DistanceUnit.StatuteMiles)
+ ' Set the text box to the distance, formatted as a string
+ MyTextBox.Text = MyDistance.ToString("## uuu", CultureInfo.CurrentUICulture)
+
+
+ // Declare a distance of 75 miles
+ Distance MyDistance = new Distance(75, DistanceUnit.StatuteMiles);
+ // Set the text box to the distance, formatted as a string
+ MyTextBox.Text = MyDistance.ToString("## uuu", CultureInfo.CurrentUICulture);
+
+
+ ' Declare a distance of 0 mi.
+ Dim MyDistance As New Distance(0, DistanceUnit.StatuteMiles)
+ ' Change the distance to 100 mi.
+ MyDistance.Value = 100
+ ' Change the distance to 12.3456 mi.
+ MyDistance.Value = 12.3456
+ ' Convert the measurement into kilometers
+ MyDistance = MyDistance.ToKilometers
+
+
+ // Declare a distance of 0 mi.
+ Distance MyDistance = new Distance(0, DistanceUnit.StatuteMiles);
+ // Change the distance to 100 mi.
+ MyDistance.Value = 100;
+ // Change the distance to 12.3456 mi.
+ MyDistance.Value = 12.3456;
+ // Convert the measurement into kilometers
+ MyDistance = MyDistance.ToKilometers;
+
+ 
+ ' Declare two distances
+ Dim Distance1 As New Distance(50, DistanceUnit.Meters)
+ Dim Distance2 As New Distance(100, DistanceUnit.Feet)
+ ' Store their sum in another variable
+ Dim Distance3 As New Distance(0, DistanceUnit.Meters)
+ ' INCORRECT: Changing Units property does not convert Distance2!
+ Distance2.Units = DistanceUnit.Meters
+ Distance3.Value = Distance1.Value + Distance2.Value
+
+
+ // Declare two distances
+ Distance Distance1 = new Distance(50, DistanceUnit.Meters);
+ Distance Distance2 = new Distance(100, DistanceUnit.Feet);
+ // Store their sum in another variable
+ Distance Distance3 = new Distance(0, DistanceUnit.Meters);
+ // INCORRECT: Changing Units property does not convert Distance2!
+ Distance2.Units = DistanceUnit.Meters;
+ Distance3.Value = Distance1.Value + Distance2.Value;
+
+ The correct technique is to use a conversion method to change the unit type instead
+ of modifying the Units property.
+
+ ' Declare two distances
+ Dim Distance1 As New Distance(50, DistanceUnit.Meters)
+ Dim Distance2 As New Distance(100, DistanceUnit.Feet)
+ ' Store their sum in another variable
+ Dim Distance3 As New Distance(0, DistanceUnit.Meters)
+ ' CORRECT: The ToMeters method is used to standardize unit types
+ Distance3.Value = Distance1.ToMeters().Value + Distance2.ToMeters().Value
+
+
+ // Declare two distances
+ Distance Distance1 = new Distance(50, DistanceUnit.Meters);
+ Distance Distance2 = new Distance(100, DistanceUnit.Feet);
+ // Store their sum in another variable
+ Distance Distance3 = new Distance(0, DistanceUnit.Meters);
+ // CORRECT: The ToMeters method is used to standardize unit types
+ Distance3.Value = Distance1.ToMeters().Value + Distance2.ToMeters().Value;
+
+
+ Dim MyElevation As New Elevation(90)
+
+
+ Elevation MyElevation = new Elevation(90);
+
+
+ Elevation MyElevation = new Elevation(90);
+
+
+ Dim MyElevation1 As New Elevation(105, 30, 21.4)
+
+
+ Elevation MyElevation = new Elevation(105, 30, 21.4);
+
+
+ Elevation MyElevation = new Elevation(105, 30, 21.4);
+
+
+ Dim MyElevation As Elevation = Elevation.Minimum
+
+
+ Elevation MyElevation = Elevation.Minimum;
+
+
+ Elevation MyElevation = Elevation.Minimum;
+
+
+ Dim MyElevation As Elevation = Elevation.Maximum
+
+
+ Elevation MyElevation = Elevation.Maximum;
+
+
+ Dim MyElevation As New Elevation(90)
+
+
+ Elevation MyElevation = new Elevation(90);
+
+
+ Dim MyElevation As New Elevation(12, 42.345)
+
+
+ Elevation MyElevation = new Elevation(12, 42.345);
+
+
+ Dim MyElevation As New Elevation(34, 12, 29.2)
+
+
+ Elevation MyElevation = new Elevation(34, 12, 29.2);
+
+
+ Dim MyElevation As New Elevation("123°45'67.8""")
+
+
+ Elevation MyElevation = new Elevation("123°45'67.8\"");
+
+
+ Dim Elevation1 As New Elevation(45)
+ Dim Elevation2 As Elevation = Elevation1.Mirror()
+ Debug.WriteLine(Elevation2.ToString())
+ ' Output: 225
+
+
+ Elevation Elevation1 = new Elevation(45);
+ Elevation Elevation2 = Elevation1.Mirror();
+ Console.WriteLine(Elevation2.ToString());
+ // Output: 225
+
+
+ Dim MyElevation As New Elevation(90)
+ Dim MyRadians As Radian = MyElevation.ToRadians()
+
+
+ Elevation MyElevation = new Elevation(90);
+ Radian MyRadians = MyElevation.ToRadians();
+
+
+ Dim MyElevation As New Elevation(45, 16.772)
+ Debug.WriteLine(MyElevation.ToString("h°m.mm"))
+ ' Output: 45°16.78
+
+
+ Dim MyElevation As New Elevation(45, 16.772);
+ Debug.WriteLine(MyElevation.ToString("h°m.mm"));
+ // Output: 45°16.78
+
+
+ Dim MyElevation As New Elevation(90)
+ Debug.WriteLine(MyElevation.ToString)
+ ' Output: "90°"
+
+
+ Elevation MyElevation = new Elevation(90);
+ Debug.WriteLine(MyElevation.ToString());
+ // Output: "90°"
+
+
+ Dim MyValue As Double = Latitude.ToDecimalDegrees(10, 30, 0)
+
+
+ double MyValue = Latitude.ToDecimalDegrees(10, 30, 0);
+
+
+ Dim MyRadian As Radian = Elevation.ToRadians(90)
+
+
+ Radian MyRadian = Elevation.ToRadians(90);
+
+
+ ' Create a new angle equal to one radian
+ Dim MyRadians As New Radian(1)
+ Dim MyElevation As Elevation = Elevation.FromRadians(MyRadians)
+ Debug.WriteLine(MyElevation.ToString())
+ ' Output: 57°
+
+
+ // Create a new angle equal to one radian
+ Radian MyRadians = new Radian(1);
+ Elevation MyElevation = Elevation.FromRadians(MyRadians);
+ Console.WriteLine(MyElevation.ToString());
+ // Output: 57°
+
+
+ Dim NewElevation As Elevation = Elevation.Parse("123.45°")
+
+
+ Elevation NewElevation = Elevation.Parse("123.45°");
+
+
+ ' Correct use of Increment
+ Dim Elevation1 As New Elevation(89)
+ Elevation1 = Elevation1.Increment()
+ ' Incorrect use of Increment
+ Dim Elevation1 = New Elevation(89)
+ Elevation1.Increment()
+ 'notice Elevation1 will still be 89°!
+
+
+ // Correct use of Increment
+ Elevation Elevation1 = new Elevation(89);
+ Elevation1 = Elevation1.Increment();
+ // Incorrect use of Increment
+ Elevation Elevation1 = new Elevation(89);
+ Elevation1.Increment();
+ //notice Elevation1 will still be 89°!
+
+
+ Dim Elevation1 As New Elevation(45)
+ Elevation1 = Elevation1.Add(45)
+
+
+ Elevation Elevation1 = new Elevation(45);
+ Elevation1 = Elevation1.Add(45);
+
+
+ ' Correct use of Decrement
+ Dim Elevation1 As New Elevation(91)
+ Elevation1 = Elevation1.Decrement()
+ ' Incorrect use of Decrement
+ Dim Elevation1 = New Elevation(91)
+ Elevation1.Increment()
+ ' notice Elevation1 will still be 91°!
+
+
+ // Correct use of Decrement
+ Elevation Elevation1 = new Elevation(91);
+ Elevation1 = Elevation1.Decrement();
+ // Incorrect use of Decrement
+ Elevation Elevation1 = new Elevation(91);
+ Elevation1.Decrement();
+ // notice Elevation1 will still be 91°!
+
+
+ Dim Elevation1 As New Elevation(90)
+ Elevation1 = Elevation1.Subtract(30)
+
+
+ Elevation Elevation1 = new Elevation(90);
+ Elevation1 = Elevation1.Subtract(30);
+
+
+ Dim Elevation1 As New Elevation(30)
+ Elevation1 = Elevation1.Multiply(3)
+
+
+ Elevation Elevation1 = new Elevation(30);
+ Elevation1 = Elevation1.Multiply(3);
+
+
+ Dim Elevation1 As New Elevation(90)
+ Elevation1 = Elevation1.Divide(3)
+
+
+ Elevation Elevation1 = new Elevation(90);
+ Elevation1 = Elevation1.Divide(3);
+
+
+ Dim MyElevation As New Elevation(45, 16.772)
+ Debug.WriteLine(MyElevation.ToString("h°m.mm", CultureInfo.CurrentCulture))
+ ' Output: 45°16.78
+
+
+ Dim MyElevation As New Elevation(45, 16.772);
+ Debug.WriteLine(MyElevation.ToString("h°m.mm", CultureInfo.CurrentCulture));
+ // Output: 45°16.78
+
+
+ ' Equals will return False
+ Dim Elevation1 As New Elevation(90.15);
+ Dim Elevation2 As New Elevation(90.12);
+ If Elevation1.Equals(Elevation2, 2) Then
+ Debug.WriteLine("The values are the same to two digits of precision.");
+ ' Equals will return True
+ Dim Elevation1 As New Elevation(90.15);
+ Dim Elevation2 As New Elevation(90.12);
+ If Elevation1.Equals(Elevation2, 1) Then
+ Debug.WriteLine("The values are the same to one digit of precision.");
+
+
+ // Equals will return False
+ Elevation Elevation1 = new Elevation(90.15);
+ Elevation Elevation2 = new Elevation(90.12);
+ if (Elevation1.Equals(Elevation2, 2))
+ Console.WriteLine("The values are the same to two digits of precision.");
+ // Equals will return True
+ Elevation Elevation1 = new Elevation(90.15);
+ Elevation Elevation2 = new Elevation(90.12);
+ if (Elevation1.Equals(Elevation2, 1))
+ Console.WriteLine("The values are the same to one digits of precision.");
+
+
+ ' Create an angle of 20°30'
+ Dim MyElevation As New Elevation(20, 30)
+ ' Setting the DecimalMinutes recalculated other properties
+ Debug.WriteLine(MyElevation.DecimalDegrees)
+ ' Output: "20.5" the same as 20°30'
+
+
+ // Create an angle of 20°30'
+ Elevation MyElevation = New Elevation(20, 30);
+ // Setting the DecimalMinutes recalculated other properties
+ Console.WriteLine(MyElevation.DecimalDegrees)
+ // Output: "20.5" the same as 20°30'
+
+
+ ' Create an angle of 20°10'30"
+ Dim MyElevation As New Elevation(20, 10, 30)
+ ' The DecimalMinutes property is automatically calculated
+ Debug.WriteLine(MyElevation.DecimalMinutes)
+ ' Output: "10.5"
+
+
+ // Create an angle of 20°10'30"
+ Elevation MyElevation = new Elevation(20, 10, 30);
+ // The DecimalMinutes property is automatically calculated
+ Console.WriteLine(MyElevation.DecimalMinutes)
+ // Output: "10.5"
+
+
+ Dim MyElevation As New Elevation(60.5)
+ Debug.WriteLine(MyElevation.Hours)
+ ' Output: 60
+
+
+ Elevation MyElevation = new Elevation(60.5);
+ Console.WriteLine(MyElevation.Hours);
+ // Output: 60
+
+
+ Dim MyElevation As New Elevation(45.5)
+ Debug.WriteLine(MyElevation.Minutes)
+ ' Output: 30
+
+
+ Elevation MyElevation = new Elevation(45.5);
+ Console.WriteLine(MyElevation.Minutes);
+ // Output: 30
+
+
+ Dim MyElevation As New Elevation(45, 10.5)
+ Debug.WriteLine(MyElevation.Seconds)
+ ' Output: 30
+
+
+ Dim MyElevation As New Elevation(45, 10.5);
+ Console.WriteLine(MyElevation.Seconds);
+ // Output: 30
+
+
+ ' Declare a new event
+ Dim MyAngleEvent As AngleEventHandler
+ Sub Main()
+ ' Create an angle of 90°
+ Dim MyAngle As New Angle(90);
+ ' Raise our custom Event
+ RaiseEvent MyAngleEvent(Me, New AngleEventArgs(MyAngle));
+ End Sub
+
+
+ // Declare a new event
+ AngleEventHandler MyAngleEvent;
+ void Main()
+ {
+ // Create an angle of 90°
+ Angle MyAngle = new Angle(90);
+ // Raise our custom event
+ if (MyAngleEvent != null)
+ MyAngleEvent(this, new AngleEventArgs(MyAngle));
+ }
+
+
+ ' Declare a new event
+ Dim MyAreaEvent As AreaEventHandler
+ Sub Main()
+ ' Create a Area of 125 kilometers
+ Dim MyArea As New Area(125, AreaUnit.SquareKilometers)
+ ' Raise our custom event
+ RaiseEvent MyAreaEvent(Me, New AreaEventArgs(MyArea))
+ End Sub
+
+
+ // Declare a new event
+ AreaEventHandler MyAreaEvent;
+ void Main()
+ {
+ // Create a Area of 125 kilometers
+ Area MyArea = new Area(125, AreaUnit.SquareKilometers);
+ // Raise our custom event
+ if (MyAreaEvent != null)
+ MyAreaEvent(this, New AreaEventArgs(MyArea));
+ }
+
+
+ ' Declare a new event
+ Dim MyAzimuthEvent As AzimuthEventHandler
+ Sub Main()
+ ' Create an angle of 90°
+ Dim MyAzimuth As New Azimuth(90);
+ ' Raise our custom Event
+ RaiseEvent MyAzimuthEvent(Me, New AzimuthEventArgs(MyAzimuth));
+ End Sub
+
+
+ // Declare a new event
+ AzimuthEventHandler MyAzimuthEvent;
+ void Main()
+ {
+ // Create an angle of 90°
+ Azimuth MyAzimuth = new Azimuth(90);
+ // Raise our custom event
+ if (MyAzimuthEvent != null)
+ MyAzimuthEvent(this, new AzimuthEventArgs(MyAzimuth));
+ }
+
+
+ ' Declare a new event
+ Dim MyDistanceEvent As DistanceEventHandler
+ ' Create a distance of 125 kilometers
+ Dim MyDistance As New Distance(125, DistanceUnit.Kilometers)
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyDistanceEvent(Me, New DistanceEventArgs(MyDistance))
+ End Sub
+
+
+ // Declare a new event
+ DistanceEventHandler MyDistanceEvent;
+ // Create a distance of 125 kilometers
+ Distance MyDistance = new Distance(125, DistanceUnit.Kilometers);
+ void Main()
+ {
+ // Raise our custom event
+ MyDistanceEvent(this, New DistanceEventArgs(MyDistance));
+ }
+
+
+ ' Declare a new event
+ Dim MyElevationEvent As ElevationEventHandler
+ Sub Main()
+ ' Create an angle of 90°
+ Dim MyElevation As New Elevation(90);
+ ' Raise our custom Event
+ RaiseEvent MyElevationEvent(Me, New ElevationEventArgs(MyElevation));
+ End Sub
+
+
+ // Declare a new event
+ ElevationEventHandler MyElevationEvent;
+ void Main()
+ {
+ // Create an angle of 90°
+ Elevation MyElevation = new Elevation(90);
+ // Raise our custom event
+ if (MyElevationEvent != null)
+ MyElevationEvent(this, new ElevationEventArgs(MyElevation));
+ }
+
+
+ ' Declare a new event
+ Dim MyLatitudeEvent As LatitudeEventHandler
+ Sub Main()
+ ' Create an angle of 90°
+ Dim MyLatitude As New Latitude(90);
+ ' Raise our custom Event
+ RaiseEvent MyLatitudeEvent(Me, New LatitudeEventArgs(MyLatitude));
+ End Sub
+
+
+ // Declare a new event
+ LatitudeEventHandler MyLatitudeEvent;
+ void Main()
+ {
+ // Create an angle of 90°
+ Latitude MyLatitude = new Latitude(90);
+ // Raise our custom event
+ if (MyLatitudeEvent != null)
+ MyLatitudeEvent(this, new LatitudeEventArgs(MyLatitude));
+ }
+
+
+ ' Declare a new event
+ Dim MyLongitudeEvent As LongitudeEventHandler
+ Sub Main()
+ ' Create an angle of 90°
+ Dim MyLongitude As New Longitude(90);
+ ' Raise our custom Event
+ RaiseEvent MyLongitudeEvent(Me, New LongitudeEventArgs(MyLongitude));
+ End Sub
+
+
+ // Declare a new event
+ LongitudeEventHandler MyLongitudeEvent;
+ void Main()
+ {
+ // Create an angle of 90°
+ Longitude MyLongitude = new Longitude(90);
+ // Raise our custom event
+ if (MyLongitudeEvent != null)
+ MyLongitudeEvent(this, new LongitudeEventArgs(MyLongitude));
+ }
+
+
+ ' Create a new exception
+ Dim MyException As New ApplicationException("The error was successfully created.")
+ ' Declare a new event
+ Dim MyErrorEvent As ExceptionEventHandler
+ Sub Main()
+ ' Raise our custom event
+ RaiseEvent MyErrorEvent(Me, New ExceptionEventArgs(MyException))
+ End Sub
+
+
+ // Create a new exception
+ ApplicationException MyException = new ApplicationException("The error was successfully created.")
+ // Declare a new event
+ ExceptionEventHandler MyErrorEvent;
+ void Main()
+ {
+ // Raise our custom event
+ MySatelliteEvent(this, New ExceptionEventArgs(MyException));
+ }
+
+
+ Dim MyLatitude As New Latitude(90)
+
+
+ Latitude MyLatitude = new Latitude(90);
+
+
+ Latitude MyLatitude = new Latitude(90);
+
+
+ Dim MyLatitude1 As New Latitude(105, 30, 21.4)
+
+
+ Latitude MyLatitude = new Latitude(105, 30, 21.4);
+
+
+ Latitude MyLatitude = new Latitude(105, 30, 21.4);
+
+
+ Dim MyLatitude As New Latitude(90)
+
+
+ Latitude MyLatitude = new Latitude(90);
+
+
+ Dim MyLatitude As New Latitude(39.5, LatitudeHemisphere.North)
+
+
+ Latitude MyLatitude = new Latitude(39.5, LatitudeHemisphere.North);
+
+ This example creates a new latitude of 39°30 south.
+
+ Dim MyLatitude As New Latitude(39.5, LatitudeHemisphere.South)
+
+
+ Latitude MyLatitude = new Latitude(39.5, LatitudeHemisphere.South);
+
+
+ Dim MyLatitude As New Latitude(34, 12, 29.2)
+
+
+ Latitude MyLatitude = new Latitude(34, 12, 29.2);
+
+
+ Dim MyLatitude As New Latitude(39, 12, 10, LatitudeHemisphere.North)
+
+
+ Latitude MyLatitude = new Latitude(39, 12, 10, LatitudeHemisphere.North);
+
+ This example creates a new latitude of 39°12'10" south.
+
+ Dim MyLatitude As New Latitude(39, 12, 10, LatitudeHemisphere.South)
+
+
+ Latitude MyLatitude = new Latitude(39, 12, 10, LatitudeHemisphere.South);
+
+
+ Dim MyLatitude As New Latitude(12, 42.345)
+
+
+ Latitude MyLatitude = new Latitude(12, 42.345);
+
+
+ Dim MyLatitude As New Latitude(39, 12.34, LatitudeHemisphere.North)
+
+
+ Latitude MyLatitude = new Latitude(39, 12.34, LatitudeHemisphere.North);
+
+ This example creates a new latitude of 39°12.34 south.
+
+ Dim MyLatitude As New Latitude(39, 12.34, LatitudeHemisphere.South)
+
+
+ Latitude MyLatitude = new Latitude(39, 12.34, LatitudeHemisphere.South);
+
+
+ Dim MyLatitude As New Latitude("23°45'67.8""N")
+
+
+ Latitude MyLatitude = new Latitude("23°45'67.8\"N");
+
+
+ Dim MyLatitude As New Latitude("23°45'67.8""N")
+
+
+ Latitude MyLatitude = new Latitude("23°45'67.8\"N");
+
+
+ Dim Latitude1 As New Latitude(45)
+ Dim Latitude2 As Latitude = Latitude1.Mirror()
+ Debug.WriteLine(Latitude2.ToString())
+ ' Output: 225
+
+
+ Latitude Latitude1 = new Latitude(45);
+ Latitude Latitude2 = Latitude1.Mirror();
+ Console.WriteLine(Latitude2.ToString());
+ // Output: 225
+
+
+ Dim MyLatitude As New Latitude(90)
+ Dim MyRadians As Radian = MyLatitude.ToRadians()
+
+
+ Latitude MyLatitude = new Latitude(90);
+ Radian MyRadians = MyLatitude.ToRadians();
+
+
+ Dim MyLatitude As New Latitude(45, 16.772)
+ Debug.WriteLine(MyLatitude.ToString("h°m.mm"))
+ ' Output: 45°16.78
+
+
+ Dim MyLatitude As New Latitude(45, 16.772);
+ Debug.WriteLine(MyLatitude.ToString("h°m.mm"));
+ // Output: 45°16.78
+
+
+ Dim MyLatitude As New Latitude(90)
+ Debug.WriteLine(MyLatitude.ToString)
+ ' Output: "90°"
+
+
+ Latitude MyLatitude = new Latitude(90);
+ Debug.WriteLine(MyLatitude.ToString());
+ // Output: "90°"
+
+
+ Dim MyValue As Double = Latitude.ToDecimalDegrees(10, 30, 0)
+
+
+ double MyValue = Latitude.ToDecimalDegrees(10, 30, 0);
+
+
+ Dim MyRadian As Radian = Latitude.ToRadians(90)
+
+
+ Radian MyRadian = Latitude.ToRadians(90);
+
+
+ ' Create a new angle equal to one radian
+ Dim MyRadians As New Radian(1)
+ Dim MyLatitude As Latitude = Latitude.FromRadians(MyRadians)
+ Debug.WriteLine(MyLatitude.ToString())
+ ' Output: 57°
+
+
+ // Create a new angle equal to one radian
+ Radian MyRadians = new Radian(1);
+ Latitude MyLatitude = Latitude.FromRadians(MyRadians);
+ Console.WriteLine(MyLatitude.ToString());
+ // Output: 57°
+
+
+ Dim NewLatitude As Latitude = Latitude.Parse("123.45°")
+
+
+ Latitude NewLatitude = Latitude.Parse("123.45°");
+
+
+ ' Correct use of Increment
+ Dim Latitude1 As New Latitude(89)
+ Latitude1 = Latitude1.Increment()
+ ' Incorrect use of Increment
+ Dim Latitude1 = New Latitude(89)
+ Latitude1.Increment()
+ ' notice: Latitude1 will still be 89°!
+
+
+ // Correct use of Increment
+ Latitude Latitude1 = new Latitude(89);
+ Latitude1 = Latitude1.Increment();
+ // Incorrect use of Increment
+ Latitude Latitude1 = new Latitude(89);
+ Latitude1.Increment();
+ // notice: Latitude1 will still be 89°!
+
+
+ Dim Latitude1 As New Latitude(45)
+ Latitude1 = Latitude1.Add(45)
+
+
+ Latitude Latitude1 = new Latitude(45);
+ Latitude1 = Latitude1.Add(45);
+
+
+ ' Correct use of Decrement
+ Dim Latitude1 As New Latitude(91)
+ Latitude1 = Latitude1.Decrement()
+ ' Incorrect use of Decrement
+ Dim Latitude1 = New Latitude(91)
+ Latitude1.Increment()
+ ' notice Latitude1 will still be 91°!
+
+
+ // Correct use of Decrement
+ Latitude Latitude1 = new Latitude(91);
+ Latitude1 = Latitude1.Decrement();
+ // Incorrect use of Decrement
+ Latitude Latitude1 = new Latitude(91);
+ Latitude1.Decrement();
+ // notice Latitude1 will still be 91°!
+
+
+ Dim Latitude1 As New Latitude(90)
+ Latitude1 = Latitude1.Subtract(30)
+
+
+ Latitude Latitude1 = new Latitude(90);
+ Latitude1 = Latitude1.Subtract(30);
+
+
+ Dim Latitude1 As New Latitude(30)
+ Latitude1 = Latitude1.Multiply(3)
+
+
+ Latitude Latitude1 = new Latitude(30);
+ Latitude1 = Latitude1.Multiply(3);
+
+
+ Dim Latitude1 As New Latitude(90)
+ Latitude1 = Latitude1.Divide(3)
+
+
+ Latitude Latitude1 = new Latitude(90);
+ Latitude1 = Latitude1.Divide(3);
+
+
+ ' Equals will return False
+ Dim Latitude1 As New Latitude(90.15);
+ Dim Latitude2 As New Latitude(90.12);
+ If Latitude1.Equals(Latitude2, 2) Then
+ Debug.WriteLine("The values are the same to two digits of precision.");
+ ' Equals will return True
+ Dim Latitude1 As New Latitude(90.15);
+ Dim Latitude2 As New Latitude(90.12);
+ If Latitude1.Equals(Latitude2, 1) Then
+ Debug.WriteLine("The values are the same to one digit of precision.");
+
+
+ // Equals will return False
+ Latitude Latitude1 = new Latitude(90.15);
+ Latitude Latitude2 = new Latitude(90.12);
+ if (Latitude1.Equals(Latitude2, 2))
+ Console.WriteLine("The values are the same to two digits of precision.");
+ // Equals will return True
+ Latitude Latitude1 = new Latitude(90.15);
+ Latitude Latitude2 = new Latitude(90.12);
+ if (Latitude1.Equals(Latitude2, 1))
+ Console.WriteLine("The values are the same to one digits of precision.");
+
+
+ Dim MyLatitude As New Latitude(45, 16.772)
+ Debug.WriteLine(MyLatitude.ToString("h°m.mm", CultureInfo.CurrentCulture))
+ ' Output: 45°16.78
+
+
+ Dim MyLatitude As New Latitude(45, 16.772);
+ Debug.WriteLine(MyLatitude.ToString("h°m.mm", CultureInfo.CurrentCulture));
+ // Output: 45°16.78
+
+
+ ' Create an angle of 20°30'
+ Dim MyLatitude As New Latitude(20, 30)
+ ' Setting the DecimalMinutes recalculated other properties
+ Debug.WriteLine(MyLatitude.DecimalDegrees)
+ ' Output: "20.5" the same as 20°30'
+
+
+ // Create an angle of 20°30'
+ Latitude MyLatitude = New Latitude(20, 30);
+ // Setting the DecimalMinutes recalculated other properties
+ Console.WriteLine(MyLatitude.DecimalDegrees)
+ // Output: "20.5" the same as 20°30'
+
+
+ ' Create an angle of 20°10'30"
+ Dim MyLatitude As New Latitude(20, 10, 30)
+ ' The DecimalMinutes property is automatically calculated
+ Debug.WriteLine(MyLatitude.DecimalMinutes)
+ ' Output: "10.5"
+
+
+ // Create an angle of 20°10'30"
+ Latitude MyLatitude = new Latitude(20, 10, 30);
+ // The DecimalMinutes property is automatically calculated
+ Console.WriteLine(MyLatitude.DecimalMinutes)
+ // Output: "10.5"
+
+
+ Dim MyLatitude As New Latitude(60.5)
+ Debug.WriteLine(MyLatitude.Hours)
+ ' Output: 60
+
+
+ Latitude MyLatitude = new Latitude(60.5);
+ Console.WriteLine(MyLatitude.Hours);
+ // Output: 60
+
+
+ Dim MyLatitude As New Latitude(45.5)
+ Debug.WriteLine(MyLatitude.Minutes)
+ ' Output: 30
+
+
+ Latitude MyLatitude = new Latitude(45.5);
+ Console.WriteLine(MyLatitude.Minutes);
+ // Output: 30
+
+
+ Dim MyLatitude As New Latitude(45, 10.5)
+ Debug.WriteLine(MyLatitude.Seconds)
+ ' Output: 30
+
+
+ Dim MyLatitude As New Latitude(45, 10.5);
+ Console.WriteLine(MyLatitude.Seconds);
+ // Output: 30
+
+
+ Dim MyLongitude As New Longitude(90)
+
+
+ Longitude MyLongitude = new Longitude(90);
+
+
+ Longitude MyLongitude = new Longitude(90);
+
+
+ Dim MyLongitude1 As New Longitude(105, 30, 21.4)
+
+
+ Longitude MyLongitude = new Longitude(105, 30, 21.4);
+
+
+ Longitude MyLongitude = new Longitude(105, 30, 21.4);
+
+
+ Dim MyLongitude As New Longitude(90)
+
+
+ Longitude MyLongitude = new Longitude(90);
+
+
+ Dim MyLongitude As New Longitude(39.5, LongitudeHemisphere.North)
+
+
+ Longitude MyLongitude = new Longitude(39.5, LongitudeHemisphere.North);
+
+ This example creates a new Longitude of 39°30 south.
+
+ Dim MyLongitude As New Longitude(39.5, LongitudeHemisphere.South)
+
+
+ Longitude MyLongitude = new Longitude(39.5, LongitudeHemisphere.South);
+
+
+ Dim MyLongitude As New Longitude(34, 12, 29.2)
+
+
+ Longitude MyLongitude = new Longitude(34, 12, 29.2);
+
+
+ Dim MyLongitude As New Longitude(12, 42.345)
+
+
+ Longitude MyLongitude = new Longitude(12, 42.345);
+
+
+ Dim MyLongitude As New Longitude(39, 12.34, LongitudeHemisphere.North)
+
+
+ Longitude MyLongitude = new Longitude(39, 12.34, LongitudeHemisphere.North);
+
+ This example creates a new Longitude of 39°12.34 south.
+
+ Dim MyLongitude As New Longitude(39, 12.34, LongitudeHemisphere.South)
+
+
+ Longitude MyLongitude = new Longitude(39, 12.34, LongitudeHemisphere.South);
+
+
+ Dim MyLongitude As New Longitude("123°45'67.8""")
+
+
+ Longitude MyLongitude = new Longitude("123°45'67.8\"");
+
+ | hh | +hh.h | +hh mm | +hh mm.mm | +
| hh mm ss | +hh mm ss.sss | +hhi | +hh.hi | +
| hh mmi | +hh mm i | +hh mm.mi | +hh mm.m i | +
| hh mm ssi | +hh mm ss i | +hh mm ss.si | +hh mm ss.s i | +
| hhhmmssi | ++ | + | + |
| hh | +hh.h | +hh mm | +hh mm.mm | +
| hh mm ss | +hh mm ss.sss | +hhi | +hh.hi | +
| hh mmi | +hh mm i | +hh mm.mi | +hh mm.m i | +
| hh mm ssi | +hh mm ss i | +hh mm ss.si | +hh mm ss.s i | +
| hhhmmssi | ++ | + | + |
+ Dim Longitude1 As New Longitude(45)
+ Dim Longitude2 As Longitude = Longitude1.Mirror()
+ Debug.WriteLine(Longitude2.ToString())
+ ' Output: 225
+
+
+ Longitude Longitude1 = new Longitude(45);
+ Longitude Longitude2 = Longitude1.Mirror();
+ Console.WriteLine(Longitude2.ToString());
+ // Output: 225
+
+
+ Dim MyLongitude As New Longitude(90)
+ Dim MyRadians As Radian = MyLongitude.ToRadians()
+
+
+ Longitude MyLongitude = new Longitude(90);
+ Radian MyRadians = MyLongitude.ToRadians();
+
+ | HH°MM'SS.SS" | +HHH.H° | +HH MM.MM | +HHHMMSS | +
| HH°MM'SS.SS"I | +HHH.H°I | +HH MM.MMI | +HHHMMSSI | +
+ Dim MyLongitude As New Longitude(45, 16.772)
+ Debug.WriteLine(MyLongitude.ToString("h°m.mm"))
+ ' Output: 45°16.78
+
+
+ Dim MyLongitude As New Longitude(45, 16.772);
+ Debug.WriteLine(MyLongitude.ToString("h°m.mm"));
+ // Output: 45°16.78
+
+
+ Dim MyLongitude As New Longitude(90)
+ Debug.WriteLine(MyLongitude.ToString)
+ ' Output: "90°"
+
+
+ Longitude MyLongitude = new Longitude(90);
+ Debug.WriteLine(MyLongitude.ToString());
+ // Output: "90°"
+
+
+ Dim MyRadian As Radian = Longitude.ToRadians(90)
+
+
+ Radian MyRadian = Longitude.ToRadians(90);
+
+
+ ' Create a new angle equal to one radian
+ Dim MyRadians As New Radian(1)
+ Dim MyLongitude As Longitude = Longitude.FromRadians(MyRadians)
+ Debug.WriteLine(MyLongitude.ToString())
+ ' Output: 57°
+
+
+ // Create a new angle equal to one radian
+ Radian MyRadians = new Radian(1);
+ Longitude MyLongitude = Longitude.FromRadians(MyRadians);
+ Console.WriteLine(MyLongitude.ToString());
+ // Output: 57°
+
+
+ Dim MyValue As Double = Latitude.ToDecimalDegrees(10, 30, 0)
+
+
+ double MyValue = Latitude.ToDecimalDegrees(10, 30, 0);
+
+
+ Dim NewLongitude As Longitude = Longitude.Parse("123.45°")
+
+
+ Longitude NewLongitude = Longitude.Parse("123.45°");
+
+
+ ' Correct use of Increment
+ Dim Longitude1 As New Longitude(89)
+ Longitude1 = Longitude1.Increment()
+ ' Incorrect use of Increment
+ Dim Longitude1 = New Longitude(89)
+ Longitude1.Increment()
+ ' notice: Longitude1 will still be 89°!
+
+
+ // Correct use of Increment
+ Longitude Longitude1 = new Longitude(89);
+ Longitude1 = Longitude1.Increment();
+ // Incorrect use of Increment
+ Longitude Longitude1 = new Longitude(89);
+ Longitude1.Increment();
+ // notice: Longitude1 will still be 89°!
+
+
+ Dim Longitude1 As New Longitude(45)
+ Longitude1 = Longitude1.Add(45)
+
+
+ Longitude Longitude1 = new Longitude(45);
+ Longitude1 = Longitude1.Add(45);
+
+
+ ' Correct use of Decrement
+ Dim Longitude1 As New Longitude(91)
+ Longitude1 = Longitude1.Decrement()
+ ' Incorrect use of Decrement
+ Dim Longitude1 = New Longitude(91)
+ Longitude1.Increment()
+ ' notice Longitude1 will still be 91°!
+
+
+ // Correct use of Decrement
+ Longitude Longitude1 = new Longitude(91);
+ Longitude1 = Longitude1.Decrement();
+ // Incorrect use of Decrement
+ Longitude Longitude1 = new Longitude(91);
+ Longitude1.Decrement();
+ // notice: Longitude1 will still be 91°!
+
+
+ Dim Longitude1 As New Longitude(90)
+ Longitude1 = Longitude1.Subtract(30)
+
+
+ Longitude Longitude1 = new Longitude(90);
+ Longitude1 = Longitude1.Subtract(30);
+
+
+ Dim Longitude1 As New Longitude(30)
+ Longitude1 = Longitude1.Multiply(3)
+
+
+ Longitude Longitude1 = new Longitude(30);
+ Longitude1 = Longitude1.Multiply(3);
+
+
+ Dim Longitude1 As New Longitude(90)
+ Longitude1 = Longitude1.Divide(3)
+
+
+ Longitude Longitude1 = new Longitude(90);
+ Longitude1 = Longitude1.Divide(3);
+
+
+ ' Equals will return False
+ Dim Longitude1 As New Longitude(90.15);
+ Dim Longitude2 As New Longitude(90.12);
+ If Longitude1.Equals(Longitude2, 2) Then
+ Debug.WriteLine("The values are the same to two digits of precision.");
+ ' Equals will return True
+ Dim Longitude1 As New Longitude(90.15);
+ Dim Longitude2 As New Longitude(90.12);
+ If Longitude1.Equals(Longitude2, 1) Then
+ Debug.WriteLine("The values are the same to one digit of precision.");
+
+
+ // Equals will return False
+ Longitude Longitude1 = new Longitude(90.15);
+ Longitude Longitude2 = new Longitude(90.12);
+ if (Longitude1.Equals(Longitude2, 2))
+ Console.WriteLine("The values are the same to two digits of precision.");
+ // Equals will return True
+ Longitude Longitude1 = new Longitude(90.15);
+ Longitude Longitude2 = new Longitude(90.12);
+ if (Longitude1.Equals(Longitude2, 1))
+ Console.WriteLine("The values are the same to one digits of precision.");
+
+ | HH°MM'SS.SS" | +HHH.H° | +HH MM.MM | +HHHMMSS | +
| HH°MM'SS.SS"I | +HHH.H°I | +HH MM.MMI | +HHHMMSSI | +
+ Dim MyLongitude As New Longitude(45, 16.772)
+ Debug.WriteLine(MyLongitude.ToString("h°m.mm", CultureInfo.CurrentCulture))
+ ' Output: 45°16.78
+
+
+ Dim MyLongitude As New Longitude(45, 16.772);
+ Debug.WriteLine(MyLongitude.ToString("h°m.mm", CultureInfo.CurrentCulture));
+ // Output: 45°16.78
+
+
+ ' Create an angle of 20°30'
+ Dim MyLongitude As New Longitude(20, 30)
+ ' Setting the DecimalMinutes recalculated other properties
+ Debug.WriteLine(MyLongitude.DecimalDegrees)
+ ' Output: "20.5" the same as 20°30'
+
+
+ // Create an angle of 20°30'
+ Longitude MyLongitude = New Longitude(20, 30);
+ // Setting the DecimalMinutes recalculated other properties
+ Console.WriteLine(MyLongitude.DecimalDegrees)
+ // Output: "20.5" the same as 20°30'
+
+
+ ' Create an angle of 20°10'30"
+ Dim MyLongitude As New Longitude(20, 10, 30)
+ ' The DecimalMinutes property is automatically calculated
+ Debug.WriteLine(MyLongitude.DecimalMinutes)
+ ' Output: "10.5"
+
+
+ // Create an angle of 20°10'30"
+ Longitude MyLongitude = new Longitude(20, 10, 30);
+ // The DecimalMinutes property is automatically calculated
+ Console.WriteLine(MyLongitude.DecimalMinutes)
+ // Output: "10.5"
+
+
+ Dim MyLongitude As New Longitude(60.5)
+ Debug.WriteLine(MyLongitude.Hours)
+ ' Output: 60
+
+
+ Longitude MyLongitude = new Longitude(60.5);
+ Console.WriteLine(MyLongitude.Hours);
+ // Output: 60
+
+
+ Dim MyLongitude As New Longitude(45.5)
+ Debug.WriteLine(MyLongitude.Minutes)
+ ' Output: 30
+
+
+ Longitude MyLongitude = new Longitude(45.5);
+ Console.WriteLine(MyLongitude.Minutes);
+ // Output: 30
+
+
+ Dim MyLongitude As New Longitude(45, 10.5)
+ Debug.WriteLine(MyLongitude.Seconds)
+ ' Output: 30
+
+
+ Dim MyLongitude As New Longitude(45, 10.5);
+ Console.WriteLine(MyLongitude.Seconds);
+ // Output: 30
+
+
+ ' Create a distance of ten miles
+ Dim TravelDistance As New Distance(10, DistanceUnit.StatuteMiles)
+ ' Calculate the point
+ Dim DestinationPoint As Position
+ DestinationPoint = Position.CurrentPosition.TranslateTo(Azimuth.Northwest,
+ TravelDistance)
+
+ 
| vu | +vv.vu | +v u | +
| FEET | +FOOT | +METER | +
| METERS | +METRE | +METRES | +
| KILOMETER | +KILOMETRE | +KILOMETERS | +
| KILOMETRES | +KNOT | +KNOTS | +
| MILE | +MILES | +STATUTE MILE | +
| STATUTE MILES | +F | +FT | +
| M | +KM | +K | +
| PER | +-PER- | +/ | +
| SECOND | +SEC | +S | +
| HOUR | +HR | +H | +

+ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable)
+
+
+ int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
+
+
+ struct sqlite3_index_info {
+ /* Inputs */
+ const int nConstraint; /* Number of entries in aConstraint */
+ const struct sqlite3_index_constraint {
+ int iColumn; /* Column on left-hand side of
+ * constraint */
+ unsigned char op; /* Constraint operator */
+ unsigned char usable; /* True if this constraint is usable */
+ int iTermOffset; /* Used internally - xBestIndex should
+ * ignore */
+ } *const aConstraint; /* Table of WHERE clause constraints */
+ const int nOrderBy; /* Number of terms in the ORDER BY
+ * clause */
+ const struct sqlite3_index_orderby {
+ int iColumn; /* Column number */
+ unsigned char desc; /* True for DESC. False for ASC. */
+ } *const aOrderBy; /* The ORDER BY clause */
+ /* Outputs */
+ struct sqlite3_index_constraint_usage {
+ int argvIndex; /* if greater than zero, constraint is
+ * part of argv to xFilter */
+ unsigned char omit; /* Do not code a test for this
+ * constraint */
+ } *const aConstraintUsage;
+ int idxNum; /* Number used to identify the index */
+ char *idxStr; /* String, possibly obtained from
+ * sqlite3_malloc() */
+ int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if
+ * true */
+ int orderByConsumed; /* True if output is already ordered */
+ double estimatedCost; /* Estimated cost of using this index */
+ };
+
+
+ #define SQLITE_INDEX_CONSTRAINT_EQ 2
+ #define SQLITE_INDEX_CONSTRAINT_GT 4
+ #define SQLITE_INDEX_CONSTRAINT_LE 8
+ #define SQLITE_INDEX_CONSTRAINT_LT 16
+ #define SQLITE_INDEX_CONSTRAINT_GE 32
+ #define SQLITE_INDEX_CONSTRAINT_MATCH 64
+
+
+ column OP EXPR
+
+
+ a = 5
+
+
+ x BETWEEN 10 AND 100 AND 999>y
+
+
+ x >= 10
+ x <= 100
+ y < 999
+
+
+ sqlite3_result_blob()
+ sqlite3_result_double()
+ sqlite3_result_int()
+ sqlite3_result_int64()
+ sqlite3_result_null()
+ sqlite3_result_text()
+ sqlite3_result_text16()
+ sqlite3_result_text16le()
+ sqlite3_result_text16be()
+ sqlite3_result_zeroblob()
+
+
+ argc = 1
+
+
+ argc > 1
+ argv[0] = NULL
+
+
+ argc > 1
+ argv[0] ? NULL
+ argv[0] = argv[1]
+
+
+ argc > 1
+ argv[0] ? NULL
+ argv[0] ? argv[1]
+
+
+ UPDATE table SET rowid=rowid+1 WHERE ...;
+
+
+ public static class Sample
+ {
+ public static void Main()
+ {
+ using (SQLiteConnection connection = new SQLiteConnection(
+ "Data Source=:memory:;"))
+ {
+ connection.Open();
+
+ connection.CreateModule(new SQLiteModuleEnumerable(
+ "sampleModule", new string[] { "one", "two", "three" }));
+
+ using (SQLiteCommand command = connection.CreateCommand())
+ {
+ command.CommandText =
+ "CREATE VIRTUAL TABLE t1 USING sampleModule;";
+
+ command.ExecuteNonQuery();
+ }
+
+ using (SQLiteCommand command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT * FROM t1;";
+
+ using (SQLiteDataReader dataReader = command.ExecuteReader())
+ {
+ while (dataReader.Read())
+ Console.WriteLine(dataReader[0].ToString());
+ }
+ }
+
+ connection.Close();
+ }
+ }
+ }
+
+ this, if the geometry is not a collection.
+ this, if the geometry is not a collection.
+ PriorityQueue object. The
+ PriorityQueue object allows objects to be
+ entered into the queue and to leave in the order of
+ priority i.e the highest priority get's to leave first.
+ PriorityQueue object. The
+ PriorityQueue object allows objects to
+ be entered into the queue an to leave in the order of
+ priority i.e the highest priority get's to leave first.
+
+ @param capacity the initial capacity of the queue before
+ a resize
+ PriorityQueue object. The
+ PriorityQueue object allows objects to
+ be entered into the queue an to leave in the order of
+ priority i.e the highest priority get's to leave first.
+
+ @param capacity the initial capacity of the queue before
+ a resize
+ @param maxPriority is the maximum possible priority for
+ an object
+ PriorityQueue,
+ its priority is the long priority. The way in which priority can be
+ associated with the elements of the queue is by keeping the priority
+ and the elements array entrys parallel.
+
+ @param element is the object that is to be entered into this
+ PriorityQueue
+ @param priority this is the priority that the object holds in the
+ PriorityQueue
+ PriorityQueue). If the priority of an element
+ at subscript 'pos' is less than it's children then it must
+ be put under one of these children, i.e the ones with the
+ maximum priority must come first.
+
+ @param pos is the position within the arrays of the element
+ and priority
+