Custom Error Message to show current function - c#-4.0

In my current error handling, I specify the Form, function and error message in a messagebox similar to the following.
try
{
//Some code here
}
catch(Exception ex)
{
MessageBox.Show("Form Title : " + this.Title + "\nFunction : CurrentFunction \nError : " + ex.Message);
return;
}
This works for me, but was curious if I can make the process even more simple, and generate the function name, instead of typing it out every time I want to display the error message.
Additionally:
I know you can include the stacktrace and view the top few lines, but I was curious if there was a cleaner way to show the function.

Yes, if you just need the current function (not the calling function), you can use MethodBase.GetCurrentMethod:
string currentMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;

Related

Macro in PublishedSearchResult Content throw ArgumentNullException

I work with Umbraco version 8.9.1. I have a simple macro video to add local video (in Umbraco Media) in place of public url video. I also use a Search (IPublishedContentQuery) that return me a IEnumerable of PublishedSearchResult. It works well except when I use my macro video in a field, then the field (here body) throw an error : System.ArgumentNullException.
Apparently it's the mapping that cannot be done. The property is in the item.Content.Property and the item.Content.HasValue(property) return true.
public List<IPublishedProperty> CheckTheValues(PublishedSearchResult item, string searchValue)
{
foreach (var property in item.Content.Properties) // return me "body"
{
if (!item.Content.HasValue(property.Alias)) // HasValue return true
continue;
var contentValue = item.Content.Value(property.Alias); // throw System.ArgumentNullException
...
}
}
I suppose that's because the mapping cannot translate the macro in something known but it's awkward because I have the html code in my cache like <?UMBRACO_MACRO ... />.
Is there a way to add an alternative content to the macro (not on the video tag), I think about alt property that exists on html img to write an alternative text if the image doesn't exists ?
If not, is there a way to force to get the html code ? (to get the tag umbraco_macro in place of an error)
If not, is there a way to ignore the "not understand" part tags of the content "body" ? so return all except this macro tag.
If not, except with a try catch continue, is there a proper way to ignore this result from my search ?
Thanks a lot !

Unable to Invoke Inserted Javascript Fragment

I am attempting to insert a Javascript fragment into a webpage and then invoke it using blue prism. The purpose of this is to analyse what elements are returned from a search to determine where to go next in the overall process flow.
I have tested the Javascript code on the intended website using the IE 11 developer console and it works without issue. The code is below in case it is useful.
function includes(stringToCheck, CharacterToSearchFor)
{
var found = new Boolean();
var splitString = stringToCheck.split("");
for (var index = 0; index < splitString.length; index++)
{
if(splitString[index] == CharacterToSearchFor)
{
return true;
}
}
return false;
}
function getPartners() //declare a function which can be called from BP. once called all code within the enclosing {} will be run
{
var searchResults = document.getElementsByClassName("findASolicitorListItem"); //search the web page for all elements with a specific tag and store them in a variable called searchResults.
if(searchResults.length == 0) // If the number
{
alert( "No Solicitors were found.");
}else if(searchResults.length == 1)
{
var innerSearchResults = searchResults[0].getElementsByTagName("span");
for(i = 0; i < innerSearchResults.length; i++)
{
var spanText = innerSearchResults[i].innerText.toString();
if((spanText != ""))
{
if(!includes(spanText, "|"))
{
alert("One Solicitor found. " + spanText);
}
}
}
}else if (searchResults.length > 1)
{
alert( "More than one solicitor was found. Manual Checking required.");
}
}
This is stored in a data item and is passed into the Navigate stage (Insert Javascript Fragment) parameter.
PrintScreen of Insert Javascript Fragment stage
When this stage is ran it successfully injects the Javascript functions into the webpage.
I then try and invoke this inserted javascript fragment
Printscreen of Invoke Javascript Function stage
When this stage runs I get the following error message raised by Blue Prism.
Internal : Failed to perform step 1 in Navigate Stage 'Analyse Result' on page 'Analyse Search Results' - Failed while invoking javascript method:Exception from HRESULT: 0x80020101-> at mshtml.HTMLWindow2Class.IHTMLWindow2_execScript(String code, String language)
at BluePrism.ApplicationManager.HTML.clsHTMLDocument.InvokeJavascriptMethod(String methodname, String jsonargs, Object& retval, String& sErr)
I have searched for this error code and found this answer which indicates there is a problem with the code however I can manually run this code just fine.
Does anyone have any experience with using these methods in BluePrism or have seen this error message before who can help me resolve?
I was actually never able to get Invoke Function working reliably with parameters, I always use Insert Fragment for everything, invoking included.
If you insert this function as a fragment...
function sayHello(name)
{
alert("Hello " + name + "!");
}
...to invoke it you just insert this as another fragment:
sayHello("World");
Tadaa!
As a side note, I am not sure which element in Application Modeler you are using for fragment insertion, but it seems like you are using the root (application) node. I had better experience with inserting the fragment to a dedicated HTML BODY element, for some reason the performance is much greater.
To invoke function by action "Invoke Javascript function", in Arguments field you should put arguments in JSON syntax. If there is no argument you put "[{}]".
On the above Marek's example the function should look:
function sayHello(name)
{
alert("Hello " + name.name + "!");
}
and arguments: "[{'name':'world'}]".

