internal static void Install(BundleLibraryManifest manifest, string library_bundle_filename)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            WebLibraryDetail web_library_detail = WebLibraryManager.Instance.GetLibrary(manifest.Id);

            if (null != web_library_detail)
            {
                MessageBoxes.Info("You already have a version of this Bundle Library.  Please ensure you close all windows that use this library after the latest has been downloaded.");
            }

            string library_directory = WebLibraryDetail.GetLibraryBasePathForId(manifest.Id);

            Directory.CreateDirectory(library_directory);

            // Unzip the bundle
            string parameters = String.Format("-y x \"{0}\" -o\"{1}\"", library_bundle_filename, library_directory);

            using (Process process = ProcessSpawning.SpawnChildProcess(ConfigurationManager.Instance.Program7ZIP, parameters))
            {
                using (ProcessOutputReader process_output_reader = new ProcessOutputReader(process))
                {
                    process.WaitForExit();

                    Logging.Info("7ZIP Log Bundle Install progress:\n{0}", process_output_reader.GetOutputsDumpStrings());
                }
            }

            // Reflect this new bundle
            WebLibraryDetail new_web_library_detail = WebLibraryManager.Instance.UpdateKnownWebLibraryFromBundleLibraryManifest(manifest, suppress_flush_to_disk: false);

            WPFDoEvents.InvokeInUIThread(() => {
                MainWindowServiceDispatcher.Instance.OpenLibrary(new_web_library_detail);
            });
        }
        internal void ShowBundleLibraryJoiningControl(BundleLibraryManifest manifest)
        {
            BundleLibraryJoiningControl control = new BundleLibraryJoiningControl();

            control.Show();
            control.FocusOnManifest(manifest, "Automatically downloaded manifest...");
        }
        private void TailZIPProcess(BundleLibraryManifest manifest, Process zip_process)
        {
            string STATUS_TOKEN = "Bundle-" + manifest.Version;

            StatusManager.Instance.ClearCancelled(STATUS_TOKEN);

            int iteration = 0;

            while (true)
            {
                ++iteration;

                if (StatusManager.Instance.IsCancelled(STATUS_TOKEN))
                {
                    zip_process.Kill();
                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Cancelled creation of Bundle Library.");
                    return;
                }

                if (zip_process.HasExited)
                {
                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Completed creation of Bundle Library.");
                    return;
                }

                StatusManager.Instance.UpdateStatusBusy(STATUS_TOKEN, "Creating Bundle Library...", iteration, iteration + 1, true);

                Thread.Sleep(1000);
            }
        }
Exemplo n.º 4
0
        internal void FocusOnManifestFilename(string filename)
        {
            string json = File.ReadAllText(filename);
            BundleLibraryManifest manifest = BundleLibraryManifest.FromJSON(json);

            FocusOnManifest(manifest, filename);
        }
Exemplo n.º 5
0
        internal static void Install(BundleLibraryManifest manifest, string library_bundle_filename)
        {
            Library library = WebLibraryManager.Instance.GetLibrary(manifest.Id);

            if (null != library)
            {
                MessageBoxes.Info("You already have a version of this Bundle Library.  Please ensure you close all windows that use this library after the latest has been downloaded.");
            }

            //string library_directory = @"C:\temp\LIBZZZZ";
            string library_directory = Library.GetLibraryBasePathForId(manifest.Id);

            Directory.CreateDirectory(library_directory);

            // Unzip the bundle
            string  parameters  = String.Format("-y x \"{0}\" -o\"{1}\"", library_bundle_filename, library_directory);
            Process zip_process = Process.Start(ConfigurationManager.Instance.Program7ZIP, parameters);

            zip_process.WaitForExit(10000);

            // Reflect this new bundle
            WebLibraryDetail new_web_library_detail = WebLibraryManager.Instance.UpdateKnownWebLibraryFromBundleLibraryManifest(manifest);

            Application.Current.Dispatcher.Invoke(((Action)(() =>
                                                            MainWindowServiceDispatcher.Instance.OpenLibrary(new_web_library_detail.library)
                                                            )));
        }
