Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug in VS 2013?
Message
From
02/05/2014 17:18:11
 
General information
Forum:
ASP.NET
Category:
Troubleshooting
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01599384
Message ID:
01599472
Views:
25
What smelly code. Needs some refactoring...and rearchitecting. I don't know how you can test this properly.


>
>I didn't post the whole thing yet :)
>
>
>      /// <summary>
>      /// Main Invoke method
>      /// </summary>
>      /// <param name="input"></param>
>      /// <returns></returns>
>      public String Invoke(String input)
>      {
>         this.CurrentRequest = new Request();
>         this.CurrentRequest.InvokeString = input; // Save invoke string
>         Logging.Log(2, "Invoke called with " + input);
>         this.CurrentRequest.InvokeStartTime = DateTime.Now;
>
>         this.data.CurrentRequest = this.CurrentRequest;
>         this.sales.CurrentRequest = this.CurrentRequest;
>         this.bookings.CurrentRequest = this.CurrentRequest;
>         this.validation.CurrentRequest = this.CurrentRequest;
>         this.retail.CurrentRequest = this.CurrentRequest;
>
>         Dictionary<String, String> parameters = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
>
>         try
>         {
>            parameters.PopulateFromSQML(input);
>         }        
>         
>         catch (Exception ex)
>         {
>            String error = ex.ToString();
>            Logging.Log(error, 1);
>            this.CurrentRequest.LastError = new ErrorState(100, error);            
>         }
>
>         if (this.CurrentRequest.LastError ==null && !parameters.ContainsKey("func"))
>         {
>            this.CurrentRequest.LastError = new ErrorState(100, "Parameter 'func' not specified");          
>         }
>
>         if (this.CurrentRequest.LastError == null && !invokeMethods.ContainsKey(parameters["func"]))
>         {
>            this.CurrentRequest.LastError = new ErrorState(100, String.Format("Function '{0}' is not available", parameters["func"]));            
>         }
>
>         if (this.CurrentRequest.LastError != null)
>         {            
>            return this.CurrentRequest.FormatError();
>         }
>         String cReturnValue = "";
>       
>         // If the <TestOnly> tag was passed in the Invoke call, roll back the entire Invoke call once it completes (see below)
>         if (parameters.ContainsKey("testonly"))
>            database.rollbackGlobalInvoke = true;
>
>         try
>         {
>            if (database.rollbackGlobalInvoke)
>            {
>               using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted }))
>               {
>                  database.globalTransaction = true;
>                  if (database.sqlConnection != null && database.sqlConnection.State == ConnectionState.Open)
>                     database.sqlConnection.EnlistTransaction(Transaction.Current);
>                  cReturnValue = invokeMethods[parameters["func"]](parameters);
>                  database.globalTransaction = false;
>                  // Do not call Complete(), so the entire Invoke call will be automatically rolled back.
>                  // scope.Complete();   
>               }
>            }
>            else
>               cReturnValue = invokeMethods[parameters["func"]](parameters);
>         }
>
>         catch (SiriusException ex)
>         {
>            Logging.LogFormat(1,"Sirius Exception Caught: {0}", ex.Message);
>            this.CurrentRequest.LastError = new ErrorState((Int16)ex.statusCode, ex.Message);
>            // Lookup error codes for the status returned if necessary.
>            cReturnValue = this.CurrentRequest.FormatError();
>         }
>
>         catch (Exception ex)
>         {
>            String error = ex.ToString();
>            Logging.Log(error, 1);
>            this.CurrentRequest.LastError = new ErrorState(100, error);
>            cReturnValue = this.CurrentRequest.FormatError();
>         }
>         
>         this.CurrentRequest.InvokeEndTime = DateTime.Now;
>         Logging.Log(2, "Invoke took " + this.CurrentRequest.InvokeDuration.ToString());
>         this.CurrentRequest.Dispose();
>         return cReturnValue;
>      }
>   }
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Reply
Map
View

Click here to load this message in the networking platform