Solved

Suggestions for digesting how code is functioning

Posted on 2012-03-21
6
148 Views
Last Modified: 2012-03-22
I am looking for recommendations on how to convert code into a flowchart.

How are variable declarations / initializations expressed?

 public int Export()
        {   
            var startTime = DateTime.Now;

            FilesUploaded = 0;
            FilesUploadedText = new StringBuilder();

            // Default exception message
            string exceptionMessage = Resources.ERROR_GENERIC;
            try
            {
                log.Event(LogLevel.Info, string.Format("{0}: Starting", group.Name));

                // Run Pre check on export upload components
                exceptionMessage = Resources.ERROR_PRECHECK;
                if (!log.ExecuteTimeLog<bool>(AvailabilityCheck))
                {
                    throw new ExportUploadPreCheckExportUpload();
                }

                exceptionMessage = Resources.ERROR_MARKFOREXPORT;
                DocumentCount = log.ExecuteTimeLog<int>(MarkFilesForExport);

                // Check for Nothing to upload
                if (DocumentCount <= 0)
                {
                    return 0;
                }

                try
                {
                    // Export failed stop execution
                    exceptionMessage = Resources.ERROR_EXPORT;
                    if (!log.ExecuteTimeLog<bool>(ExportFiles))
                    {
                        throw new ExportUploadExportFailureException();
                    }

                    // Zip failed stop execution
                    exceptionMessage = Resources.ERROR_ZIP;
                    if (!log.ExecuteTimeLog<bool>(ZipFiles))
                    {
                        throw new ExportUploadZipException();
                    }

                    // Pgp failed stop execution
                    exceptionMessage = Resources.ERROR_ENCRYPTION;
                    if (!log.ExecuteTimeLog<bool>(PgpFiles))
                    {
                        throw new ExportUploadEncryptionFailureException();
                    }
                }
                catch (Exception e)
                {
                    if (MarkFilesAsError()) exceptionMessage = Resources.ERROR_PREPARE;
                    throw e;
                }

                try
                {
                    // Upload failed stop 0execution
                    exceptionMessage = Resources.ERROR_UPLOAD;
                    if (!log.ExecuteTimeLog<bool>(UploadFiles))
                    {
                        throw new ExportUploadUploadException();
                    }
                }
                catch (BeforeUploadException)
                {
                    if (MarkFilesAsError()) exceptionMessage = Resources.ERROR_PREPARE;
                    throw;
                }

                exceptionMessage = Resources.ERROR_HISTORY;
                log.ExecuteTimeLog(AttemptToMoveToHistory);

                // Custom wait for upload for basware
                // Disabled by Nathan on 10/21
                // This is a point of no return. The files are already in the folder.
                // We have had multiple cases recently were the verification failed but it was uploaded.
                // log.ExecuteTimeLog(VerifyUpload);

                exceptionMessage = Resources.ERROR_COMPLETE;
                if (!log.ExecuteTimeLog<bool>(MarkFilesAsComplete))
                {
                    throw new ExportUploadMarkCompleteFailureException();
                }

                var stopTime = DateTime.Now;

                // Send out the export email
                exceptionMessage = Resources.ERROR_EMAIL;
                log.Event(LogLevel.Info, string.Format("{0}: Successfully exported and uploaded", group.Name));

                StringBuilder emailBody = new StringBuilder();
                emailBody.AppendLine("  Upload Summary:");
                string filesUploadCountText = "  -- There " + ((FilesUploaded == 1) ? "was" : "were") + " " + FilesUploaded + " file" + (FilesUploaded == 1 ? "" : "s") + " uploaded.";
                emailBody.AppendLine(filesUploadCountText);
                emailBody.AppendLine();
                if (DocumentCount > 0)
                {
                    emailBody.AppendLine("  Document Export Counts:\r\n" + "  -- Total Documents : " + DocumentCount);
                    emailBody.AppendLine();
                }
                if (FilesUploadedText.Length > 0)
                {
                    emailBody.AppendLine("  File Detail:");
                    emailBody.AppendLine(FilesUploadedText.ToString());
                    emailBody.AppendLine();
                }

                emailBody.AppendLine(string.Format("\r\n\r\nThe process took {0} seconds to run.", stopTime.Subtract(startTime).TotalSeconds.ToString("##.##")));
                emailBody.AppendLine(string.Format("\r\n{0}", listFilesExtraInfo.Guid));

                emailBody.AppendLine("\r\n\t Related Guids:");
                foreach (var exportFile in listFilesExtraInfo)
                {
                    try
                    {
                        emailBody.AppendLine(String.Format(
                            "\r\n\t Export File Name: '{0}', File ID: '{1}', File To Export: '{2}', Guid: '{3}', Document Count: '{4}', Seq Daily: '{5}', Seq Life: '{6}'",
                            exportFile.ExportFile, exportFile.FileID, exportFile.OriginalFileName, exportFile.Guid, exportFile.DocumentCount, exportFile.SequenceDaily, exportFile.SequenceLifeTime));
                    }
                    catch (Exception e)
                    {
                        log.EventException(LogLevel.Error, "An error occured while creating export summary line to email body in the Export() method of the ExportGroup class", e);
                    }
                }

                string message = string.Format("{0} {1} Finished", Globals.ApplicationName, group.Name);
                if (listFilesExtraInfo.Any(x => x.ExportHasErrors))
                {
                    message += " with Errors";
                }

                Globals.SendNotification(group.EmailConfirmation, message, emailBody.ToString(), MailPriority.Normal);

                return DocumentCount;
            }
            catch (SmtpException sex)
            {
                // Unable to connect to mail server -- don't attempt to send an email about that
                log.EventException(LogLevel.Fatal, exceptionMessage + "\r\n\r\n" + string.Format("Fatal Exception occurred while sending an email {0}", sex.Message), sex);

                return DocumentCount;
            }
            catch (Exception ex)
            {
                log.EventException(
                    LogLevel.Fatal,
                    "Fatal exception occurred in Run()",
                    ex);

                try
                {
                    var stopTime = DateTime.Now;

                    StringBuilder emailBody = new StringBuilder();
                    emailBody.AppendLine(exceptionMessage);
                    emailBody.AppendLine();
                    emailBody.AppendLine("Exception Details:");
                    emailBody.AppendLine(ex.ToString());

                    emailBody.AppendLine(string.Format("\r\n\r\nThe process took {0} seconds to run.", stopTime.Subtract(startTime).TotalSeconds.ToString("##.##")));
                    if (listFilesExtraInfo != null)
                    {
                        emailBody.AppendLine(string.Format("\r\n{0}", listFilesExtraInfo.Guid));
                    }

                    Globals.SendNotification(
                        group.EmailError,
                        Globals.ApplicationName + " " + group.Name + " Exception",
                        emailBody.ToString(),
                        MailPriority.High);
                }
                catch (Exception subEx)
                {
                    log.EventException(
                    LogLevel.Fatal,
                    "Fatal exception occurred while attempting to send error email.",
                    subEx);
                }

                throw;
            }
        }

