public void OnDownloadProgressChanged(MyProgress value) { var args = new MyDownloadEventArgs() { TotalFileSize = value.TotalFileSize, CurrentFileSize = value.CurrentFileSize }; DownloadProgressChanged?.Invoke(this, args); }
public void Progress_ToObserver() { var xs = new List <int>(); var p = new MyProgress <int>(xs.Add); var o = p.ToObserver(); o.OnNext(42); o.OnNext(43); Assert.IsTrue(xs.SequenceEqual(new[] { 42, 43 })); }
private void SetProgress(MyProgress progress) { Action action = () => { this.textBox1.Text = progress.Circle; this.textBox2.Text = progress.Status; }; if (this.InvokeRequired) { this.Invoke(action); } else { action(); } }
private static double SendDownloadProgress(IProgress <MyProgress> onProgressChanged, Model.Download download, double oldPercentDone) { var myProgress = new MyProgress() { CurrentFileSize = download.GetBytesFromAllParts(), TotalFileSize = download.TotalFileSize }; var percentDone = (double)myProgress.CurrentFileSize / myProgress.TotalFileSize; if (!(percentDone - oldPercentDone > 0.05)) { return(oldPercentDone); } onProgressChanged?.Report(myProgress); return(percentDone); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.lblCurrentOp = new System.Windows.Forms.Label(); this.lblOp = new System.Windows.Forms.Label(); this.lblProgrress = new System.Windows.Forms.Label(); this.lblProg = new System.Windows.Forms.Label(); this.btnCancel = new Avat.Components.RoundedButton(); this.progressBar = new Avat.Components.MyProgress(); this.SuspendLayout(); // // lblCurrentOp // this.lblCurrentOp.Anchor = System.Windows.Forms.AnchorStyles.None; this.lblCurrentOp.AutoSize = true; this.lblCurrentOp.ForeColor = System.Drawing.Color.Gray; this.lblCurrentOp.Location = new System.Drawing.Point(12, 14); this.lblCurrentOp.Name = "lblCurrentOp"; this.lblCurrentOp.Size = new System.Drawing.Size(99, 13); this.lblCurrentOp.TabIndex = 1; this.lblCurrentOp.Text = "Aktuálna operácia: "; // // lblOp // this.lblOp.Anchor = System.Windows.Forms.AnchorStyles.None; this.lblOp.AutoSize = true; this.lblOp.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblOp.ForeColor = System.Drawing.Color.Gray; this.lblOp.Location = new System.Drawing.Point(117, 14); this.lblOp.Name = "lblOp"; this.lblOp.Size = new System.Drawing.Size(44, 13); this.lblOp.TabIndex = 2; this.lblOp.Text = "žiadna"; // // lblProgrress // this.lblProgrress.Anchor = System.Windows.Forms.AnchorStyles.None; this.lblProgrress.AutoSize = true; this.lblProgrress.ForeColor = System.Drawing.Color.Gray; this.lblProgrress.Location = new System.Drawing.Point(12, 59); this.lblProgrress.Name = "lblProgrress"; this.lblProgrress.Size = new System.Drawing.Size(49, 13); this.lblProgrress.TabIndex = 3; this.lblProgrress.Text = "Priebeh: "; // // lblProg // this.lblProg.Anchor = System.Windows.Forms.AnchorStyles.None; this.lblProg.AutoSize = true; this.lblProg.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblProg.ForeColor = System.Drawing.Color.Gray; this.lblProg.Location = new System.Drawing.Point(117, 59); this.lblProg.Name = "lblProg"; this.lblProg.Size = new System.Drawing.Size(44, 13); this.lblProg.TabIndex = 4; this.lblProg.Text = "žiadna"; // // btnCancel // this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.None; this.btnCancel.FlatAppearance.BorderColor = System.Drawing.Color.Gray; this.btnCancel.FlatAppearance.MouseDownBackColor = System.Drawing.Color.WhiteSmoke; this.btnCancel.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Gainsboro; this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnCancel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnCancel.ForeColor = System.Drawing.Color.Gray; this.btnCancel.Location = new System.Drawing.Point(401, 73); this.btnCancel.Margin = new System.Windows.Forms.Padding(0); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(100, 26); this.btnCancel.TabIndex = 5; this.btnCancel.TabStop = false; this.btnCancel.Text = "Cancel"; this.btnCancel.UseVisualStyleBackColor = false; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); // // progressBar // this.progressBar.Anchor = System.Windows.Forms.AnchorStyles.None; this.progressBar.Location = new System.Drawing.Point(15, 30); this.progressBar.Name = "progressBar"; this.progressBar.Size = new System.Drawing.Size(486, 26); this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous; this.progressBar.TabIndex = 0; // // Progress // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(518, 139); this.ControlBox = false; this.Controls.Add(this.btnCancel); this.Controls.Add(this.lblProg); this.Controls.Add(this.lblProgrress); this.Controls.Add(this.lblOp); this.Controls.Add(this.lblCurrentOp); this.Controls.Add(this.progressBar); this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MinimumSize = new System.Drawing.Size(526, 147); this.Name = "Progress"; this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Priebeh"; this.ResumeLayout(false); this.PerformLayout(); }
private void SetProgress(MyProgress progress) { Action action = () => { this.textBox1.Text = progress.Circle; this.textBox2.Text = progress.Status; }; if (this.InvokeRequired) this.Invoke(action); else action(); }
public ProgressPage() { InitializeComponent(); MyProgress.ProgressTo(0.9, 1500, Easing.Linear); }
/// <summary> /// Download the requested books and create the appropriate index files for MSDN HelpViewer /// </summary> /// <param name="bookGroups"> /// The collection of bookGroups to with the books to download indicated by the Book.Wanted /// property /// </param> /// <param name="cachePath"> /// The path where the downloaded books are cached /// </param> /// <param name="progress"> /// Interface used to report the percentage progress back to the GUI /// </param> /// <exception cref="ArgumentNullException"> /// If any of the parameters are null /// </exception> /// <exception cref="WebException"> /// If the data cannot be downloaded /// </exception> /// <exception cref="XmlException"> /// If the data cannot be processed /// </exception> /// <exception cref="IOException"> /// If there was a problem reading or writing to the cache directory /// </exception> /// <exception cref="UnauthorizedAccessException"> /// If the user does not have permission to write to the cache directory /// </exception> /// <exception cref="InvalidOperationException"> /// If the data cannot be processed /// </exception> public void DownloadBooks(ICollection <BookGroup> bookGroups, string cachePath, string finalDirectory, Locale locale, MyProgress progress) { if (bookGroups == null) { throw new ArgumentNullException("bookGroups"); } if (cachePath == null) { throw new ArgumentNullException("cachePath"); } if (cachePath == null) { throw new ArgumentNullException("progress"); } // Create cachePath string targetDirectory = Path.Combine(cachePath, "Packages"); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } // Create content directories string contentDirectory = null; string indexDirectory = null; if (finalDirectory != null) { if (!Directory.Exists(finalDirectory)) { Directory.CreateDirectory(finalDirectory); } contentDirectory = Path.Combine(finalDirectory, "ContentStore"); if (!Directory.Exists(contentDirectory)) { Directory.CreateDirectory(contentDirectory); } indexDirectory = Path.Combine(finalDirectory, "IndexStore"); if (!Directory.Exists(indexDirectory)) { Directory.CreateDirectory(indexDirectory); } string localeName = "en-US"; try { localeName = CultureInfo.CreateSpecificCulture(locale.Name).Name; } catch { } contentDirectory = Path.Combine(contentDirectory, localeName); if (!Directory.Exists(contentDirectory)) { Directory.CreateDirectory(contentDirectory); } indexDirectory = Path.Combine(indexDirectory, localeName); if (!Directory.Exists(indexDirectory)) { Directory.CreateDirectory(indexDirectory); } } // Create locale name // Cleanup index files Directory.GetFiles(cachePath, "*.msha").ForEach(File.Delete); Directory.GetFiles(cachePath, "*.xml").ForEach(File.Delete); // Creating setup indexes File.WriteAllText( Path.Combine(cachePath, "HelpContentSetup.msha"), HelpIndexManager.CreateSetupIndex(bookGroups), Encoding.UTF8); // Create list of unique packages for possible download and write the book group and // book index files Dictionary <string, Package> packages = new Dictionary <string, Package>(); foreach (BookGroup bookGroup in bookGroups) { File.WriteAllText( Path.Combine(cachePath, bookGroup.CreateFileName()), HelpIndexManager.CreateBookGroupBooksIndex(bookGroup), Encoding.UTF8); Debug.Print("BookGroup: {0}", bookGroup.Name); foreach (Book book in bookGroup.Books) { if (book.Wanted) { Debug.Print(" Book: {0}", book.Name); File.WriteAllText( Path.Combine(cachePath, book.CreateFileName()), HelpIndexManager.CreateBookPackagesIndex(bookGroup, book), Encoding.UTF8); foreach (Package package in book.Packages) { string name = package.Name.ToUpperInvariant(); Debug.Print(" Package: {0}", name); if (!packages.ContainsKey(name)) { packages.Add(name, package); } } } } } // Cleanup old files foreach (string file in Directory.GetFiles(targetDirectory, "*.cab")) { string fileName = Path.GetFileNameWithoutExtension(file); if (!string.IsNullOrEmpty(fileName)) { fileName = fileName.ToUpperInvariant(); if (!packages.ContainsKey(fileName)) { File.Delete(file); } } } // Download the packages int packagesCountCurrent = 0; client.BaseAddress = "http://packages.mtps.microsoft.com/"; foreach (Package package in packages.Values) { string targetFileName = Path.Combine(targetDirectory, package.CreateFileName()); if (package.State == PackageState.NotDownloaded || package.State == PackageState.OutOfDate) { Debug.Print(" Downloading : '{0}' to '{1}'", package.Link, targetFileName); client.DownloadFile(package.Link, targetFileName); File.SetCreationTime(targetFileName, package.LastModified); File.SetLastAccessTime(targetFileName, package.LastModified); File.SetLastWriteTime(targetFileName, package.LastModified); } progress.Report(100 * ++packagesCountCurrent / packages.Count); } // move files if (finalDirectory != null) { packagesCountCurrent = 0; progress.Report(0); Directory.GetFiles(contentDirectory, "*.*").ForEach(File.Delete); Directory.GetFiles(indexDirectory, "*.*").ForEach(File.Delete); foreach (Package package in packages.Values) { string targetFileName = Path.Combine(targetDirectory, package.CreateFileName()); Debug.Print(" Moving : '{0}' to '{1}'", targetFileName, finalDirectory); Move(targetFileName, contentDirectory, indexDirectory); progress.Report(100 * ++packagesCountCurrent / packages.Count); } } }
private void GetFilesToKeep(string sdk) { var myFiles = new List <string>(); string compressedArchivePath = Path.Combine(mSdksFolder, sdk, "nuGetPackagesArchive.lzma"); Console.WriteLine("Decompressing " + compressedArchivePath); using (var archiveStream = CreateTemporaryFileStream()) { // decompress the LZMA stream using (var lzmaStream = File.OpenRead(compressedArchivePath)) { var progress = new MyProgress(); CompressionUtility.Decompress(lzmaStream, archiveStream, progress); } // reset the uncompressed stream archiveStream.Seek(0, SeekOrigin.Begin); Console.WriteLine("Rooting files in " + compressedArchivePath); // read as a zip archive using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Read)) { var indexEntry = archive.GetEntry(IndexFileName); using (var indexReader = new StreamReader(indexEntry.Open())) { for (var line = indexReader.ReadLine(); line != null; line = indexReader.ReadLine()) { var lineParts = line.Split(pipeSeperator); if (lineParts.Length != 2) { throw new Exception("Unexpected index line format, too many '|'s."); } string target = lineParts[0]; string source = lineParts[1]; var zipSeperatorIndex = target.IndexOf("::", StringComparison.OrdinalIgnoreCase); string destinationPath; if (zipSeperatorIndex != -1) { string zipRelativePath = target.Substring(0, zipSeperatorIndex); destinationPath = Path.Combine(mFallbackFolder, zipRelativePath); } else { destinationPath = Path.Combine(mFallbackFolder, target); } //Normalize path (forward slash to backslash) myFiles.Add(Path.GetFullPath(destinationPath)); } } } } lock (mFilesToKeep) { foreach (var f in myFiles) { mFilesToKeep.Add(f); } } }
/// <summary> /// Download the requested books and create the appropriate index files for MSDN HelpViewer /// </summary> /// <param name="bookGroups"> /// The collection of bookGroups to with the books to download indicated by the Book.Wanted /// property /// </param> /// <param name="cachePath"> /// The path where the downloaded books are cached /// </param> /// <param name="progress"> /// Interface used to report the percentage progress back to the GUI /// </param> /// <exception cref="ArgumentNullException"> /// If any of the parameters are null /// </exception> /// <exception cref="WebException"> /// If the data cannot be downloaded /// </exception> /// <exception cref="XmlException"> /// If the data cannot be processed /// </exception> /// <exception cref="IOException"> /// If there was a problem reading or writing to the cache directory /// </exception> /// <exception cref="UnauthorizedAccessException"> /// If the user does not have permission to write to the cache directory /// </exception> /// <exception cref="InvalidOperationException"> /// If the data cannot be processed /// </exception> public void DownloadBooks( ICollection<BookGroup> bookGroups, string cachePath, string finalDirectory, Locale locale, MyProgress progress ) { if ( bookGroups == null ) { throw new ArgumentNullException( "bookGroups" ); } if ( cachePath == null ) { throw new ArgumentNullException( "cachePath" ); } if ( cachePath == null ) { throw new ArgumentNullException( "progress" ); } // Create cachePath string targetDirectory = Path.Combine( cachePath, "Packages" ); if ( !Directory.Exists( targetDirectory ) ) { Directory.CreateDirectory( targetDirectory ); } // Create content directories string contentDirectory = null; string indexDirectory = null; if (finalDirectory != null) { if ( !Directory.Exists( finalDirectory ) ) { Directory.CreateDirectory( finalDirectory ); } contentDirectory = Path.Combine( finalDirectory, "ContentStore" ); if ( !Directory.Exists( contentDirectory ) ) { Directory.CreateDirectory( contentDirectory ); } indexDirectory = Path.Combine( finalDirectory, "IndexStore" ); if ( !Directory.Exists( indexDirectory ) ) { Directory.CreateDirectory( indexDirectory ); } string localeName = "en-US"; try { localeName = CultureInfo.CreateSpecificCulture(locale.Name).Name; } catch { } contentDirectory = Path.Combine( contentDirectory, localeName); if ( !Directory.Exists( contentDirectory ) ) { Directory.CreateDirectory( contentDirectory ); } indexDirectory = Path.Combine( indexDirectory, localeName ); if ( !Directory.Exists( indexDirectory ) ) { Directory.CreateDirectory( indexDirectory ); } } // Create locale name // Cleanup index files Directory.GetFiles( cachePath, "*.msha" ).ForEach( File.Delete ); Directory.GetFiles( cachePath, "*.xml" ).ForEach( File.Delete ); // Creating setup indexes File.WriteAllText( Path.Combine( cachePath, "HelpContentSetup.msha" ), HelpIndexManager.CreateSetupIndex( bookGroups ), Encoding.UTF8 ); // Create list of unique packages for possible download and write the book group and // book index files Dictionary<string, Package> packages = new Dictionary<string, Package>(); foreach ( BookGroup bookGroup in bookGroups ) { File.WriteAllText( Path.Combine( cachePath, bookGroup.CreateFileName() ), HelpIndexManager.CreateBookGroupBooksIndex( bookGroup ), Encoding.UTF8 ); Debug.Print( "BookGroup: {0}", bookGroup.Name ); foreach ( Book book in bookGroup.Books ) { if ( book.Wanted ) { Debug.Print( " Book: {0}", book.Name ); File.WriteAllText( Path.Combine( cachePath, book.CreateFileName() ), HelpIndexManager.CreateBookPackagesIndex( bookGroup, book ), Encoding.UTF8 ); foreach ( Package package in book.Packages ) { string name = package.Name.ToUpperInvariant(); Debug.Print( " Package: {0}", name ); if ( !packages.ContainsKey( name ) ) { packages.Add( name, package ); } } } } } // Cleanup old files foreach ( string file in Directory.GetFiles( targetDirectory, "*.cab" ) ) { string fileName = Path.GetFileNameWithoutExtension( file ); if ( !string.IsNullOrEmpty( fileName ) ) { fileName = fileName.ToUpperInvariant(); if ( !packages.ContainsKey( fileName ) ) { File.Delete( file ); } } } // Download the packages int packagesCountCurrent = 0; client.BaseAddress = "http://packages.mtps.microsoft.com/"; foreach ( Package package in packages.Values ) { string targetFileName = Path.Combine( targetDirectory, package.CreateFileName() ); if ( package.State == PackageState.NotDownloaded || package.State == PackageState.OutOfDate ) { Debug.Print( " Downloading : '{0}' to '{1}'", package.Link, targetFileName ); client.DownloadFile( package.Link, targetFileName ); File.SetCreationTime( targetFileName, package.LastModified ); File.SetLastAccessTime( targetFileName, package.LastModified ); File.SetLastWriteTime( targetFileName, package.LastModified ); } progress.Report( 100 * ++packagesCountCurrent / packages.Count ); } // move files if (finalDirectory != null) { packagesCountCurrent = 0; progress.Report(0); Directory.GetFiles( contentDirectory, "*.*" ).ForEach( File.Delete ); Directory.GetFiles( indexDirectory, "*.*" ).ForEach( File.Delete ); foreach ( Package package in packages.Values ) { string targetFileName = Path.Combine( targetDirectory, package.CreateFileName() ); Debug.Print( " Moving : '{0}' to '{1}'", targetFileName, finalDirectory ); Move(targetFileName, contentDirectory, indexDirectory); progress.Report( 100 * ++packagesCountCurrent / packages.Count ); } } }