?
Solved

Suggestions for digesting how code is functioning

Posted on 2012-03-21
6
Medium Priority
?
158 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 40
ID: 37750743
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:Tom Knowlton
ID: 37753069


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
ID: 37753299
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 37753334
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 2000 total points
ID: 37753543
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:Tom Knowlton
ID: 37753627
Thanks for exploring this topic with me and thanks for your time.

Tom
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

762 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