What I want:
get a xml from the AppData to use
What I code
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile sampleFile = localFolder.GetFileAsync("abc.xml");
What I get
Error: Cannot implicitly convert type 'Windows.Foundation.IAsyncOperation' to 'Windows.Storage.StorageFile'
What I Check
When this method completes successfully, it returns a StorageFile that
represents the file.
from MSDN
What I have
Windows 8 Release Preview 64bit;
Visual Studio Express 2012 RC for Windows 8;
C#
I write the code according to the MSDN doc, Why does this error happen and how to resolve it?
Larry gave you the right solution. Let me try to explain what was going on.
If you look at the MSDN documentation for GetFileAsync, you will see that it returns an IAsyncOperation. Your code assumes that it returns a SampleFile. GetFileAsync doesn't provide a file, it provides an object which will provide a file once the retrival is complete.
Await in C# provides a function that will be called by that object (or on behalf of that object) once the conditions for completion are satisfied. That function then returns the value to you. A promise in JavaScript (.then or .done) provides similar functionality, but you have to supply the function yourself.
The reason for this is so that the application can be responsive. File access is slow. If accessing memory took 1 second, then file access would take about 15 minutes. Asynchronous programming allows other things to happen while your program is waiting.
Try using "StorageFile sampleFile = await localFolder.GetFileAsync("abc.xml")" if you're in C# or "localFolder.GetFileAsnc("abc.xml").done(function (sampleFile) {})" if you're using JS.
Related
I'm trying to convert a sub to be async and, according to every documentation (and as far as I can remember, I did it in the past), it says that I should convert my sub to a Function() as Task.
My problem is that as soon as I hit enter, it is modified to Function() as Task(of Task). To make sure it was not something inside my method, I did an empty one but it resulted in the same behaviour. I also tried doing ctrl+z to force to keep as Task but then I get, on the method,
BC36945 Visual Basic AND VB.NET The 'Async' modifier can only be used on Subs, or on Functions that return Task or Task#Of T#.
and on the caller,
BC36930 Visual Basic AND VB.NET 'Await' requires that the type 'Task' have a suitable GetAwaiter method.
Is it normal? Is it a new behaviour in 4.6.1? Or is there something additional I should do to have it work as expected and return void?
Note: I'm on Framework 4.6.1 with TupleValue nuget installed.
As mentionned by #HansPassant, for Task to be used directly without its full namespace (System.Threading.Tasks.Task), the correct import must be present (which is generally the case by default) and no other namespace should collide with it.
In my specific case, I had Microsoft.Exchange.WebServices.Dataimported which also contains a Task type so when VS modified my signature for async with as Task(of Task), what was really there was as System.Threading.Tasks.Task(Of Microsoft.Exchange.WebServices.Data.Task).
In my project, I fixed the ambiguity by adding Imports Tsk = System.Threading.Tasksand then I was able to simply write as Tsk.Task.
Trying to implement document locking in a small database. We use it in XPiNC. I found Julian Boss's excellent answer in in which he provides a javascript function that seems to have everything I need.
So in a small test database I added the script library and added as a resource. In my edit button I have the following code:
var ntdDoc:NotesDocument = document1.getDocument();
documentLocking.lockDoc(ntdDoc)
But this throws the following error:
Script interpreter error, line=2, col=17: [TypeError] Error calling method 'lockDoc(lotus.domino.local.Document)' on an object of type 'Object [JavaScript Object]'
1: var ntdDoc:NotesDocument = document1.getDocument();
-> 2: documentLocking.lockDoc(ntdDoc)
I have tried passing in the data source and that didn't work either. What do I need to pass?
That answer is a few years old and I'm not sure of the current recommendations around storing SSJS global variables. Storing SSJS functions as objects is no longer recommended.
Domino has in-built document locking, which is equally valid for use in XPages. Mastering XPages Second Edition had a very good and comprehensive walk-through of how to use the document locking. The only (potential) gotcha is that you need to lock the document before deleting it - because to delete it you need to modify it, and to modify it you need to lock it.
I'm working on a service that will download a .NET solution from a repository and build it (not unlike a continuous-integration build service). What I want to know is, using MSBuild programmatically via the Microsoft.Build namespace classes, can I can load the solution and project(s) into memory and build it without first saving them to disk in a temporary folder?
I'm still learning MSBuild and trying things, but I figure someone on Stack Overflow has tried this and has some insight.
I can't speak to whether this is a good idea or not, but it's possible to do.
ProjectInstance has a constructor that accepts a ProjectRootElement, which can be constructed via the Create(XmlReader) method. And as you may know, XmlReader can be attached to various Streams including a MemoryStream.
Here's how something like this may look:
var xmlReader = XmlTextReader.Create([your existing memory stream]);
var project = ProjectRootElement.Create(xmlReader);
var buildParams = new BuildParameters();
var buildData = new BuildRequestData(new ProjectInstance(project),
new string[] { "Build", "Your Other Target Here" });
var buildResult = BuildManager.DefaultBuildManager.Build(buildParams, buildData);
After researching MSBuild and all the involved components, it appears as though it's necessary to have the entire project set up on the file system before being able to build it. Unfortunately, what I'm trying to do just can't be done with the provided toolset.
I'm trying to get containers for my app settings and files and i found this code in Microsoft Website
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.ApplicationDataContainer localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
but when i paste it to my code it give me an Error
anyone know what is the error ? how can i solve it ?
LocalFolder isn't a storage container, its a storage folder. Wouldn't something like this work better?
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
The property you are accessing returns an object of type StorageFolder (as documented on the same MS webpage where you found an incorrect example). So, just change the type of localFolder as appropriate.
Don't trust examples, they often contain errors for the first several years after publishing. Also, learn to read and understand error messages. The error you posted explicitly says what's wrong and how to fix it.
I'am obviously new to Google Apps Script, nevertheless I have some experience in coding in C, PHP and Java. Since we would like to create a small CRM in our company with Google Apps Script, we need to create an application with a form available on Google Sites. I've been searching an answer for this problem a long time, I haven't unfortunately found any answer. I have a code like this:
var klienci_id = new Array(100);
var klienci_nazwa = new Array(100);
var klienci_adres = new Array(100);
var klienci_osoba = new Array(100);
var klienci_telefon = new Array(100);
var klienci_email = new Array(100);
function doGet(e) {
var app = UiApp.createApplication();
// hello world label
var helloworldLabel = app.createLabel("I love Apps Script!").setStyleAttribute("fontSize","16px");
// add the label to the app container
app.add(helloworldLabel);
return app;
}
function main() {
var klienci = SpreadsheetApp.openById("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E");
var kuchnia_polska = klienci.getSheetByName("Kuchnia polska");
var dane = kuchnia_polska.getRange("D7:F22");
doGet();
}
And everytime I try to publish it and enter the given link I get the error "Unknown macro doGet". I know this is a common problem when somebody doesn't use doGet() function but I do - and it still doesn't work. I also believe that Google should create a thorought documentation on Google Apps Script, which would work the way the Unix manual does, since I just cannot get through all these strange pages of goddamn help :) It's neither a Windows help, nor a good manual ;)
Regards,
Kamil
I have a suspicion that you made a "version" once, published the app, went to the "real" link and not the "development" link, and then added the doGet() function. When you make a version, it freezes the code at that time. The version that the app is published at is the version of the code that will run at the "real" link (what you give users), which allows you to keep editing the code without disturbing existing users of your app. There is a special "development" link given to you in the publish dialog that always refers to the most recent version of the code, but which will only work for you and no one else.
I'm affraid there is a little misunderstanding on your side concerning the use of the 'doGet()' function. When you want to run an application as a webapp, the doc says indeed that it must contain a doGet function but what it doesn't say explicitely is that this function is supposed to be the starting point of the whole app, ie the function that the url will call in the first place. So it doesn't make much sense to have the doGet function called from a so called "main" function since the "main" function is not the main function...
I cannot imagine right now a situation where some function calls the doGet function since every function in the script is called initially (directly or indirectly) from this doGet function.... in fact the 'end' of any other function in the script 'returns' to the doGet initial function. Well this is maybe not absolutely true in every case but it gives you the general idea about how it works.
I'm hoping this is clear enough and, to return to your code snippet, if you remove the doGet(e) call, it will ideed show a nice "I love Apps Script!" but it will never do anything else, certainly not see the "main" function.
I've copied your code here https://script.google.com/macros/d/MJ80AK8t7kbgDcC-NaLPYvH797_hv7HHb/edit?template=app&folder=0AKGkLMU9sHmLUk9PVA
and when deployed as a web app appears to work https://script.google.com/macros/s/AKfycbxOiaukLt7P4pIm7bms7aU16uEo6FuZ-MNOh0tSqUwr/dev
Only thing I can think of is there is something else in your code not copied into the snippet that is throwing the exception.
[Just before the GUI Builder was published I came up with Creating a framework for custom form interfaces using Google Apps Script which might help you with your project]
Thank you both for help. Serge, yes, it's really not obvious what the structure of Google Apps Scripts should be. They are based on JavaScript, however, due to lack of HTML in the code they have completely different flow - so naturally, there has to be a main function which is executed first. And of course in every programming environment it has to have a different name to make it more distinguishable ;-)
I created a new copy of my application, not changing the code completely - deployed it and it works beautifuly. Since I haven't changed anything in access options, it's quite strange that two applications with the same code and the same options don't give the same result. I think it may be a kind of the environment flaw, maybe someone from Google should look at this :)
Here's the link to the script, I've set access to "Anyone with the link".
https://script.google.com/a/macros/foodbroker.pl/s/AKfycbwk2IM-rIYLhQl6HOlbppwGOnw4Ik_kH7ixbaSNVxIE-QR7cq8/exec