Umbraco Document.getProperty(...).Value throws Null Reference Exception - console-application

I am writing a small app that links into Umbraco (a small stand-alone console application that will eventually run as a scheduled task on the server) and I'm using the Umbraco APIs (4.5.2) to make changes to the database/document.
Here is a fragment of what I'm doing:
IEnumerable<Document> documents = Document.GetChildrenForTree(parentDocumentId);
foreach (Document doc in documents.Where(d => d.Published))
{
doc.getProperty("myData").Value = "some data"; // Exception here
// ...other stuff here...
}
However I always get a NullReferenceException because there are no properties. This confuses me because I can see that there are 5 properties in the umbraco interface.
A colleague suggested that I use a Node instead of a document, however I can't even create one as I get a NullReferenceException from the Node class constructor.
Node myNode = new Node(-1); // NullReferenceException here
Does anyone have any ideas?

The document class gets/sets information from the umbraco database. Since your running code in an out of band console application it can't find the umbraco context. Therefore throwing a null reference exception.
You need to run the code inside of the umbraco process. There is a asmx webservice that exists for third party integration. /umbraco/webservices/api/documentservice.asmx

Another way of achieving this could be to use linq2umbraco.
for further details see http://our.umbraco.org/forum/core/41-feedback/7699-UmbracoLinq-in-console-app--Having-some-troubles

I checked out the 4.5.2 source recently, to find that populating Document and Node objects only requires a connection using umbracoDbDsn. So if you have an AppSetting called umbracoDbDsn which points to a valid Umbraco database instance, you'll be good.
HTH,
Benjamin

Related

XSockets.NET 4.0 - new controller instance created on method call

