Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can one class set a property to be seen by another c
Message
 
 
To
27/02/2013 10:04:09
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01566989
Message ID:
01567051
Views:
26
>>>>>Of course - if you set an instance property of classX, don't expect that this will change an instance property of classY
>>>>
>>>>But this is what I need. I need to set the string in one class and read it in the other class.

>>>
>>>And that's what I thought you meant from the beginning! It'll need to be to be static ...
>>>
>>
>>Yeah - but static means common to all instances - don't know whether that is a good solution here

>
>Yeah, I know ... but it sounded like Naomi needed to read the property outside of an instance of the class. I probably still am misunderstanding her intent.
>
>~~Bonnie

Yes, because we have two separate classes. One class makes invoke call and another is the actual implementation of each method. The class that does invoke call changes the invoke string into a dictionary of parameters. But for logging purpose (and for some other purposes) I want to get the actual invoke string also.

So, this is what we have in the MiddlewareMain
 public String Invoke(String input)
      {
         Dictionary<String, String> parameters = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);

         this.SetInvokeString(input);
         // Need to create a dummy root node
         String rootNode = "Invoke";
         String xml = String.Format("<{0}>{1}</{0}>", rootNode, input);

         try
         {
            XElement elements = XElement.Parse(xml);

            foreach (XElement xe in elements.Elements())
            {
               StringBuilder parameterValue = new StringBuilder();
               foreach (XNode xn in xe.Nodes())
               {
                  parameterValue.Append(xn.ToString());
               }

               parameters.Add(xe.Name.ToString(), parameterValue.ToString());
            }
         }
         catch (Exception ex)
         {
            String error = ex.ToString();
            Logging.Log(error, 1);
            return String.Format("<ERR>0</ERR><STATUSCODE>100</STATUSCODE><MSG>{0}</MSG>", error);
         }

         if (!parameters.ContainsKey("func"))
            return "<ERR>0</ERR><STATUSCODE>100</STATUSCODE><MSG>Parameter 'func' not specified</MSG>";

         if (!invokeMethods.ContainsKey(parameters["func"]))
            return String.Format("<ERR>0</ERR><STATUSCODE>100</STATUSCODE><MSG>Function '{0}' not available</MSG>", parameters["func"]);

         String cReturnValue = "";
         //String cTransactionName = "";
         //if (_bShouldRollback)
         //{
         //    //cTransactionName = "_" + DateTime.Now.Ticks.ToString();
         //    database.BeginTransaction(cTransactionName);
         //}

         // TODO: This is just a temporary change.  Ideally, need to wrap the entire Invoke in a single BEGIN TRANSACTION/ROLLBACK instead
         //       of rolling back each processed SQL execution statement.
         if (parameters.ContainsKey("testonly"))
            database.rollback = true;

         cReturnValue = invokeMethods[parameters["func"]](parameters);

         //if (_bShouldRollback)
         //{
         //    database.RollbackTransaction(cTransactionName);
         //}
         return cReturnValue;
      }
   }
}
And we also have the following:
private delegate String InvokeMethod(Dictionary<String, String> parameters);
private Dictionary<String, InvokeMethod> GetInvokeMethods()
      {
         Dictionary<String, InvokeMethod> methodDictionary = new Dictionary<String, InvokeMethod>(StringComparer.OrdinalIgnoreCase)
            {
                // Base
                {"GetServerVersion", GetServerVersion},
                
                //Data
                {"AppendRecs"                           , data.AppendRecs}, // JT 02/18/2013 Done
                {"DeleteAlreadyCreatedTransactionRecord", data.DeleteAlreadyCreatedTransactionRecord},
                {"GetItemNextModified"                  , data.GetItemNextModified},
                {"GetItemTable"                         , data.GetItemTable},
So, we mapped each method to its class implementation. In my Sales class I want to see how exactly I was invoked.

In the meantime we just agreed to call the new class Application.cs So, this is how I am going to proceed now.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform