Execute code in assembly and access its objects - reflection

i have a difficult question:
I want to write some code into a textbox and compile it at runtime, like "Application.GetSystem().ObjectList.Count" so that i can get the result and display it in another textbox.
Would this be possible? It should be flexible, but you must access the same assembly-instance.
I know, CodeDOM gives you the possibility to compile assemblys at runtime, but if i used that one, it wouldn´t be the same instance and i don´t get the right result.
So, what would be a way to do this? CodeDOM looks like the right way. Reflection enables the access, but only if i use the same assembly... Or may i invoke the method of the generated assembly but in my programs assembly?
It´s more a theoretical question. I don´t know if i try it out, but would be nice to know :)

Yes, this is possible using reflection.

Related

Which functoid(s) allow use of a DataTable, returned from an external assembly, in a BizTalk map?

I figured I'd be able to use an Index functoid but it doesn't seem to like my first parameter (the scripting functoid that calls the external assembly) - a red X in place of the usual green check mark.
The thing that makes me think it's possible, is that the Index functoid doesn't give me an error at all - it compiles and deploys with no complaints. The problem is that the mapping never takes place, I get a catastrophic failure (IMO) because it doesn't even return an error.
So, any way to use an external assembly that returns a DataTabe/DataRow/DataSet in a BizTalk map?
I know this does not address your question entirely but I always think that any calls to external dependencies should be done before the mapping stage, and the results stored in a message.
The map would have multiple input schemas, one of which could be a DataRow (modelled on the ADO DataRow).
Then when you call the transform you pass all the messages in which are needed to do the transform. This makes it much easier to isolate your genuine mapping failures from other failures.
This might help:
Code Behind BizTalk Functoids
You may be able to get some insight into how the mapper does its thing.

Copy message parts from message to message in BizTalk

The only way I could find is to write a custom .NET assembly to perform the task.
Is there a way to do it within expression in orchestration? I have an input message that has parts and I'd like to copy those to the destination (mapped) message.
Thank you.
It basically depends what those parts are, but assuming we're talking about parts that aren't explicitly presented in a multi-part message type, and/or you don't want to use a map for each one, then yeah, the only way is through a helper component.

GetGlobalResourceObject or Resources.Resource - what's better?

I have an application that is multilingual. I'm using the out-of-the-box .Net features for this. Each language has its own file in the App_GlobalResources (see iamge below)
In the code behind what is better?
GetGlobalResourceObject("LocalizedText", "ErrorOccured")
Resources.LocalizedText.ErrorOccured
The 2nd one uses less code and it's type safe, it will return an error during compile time and not run time.
alt text http://img340.imageshack.us/img340/5562/langl.gif
These are the advantages of each approach:
Advantages of GetGlobalResourceObject (and GetLocalResourceObject):
You can specify a particular culture instead of using the CurrentCulture.
You can use a late-bound expression (i.e. a string) to decide which resource to load. This is useful if you can't know ahead of time which resource you will need to load.
It works with any resource provider type. For example, it works not only with the built-in default RESX-based provider but it'll work the same against a database-based provider.
Advantages of strongly-typed RESX types:
You get compile-time errors if you access a resource that doesn't exist.
You get Intellisense while working on the project.
So, as with many "which is best" questions, the answer is: It depends! Choose the one that has advantages that will benefit your particular scenarios the most.
So use the second one, if you know up-front what the resource file and key will be.
The GetGlobalResourceObject() method is useful if you don't know what the resource file or (more likely) the key will be at compile time.

Suppress MessageBox from a referenced assembly

How do I suppress a MessageBox from showing that comes from a reference to an assembly that I do not own (nor have the code for)?
For example, my application (MyApplication.exe) is referencing an assembly coded by someone else (SomeoneElsesAssembly.dll). Inside of this assembly I'm calling a static method, which does what it's supposes to, but also is firing a MessageBox that I want to suppress.
I thought there was a way to reference an assembly in Non-Interactive mode or something along these lines.
Thank you for your help.
-Jessy Houle
This article may be able to help
What you are asking is basically "How can I modify the behavior of code in a third-party assembly".
Short of disassembling/reassembling, the answer is "You can't".
There are some icky options;
With managed code you always have the source in some form. If the function is somewhat self-contained you could use Reflector to copy it into your own code
You could have a 2nd thread that waits till the message box appears and then automatically closes it.
I thought there was a way to reference an assembly in Non-Interactive mode or something along these lines.
I believe it's possible to run a process in a non-interactive mode (such as Windows Services, for example), but assemblies are loaded into the process and are subject to the same interaction levels as other assemblies in the process, afaik.
So, either disassemble-reassemble or send windows messages directly to the box to automatically close it.
Basically you're asking if you can reference an assembly which calls MessageBox() and have the code not actually show a message box. The answer is unfortunately no.
You're best bet is to use screen scraping to close the message box once it shows up. This post has some example code of how to close an InProc message box. http://www.codeproject.com/KB/dialog/AutoCloseMessageBox.aspx

Looking for a simple explanation on using trace logging

I have seen several projects that use the Trace functionality to capture events and stream them out to a log file. I have been unsuccessful in finding a simple to follow guide that will show me how to configure Trace to capture and write said logfile. Does anyone have a link recommendations, or provide some simple steps to follow?
The Trace object writes the statements to any attached TraceListeners. You can build your own, but there are a number already defined in the System.Diagnostics namespace, including:
ConsoleTraceListener (Console)
DefaultTraceListener (Visual Studio / Debugger)
DelimitedListTraceListener (TextWriter, special formatting)
EventLogTraceListener (EventLog - anything that inherits from System.Diagnostics.EventLog)
TextWriterTraceListener (TextWriter - think file)
You can, of course, inherit your own from the TraceListener class that writes to where ever you want. For example, you could log to a database, have it send e-mails or pages in certain situations, or write the statements back to a logging platform like log4net.
The big thing is that you need to create an instance of whatever listeners you want and then add them to the Trace' class Listeners collection. You can add as many as you need and Trace will write to all of them. This way, you can write your logging code once using a well-supported and understood object that's part of the framework, and you can attach anything you need to it.
I stumbled into a MSDN article that really helps. Sorry I didn't find it before posting the question but perhaps others may have the same question and haven't found this link.
Take a look at logging frameworks. We rolled out own, but are now migrating over to log4net available free at http://logging.apache.org/log4net/
Im looking for a way to set the Category of the EventLog, the FormattedEventLogTraceListener writes into (not the category of the message).
But I can't find an appropriate property of this class.
Is it possible to set this?

Resources