Open in new window

0
Comment
Question by:knowlton
  • 3
  • 3
6 Comments
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
You must be as old as I am to know what a flowchart is :-)

With event driven programming, flowcharts have lost their appeal, because there is almost now way to chart the user interaction with the application or the order in which properties and methods are called. You find a lot of tools that convert code to class diagrams and/or the reverse, but I do not know of any tool that creates a flowchart from code.

Personnally, I still use flowcharts from time to time, but do the thing manually. I have used Visio for a while, when it was its primary use and did not cost a fortune. But now that it can do everything up to tracing a trajectory through the universe, I find that 95% of the price I pay for it is for useless stuff.

So I ended up doing the thing the old way... with a pencil and my old flowchart stencils, and naturally, a good eraser. The presentation is not as clean, but at least, if I become famous, I will be able to sell it as art.
0
 
LVL 5

Author Comment

by:knowlton
Comment Utility


You must be as old as I am to know what a flowchart is :-)


So I ended up doing the thing the old way... with a pencil and my old flowchart stencils, and naturally, a good eraser. The presentation is not as clean, but at least, if I become famous, I will be able to sell it as art.


LOL.

It does not need to be a flowchart.  UML is fine.

But yes, asking for a flowchart dates me a bit, you are right about that.

I found a few applications that try to do what I am wanting.  CodeRocket for example (see attached image).  But I want something that can go through and map everything at once, not per source code file.

I realize this is a tall order.

What about some sort of software that can just make what classes I use at runtime?

I don't know what the answer is.
ProgramCS.jpg
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
The complexity of event driven programming, with the fact that on each run of the application the steps taken by the user are different make the creation of such a tool very difficult. No type of diagram that I know of can provide a usable graphical representation of all the possibilities between events.

What if the user clicks on Button1 before going to the TextBox1. He could have clicked on 25 different buttons, or come from another textbox instead of coming from a button. And we are still at the level on one class. You seem to want to have an overview across classes. Quite a feat if somebody can come up with something like that.

Microsoft provides some tools that could help a bit, but unfortunately, they are available only the costly editions (Premium and Ultimate).

I have something called Call Hierarchy in my Visual Studio 2010 Premium that can give you a hint, although I find that the interface for the presentation is not very good (lots of clicks). I do not know if it is available in the Professional edition. Most probably not in Express. Does not work with VB, but could be useful in C#.

As for external solutions, I am not very found of them, so I have nothing to recommend.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Author Comment

by:knowlton
Comment Utility
I should explain a bit more.

This is a Console application that runs on the command line.

There is no interaction with the user -- just pure processing.  No GUI.

This is not to say that decisions are not made to to do one thing or another, but it is depending on the circumstances at that moment in time -- not due to user interaction.

Does this help, and perhaps change your outlook on the feasibility?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
This indeed changes make the thing feasible. But I cannot lead you to a solution.

However, if you Bing ".net flowchart", you will end up with a good number of hits. You might find what you want in there.
0
 
LVL 5

Author Closing Comment

by:knowlton
Comment Utility
Thanks for exploring this topic with me and thanks for your time.

Tom
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now