Solved

Suggestions for digesting how code is functioning

Posted on 2012-03-21
6
151 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
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: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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 5

Author Comment

by: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 500 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:knowlton
ID: 37753627
Thanks for exploring this topic with me and thanks for your time.

Tom
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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