Best practices for user settings/configuration in a c# client app - c#

I am working on a .NET app that will also run on iphone via monotouch and osx/linux via mono. The app will hold profiles for various users and the profile used for a particular session will be selected on startup, kind of like Skype.
To store per-user settings, I am considering using the Application Settings system that's part of .NET. However, this system seems to rely on reflection, which is not available on iphone. I am also not sure if this system will function on platforms other than Windows.
I could also use the app's sqlite database that stores the application data to store settings, and simply roll my own settings classes that would be serialized/deserialized to the sqlite database like all the other application data.
Finally I could roll my own file-based solution.
What are the tradeoffs for these approaches? Why does .NET have dedicated support for user settings? It seems like a quite simple thing that coders should do on their own, and the existence of dedicated support within the .NET framework makes me suspect that I'm missing some point of complexity.
Thanks!

First thought - don't use configuration settings, use the sqlite database as that is on the iPhone and the best approach to take. Remember MonoTouch just transliterates the .NET code to the Objective C equivalent code and compiled to native binary, and you may run into snags if you use Windows/Mono specific code that may not be present on the iPhone.
Avoid pinvokes like the plague if you want your code to work across all platforms.
.Net has support for user settings because Microsoft designed them that way.
Hope this helps,
Best regards,
Tom.

Related

converting c#.net application to android

I know this is very vaque question but still I am asking.
Is there any one I can convert my existing WinForm built in c#.net and DB as SQLSERVER 2008, to andorid application ?
If no, then is thr any easier way to built an app as I am not familiar with any Mobile Application tools.
Generally, no. The languages are somewhat similar, but the way the UI is built is vastly different and will have to be rewritten from scratch. Also, database access differs. I actually doubt that Android have libraries required to "talk" to SqlServer. Even if it managed to talk over some generic ODBC layer, still the DB-access will also differ very much. I assume this would consist of more than 80% of your application - so it can safely be estimated that whole application cannot be converted, and a new application has to be written. Of course, some SQL queries might be reused, some application classes might be usable too (if written in an enough platform-independent way, so they can be translated to Java)..
No there is no way to do that in easy way.
Android development is similiar in UI level to WPF (you can find some simliarities) + you have completely different behavior model as you're talking about mobile development.
In short, if you want to continue with C#, you may think of picking Mono Droid.
It's payed.
This is not easy as far as I know. If you want the conversion for free you should rewrite it in Java using the Android SDK (run on Dalvik - a custom VM). As stated above, you will have little effort learning it if you already know C#, you could also use Mono Droid or hire a developer if you have the possibility to do so.

Framework/Dll/... to manage a cache + polling to a service

