Possible to work with Isolated Storage from Javascript? - c#

I'm needing to delete a value in Isolated storage from javascript code.
If this is possible how is it done? I found some code from a post written in 2007 and Silverlight has changed a lot since then.

The best way would be to call a Silverlight method from JavaScript. This link provides examples on how to handle this:
http://weblogs.asp.net/mschwarz/archive/2007/06/01/call-scribtable-methods-from-javascript-with-silverlight.aspx

Expatiating Keith Adler's answer a bit...
IsolatedStorage can only be accessed by managed code, which is a term Microsoft uses to refer to code in one of the .NET languages. Fortunately, Javascript can be used to communicate with managed code, and vice-versa. As shown in the article you linked, this is done through a Silverlight object.
Microsoft has a set of very detailed walk-through articles on this very topic. But perhaps you and others would prefer (or perhaps more appropriately, would have preferred) an existing solution over rolling out your own.
If that's the case, check out BakedGoods. Its a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities, including IsolatedStorage.
With it, you can accomplish what you want by using something like the following code snippet:
bakedGoods.remove({
data: ["targetItemKey"],
storageTypes: ["silverlight"],
complete: function(byStorageTypeRemovedItemKeysObj, byStorageTypeErrorObj){/*code*/}
});
Oh, and for the sake of complete transparency, BakedGoods is maintained by none other than yours truly :) .

Related

Xamarin - Storage data in smartphone memory

I am work with xamarin and I need to storage data in memory of my Android device. In order to have the data once the game has reopened. How can I do? where can I find an example code?
Depends on data type, structure and your specific needs the approach may vary. Since we are talking about a game most probably you need a database. Luckily the official documentation nicely covering this topic.
Beside that if you using .NET Standard take a look on EntityFramework.
P.S.: Generally I would recommend to make a research (as the options above are not the only one) to compare existing solutions and than decide which way to go.
Akavache could be a good solution. It's fairly simple and flexible too.

How would I generate code based on the Google API?

Summary and Question
I'm looking to generate code in C# to prevent significant repetition and wrap the Google APIs in a way like they do themselves, as stated on their .Net Client library page. Edit: Their generator is written in Python, apparently. I will continue to investigate other .Net options.
Where should I focus my attention, CodeDOM, Roslyn or something else? Should I not be considering Code Generation at all - and if so, what alternative track should I take to properly handle this situation?
Details
I am working on writing a wrapper for the Google .Net APIs to make a Google API library for PowerShell (for any and all Google APIs). I already have it working on three of the APIs, but since my project handles all of the authentication (and storage thereof) and other things like pagination, I have to basically wrap each API method call to work with my own authentication so that the user doesn't have to worry about it. This leads to a lot of repetitious coding encapsulating methods that already exist in the .Net Libraries:
public Data.Asp Get(string userKey, int codeId)
{
//I have to wrap their get method with my own using GetService(), for example
return GetService().Asps.Get(userKey, codeId).Execute();
}
Since this is all patterned on information that exists either through the Google Discovery API or through the underlying client libraries, I feel like there should be some way to generate the code and save my hands some trouble.
Some Background and Related Info
On the main page for the Google API .Net Client libraries it is stated:
The source code for the individual Google APIs is programmatically generated using the Discovery API.
I would like to do something similar, though I have no idea where to focus my time and research. I've looked up CodeDOM (and the inherent limitations), Roslyn as well as some differences between the two. I've also checked out the T4 Text Templates for Visual Studio.
To be clear, I am not looking to generate code at runtime as I would with something like Reflection, I am looking to generate bits of a library - though I'm not sure if I am looking for active or passive generation yet.
I work at Google on the .NET client libraries (among other things). Your question is pretty far reaching, but here is the general idea:
The metadata for describing "most" Google APIs is through a discovery document. That describes the methods and types the API has.
Client libraries for accessing Google's APIs then are generated, like you point out, from a Python library. (Using Django as a templating language, specifically.)
Once the code is generated for each Google API, we invoke MSBuild, package the binaries, and deploy them to NuGet.
As for your specific question about how to generate code, I would recommend you build two separate components. The first is something that will read and parse the discovery document, the second is the component that will emit the code.
For the actual code gen, here are some personal opinions:
The simplest thing to do would be to use a text-based templating language. (e.g. Django or just write your own.)
CodeDOM is an interesting choice, but probably much more difficult to use than you want. It is how Visual Studio does some of its codegen, e.g. you describe the code and CodeDOM will emit C#, VB, MC++ to match your desires. However, since you are only focusing on C#, the benefit of CodeDOM supporting multiple languages isn't useful.
Roslyn certainly is a cool, new technology, but that probably won't be of much use. I believe Roslyn has the ability to dynamically model code and round-trip the AST to disk. But that is probably overkill, since you aren't trying to build a general-purpose C# codegen solution, and instead just target generating code that matches the API discovery document.
So I would suggest a basic text-based solution for now, and see how far that can get you. If you have any other questions feel free to message me or log an issue on the GitHub issue tracker.

