예제 #1
0
 // Call this method from the worker thread to finalize the progress meter
 public void End(ThreadError threadError)
 {
     if (fRequiresClose)
     {
         Invoke(new EndInvoker(DoEnd), new object[] { threadError });
     }
 }
        public static ManualResetEvent Delay(TimeSpan aExecAfterTimeout, Action aAction, string name)
        {
            var localExit = new ManualResetEvent(false);

            try
            {
                new Thread(() =>
                {
                    try
                    {
                        localExit.WaitOne(aExecAfterTimeout);
                        aAction();
                    }
                    catch (Exception Error)
                    {
                        Log(Error.ToString());
                    }
                })
                {
                    IsBackground = true,
                    Name         = name
                }.Start();
            }
            catch (Exception ThreadError)
            {
                Log(ThreadError.ToString());
            }
            return(localExit);
        }
        public static ManualResetEvent Intervall(int aMillisecondsIntervall, Action aAction, string name)
        {
            var localExit = new ManualResetEvent(false);

            try
            {
                new Thread(() =>
                {
                    bool isLocalExit = false;
                    while (!isLocalExit)
                    {
                        try
                        {
                            aAction();
                        }
                        catch (Exception Error)
                        {
                            Log(Error.ToString());
                        }
                        isLocalExit = localExit.WaitOne(aMillisecondsIntervall);
                    }
                })
                {
                    IsBackground = true,
                    Name         = name
                }.Start();
            }
            catch (Exception ThreadError)
            {
                Log(ThreadError.ToString());
            }
            return(localExit);
        }
예제 #4
0
        // The partner of End(). Handles finalising the progres meter.
        private void DoEnd(ThreadError threadError)
        {
            ThreadError.Error   = threadError.Error;
            ThreadError.Message = threadError.Message;

            if (ThreadError.Error == 1)
            {
                DialogResult = DialogResult.Cancel;
            }
            else if (ThreadError.Error == 2)
            {
                DialogResult = DialogResult.Abort;
            }
            else if (ThreadError.Error == 3)
            {
                DialogResult = DialogResult.Retry;
            }
            else
            {
                DialogResult = DialogResult.OK;
            }
        }