Exemplo n.º 6
0
        private void ManageDownload(BundleLibraryManifest manifest)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            string url = manifest.BaseUrl + @"/" + manifest.Id + Common.EXT_BUNDLE;

            using (UrlDownloader.DownloadAsyncTracker download_async_tracker = UrlDownloader.DownloadWithNonBlocking(url))
            {
                string STATUS_TOKEN = "BundleDownload-" + manifest.Version;

                StatusManager.Instance.ClearCancelled(STATUS_TOKEN);
                while (!download_async_tracker.DownloadComplete)
                {
                    if (ShutdownableManager.Instance.IsShuttingDown)
                    {
                        Logging.Error("Canceling download of Bundle Library due to signaled application shutdown");
                        StatusManager.Instance.SetCancelled(STATUS_TOKEN);
                    }

                    if (StatusManager.Instance.IsCancelled(STATUS_TOKEN))
                    {
                        download_async_tracker.Cancel();
                        break;
                    }

                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Downloading Bundle Library...", download_async_tracker.ProgressPercentage, 100, true);

                    ShutdownableManager.Sleep(3000);
                }

                // Check the reason for exiting
                if (download_async_tracker.DownloadDataCompletedEventArgs.Cancelled)
                {
                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Cancelled download of Bundle Library.");
                }
                else if (null != download_async_tracker.DownloadDataCompletedEventArgs.Error)
                {
                    MessageBoxes.Error(download_async_tracker.DownloadDataCompletedEventArgs.Error, "There was an error during the download of your Bundle Library.  Please try again later or contact {0} for more information.", manifest.SupportEmail);
                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Error during download of Bundle Library.");
                }
                else if (null == download_async_tracker.DownloadDataCompletedEventArgs.Result)
                {
                    MessageBoxes.Error(download_async_tracker.DownloadDataCompletedEventArgs.Error, "There was an error during the download of your Bundle Library.  Please try again later or contact {0} for more information.", manifest.SupportEmail);
                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Error during download of Bundle Library.");
                }
                else
                {
                    StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Completed download of Bundle Library.");
                    if (MessageBoxes.AskQuestion("The Bundle Library named '{0}' has been downloaded.  Do you want to install it now?", manifest.Title))
                    {
                        LibraryBundleInstaller.Install(manifest, download_async_tracker.DownloadDataCompletedEventArgs.Result);
                    }
                    else
                    {
                        MessageBoxes.Warn("Not installing Bundle Library.");
                    }
                }
            }
        }
        internal static void Check(WebLibraryDetail web_library_detail)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            // We can operate only on bundle libs
            if (!web_library_detail.IsBundleLibrary)
            {
                return;
            }

            // Only check every hour
            if (DateTime.UtcNow.Subtract(web_library_detail.LastBundleManifestDownloadTimestampUTC ?? DateTime.MinValue).TotalMinutes < 60)
            {
                return;
            }

            // Flag that we are running this update check now
            web_library_detail.LastBundleManifestDownloadTimestampUTC = DateTime.UtcNow;
            WebLibraryManager.Instance.NotifyOfChangeToWebLibraryDetail();

            // Download the new manifest
            BundleLibraryManifest manifest_existing = BundleLibraryManifest.FromJSON(web_library_detail.BundleManifestJSON);
            string manifest_latest_url = manifest_existing.BaseUrl + @"/" + manifest_existing.Id + Common.EXT_BUNDLE_MANIFEST;

            using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(manifest_latest_url))
            {
                string manifest_latest_json           = Encoding.UTF8.GetString(ms.ToArray());
                BundleLibraryManifest manifest_latest = BundleLibraryManifest.FromJSON(manifest_latest_json);

                // It is an old version or we have this version
                if (0 <= String.Compare(manifest_existing.Version, manifest_latest.Version))
                {
                    return;
                }

                // It is a version the user has chosen to ignore
                if (web_library_detail.LastBundleManifestIgnoreVersion == manifest_latest.Version)
                {
                    return;
                }

                BundleLibraryUpdateNotification blun = new BundleLibraryUpdateNotification(web_library_detail, manifest_latest);

                NotificationManager.Instance.AddPendingNotification(
                    new NotificationManager.Notification(
                        String.Format("An update is available for your Bundle Library '{0}', from version {1} to {2}.", manifest_latest.Title, manifest_existing.Version, manifest_latest.Version),
                        "Bundle Library update available!",
                        NotificationManager.NotificationType.Info,
                        Icons.LibraryTypeBundle,
                        "Download!",
                        blun.Download,
                        "No thanks!",
                        blun.NoThanks
                        )
                    );
            }
        }
        internal static void Check(Library library)
        {
            // We can operate only on bundle libs
            if (!library.WebLibraryDetail.IsBundleLibrary)
            {
                return;
            }

            // Only check every hour
            if (DateTime.UtcNow.Subtract(library.WebLibraryDetail.LastBundleManifestDownloadTimestampUTC ?? DateTime.MinValue).TotalMinutes < 60)
            {
                return;
            }

            // Flag that we are running this update check now
            library.WebLibraryDetail.LastBundleManifestDownloadTimestampUTC = DateTime.UtcNow;
            WebLibraryManager.Instance.NotifyOfChangeToWebLibraryDetail();

            // Download the new manifest
            BundleLibraryManifest manifest_existing = BundleLibraryManifest.FromJSON(library.WebLibraryDetail.BundleManifestJSON);
            string       manifest_latest_url        = manifest_existing.BaseUrl + "/" + manifest_existing.Id + ".qiqqa_bundle_manifest";
            MemoryStream ms;

            UrlDownloader.DownloadWithBlocking(ConfigurationManager.Instance.Proxy, manifest_latest_url, out ms);
            string manifest_latest_json           = Encoding.UTF8.GetString(ms.ToArray());
            BundleLibraryManifest manifest_latest = BundleLibraryManifest.FromJSON(manifest_latest_json);

            // It is an old version or we have this version
            if (0 <= String.Compare(manifest_existing.Version, manifest_latest.Version))
            {
                return;
            }

            // It is a version the user has chosen to ignore
            if (library.WebLibraryDetail.LastBundleManifestIgnoreVersion == manifest_latest.Version)
            {
                return;
            }

            {
                BundleLibraryUpdateNotification blun = new BundleLibraryUpdateNotification(library, manifest_latest);

                NotificationManager.Instance.AddPendingNotification(
                    new NotificationManager.Notification(
                        String.Format("An update is available for your Bundle Library '{0}', from version {1} to {2}.", manifest_latest.Title, manifest_existing.Version, manifest_latest.Version),
                        "Bundle Library update available!",
                        NotificationManager.NotificationType.Info,
                        Icons.LibraryTypeBundle,
                        "Download!",
                        blun.Download,
                        "No thanks!",
                        blun.NoThanks
                        )
                    );
            }
        }