Calling a Java function from C#.Net

I just want to call a java function from ASP.Net... Please guide me !!!
I have seen JNBridge but its not free... :(
Thanks in anticipation
Possible options that i can think of :-
Expose the java function's functionality through a service (Recommended - Loosely Coupled)
Integrate through backend eg: database. Both programs can access a common database and pass data through here. (Not Highly Recommented - Very Tightly Coupled)
Use an open source bridge eg : jni4net
Note: I have not used this bridge ever but it seems to be something similar to what you are looking for. Refer their sample here
Not sure if it's exactly what you are looking for, but you could check out IKVM.NET.
and why you wanna do that?
1- It will slow your code also as Plateform Conversion came into picture
2- It will make your code hard to test.
3- It will make your code hard to understand.
There must be very solid reason because what ever you can do with Java , you can do in C#
if possible you can always COPY & PASTE same function in ASP.Net application

How should I make a library (.dll) file for other devs to use in their projects using C#?

Sure, there's a type of project in Visual Studio that outputs a DLL that people can use. I know that. I'm just wondering what are some of the standards that devs will expect when using my DLL file.
I'll be providing a class that searches for movies in IMDB and returns results for a dev to consume.
Not a webservice, but a local DLL file. (I'm aware that IMDB frowns upon web scraping, but I'm also aware that they give permission to people if asked. My permission is already sent.)
How should I approach this?
Check out Microsoft's Design Guidelines for Class Library Developers.
Or the newer version of same (thanks to paper1337).
You're then interested in best practices when designing a class library. There is much to say to this thema.
One of the first and foremost things you need to do is to publish all your dependencies. Avoid any hidden dependencies in your code.
For example, don't rely on some key to be set in a shared key-value collection, such as Session. There is no way a user of your library can find it out.
If some method requires some service to be preinitialized, require a valid reference to be passed as an argument.
You need to provide a simple to use API, full documentation and worked examples as a minimum. If you can provide unit tests that would be a bonus.
Internally, you need to verify all inputs into your routines, as well as clearly document what configuration the user is expected to do. Solid exception handling is a given, and you should possibly consider some localisation support in there as well.
If you, or anybody, is serious about creating a good framework for others to use, check out http://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321246756
What ever you make public, should remain public and their signatures cannot be changed in your next version and you must support it forever.
So, take care in establishing your contracts and document them with examples. Make public members only if it needs to be.
Easy-to-use API with appropriate class, method and property names.
API has been tested (e.g. unit tests)
Supporting documentation.

Manage localization with Baml

I'm developping a little application in WPF and I want to localize my resources.
I've always used resources files (.resx), but I heard about BAML that was suppose to change the way of manage localization in a WPF application.
I made my research and I found a way to translate my application using those files.
I wrote a blog post to show how I did it over here (french only, sorry). You can see references at the end of the post for english links.
The fact is, I really dislike this way of managing resources. I think it's way more complicated and I don't see the pros of using this method.
Am I wrong or did I misunderstand something about BAML ?
Thanks.
I think you've got a fairly good grasp on the concept, and yes, it is too complicated.
BAML is just compiled XAML. You're using an external tool to extract the resource, make changes, and embed your resources back. It's definately not streamlined, and hopefully this process is made easier in the future.
Even on the documentation of the process, you'll notice at the bottom someone has recommended using .resx instead of this process. If this is already a method you're using for localization, you probably won't find much advantage in taking the LocBaml route.

Categories