-1

What constructs should I use to create a shared object in C# which can be used in some other third party software or program?

Example:

My program reads a abc.xml and I need to share data read from this file. I have another perl script which needs to read this shared data and hence I want to know what would be best approach for such scenarios.

Thanks.

nestedloop
  • 2,596
  • 23
  • 34
sia
  • 1,872
  • 1
  • 23
  • 54
  • AS you are using an XML file, I belive, Serializing the object back into an XML would be the best option, so that any program which understands xml can use it. – Nilesh Jun 02 '14 at 10:15
  • How do you run that perl script? Perhaps you can *generate* call with parameters, containing data what you want to pass to it? And don't try to ask generic question, there are too many possible scenarios (via file, IPC, registry, etc). – Sinatr Jun 02 '14 at 10:15
  • @Nilesh - i'm not only using xml file, i may need to use txt,csv or excel files also. – sia Jun 02 '14 at 10:39

3 Answers3

1

For serializing access across applications you can look into using a named mutex. I am not sure whether you can access those from Perl but you can certainly do that from multiple .NET applications.

NeddySpaghetti
  • 13,187
  • 5
  • 32
  • 61
1

You need to open you file in both C# and Perl in a non blocking mode. In C# you can use:

new FileStream(logfileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

If the file changes, you need to update your deserialized representation and notify your interested parties of the change. You can look into the FileSystemWatcher class for this.

However, this kind of application integration, using a private datastore should be discouraged. It is a better practice to consider such data private to one application, and use explicit APIs using webservices for instance for inter application communication.

Hylaean
  • 1,237
  • 13
  • 19
0

I may be missing something here.

But isn't a FILE itself a shared resource that can be accessed across programs? If a perl script needs the file why not just read it in as part of perl script?

What is the advantage you are gaining from loading it in .net?

I know this isn't what you have asked but i don't understand why you are doing what you are doing.

If you want to get enterprisey why not use a message queue? Or write a .net service that the perl script can query?

If you cannot do everything you want in one language and dont want to figure it out, why not use powershell or a batch file to tie it all together,

John Nicholas
  • 4,778
  • 4
  • 31
  • 50