Allow all file types to be selected in Extendscript's File object openDlg() method on MacOS

I am trying to get a reference to a File object using the File.openDlg() method using Extendscript, but when I do this it only seems to allow me to select a specific file type. I want the dialog to allow me to open any type of file. When I use File.openDialog() I am able to select any file type, but because I am launching the OS specific file chooser when a modal dialog button is clicked, it causes the open file chooser to keep popping up--I don't know why it keeps looping, but I suspect it has to do with the "modalness" of the dialog that is currently up when the method is called. So, I am left with simply using the File.openDlg() method, but I don't understand how to inform the MacOS to allow a user to select any file type.
In Adobe's documentation the signature for the .openDlg method is as follows:
fileObj.OpenDlg ([prompt][,filter][,multiSelect])
Then it specifies that the [filter] paramter is:
In Mac OS, a filter function that takes a File instance and returns true if the file
should be included in the display, false if it should not.
So, because I do not want any filetype masking I call the method like so:
newFootageSrc.openDlg("Select your file", function(file) {return true;}, false);
This doesn't work, so I found older Adobe documentation where this was specified for the [filter] param:
In Mac OS, a string containing the name of a function defined in the current
JavaScript scope that takes a File object argument. The function is called
foreach file about to be displayed in the dialog, and the file is displayed
only whenthe function returns true
So, I simply made a named function like this
function allFileTypesOSX(file){ return true; }
And then referenced allFileTypesOSX in the method call like this:
newFootageSrc.openDlg("Select your file", "allFileTypesOSX", false);
That didn't work, so I thought maybe just passing in the identifier itself rather than string would do the trick:
newFootageSrc.openDlg("Select your file", allFileTypesOSX, false);
But alas, that didn't work. Has anybody successfully been able to control file types in the MacOS dialog using ExtendScript?
I know I have this working in scripts at home, so I'll double check the syntax I use when I get home, but I do something along these lines (I'm supporting both windows and mac users).
var fileMask;
if(isWindows()) fileMask = '*.psd';
if(isMac()) fileMask = function(file){file.name.match(/\.psd$/i) ? true:false;}
var files = File.openDialog ('prompt', fileMask, true);
Its more similar to original attempt - you should be passing the actual filter function, not its name.
ETA: If you're not trying to actually limit the selectable files - have you tried just passing null, or leaving the parameter out altogether? They are all optional.
ETA: actual code from a working script (for Photoshop, works in CS3+). By 'works' I mean users on macs are able to select the files they need. I don't have a mac myself to actually see what they see. In a different script I found the following comment to myself above the isSupported function: 'returns true or false depending on if file is a png. 'Filter' doesn't seem to be working right on macs so this is a double check'. If the filter function isn't working as per the documentation this will definately be a problem for you when using the openDlg version of the method.
var filter;
if (isWindows()) {
filter = ["PNG:*.png"];
}
else {
filter = isSupported;
}
win.btnAdd.onClick = function() {
var f = File.openDialog("Open File", filter, false) ;
if (f == undefined)
return;
if (isSupported(f)) {
files = new Array();
files[0]=f;
win.lstImages.text = f.name;
methodInvoker.EnableControls();
} else {
alert("'" + decodeURI(f.name) + "' is an unsupported file.");
}
};
isSupported = function(file) {
try {
//macs will send a file or a folder through here. we need to respond true to folder to allow users to navigate through their directory structure
if (file instanceof Folder)
return true;
else
return file.name.match(/\.png$/i) != null;
} catch (e) {
alert("Error in isSupported method: " + e);
}
}