예제 #5
0
        // The heart of GEDmill is here.
        public void Create()
        {
            fLogger.WriteInfo("Website::Create()");

            // 1 means the process was aborted, for signalling back to calling thread. 2 means file nError.
            ThreadError threaderror = new ThreadError(1, "No error");

            try {
                // The value to indicate in the progress bar to show how much of the website creation is complete.
                int progress = 0;

                int[] gfstats = fTree.GetRecordStats();

                // The maximum value of the progress bar, i.e. when website creation is fully complete.
                int progressMax =
                    1    // Site-wide multimedia files
                    + 1  // W3C Sticker
                    + 1  // Background image
                    + 1  // Style sheet
                    + gfstats[(int)GDMRecordType.rtIndividual]
                    + 1  // Individuals Index
                    + gfstats[(int)GDMRecordType.rtSource]
                    + 1  // Front page
                    + 1  // CD ROM (Doesn't matter here that CD ROM autorun might not be included.)
                    + 1; // Scripts (Doesn't matter here that scripts might not be included.)

                // The paintbox with which to draw the mini tree
                var paintbox = new Paintbox(GMConfig.Instance);
                paintbox.SetBackgroundImage(GMConfig.Instance.BackgroundImage);

                // Object to keep count of number of files created etc.
                var stats = new Stats();

                // Here goes....

                // Start the progress indicator.
                fProgressWindow.Begin(0, progressMax);
                if (fProgressWindow.IsAborting)
                {
                    return;
                }
                // Copy the images to use in place of non-pic multimedia files.
                fProgressWindow.SetText("Copying multimedia");
                CopyIcons();
                if (fProgressWindow.IsAborting)
                {
                    return;
                }
                fProgressWindow.StepTo(++progress);

                // Copy the W3C sticker file.
                fProgressWindow.SetText("Copying W3C sticker");
                string sW3CFilename = "";
                if (GMConfig.Instance.IncludeValiditySticker)
                {
                    sW3CFilename = CopyW3CSticker();
                }
                if (fProgressWindow.IsAborting)
                {
                    return;
                }
                fProgressWindow.StepTo(++progress);

                // Create the index creator for use by the individuals records creator.
                var indiIndexCreator = new CreatorIndexIndividuals(fTree, fProgressWindow, sW3CFilename);

                // Copy the image for the background of the webpages.
                fProgressWindow.SetText("Copying background image");
                string backgroundImageFilename = CopyBackgroundImage();
                if (fProgressWindow.IsAborting)
                {
                    return;
                }
                fProgressWindow.StepTo(++progress);

                // Create the style sheet
                fProgressWindow.SetText("Creating style sheet");
                string cssFilename = string.Concat(GMConfig.Instance.OutputFolder, "\\", GMConfig.Instance.StylesheetFilename, ".css");
                if (GMConfig.Instance.StylesheetFilename.Length > 0 && (!GMConfig.Instance.PreserveStylesheet || !File.Exists(cssFilename)))
                {
                    var csc = new CreatorStylesheet(fTree, fProgressWindow, sW3CFilename, cssFilename, backgroundImageFilename);
                    csc.Create();
                }

                if (fProgressWindow.IsAborting)
                {
                    return;
                }

                fProgressWindow.StepTo(++progress);

                // Create the pages for the individual records.
                fProgressWindow.SetText("Creating individual pages");
                var indiList = fTree.GetRecords <GDMIndividualRecord>();
                foreach (GDMIndividualRecord ir in indiList)
                {
                    var ipc = new CreatorRecordIndividual(fTree, fProgressWindow, sW3CFilename, ir, indiIndexCreator, paintbox);
                    if (ipc.Create(stats))
                    {
                        stats.Individuals++;
                    }
                    if (fProgressWindow.IsAborting)
                    {
                        return;
                    }

                    fProgressWindow.StepTo(++progress);
                }

                // Create the index for the individual records pages.
                fProgressWindow.SetText("Creating individuals index");
                indiIndexCreator.Create();
                if (fProgressWindow.IsAborting)
                {
                    return;
                }

                fProgressWindow.StepTo(++progress);

                // Clear list of copied files, so that source images get copied afresh
                // and so get resized differently to any indi images based on the same file.
                Creator.ClearCopiedFilesList();

                // Create the pages for the source records.
                fProgressWindow.SetText("Creating source pages");
                var sourList = fTree.GetRecords <GDMSourceRecord>();
                foreach (GDMSourceRecord sr in sourList)
                {
                    var spc = new CreatorRecordSource(fTree, fProgressWindow, sW3CFilename, sr);
                    if (spc.Create(stats))
                    {
                        stats.Sources++;
                    }

                    if (fProgressWindow.IsAborting)
                    {
                        return;
                    }

                    fProgressWindow.StepTo(++progress);
                }

                if (fProgressWindow.IsAborting)
                {
                    return;
                }

                // Create the front page
                fProgressWindow.SetText("Creating front page");
                string front_page_filename = string.Concat(GMConfig.Instance.OutputFolder, "\\", GMConfig.Instance.FrontPageFilename, ".", GMConfig.Instance.HtmlExtension);
                if (GMConfig.Instance.FrontPageFilename.Length > 0 && (!GMConfig.Instance.PreserveFrontPage || !File.Exists(front_page_filename)))
                {
                    CreatorFrontPage fpc = new CreatorFrontPage(fTree, fProgressWindow, sW3CFilename, stats);
                    fpc.Create();
                }
                fProgressWindow.StepTo(++progress);
                if (fProgressWindow.IsAborting)
                {
                    return;
                }

                // Copy the CD ROM autorun file
                fProgressWindow.SetText("Creating CD-ROM files");
                if (GMConfig.Instance.CreateCDROMFiles)
                {
                    CreateCDROMFiles();
                }
                if (fProgressWindow.IsAborting)
                {
                    return;
                }

                fProgressWindow.StepTo(++progress);

                // Copy the Javascript
                fProgressWindow.SetText("Creating Javascript file");
                // Currently (10Dec08) the only thing that uses javascript is the multiple images feature.
                if (GMConfig.Instance.AllowMultipleImages)
                {
                    CreateJavascriptFiles();
                }
                if (fProgressWindow.IsAborting)
                {
                    return;
                }

                fProgressWindow.StepTo(++progress);

                // Done
                fLogger.WriteInfo("Website::CreateFinished");
                fProgressWindow.SetText("Done");
                threaderror.Error   = 0;
                threaderror.Message = "";
            } catch (ArgumentException e) {
                fLogger.WriteError("Caught Argument Exception : ", e);
                threaderror.Error   = 2; // 2 => abnormal abort.
                threaderror.Message = "";
            } catch (IOException e) {
                fLogger.WriteError("Caught IO Exception : ", e);
                threaderror.Error   = 2; // 2 => abnormal abort.
                threaderror.Message = "";
            } catch (NullReferenceException e) {
                fLogger.WriteError("Caught NullReference Exception : ", e);
                threaderror.Error   = 2; // 2 => abnormal abort.
                threaderror.Message = "";
            } catch (HTMLException e) {
                threaderror.Error   = 2; // 2 => abnormal abort.
                threaderror.Message = e.Message;
            } catch (Exception e) {
                fLogger.WriteError("Caught Exception : ", e);
                threaderror.Error   = 2; // 2 => abnormal abort.
                threaderror.Message = "";
            } finally {
                fLogger.WriteInfo("Thread ending...");
                if (fProgressWindow != null)
                {
                    fProgressWindow.End(threaderror);
                }
            }
        }
예제 #6
0
 public ProgressWindow()
 {
     InitializeComponent();
     ShowInTaskbar = false;
     ThreadError   = new ThreadError(1, "No error");
 }
예제 #7
0
 protected void OnThreadError(Exception error)
 {
     ThreadError?.Invoke(this, new ThreadExceptionEventArgs(error));
 }
예제 #8
0
 private void OnThreadError(Exception ex)
 {
     ThreadError?.Invoke(this, ex);
 }