Suggestions for digesting how code is functioning

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

LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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
Tom KnowltonWeb developerAuthor Commented:


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
Jacques Bourgeois (James Burger)PresidentCommented:
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
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Tom KnowltonWeb developerAuthor Commented:
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
Jacques Bourgeois (James Burger)PresidentCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Thanks for exploring this topic with me and thanks for your time.

Tom
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.