Exception occurred calling method NotesDocumentCollection.putAllInFolder(string)

I am getting the following error while copying more than 17000 documents to a folder:
Exception occurred calling method NotesDocumentCollection.putAllInFolder(string)
This is my code:
docColl = database.search(formula);
getComponent("TempName").setValue(docColl.getCount());
docColl.putAllInFolder("f_Statistics");
If I move less than 17000 documents, it works. There is nothing to with no of documents in the view.
How can I solve this problem?
Perhaps you can use a loop and a try... catch to handle the error. I'm not sure about the exact syntax you would need for xpages, but could be something like this:
docColl = database.search(formula);
exceptionCaught = true; // little white lie
while(exceptionCaught = true);
{
getComponent("TempName").setValue(docColl.getCount());
exceptionCaught = false;
try
{
docColl.putAllInFolder("f_Statistics");
}
catch (Exception e)
{ // It blew up; assume that this means there were too many docs
View folder = db.getView("f_Statistics");
docColl.Subtract(folder.getAllEntries();
exceptionCaught = true;
}
}
Yes, it's a hack.
And no... the above is not tested, or even syntax checked. I'm just throwing out the idea.
If you try this, I strongly recommend that you do some additional checking to make sure that the cause of the exception really is the number of docs, because if any other exception occurs, the above code will most likely be an infinite loop!
How can I solve this problem?
Copy fewer documents? Whty not split it up into multiple moves if you are having problems when the number of documents exceede a certain number?

Problems with LWUIT in J2ME on Nokia E72

Well, I'm developing a app in my cellphone that is going to connect to my PC, the problem is that everytime that I return a URLRequest to the cellphone, it shows the previous Form on the screen and not de actual one, for example this is what goes in my actionListener:
public void actionPerformed(ActionEvent ae) {
if (ae.getCommand() == guiaUtil.cSelecionar()) {
LoginRemote loginRemote = new LoginRemote();
try {
//This is the request, returns true or false, does not affect the form
loginRemote.login(tLogin.getText(), tPassword.getText());
} catch (Exception e) {
GuiaUtil.error(e);
return;
}
guiaUtil.mainApp().startMenu();
}
}
Then in the "guiaUtil.mainApp().startMenu()" I have this
public void startMenu() {
if (itemsMenu == null) {
itemsMenu = new List();
itemsMenu.setWidth(320);
itemsMenu.addItem("Sincronize Spots");
itemsMenu.addItem("Find Spots");
itemsMenu.addItem("Work");
itemsMenu.setFocus(true);
this.addComponent(itemsMenu);
this.addCommandListener(this);
this.addCommand(guiaUtil.cSelect());
Form form = new Form();
form.addComponent(itemsMenu);
}
form.show();
}
Anyway, after the request returns, it shows my Login form again, instead of showing the Menu List
Maybe what is going is that you are getting an exception, treating it with GuiaUtil.error and returning from actionPerformed without calling startMenu.
I would move guiaUtil.mainApp().startMenu() inside the try/catch block.
Not sure what happens in loginRemote.login(tLogin.getText(), tPassword.getText());
If you access the network, I would put that part in a different thread.
Inform the main thread by some kind of callback when the "remote login" is done,
you can show the menuForm from the edt then.
You have to put the following code outside the if condition.
Form form = new Form();
form.addComponent(itemsMenu);
You are having two form object. one inside if and another one outside of if. Object created inside the loop will loses the scope inside if. You are showing form object outside if. That's why, menu list screen was not displayed.

Resources