Extract an unreferenced assembly from xap file - silverlight-4.0

I have a xap file that contains an unreferenced assembly: b.dll.
This assembly was put in the xap file manually (by a post build step, in which I just add the dll to zip(xap) file).
Now at runtime I want to access b.dll and call CreateInstance on it.
This is where I am stuck. How can I get an Assembly instance for b.dll from the xap file?
Thank you!

You can initialise a StreamResourceInfo object with a downloaded zip stream (Xap or otherwise).
You can then use Application.GetResourceStream to pull a stream for file from that zip using a Uri. In this case the dll which can then load with AssemblyPart and then call a CreateInstance on it:-
WebClient client = new WebClient()
client.OpenReadCompleted += (s, args) =>
{
StreamResourceInfo zip = new StreamResourceInfo(args.Result, "application/zip");
StreamResourceInfo dll = Application.GetResourceStream(zip, new Uri("b.dll", UriKind.Relative));
AssemblyPart assemblyPart = new AssemblyPart();
Assembly assembly = assemblyPart.Load(dll.Stream);
_someClassFromB = assembly.CreateInstance("b.SomeClass");
};
client.OpenReadAsync(new Uri("your.xap", UriKind.Relative));

Related

how to download exe files in vb.net (Visual Studio 2015)

I try make one program for download one .exe file and run for help in my job.
But idk how to make this, i'm new in VB.
I am using this code, as shown in the Visual Basic document reference:
My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/WineList.txt", _
"C:\Documents and Settings\All Users\Documents\WineList.txt")
But when I try to download an .exe file, the entire file doesn't complete and I the file is only 1 kb after download.
The webclient should be the way to go a comment above highlights that too.
This is an example from another question:
Either use sync method:
public void DownloadFile()
{
using(var client = new WebClient())
{
client.DownloadFile(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Or use new async-await approach:
public async Task DownloadFileAsync()
{
using(var client = new WebClient())
{
await client.DownloadFileTaskAsync(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Then call this method like this:
await DownloadFileAsync();
Open up the .exe file you are trying to download in a text editor like NotePad. Odds are what is being downloaded is an HTML page showing some kind of error message like 404 not found.
Another possibility might be that AntiVirus software is moving the original EXE into quarantine and replacing it with a Quarantine MetaData file.
If the file does actually contain binary content your connection could be getting interrupted but odds are if this happened an exception would be thrown.

use beanshell to execute a scripts from a specific folder (error no such file or directory)

I added the library bsh to my android project (jar file), the I create a file executor.bsh under scripts(a folder that I have created under the project)
I used the code below
private final Interpreter i= new Interpreter();
i.source("scripts/executor.bsh");
I got an error:
No such file or directory
Help !!
Interpreter.source(..) looks for a File, where you have a jar entry. However, you can still use it with:
try (Reader script = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("scripts/executor.bsh")) {
Interpreter in = new Interpreter(script, System.in, System.out, System.err, false);
// your script was already loaded
// do something with Interpreter here.
}

writing files in exported eclipse rcp product

I am a newbie and I am working on eclipse-rcp and trying to build a address book with data saved in xml files.when I am running the project it is able to read and write into the xml file but when I am exporting it into a rcp product it is only reading the file but not able to write.
I tried searching Google but couldn't find the relevant answers so I turned to SO.
Any suggestions??
Edit This is my method where I am trying to read the file and writing it into xml file
public void writedata() {
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL = bundle.getEntry("/xmlfiles/person.xml");
InputStream inputStream=fileURL.openStream();
Document xmlDocument = builder.parse(inputStream);
..................................................
..................................................
..................................................
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(xmlDocument);
Bundle bundle1 = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL1 = bundle1.getEntry("/xmlfiles/person.xml");
StreamResult result = new StreamResult(new File(FileLocator.resolve(fileURL1).getPath()));
transformer.transform(source, result);
When you run your application from Eclipse it uses the expanded project folder for your plugin. Your XML file is writeable in this location.
When you export as an RCP application your plugin gets packaged up as a plugin jar file with the XML file inside it. You won't be able to write to this file.
For the file to be writeable it needs to be outside your plugin project, either in the RCP application workspace or in an external folder.

Get/Read files from SharePoint document library and ZIP them using DotNetZip?

I have files uploaded to sharepoint document library. Trying to use DotNetZip to get those files from document library, zip them and render the zip file.
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + "MyFiles.zip");
using (ZipFile zip = new ZipFile())
{
//Query the sharepoint document library and get SPFolder (folder in this case)
foreach (SPFolder folder in userFolder.SubFolders)
{
foreach (SPFile file in folder.Files)
{
zip.AddFile(file.URL);// Is this possible?
}
}
zip.Save(Response.OutputStream);
Can we pass file URL to AddFile method? If not, is there any another way to do this?
The dotnetzip addfile method does not accept urls. It needs to be a relative or full qualified path. See the documentation
Try the vZIP add-on, it is working great on our SharePoint 2010.

Using WCF in MonoDevelop / MonoTouch: how to use the app.config file?

I have added a web reference to a WCF service in my MT project (using MonoDevelop 2.4.2 here).
I am trying to recycle the app.config file that is used by Visual Studio. I copied it over into my MT's root directory and specified "copy to output directory" in MonoDevelop. Still it does not work.
What is the correct way to use an app.config in MonoDevelop?
René
You can't use app.config files in Monotouch unfortunately. You have to create all the bindings yourself in code. In one of our projects, this is what we have done:
public static ServiceClient GetClient()
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.OpenTimeout = new TimeSpan(0,0,10);
binding.CloseTimeout = new TimeSpan(0,0,10);
binding.SendTimeout = new TimeSpan(0,0,10);
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.BypassProxyOnLocal = false;
binding.AllowCookies = false;
// snip - we set all the properties found in the serverside config file in code here
EndPointAddress endpointAddress = new EndpointAddress("https://www.domain.com/ServiceClient.svc");
ServiceClient client = new ServiceClient(binding, endpointAddress);
return client;
}
You need to go through and set EVERY property that is found in the server's app.config file, ensuring that the values match exactly, otherwise this won't work.
(If I've misunderstood your question, then I do apologise!).
I think you just need to properly name the .config file and place it in your output directory:
myapp.exe.config
I do not think MD does it automatically for you like VS does.