I remark that for my project I really need often something to manage a cache of our data(for data access performance, for offline work, ...).
So I was asking me if there was something which could respond to my needs or if I will have to create my own framework for this. It can be only a "Core" which furnish the logic, and we have to implement the business part.
My needs are:
Data sources can be WCF/Web service/...(this part should be implemented on every new project
It has to manage an store of data
available
This store must be refreshed regularly by polling the service
This store can be persistent(write cache on disk for the next start)
The framework must allows modifications, online and offline,
asynchronous and synchronous(if online)
It has to run with c# 4.0
If the local cache store can be accessed through LINQ, it would be great(like directly through a list
The concurrency has to be managed(or offer us a way to manage it)
The use/configuration of this framework should be shorter than implement myself it every time
So here we are, do you know a tools which can fits into my query?
Somebody tell me that MS entreprise library should have something like that, but I didn't found anything.
Thank you!
You could have a look at
Windows Server AppFabric. It used to be called 'velocity'.
It is a distributed in-memory application cache platform for
developing scalable, high-performance applications.
Otherwise, the Enterprise Library Caching Application Block you're talking about is here: The Caching Application Block however, this page says:
Caching Application Block functionality is built into .NET Framework
4.0; therefore the Enterprise Library Caching Application Block will
be deprecated in releases after 5.0. You should consider using the
.NET 4.0 System.Runtime.Caching classes instead of the Caching
Application Block in future development.
And actually, the System.Runtime.Caching Namespace is a very good building block to build on if you're going to write something by yourself. I don't think it implements the notion of distributed cache, that's why Windows Server AppFabric exists.
Now, there is also non-Microsoft technologies available in the .NET space. Have a look a memcached and .NET implementation or usage:
Is there a port of memcache to .Net?
Memcached with Windows and .NET
You also have commercial packages available, like NCache (I'm not affiliated). I don't know what they provide, but it's also probably interesting to have a look at it, just to be aware what they provide, to ensure you don't miss any feature you'd need later one.
Have a look at SharedCache.

Caching across Applications in .Net on a Windows Machine

I am trying to implement caching in .Net such that the cached data is accessible not just by an application that may run multiple times on the same machine but by other types of applications that may run on the machine. They could be windows services, web services, win forms etc.
I have looked at System.Runtime.Caching (because Enterprise Application Blocks Caching is going to become obsolete) as a means to achieve this. The default MemoryCache is insufficient to achieve this as I don't believe that it work across app domains.
Is there a way I can implement the kind of caching I am looking for or is there a caching dll of some sort (must be free) that I can use to achieve my goal?
Is there a way to use System.Runtime.Caching with IsolatedStorage scoped to MachineLevel?
I've looked at memcache too and can't use it because we need this to run on windows machines. I started looking at SharedCache (http://www.codeproject.com/KB/web-cache/AdvanceCaching.aspx) and am curious about the pitfalls it has as well.
Thanks.
-- Revision 1 --
I think the optimal solution for me would use the Caching object to a Memory Mapped File (http://msdn.microsoft.com/en-us/library/dd997372.aspx). So the question I have now is whether anyone has done that with the System.Runtime.Caching object. There must be a way to extend it if necessary...examples of how to do so would also be much appreciated.
You're looking for AppFabric Cache. It's a Windows Server technology from Microsoft. It's free.
I should also say that if you like memcached, you can use that on Windows as well, and in fact Microsoft Azure team members used to recommend it, before the AppFabric caching was available on Windows Azure.
Have you evaluated Microsoft Velocity? Take a look - I believe if you are not okay with using the AppFabric Cache, this should work out for you:
http://msdn.microsoft.com/en-us/magazine/dd861287.aspx#id0450004
For simple client based caching, you can look at file based caching.

Advantages/disadvantages of writing a web app using Adobe Air/Java as opposed to platform specfic languages?

I need to write a web app (that also works offline) for windows and mac (and linux as well perhaps).
I was wondering if I should use something like air/flash/java for this, the advantage being I will only need to write the app once.
However, I was wondering if there are any disadvantages of doing it that way as opposed to writing it in c# for windows specifically and then objective-C/cocoa/whatever for mac. Will the functionality of the app be limited if i do it in Air/Java? Are there any advantages to writing it in the language specific to the platform?
If possible it would be nice to know what the advantages/disadvantages of both methods are as it would help me (and hopefully others) come to a decision on the best way to create such an app according to ones needs.
Any help would be much appreciated! Thanks.
The first thing to realise is that writing cross platform applications that look and behave native on each target platform is a hard thing to do.
Using a cross platform kit (AIR/java):
Less work, in theory should be quicker to build
Common language and toolkit, only one thing to learn
Adding a new supported platform should be easy(ish), build installer, debug provide any native platform integration etc
There is a tendency towards only implementing the lowest common denominator feature. An example of this would be the java File api. It only supports the basic concepts of files where as Windows, OSX and linux all have addition
May still require platform specific integration code (maybe native) in order to get an acceptable level of integration.
Using the native toolkits:
A lot to learn, moving between Windows MFC (or .Net winforms) and Cococa is going to be quite jaring
Not only will you have different languages, you will also have different tooling
There is no limit or false ceiling to what can be achieved using the native toolkit gives you access to everything
Making your app look like it belongs on the platform (important for Macs) is pretty much out of the box
Personal recommendation: go with the language tool kit you know the best, depending on how thick your app is (you mentioned it's part online) you may be able to rewrite it in another language latter once you have a successful application.
Much depends on the kind of app you will be writing. I use Adobe AIR for a lot of in-house tools.
If you write for AIR what you'll get is something that looks like a web page. That's fine, because people feel at home operating a browser interface--maybe even more at home than with a native app.
But, yes, you'll absolutely have limitations.
So what's your app?

Silverlight, Wpf Web App (xbap) or Click Once? Pros and Cons

We are starting a new project and I'm trying to decide which of the Wpf-esque develop/deploy strategies we should go with. In our case we are looking at quite a complex business app that will be used by 100s (not 1000s) of people, So I'm leaning towards a click-once app. My boss likes the idea of a Silverlight app as it means easier deployment. So which way should we jump?
The answer is, of course, "it depends".
So what are the pros and cons of each?
I'll start the ball rolling (Edit Added in some answers from artur carvalho):
Silverlight
Pros
Cross browser
Doesn't require full framework.
Better control of users. If your users login, you dont have to worry with activation keys or similar stuff.
It works on Windows and Mac.
You can update all your users apps easily.
Cons
Can't interact with client's file system etc
Has less functionality compared with full Wpf (anyone got a good resource that documents differences?)
Single window
Single version
Wpf Web App (xbap)
Pros
Full Wpf.
Cons
Single browser
Requires full framework
Can't interact with client's file system etc
Single window
Single version
Wpf Click once
Pros
Full Wpf
Can work offline
Multiple windows
Multiple versions (con?)
Better access to low level parts of the computer
No downtime for maintenance
Cons
Single browser
Requires full framework
Slightly(?) harder to install.
First, I would evaluate whether a web client (ideally MVC+jQuery) can't do the job...
Assuming a full client is warranted:
If it is a business app that demands a client, I would tend to go with the full framework and ClickOnce; the main difference here (re deployment) is that the client must have the framework installed - but past that, ClickOnce deployment is very pain free. Actually, building a ClickOnce manifest is much easier than Silverlight etc, since the IDE will do almost all of it for you; you just have to host the files somewhere (could be a web URL; could be a network UNC).
This gives you much more control (and power) at the client, as well as a far greater range of existing resources to use (for example, if you need, you can use some legacy winform code on the WPF surface). The "requires full framework" is also one of the largest benefits: "has full framework".
You should also perhaps consider the 3.5 "client profile" setup; not sure how wide-spread this is in reality... but worth knowing about.
You didn't say if this is a company only application or a public facing one. That alone will decide it for you.
If company only, I would go with full WPF click once. This will give you everything.
Full framework should not be an issue. It's a one time install running in the background so it's not something that your decision should depend on. Cons: it runs in Windows only but if your company is Windows only, this should not be an issue.
However WPF apps could be resource hungry so you need to know if all your client machines are capable of running WPF apps smoothly.
If it's an Internet app, go for Silverlight: it runs under different operating systems.
PROs vs. ASP.NET Web Forms
No ViewState or "surprise crap"
o This applies to Silverlight as well. Silverlight brings the "desktop" experience to the end user and there is no ViewState that is used in Silverlight.
Faster server-side & client-side
o Silverlight is faster on the client/server side depending on how you look at it. Silverlight is compiled in a .NET subsystem of Silverlight. You have access to multithreading, LINQ, complex data structures, etc. The performance vs. an ASP.NET or AJAX/JavaScript application is it magnitudes times better because of the client execution and some of the items that normally are handled in a server BLL can be brought down to the client
Simplified model for multiple related views
o Silverlight supports the complete seperation of the data and the UI. Taking this further by just creating seperate views for say another consumer of Silverlight is pretty powerful. You can apply the same MVC/MVP pattern inside Silverlight and attain this level of abstraction. Jason mentions an example of being able to create a seperate view for an iPhone and only the View component has to change. This applies to Silverlight as well for different things. For example, I have large sized Silverlight app I want to port to SharePoint. I can create a "Smaller View" for SharePoint so it fits nicer into the UI. Furthermore, Silverlight Mobile is being private tested now. I would assume that same very powerful level of abstraction applies as well to create a "Mobile view" for your Silverlight application.
Unit Testable
o Silverlight includes a Unit Test framework as well. It can be downloaded here: http://code.msdn.microsoft.com/silverlightut/
Challenges if you are not running IIS 7
o Silverlight does NOT care if you are not running on IIS 6 or IIS 7 or Apache for that matter. This is one feature where Silverlight has an advantage over ASP.NET MVC.
Client Caching
o In ASP.NET Web Forms or MVC, you are caching on the server. Silverlight allows you to cache on the client via Isolated Storage (which can be increased to hundreds of megs if necessary). This allows applications to perform ultra fast without bogging down the hosting server.
CONs vs. ASP.NET Web Forms
Difficult to convert existing code
o Silverlight is a completely different programming platform than either ASP.NET WebForms or MVC. Not only will a lot of the code not convert, you also have to think about the client layer and in most cases a complete re-architecture is needed if you are replacing large modules inside your existing ASP.NET site.
NOT the best SEO out of the box
o Google several months ago started spidering SWF files and adding them to the search engine. I think Silverlight is probably still a ways away here. What you can do for Silverlight SEO is the basic tricks to describe the meta data tags really well around the plug in.
Data access
o Data access in Silverlight is limited to Web Services/WCF/ADO.NET Data Services. You cannot make direct calls via ADO.NET or stored procedures to a database.
Security
o Silverlight runs on the client. A lot of your bits are then roaming in the wild on the internet. Furthermore, some of the data access techniques do not support full WS* standard security. Therefore, beyond certificate based transport security, you are either writing a lot of your own plumbing code or waiting for the next rev. The XAML code is pretty much insecure; not many applications have their Intellectual Property in their UI. In Silverlight, that can be very easily reverse engineered using Silverlight Spy for example. Silverlight, just by nature, is a little less secure than an ASP.NET MVC application. Obviously, you would want to encrypt/obfuscate your Silverlight assemblies before letting them off in the wild.
1. Silverlight can access the DOM from the hosting page and
2. the hosting page can access the Silverlight part.
That's a big + for Silverlight
But all other limitations cry for WPF/Windows-Forms with Clickonce
file access, right mouse click, ease of db access
The pros
The Silverlight plug-in means developers can target a single, consistent runtime for browser-based applications, rather than dealing with the complexity of multiple browsers in different versions. You also get video and multimedia effects that are hard or impossible with pure HTML and JavaScript, though Adobe Systems' Flash has the same advantages.
Execute .NET code without deploying the .NET runtime. The Silverlight plug-in does include a cut-down .NET runtime, but instead of dealing with a large download and the complexities of the Windows installer, the user has a small download of about 4MB, all handled within the browser. In my experience so far, installation is smooth and easy.
Performance is promising. Silverlight comes out well in this prime number calculator, thanks no doubt to JIT compilation to native code, though it may not compare so well for rendering graphics.
Support for Moonlight means there will be an official open source implementation of Silverlight, mitigating the proprietary aspect.
Silverlight interprets XAML directly, whereas Adobe’s XML GUI language, MXML, gets converted to SWF at compiling time. In fact, XAML pages are included as resources in the compiled .XAP binary used for deploying Silverlight applications. A .XAP file is just a ZIP with a different extension. This also means that search engines can potentially index text within a Silverlight application, just as they can with Flash.
Third-party component vendors are already well on with Silverlight add-ons. For example, Infragistics, ComponentOne and DevExpress.
Take your .NET code cross-platform. With Macs popping up everywhere, the ability to migrate Visual Basic or C# code to a cross-platform, browser-based Silverlight client will be increasingly useful. Clearly this only applies to existing .NET developers - I guess this is the main market for Silverlight, but it is a large one. The same applies to the next point:
Uses Visual Studio. Microsoft’s IDE is a mature and well-liked development environment, and since it is also the tool for ASP.NET you can use it for server-side code, as well as for the Silverlight client. For those who don’t get on with Visual Studio, the Silverlight SDK also supports command-line compilation.
Choose your language. Support for multiple languages has been part of .NET since its beginning, and having the .NET runtime in Silverlight 2.0 means you can code your client-side logic in C#, Visual Basic, or thanks to the Dynamic Language Runtime (DLR) Iron Ruby or Iron Python.
Isolated storage gives Silverlight applications local file access, but only in a protected location specific to the application, providing a relatively secure way to get this benefit.
The cons
If Apple won’t even allow Flash on the iPhone, what chance is there for Silverlight?
Silverlight is late to the game. Flash is mature, well trusted and ubiquitous. Silverlight 2 only comes out of beta in the Autumn (we hope). It is the version we care about - the one that includes the .NET runtime - and will still lack support on mobile devices, even Windows Mobile, though this is promised at some unspecified later date.
The design tools are Expression Blend and Expression Design - but who uses them? The design world uses Adobe PhotoShop.
While having solution compatibility between Expression Blend and Visual Studio sounds good, it’s actually a hassle having to use two separate tools, especially when there are niggling incompatibilities, as in the current beta.
No support for the popular H.264 video codec. Instead hi-def video for Silverlight must be in VC-1, which is less common.
It’s another effort to promote proprietary technology rather than open standards.
Yes Linux will be supported via Moonlight, but when? It seems likely that the Linux implementation will always lag behind the Windows and Mac releases.
Silverlight supports SOAP web services, or REST provided you don’t use PUT or DELETE, but doesn’t have an optimized binary protocol like Adobe’s ActionScript Message Format (AMF), which likely means slower performance in some scenarios.
Silverlight is a browser-only solution, whereas Flash can be deployed for the desktop using Adobe Integrated Runtime (AIR). Having said that, yes I have seen this.
You have to develop on Windows. This is particularly a problem for the Expression design tools, since designers have a disproportionately high number of Macs.
You can add to the pros and cons of the usual stuff of the online vs offline debate. Some items:
Pros
wpf(offline):
better access to low level parts of the computer.
cpu usage is local, so you rarely have cpu load issues.
not dependent of the net.
no downtime for maintenance.
silverlight(online):
Better control of users. If your users login, you dont have to worry with activation keys or similar stuff.
It works on Windows and Mac.
You can update all your users apps easily.
I simplified it a bit, there are gray areas in the list. I only tinkered with XBAP, so that one I'll leave out. The Cons are not hard to figure out after looking to the pros.
HTH
I would consider WPF ClickOnce with sync framework support (www.msdn.com/sync). This would allow you to support limited functionality when the user is not connected to the corporate network (which will eliminate any browser-based deployment scenarios, such as Silverlight and XBAP).
If you don't need all WPF I would try do it in Silvelight first Then you can switch to WPF more easily if you need it later.
Here I think it applies the “less is more” principle: it’s true that with WPF you have much more options and can access to the user computer, but that can finally be more a problem than a help as the times go. Think for example in how many changes you can need to change from Windows XP to Vista in an application that uses a lot of the “user computer” resources!
Mark, what do you mean when saying 'single browser' for XBAP? XBAP does work with Firefox for example. It indeed requires .NET Framework and it is unlikely that we will have WPF in Mono anywhere soon (if ever) so you are stuck with Windows, that's right.
Isn't click once available on firefox these days, via this addon: https://addons.mozilla.org/en-US/firefox/addon/1608

Categories