Using System.Reflection - reflection

Im loading an Exe into my application using Assembly.LoadFile().
From that is it possible to get the Method of a particular class from that EXE.
Thanks in advance .

Try:
var assembly = Assembly.LoadFile("C:\path-to-some-app.exe");
var desiredType = assembly.GetType("SomeNamespace.SomeClass");
var methodInfo = desiredType.GetMethod("MethodName");

A number of things you can do with Reflection (Including constructors, method invocation etc.) Tutorial at : http://www.csharp-examples.net/reflection-examples/

Related

Alfresco Object is not available in extension module in alfresco share

I am trying to override the javascript controller node-header.js of components\node-details with the extension module of alfresco share
This is my node-header.get.js
<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">
for (var i=0; i<model.widgets.length; i++)
{
if (model.widgets[i].id == "NodeHeader")
{
if(model.widgets[i].options.nodeRef!=null)
{
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
if(jsNode.hasAspect("custom:intranetFile")){
model.widgets[i].options.showFavourite = false;
model.widgets[i].options.showLikes = false;
}
}
}
}
I am getting this error
Error Message: 05270002 Failed to execute script
'classpath*:webscripts/custom/nodeheader/hidelikesync/node-header.get.js':
05270001 ReferenceError: "Alfresco" is not defined.
(jar:file:/C:/Alfresco/Alfresco42/tomcat/webapps/share/WEB-INF/lib/customshare.jar!/webscripts/custom/nodeheader/hidelikesync/node-header.get.js#1555)
Error lies in this line
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
as Alfresco object is not available how can I get it?
Based on my answer yesterday on the share-extras-devel list:
Your issue is that you are mixing up your web script JS with client-side JavaScript. Alfresco.util.Node is a client-side helper class and is therefore available to client-side JS running in the web browser, but not to your web script code which runs on the server.
If you look at the source of alfresco-util.js, which you are including, you will see that there is a helper class there but it is called AlfrescoUtil.
To get some information on this given node I would suggest that you want to use the static method AlfrescoUtil.getNodeDetails() from that class, e.g.
var jsNode = AlfrescoUtil.getNodeDetails(model.widgets[i].options.nodeRef);
The structure of the jsNode object will be as per the JSON returned by the doclist-v2 webscripts, so you should be able to check for the presence of your custom aspect in the aspects array property.
If you check the source of alfresco-util.js you will see that additional parameters are also supported by getNodeDetails(). It seems to me you can also pass in an optional site name, plus some options if you wish.

aspnet_compiler in Azure starup task

Does anyone know if its possible to call aspnet_compiler from an azure role startup task to force a precompilation inplace. (And if so as a foregroudn/background or simple task?)
Perhaps something like:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_precompile.exe -v / -p "F:\siteroot\0"
Or are there any better ways to accomplish this?
Yes, that should work once you figure out the right path to the compiler although I haven't tried this specific approach.
An alternative I've tried is to use ClientBuildManager.PrecompileApplication as described in this answer. I tried calling that from inside OnStart() but you can compile C# code as a .NET assembly and use that from PowerShell or just call .NET primitives from PowerShell as described here and that way call it from the startup task.
A start-up task is possible, but one problem with that is that the siteroot path is hardcoded and that can change. Instead add the following to the RoleEntryPoint OnStart method:
using (var serverManager = new ServerManager())
{
string siteName = RoleEnvironment.CurrentRoleInstance.Id + "_" + "Web";
var siteId = serverManager.Sites[siteName].Id;
var appVirtualDir = $"/LM/W3SVC/{siteId}/ROOT"; // Do not end this with a trailing /
var clientBuildManager = new ClientBuildManager(appVirtualDir, null, null,
new ClientBuildManagerParameter
{
PrecompilationFlags = PrecompilationFlags.Default,
});
clientBuildManager.PrecompileApplication();
}

using System.Net.NetworkInformation errors

I want to use NetworkInformation namespace and when I use system.net.networkInformation I'm getting error: "The type or namespace name 'NetworkInformation' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) "
I'm compact framework v2.0 or 3.5. compact framework should support networkInformation namespace?
I also tried to use this code:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
return output;
but the StandartOutput and redirectStandartoutput doesn't exist.
I'm trying to find out is the LAN is up or down. There is other way that I can use with compact framework?
You can do this with OpenNetCF's Smart Device Framework. I've used classes in this framework on several occasions when I find they are missing from CF2.0
See #ctacke's answer here:
The easiest way is to use OpenNETCF's SDF and look at the
OpenNETCF.Net.AdapterStatusMonitor class, which will raise events when
NDIS sends out notifications (like MEDIA_CONNECT and
MEDIA_DISCONNECT).

Correct way of passing and reading parameters to a .swf in Flex?

What is the preferred way of passing parameters to a Flex application deployed as a .swf and how do I read the parameters from Flex?
I'm looking for the equivalent of passing and reading URL parameters in Flex land.
I like to use FlashVars.
var paramObj:Object = Application.application.parameters;
trace(paramObj['foo']);
public function getQuerystringProperty(property:String):String {
var bm:IBrowserManager = BrowserManager.getInstance();
var oArgs:Object = {};
bm.init("", "");
oArgs = mx.utils.URLUtil.stringToObject(bm.fragment, “&”);
if (oArgs[property])
return oArgs[property].toString();
return "";
}
Gets the QueryString from within Flex (no ExternalInterface).
embed the swf object in an html page and then use external interface. These articles should help you:
http://www.adobe.com/livedocs/flex/2/langref/flash/external/ExternalInterface.html
Flex Examples

read web.config from another assembly using t4

Does anyone have a good example or helper class that would allow me to read the connection string in a web application from a T4 template residing in ANOTHER assembly referenced by the web application. I am generating some code from the database that it references and i would appresiate some help on how to get the connection string for this use.
ive read George Js example here however it only works when the template resides in the web app, please help!!!
var path = Host.ResolvePath(#"../Web.config");
var map = new ExeConfigurationFileMap { ExeConfigFilename = path };
var config = ConfigurationManager.OpenMappedExeConfiguration(
map,ConfigurationUserLevel.None);
var appSettings = config.AppSettings;
var connectionStrings = config.ConnectionStrings.ConnectionStrings;
You could try to do something like that:
var config = ConfigurationManager.OpenExeConfiguration("../somePathTo/web.config")
// use the config to get values like: config.AppSettings
after a bit of searching around ive found my answer in t4 one may use
path = Host.ResolvePath(relativeFileName)

Resources