After upgrading my .NET server and client projects to 4.0 RC
I get NullReference exceptions because my custom State object is null.
I instantiate the state property in OnOpen event handler, but inside the method body of the first call it is already null.
I have checked in debugger and see that this.GetHashCode() returns different values
in OnOpen event handler and in method, which means it is a different instance.
Is it a known issue? I assume it is very basic behavior and probably I have missed something during upgrade to new version.
Thanks in advance.
I managed to understand the problem. It happens when using PluginAlias.
[XSocketMetadata(PluginAlias =
When attribute is removed and client uses full controller name everything works as expected
and GetHashCode returns same id.
I pushed the replication code to GitHub:
https://github.com/amichel/PlayWithXSockets/tree/ReproduceBugs
When using alias there is a bug (as you have found out).
The workaround is to either use the class name of the controller or only have alias in lower casing.
In your case using
[XSocketMetadata(PluginAlias = "test")]
would work.
Regards
Uffe

Using RegularExpressionAttribute in a Custom ModelValidatorProvider

I've got a custom implementation of ModelValidatorProvider that I'm using in an ASP.NET MVC App. But I'm currently getting an error on any property that yields a RegularExpressionAttributeAdapter. The error is Either ErrorMessageString or ErrorMessageResourceName must be set, but not both. Now my code doesn't set the resource name but does set a message.​​
yield return new RegularExpressionAttributeAdapter(metadata, context, new RegularExpressionAttribute(myExpression) {
ErrorMessage = expressionErrorMessage
});`
I've tried setting both the ErrorMessageResourceName to null and setting the ErrorMessageResourceType to null but it doesn't help. If I don't set the ErrorMessage the exception goes away but then I loose my user feedback for the validation.
Now, I should note that this used to work but I've recently upgraded the app to use MVC4 instead of MVC3 and I'm curious if this is unique to MVC4 or if it's something else?
While I never found out why it was doing this I was able to uncomment my code for this after upgrading to MVC4 and it works as expected so I can only assume it was something specific to the previous version.

Having problems getting a List of Objects back from Restful service

Hey guys. I've developed some services in REST that are running on Glassfish 3.1.
I have a Java SE application and I am using Jersey as the client api.
public <T> T findAll_JSON(Class<T> responseType) throws UniformInterfaceException {
WebResource resource = webResource;
return resource.accept(MediaType.APPLICATION_JSON).get(responseType);
}
This is the client code that is generated by Netbeans.
My main problem is passing a list of objects as the response type
Here is the client code.
List<PkgLine> pkgLine = service.findAll_JSON(List.class);
System.out.println(pkgLine.get(5).getLineStatus());
service.close();
Obviously this is not working because the response needs to be a List of PkgLine. How do I pass that as a generic? My service is set to return the List of PkgLine. Thanks.
The problem is "erasure". You can declare a List<PkgLine> in your program, but at runtime the information that the objects in the List are PkgLines is erased. List<String>, List<PkgLine> and List<Object> are all the same type at runtime. (There's a reason why this is so; I won't explain it here but you can look up "erasure" if you are interested.)
The objects in the List are still PkgLines of course, but to the List they are just Objects, and you'll have to cast each one to a PkgLine. It's not pretty.
List<?> pkgLine = service.findAll_JSON(List.class);
System.out.println(((PkgLine)(pkgLine.get(5))).getLineStatus());
service.close();
What about parsing an array? It has the same json represantation.
You could write something like this:
resource.accept(MediaType.APPLICATION_JSON).get(PkgLine[].class);

Accessing Firefox tab element in nsIWebProgressListener::OnStateChange using C++

I am developing extension for Firefox 3.0-3.5 versions using VS2008.
I want to set attribute to a tab once the document load request completes within that tab window.
So in OnStateChange method, I am checking for document load.
I have used STATE_STOP & STATE_IS_DOCUMENT for it.
I want to determine which tab window has been associated with particular document request.
I have valid DOM Document pointer got from nsIWebProgress *aWebProgress which is 1st input
parameter of OnStateChange.
if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT))
{
nsCOMPtr<nsIDOMWindow> domwin;
nsCOMPtr<nsIDOMDocument> domDoc;
aWebProgress->GetDOMWindow(getter_AddRefs(domwin));
domwin->GetDocument(getter_AddRefs(domDoc));
}
I have tried to get nsIDOMDocumentXBL pointer by QIing nsIDOMDocument pointer(domDoc in my example) but it fails with Error code 0x80004002 (2147500034) i.e.NS_ERROR_NO_INTERFACE.
How do I get the tab element corresponding to document load request.
Could any one please help me?
Thanks in Advance,
Vaibhav D. Gade.
IF I understood the question correctly and you want a for a content window, you probably need https://developer.mozilla.org/en/Working_with_windows_in_chrome_code#Accessing_the_elements_of_the_top-level_document_from_a_child_window to get the chrome window, then run the implementation of gBrowser.getBrowserForDocument in the chrome window.
You'd save yourself a lot of time if you stopped writing C++ and switched to JS for such things.

Complex Object in JAX-WS is created empty

I'm testing JAX-WS to access the Oracle IRM web serviecs. I can get it to work just fine with AXIS so this isn't an Oracle problem.
What's happening is that I'm getting the following error when making the call:
Expected xsd:anyType - unknown type provided
If I look at the SOAP packet is sent I see that the owner tag is blank under JAX-WS:
<ns1:browseAccounts>
<owner/>
<accountType>All</accountType>
</ns1:browseAccounts>
The same piece under AXIS is this:
<owner xsi:type="ns1:LicenseServer"
xmlns=""
xmlns:ns1="http://www.sealedmedia.com/ls/server/schema">
<serverKey>#############</serverKey>
</owner>
Obviously the owner tag is not getting properly created, this is what I'm using to create that:
AccountServicesPort AA = ORI.getAccountServices();
LicenseServer LicSer = new LicenseServer();
LicSer.setServerKey("#######################");
List<Account> Acts = AA.browseAccounts(LicSer,AccountAccountType.ALL);
Is there some other process that I need to go through to create the object properly?
EDIT
I thought maybe running the LicenseServer creation through ObjectFactory would help. Unfortunately, it doesn't.
Despite the Oracle IRM documentation stating that BrowseAccounts accepts either a LicenseServer object or a Context object for the owner parameter it actually accepts an LicenseServer_ref.
EDIT
Further, I was running JAX-WS under JDK 1.6.0 which is a lower version than JDK 1.6.0_14. The new version supports XMLSeeAlso annotation which allowed JAX-WS to use the proper class for serialization.