Exemplo n.º 9
0
        private void ManageDownload(BundleLibraryManifest manifest)
        {
            string url = manifest.BaseUrl + "/" + manifest.Id + Common.EXT_BUNDLE;

            UrlDownloader.DownloadAsyncTracker download_async_tracker = UrlDownloader.DownloadWithNonBlocking(ConfigurationManager.Instance.Proxy, url);

            string STATUS_TOKEN = "BundleDownload-" + manifest.Version;

            StatusManager.Instance.ClearCancelled(STATUS_TOKEN);
            while (!download_async_tracker.DownloadComplete)
            {
                if (StatusManager.Instance.IsCancelled(STATUS_TOKEN))
                {
                    download_async_tracker.Cancel();
                    break;
                }

                StatusManager.Instance.UpdateStatusBusy(STATUS_TOKEN, "Downloading Bundle Library...", download_async_tracker.ProgressPercentage, 100, true);
                Thread.Sleep(1000);
            }

            // Check the reason for exiting
            if (false)
            {
            }
            else if (download_async_tracker.DownloadDataCompletedEventArgs.Cancelled)
            {
                StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Cancelled download of Bundle Library.");
            }
            else if (null != download_async_tracker.DownloadDataCompletedEventArgs.Error)
            {
                MessageBoxes.Error(download_async_tracker.DownloadDataCompletedEventArgs.Error, "There was an error during the download of your Bundle Library.  Please try again later or contact {0} for more information.", manifest.SupportEmail);
                StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Error during download of Bundle Library.");
            }
            else if (null == download_async_tracker.DownloadDataCompletedEventArgs.Result)
            {
                MessageBoxes.Error(download_async_tracker.DownloadDataCompletedEventArgs.Error, "There was an error during the download of your Bundle Library.  Please try again later or contact {0} for more information.", manifest.SupportEmail);
                StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Error during download of Bundle Library.");
            }
            else
            {
                StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Completed download of Bundle Library.");
                if (MessageBoxes.AskQuestion("The Bundle Library named '{0}' has been downloaded.  Do you want to install it now?", manifest.Title))
                {
                    LibraryBundleInstaller.Install(manifest, download_async_tracker.DownloadDataCompletedEventArgs.Result);
                }
                else
                {
                    MessageBoxes.Warn("Not installing Bundle Library.");
                }
            }
        }
        private static void TailZIPProcess(BundleLibraryManifest manifest, string parameters)
        {
            using (Process zip_process = Process.Start(ConfigurationManager.Instance.Program7ZIP, parameters))
            {
                using (ProcessOutputReader process_output_reader = new ProcessOutputReader(zip_process))
                {
                    string STATUS_TOKEN = "Bundle-" + manifest.Version;

                    StatusManager.Instance.ClearCancelled(STATUS_TOKEN);

                    int iteration = 0;
                    while (true)
                    {
                        ++iteration;

                        if (ShutdownableManager.Instance.IsShuttingDown)
                        {
                            Logging.Error("Canceling creation of Bundle Library due to signaled application shutdown");
                            StatusManager.Instance.SetCancelled(STATUS_TOKEN);
                        }

                        if (StatusManager.Instance.IsCancelled(STATUS_TOKEN))
                        {
                            zip_process.Kill();
                            zip_process.WaitForExit(5000);

                            Logging.Error("Canceled creation of Bundle Library:\n--- Parameters: {0}\n{1}", parameters, process_output_reader.GetOutputsDumpStrings());

                            StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Canceled creation of Bundle Library.");
                            return;
                        }

                        if (zip_process.HasExited)
                        {
                            Logging.Info("Completed creation of Bundle Library:\n--- Parameters: {0}\n{1}", parameters, process_output_reader.GetOutputsDumpStrings());

                            StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Completed creation of Bundle Library.");
                            return;
                        }

                        StatusManager.Instance.UpdateStatus(STATUS_TOKEN, "Creating Bundle Library...", cancellable: true);

                        ShutdownableManager.Sleep(3000);
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void ButtonDownload_Click(object sender, RoutedEventArgs e)
        {
            FeatureTrackingManager.Instance.UseFeature(Features.StartPage_JoinBundleLibrary);

            BundleLibraryManifest manifest = DataContext as BundleLibraryManifest;

            if (null == manifest)
            {
                MessageBoxes.Error("Please select a Bundle Library manifest file (*" + Common.EXT_BUNDLE_MANIFEST + ").");
                return;
            }

            // Kick off the downloader
            SafeThreadPool.QueueUserWorkItem(o => ManageDownload(manifest));

            Close();
        }
        public WebLibraryDetail UpdateKnownWebLibraryFromBundleLibraryManifest(BundleLibraryManifest manifest)
        {
            Logging.Info("+Updating known Bundle Library {0} ({1})", manifest.Title, manifest.Id);

            WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

            new_web_library_detail.BundleManifestJSON = manifest.ToJSON();
            new_web_library_detail.Id          = manifest.Id;
            new_web_library_detail.Title       = manifest.Title;
            new_web_library_detail.Description = manifest.Description;
            new_web_library_detail.IsReadOnly  = true;
            new_web_library_detail.Deleted     = false;

            UpdateKnownWebLibrary(new_web_library_detail);

            Logging.Info("-Updating known Bundle Library {0} ({1})", manifest.Title, manifest.Id);

            return(new_web_library_detail);
        }
        internal static void Install(BundleLibraryManifest manifest, byte[] library_bundle_binary)
        {
            string temp_filename = Path.GetTempFileName();

            try
            {
                File.WriteAllBytes(temp_filename, library_bundle_binary);
                Install(manifest, temp_filename);
            }
            finally
            {
                try
                {
                    File.Delete(temp_filename);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem deleting the temporary library bundle file.");
                }
            }
        }
Exemplo n.º 14
0
        public WebLibraryDetail UpdateKnownWebLibraryFromBundleLibraryManifest(BundleLibraryManifest manifest, bool suppress_flush_to_disk = true)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            Logging.Info("+Updating known Bundle Library {0} ({1})", manifest.Title, manifest.Id);

            WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

            new_web_library_detail.BundleManifestJSON = manifest.ToJSON();
            //new_web_library_detail.IsBundleLibrary = true;
            new_web_library_detail.Id          = manifest.Id;
            new_web_library_detail.Title       = manifest.Title;
            new_web_library_detail.Description = manifest.Description;
            new_web_library_detail.Deleted     = false;

            UpdateKnownWebLibrary(new_web_library_detail, suppress_flush_to_disk);

            Logging.Info("-Updating known Bundle Library {0} ({1})", manifest.Title, manifest.Id);

            return(new_web_library_detail);
        }
        public void ReflectLibrary(Library library_)
        {
            library  = library_;
            manifest = new BundleLibraryManifest();

            string bundle_title = library_.WebLibraryDetail.Title + " Bundle Library";

            bundle_title = bundle_title.Replace("Library Bundle Library", "Bundle Library");

            // Set the manifest
            manifest.Id      = "BUNDLE_" + library_.WebLibraryDetail.Id;
            manifest.Version = DateTime.UtcNow.ToString("yyyyMMdd.HHmmss");

            manifest.Title       = bundle_title;
            manifest.Description = library_.WebLibraryDetail.Description;

            // GUI updates
            DataContext            = manifest;
            ObjRunLibraryName.Text = library_.WebLibraryDetail.Title;

            ResetProgress();
        }
Exemplo n.º 16
0
 internal void FocusOnManifest(BundleLibraryManifest manifest, string filename_prompt)
 {
     TxtManifestFilename.Text = filename_prompt;
     DataContext = manifest;
 }
 public BundleLibraryUpdateNotification(Library library, BundleLibraryManifest manifest_latest)
 {
     this.library         = library;
     this.manifest_latest = manifest_latest;
 }
 public BundleLibraryUpdateNotification(WebLibraryDetail web_library_detail, BundleLibraryManifest manifest_latest)
 {
     this.web_library_detail = web_library_detail;
     this.manifest_latest    = manifest_latest;
 }