I have an AxShockwaveFlash object in a Windows Forms application, and load a (AS3) movie into it with LoadMovie. The movie plays correctly, but I am having a problem getting a variable from flash.
I have tried using GetVariable but it always returns an empty string. How can I get the value of a variable from flash?
I think the new security policy for AVM2 requires you to explicitly expose the variables/functions to the container application using ExternalInterface.
If you can't edit the swf, I can't think of a way to get access to them. It was really easy with AS2 though, if you defined it, you could get and set it via javascript/C#/whatever without any extra code in the swf.
Yo can use fscommand method to talk to C# from shockwave player:
fscommand("sendCmd", arg);
to catch value in C# use
flashPlayer.FSCommand += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEventHandler(flashPlayer_FSCommand);
....
void flashPlayer_FSCommand(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent e)
{
tbOut.Text += e.command + " (" + e.args + ")" + "\r\n";
}
Related
I have a webform, and I am trying to make a log of who is using it. All the research I did, was all about using on a local box, not through IIS.
using System.Security.Principal;
private void Form1_Load(object sender, EventArgs e)
{
string curuser = WindowsIdentity.GetCurrent().Name;
}
Where I get the Output:
tw.WriteLine(DateTime.Now + ": " + CurUser);
Output displayed:
12/1/2017 4:13:18 PM: System.Web.UI.WebControls.Label
I am assuming it is something silly and dumb. Thanks guys
Note: I have 'Windows Authentication' enabled within IIS for this site.
Whatever or wherever CurUser is, it's an instance of a Label. It's not your curuser variable that you declared in Page_Load and then never used.
When you try to output an object as a string, the system internally invokes the .ToString() implementation on that object. Unless overridden (and Label doesn't override it), the default implementation for .ToString() (inherited from System.Object) is to output the name of the type. In this case "System.Web.UI.WebControls.Label".
(Makes sense. After all, how would the system inherently know how a complex object, particularly any custom object you could write, should be represented as a string?)
Don't output an unrelated object, output the value:
string curuser = WindowsIdentity.GetCurrent().Name;
tw.WriteLine(DateTime.Now + ": " + curuser);
I'm trying to create a clearcase dynamic view using CAL in C# using the following code.
private static ClearCase.ClearTool ct;
string viewName = "tmp_view";
string cmd = "mkview –tag "+ viewName + " –stream " + selectedStream +"#"+ projectVob + " \\\\<Network Shared Path>\\"+ viewName +".vws";
ct.CmdExec(cmd);
On execution, ct.CmdExec method throws exception saying viewTag must be specified.
For the same cmd string I'm able to create a view using cleartool command prompt.
Can you please tell me why I'm unable to create a view in C#?
It is possible that you didn't used -tag but –tag: replace '–' (minus) by '-' (hyphen minus).
Note: same for –stream: use -stream.
(plus , minus , hyphen-minus)
See What's the toughest bug you ever found and fixed? :
"Hyphen-minus" is the regular familiar character on keyboards, ASCII 45 and U+002D, (ab)used in both "5-4=1" and "vice-versa".
The actual minus sign, which is longer, is U+2212 and is not in ASCII.
It is typical of IBM documentation which, unfortunately, use minus (the long '–'): any copy-paste coming from their page doesn't work immediately.
I'm pretty new to C# and am having a mare trying to get what should be a simple task to work, in a nutshell I've written a PowerShell script to create VApps within a vSphere environment, the PoSh script works perfectly, next I have created (my first go) a Windows Console Application to run (initially) this script with user input, here's the problem, within my console app I'm using Process.Start to call my PoSh script and pass parameters, but, they come out joined up and completely missing the last parameter, here's the line in question:
Process.Start("Powershell.exe","-ExecutionPolicy bypass F:\\hello.ps1 -Location " + location + " -AppName" + appname);
AppName is completely ignored and Location tends to come out as -Locationanywhere instead of -Location Anywhere, I'm sure it's something basic and I've trawled the usual group and RTFM but no joy!
Hello.ps1 is a test script that just records the parameters passed to it so I can check the output before touching my real script.
Any help gratefully received.
You're lacking a space between -AppName and the double quotes.
string.Format is a useful method in .Net - it allows you to easily replace placeholders with dynamic content in a way that makes viewing the 'complete' string intuitive:
string parameters = string.Format("-ExecutionPolicy bypass F:\\hello.ps1 -Location {0} -AppName {1}", location, appName);
Process.Start("Powershell.exe", parameters);
I'm not sure, but I think you need an space between -AppName and the appname
" -AppName " + appname
It's all I can help you :(
Might I suggest using String.Format() instead of using the + operator?
String.Format("-ExecutionPolicy bypass F:\\hello.ps1 -Location {0} -AppName {1}", location, appname)
We are currently developing an ASP.NET MVC application which makes heavy use of attribute-based metadata to drive the generation of JavaScript.
Below is a sample of the type of methods we are writing:
function string GetJavascript<T>(string javascriptPresentationFunctionName,
string inputId,
T model)
{
return #"function updateFormInputs(value){
$('#" + inputId + #"_SelectedItemState').val(value);
$('#" + inputId + #"_Presentation').val(value);
}
function clearInputs(){
" + helper.ClearHiddenInputs<T>(model) + #"
updateFormInputs('');
}
function handleJson(json){
clearInputs();
" + helper.UpdateHiddenInputsWithJson<T>("json", model) + #"
updateFormInputs(" + javascriptPresentationFunctionName + #"());
" + model.GetCallBackFunctionForJavascript("json") + #"
}";
}
This method generates some boilerplace and hands off to various other methods which return strings. The whole lot is then returned as a string and written to the output.
The question(s) I have are:
1) Is there a nicer way to do this other than using large string blocks?
We've considered using a StringBuilder or the Response Stream but it seems quite 'noisy'. Using string.format starts to become difficult to comprehend.
2) How would you go about unit testing this code? It seems a little amateur just doing a string comparison looking for particular output in the string.
3) What about actually testing the eventual JavaScript output?
Thanks for your input!
We created a library specifically for the purpose of embedding JavaScript in a fluent-like syntax into our C# code, and then made it open source.
Have a look at Adam.JSGenerator.
I typically try to create a separate .js file for most/all of my javascript code. Usually I will need to have common bahvior applied to many elements that are dynamically created by ASP controls or server-side code, so I may not be able to code everything into a .js file.
I've found that the main reason that you want to generate javascript on the server is because you won't know the IDs of elements until the page renders. Therefore, I try to condense that dependency down as much as possibly so that I'm generating as little javascript as possible. For example, in traditional ASP.Net (not MVC) if I were rendering a set of forms such as in the example, each with multiple fields, then I would probably have something in the code behind such as this:
protected void FormRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Control form = e.Item.FindControl("MyForm");
ClientScript.RegisterStartupScript(this.GetType(), "prepareForm_" + form.ClientID, #"prepareForm('" + form.ClientID + "');", true);
}
A separate .js file would include the definition of the prepareForm function, which would be something like this:
// define a formPresenter "class" that encapsulates the behavior for a given form
function formPresenter(formId) {
this.setFirstName = function(value) {
$("#" + formId + "_FirstName").val(value);
}
this.setLastName = function(value) {
$("#" + formId + "_LastName").val(value);
}
// create other functions to handle more complicated logic
// clear fields
this.clearInputs = function() {
this.setFirstName("");
this.setLastName("");
//...
}
// receive Json object
this.handleJson = function(json) {
this.clearInputs();
// populate fields with json object
this.setFirstName(json.FirstName);
this.setLastName(json.LastName);
//...
}
// "constructor" logic
}
function prepareForm(formId) {
// create a new formPresenter object and shove it onto the specified element as the "presenter"
document.getElementById(formId).presenter = new formPresenter(formId);
}
Now almost all of your actual logic is in its own .js file, which should be much easier to maintain. If you need to access the formPresenter object for a given form, then you just need to get a reference to whatever element is referenced by the formId parameter and access the presenter variable:
"document.getElementById(" + form.ClientID + ").presenter.handleJson(json);"
Note: Since I've been using JQuery, I've found less of a need to even include any javascript generated by the server. Typically I can find the elements that I need by looking for a specific CSS class name (or something to that effect) and perform whatever setup/initialization I need.
We're doing a lot of JS generation in our project as well, and we're using StringBuilder to do it.
StringBuilder sb = new StringBuilder();
sb.Append("some javascript stuff")
.Append("some more")
.AppendFormat("formatted stuff {0}", "here");
return sb.ToString();
It's not pretty, but no solution is going to be.
And concerning testing, we don't actually do any unit tests on the generated code. Before release people go and test all the features to make sure they work as expected.
If you don't care about super duper performance you could use a templating language to generate the javascript.
Then for unit testing you would just fill the templates with their appropriate bindings/variables and then run it through a Javascript evaluator like Rhino or whatever the .NET equivalent is to at least test the syntax if not the actual JS code.
Other than that I would seriously question the design of software that is generating Javascript like this. It also looks like you are using JQuery but are referencing the $ directly which may lead to some problems down the line.
If compilers generating Javascript is one thing (ala GWT) but I would separate your client side JS code as much as possible from your .NET code (not to mention your .NET code looks like server side JS talk about confusing).
This in vogue kind of design of separating the client crap from the server is known as SOFEA. I let you google that.
AA,
I want to add a custom property to a WMi Object's Propert Collection. So that whenever i retrieve the properties of that object, i get the custom added property as well. Specifically speaking lets see the following code.
foreach (ManagementObject WebSite in WebSitesCollection)
{
if (WebSite.Properties["Name"].Value.ToString().Contains(appPoolName))
{
foreach (PropertyData propertyData in WebSite.Properties)
{
try
{
HttpContext.Current.Response.Write(propertyData.Name + " " + propertyData.Value + "<br/>");
if (propertyData.Name.Equals("Enable32BitAppOnWin64"))
{
AppPoolx.SetPropertyValue("Enable32BitAppOnWin64", true);
AppPoolx.Put(); return true;
}
else
{
AppPoolx.Properties.Add("Enable32BitAppOnWin64", true);
AppPoolx.Put(); return true;
}
}
catch (Exception ex1)
{
HttpContext.Current.Response.Write("Error Ocurred while Setting Property: " + ex1.Message + "<br />");
break;
}
}
}
}
But the AppPoolx.Properties.Add("Enable32BitAppOnWin64", true); returns error
Operation is not valid due to current state of the object.
I was wondering whether it was even possible to add a custom property to the WMi object. If what is this Add() function for?
In any case, what is the correct procedure of add a "Custom Property to a WMI Object."
Please do not suggest that i may store in DB.
Regards
Steve
WMI Objects are basically com objects, much like a C# object those objects are populated by the code at the other end.
For you to add this custom property you would have to have the functionality in the code at the other end to store the object data for your custom property.
The add property method you're calling is not valid for all (pretty much most) com objects that are returned by WMI API's this is likely your problem, i understand that this is something to do with how the objects from WMI calls are marshalled from the com component in which they are called from.
So in short:
This is not likely possible.
A more correct approach would be to determine the actual type of the object you are working with and set a property value on a property that is writable for the object then push that back to the WMI API.