I'm new in NHibernate world and I'm starting to build a simple C# Windows Form Application that imports some XLS files into a DB (SQL2008), elaborates data and than exports a CSV file.
I've tried to search some examples to how use and manage NHibernate session; some of them are useful for Web Application. I've seen that in MVC Application the NHibernate session is created on Application Start, but I can't understand when I must create the NHibernate session into a Windows Form Application.
Anyone can help me?
Thank you!
Per the feedback I'll suggest that you look into using SSIS for this kind of work. Besides being designed for ETL processes like these SSIS can also be re-executed as needed and there's no need for custom code at all. Though if you want, it's not hard to write .NET code run SSIS packages as necessary. Here's an example. Beware though that SSIS APIs still often carry DTS prefixes. DTS (Data Transformation Services) is the precursor to SSIS (SQL Server Integration Services) and much of the technology is reused.
First of all, I don't think you are using the right tool for the job.
But if still want to use NH for learning purposes, these are my advises:
I highly recommend this lecture:
http://msdn.microsoft.com/en-us/magazine/ee819139.aspx
Ayende talks about most of the issues about session handling in non-web scenarios.
What we used to do is to follow a pattern-like Model-Per Form. A Model contains a session, but the model lifetime is tied to the life time of the form. This prevents having one session per-application which a very bad decision, in fact Fabio Maulo (NH Lead) says is like having a time-bomb in your application.
Goods new this is not the only approach.
Fabio Maulo and a very smart guy named Gustavo Ringel came up with this:
http://fabiomaulo.blogspot.com/2009/01/aspect-conversation-per.html
http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part.html
Good news is not all theory, unNHAddins has a fully functional example of this concepts.
HTH
For a start I wouldn't recommend NHibernate for this scenario - imports/exports and multiple data stores are not really it's thing.
That said... Web applications generally create the NHibernate Session per page request (e.g. in the Session Start event, or as an action filter). The session factory is usually created in the Application Start though.
For a windows forms application you might want to take a look at the 'unit of work' pattern. Your session would probably want to follow this.
Related
Many thanks #Mirko for the reply and comment. So sorry if im not clear myself.
I'll try to make it alot more understandable.
First thing is, I want to create an application for a Data Entry Form on Windows (Windows Form Application .exe). This application required database
and for a database server im thinking about SQL (Need some advise here on the server).
After the Form-Design completed and linked to the database, i want it to be able accessing PDF/PNG and stamping also, For approval purpose. Thus i need some file transfer server for this and some new coding line for this function. (I need a lot of help here especially the coding line).
Please note i've also tried making a form-based application on VBA Excel and use it's sheets for the database. But im struggling on how to make an access for File transfering and stamping (Approval) protocol. Thus lead me to C# on Visual Studio, hoping this coding program could handle such file-embed system.
Edit: Nico, I am not sure this will make a great SO question. Sorry, I cannot provide this detailed feedback in comments as they do not allow enough text. You are asking for advice that is in my opinion too broad. Meaning you really have many considerations here and are in essence asking (I think) how do I build a document management and approval (workflow) application.
You may want to look into document management solutions (I am no expert on those), but many handle approval flows and meta-data on documents well.
I would recommend you carefully consider even your starting assumptions. In my opinion if you are building a green-field application now you should decide between WPF (instead of Windows Forms) and a Web Application (that is in the .NET space) and I would probably recommend ASP.NET Core Razor Pages. If more than one person will use this application I would lean towards the latter strongly as it is more easily accessed and updated.
I am not the best person to answer how to do the Stamping approval part, but you may want to consider either an existing document management solution (maybe DocuSign, etc. as an integration) as they may offer you the features you are looking for out of the box. If not take a look at PDF libraries in the .NET space (I personally used Aspose in the past, but they tend to be expensive).
If you are looking to track metadata about the documents to be uploaded/approved SQL server is often a good choice, but since you are quite literally seeming to aim for document management, more document-centric options maybe a good fit (MongoDB, Cosmos (Azure), DocumentDB (AWS), ...) as they allow you to store arbitrary meta-data.
I need to implement Audit Trail in my application which is WinForm application.
I need to log all the activity done by user on application and in System to see if he had changed any security settings or anything.
Is there any way to do this by AOP or using PostSharp or any other such method which could be done with minimal changes in existing code as it is a very big application and implementing logging in every method is a time taking steps.
I am open to create a new application which could be for auditing purpose if it helps.
Please let me know any best practices I should follow to implement Auditing.
We are using .Net 4.5 and SQL Server 2005.
Sounds like you want an audit of business-level operations attempted via your WinForms application.
Since, you asked about aspect-oriented approach - yes you can certainly use PostSharp's OnMethodBoundaryAspect to plug in some logging/auditing behaviour with almost no change to existing code.
You will also get information about the caller and values of arguments passed which you can use to make your audits meaningful. Will update shortly with example. Further Reading
DISCLAIMER: I do not work for PostSharp. I just happened to try it out recently.
Can you please provide me with some tips/guidelines when architecting, designing and implementing a .net framework application, with the requirements given below:
It will be an analytical tool which will retrieve data from files, sql databases and may be cubes. So data layer should be able to handle that. The middleware should be totally independent of the other layers so probably need an IoC container (which one would you recommend)
It will be deployed on the local intranet
The front layer might be WPF application or Silverlight in future (for now, I am concentrating on Silverlight but the point is that it will change)
It should be easy to customise and improve it in the future without changing much of the code as the framework will be deployed for many clients
I need a way to store the configuration information, which will be picked up by the application on application load events to set its feel and look.
I have two months to implement it and looking for as many tips as possible.
SoC for a start
break your application into several assemblies that use IoC (interfaces + implementations):
application model assembly - all other assemblies will reference this one because these classes will be used for inter-communication - they will mostly be just POCOs
presentation assembly - references app model and business services - this one is either WPF or Silverlight in any case use MVVM to make your testing life easier
business services assembly - references app model and data repositories assembly
data repositories - these define repositories that actually get data from the stores
Then I'd create three additional ones:
file data providers
database providers
cube providers
Data repositories would reference all three and use them to provide necessary data.
If configuration becomes very complex with a lot of functionality then you should put it in a separate assembly as well and reference it by business services assembly.
Which MVVM library to use
Since you mentioned time I suppose you'll have hard time catching your deadline. When using MVVM (which I suggested to use) I also suggest you don't use a full blown PRISM (a.k.a. Composite Application Guidance from P&P) but rather go with MVVM Light Toolkit. It will take you less time to get on the bandwagon.
Code generation
In places where appropriate I suggest you use T4 to its full potential. I use it to import stored procedure calls to avoid using magic strings when calling stored procedures (and using their parameters). Check my blog post about it as well.
DAL technology/library
Don't write your own data access code using things like SqlConnection/SqlConnection functionality. There're many data access layer libraries/technologies today that you can use and not reinvent the wheel. If you know nHibernate, then use that. If you know EF, then use that. If you know anything else, use that. Anything that will provide/generate as much code for you as possible that is already tested and debugged.
So it all boils down to:
DRY + YAGNI
a.k.a. Don't repeat yourself and You ain't gonna need it = don't over-engineer you code.
Agile developers are supposed to be lazy
They should develop just as much as it's needed and no more! TDD implicitly provides this process by the red => green => refactor steps.
I would recommend using MVVM and Test Driven Development. The MVVM will give you good separation between the front and middleware, and the TDD will help control the chaos that comes with any nontrivial app development.
Have a look at the Composite Application Guidance from Microsoft's Patterns and Practices group, it may not match what you are doing exactly but will give you some good ideas.
From an architectural standpoint, I highly recommend taking a look at the Microsoft Application Architecture Guide. Since you are already using the Microsoft technology stack, I would consider using Microsoft Unity for IoC. You indicated that your presentation layer might use WPF or Silverlight, so take a look at using Windows Communication Foundation, as you will be somewhat constrained in Silverlight when it comes to communication with your data layer.
I will soon begin the painful*(kidding)* process of migrating multiple, separate, Access Applications to "Real" applications*(notice the quotes, no flame wars please)*. Most likely this will be Web Apps as the usual reason is multiple users and deployability but I will take it case by case.
Some of these are traditional Access apps using Access as the back end and others are using SQL Server(a central one) as the back end.
What I am looking for is a combination of your experience doing this and what resources you used to help.
Websites, apps, standards, best practices, gotcha's, don't forget's, etcetera.
I am a 1 person C# shop with SQL Server back end so whether Web or not I will be looking that direction.
Also, is it overkill or unattainable to try and develop a Framework for this kind of thing? Would there just be TOO MANY variables to even try and walk this path? Anyone ever try this?
Some further info based on below questions. We currently have ~250 users and they are spread between 5 Locations.
What I meant by deployability is perhaps a little vague. I simply meant that we are a Non-Profit Organization and as such we do not have the best bandwidth available so deploying full apps, even through ClickOnce can be tricky when combinded with the highly fickle nature of my users*(I want that box purple, no green, no get rid of it altogether type stuff...)*.
My idea is to try and develop a "framework", of sorts, that will help to streamline the process of moving an Access App to a .Net App.
Now I fully understand that this "framework" may be nothing more than a set of steps and guidelines; like, Use ORM*(LINQ2SQL or SubSonic)*to generate DAL, Copy UI to corresponding UserControls, rewrite Business Logic.
I am just looking for your experience/expertise to help me streamline my streamlining process... ;)
Those apps which use an Access database to store tables and which need web access should first be upsized to SQL Server. There is a tool from the SQL Server group. SQL Server Migration Assistant for Access (SSMA Access)
Then consider moving to the web only that portion of the app that requires remote access. And leaving the rest of the app in Access. That could save a considerable amount of time.
Alternatively consider going to Terminal Server. That along with a VPN means just some software licensing costs and next to no work on your part.
That said what do you mean by "multiple users" and "deployability"? Possibly we can give you some suggestions there. Access is multi user out of the box. However if you have mission critical data or can't rekey the data in the event of a corruption or have more than 25-50 users on the LAN then you should be moving the data to SQL Server.
Now that it's public Access 2010 can deploy applications to the web. All kinds of very interesting stuff can be done. For more information check the Microsoft Access product group blog or my blog with the appropriate Access 2010 tags
Speaking from experience I think you would need to upgrade on a case by case basis. Upgrading is essentially a re-write from scratch and you should take the opportunity here to re-design as necessary. The type of application structure and code style used for Access (likely to be procedural I'm guessing) is very different to a well designed OO .Net app.
You will be able to re-use the SQL Server databases of course and, depending on the apps maybe even the Access ones. If you're feeling brave you could even try the upsizing wizard although I wouldn't recommend it as we found the results less than ideal.
I would also advise you take a look at some kind of ORM tool (we use Subsonic) as this can massively reduce the amount of boiler plate code you need to write. Some ORM tools will also generate DDL for your database too.
We follow these standards (good idea to pick a standard early on and stick to it we found) and also found this really useful to get up and running.
Hope this was some help.
I'm writing simple database driven application, 80% of functionality is CRUD operations on about 15 tables.
Coming from web development background I figured I can cover almost all of these CRUD cases with Rails scaffolding or say Django admins.
So I started to look around for Rails/Django-like framework but for Windows Forms applications (ofcourse I understand that "rich client" application
development significantly differs from a web development and I'm not expecting anything really similar).
I was surprised that except for a variety of ORMs (let's call it Model-layer) it seems like I'm left with little choice
when it comes to View-Controller layer. Maybe I'm missing something?
PS. I evaluated Visual Studio DataSet Designer, but it seems to work only for the most simple cases, and requires additional code for any slightly nontrivial task.
(added) so far I've found:
TrueView for .NET (thanks to Vijay Patel)
NConstruct
I would start to look at the Entity Framework if you can use .net3.5
Introducing the Entity Framework
How to: Bind Objects to Windows Form Controls (Entity Framework)
You could try DevExpress eXpressAppFramework. If I've understood you correctly it should do what you're looking for. It works with Winforms and ASP.NET and also has an accompanying ORM framework. There are some videos here that demonstrate the product. And there are forums here if you need to ask specific questions.
Did you check Rocket Framework for Windows Form
Everything is perfectly in order to support your requirement.
This use Entity Framework as the back-end
Use Object Data Source to Auto-Bind Object to UI
Use Generic to minimize the amount of code you need to write
Additionally, the documentation also is very well done and architecture is pretty good and stable too..
I am using it right now and it is serving me pretty well
As far as I know MVC framework for Winforms don't exist. I've thought about it but I think it would just get too constricting no matter how hard you tried. The fact you're not tied to a single page in a browser just completely throws alot of standards out the window. According to your needs you can have a single MDI form that would be similar to the web and web ideologies would be applicable, or you could have an MDI form that could be filled with MDI forms and standard forms and they could need to talk to each other to make sure they're up to date, even in the background which isn't an issue in webforms.
At the same time threading becomes a huge issue as a half a second wait on the web is nothing while if a program freezes for even that long you have problems. There are even more approaches to threading than there are to the MDI/Form Design issue.
I've almost always lived in the WinForms world and I tend to start with a VERY generic MVC implementation and let it evolve as needed to meet the current needs. I've yet been able to apply an entire previous implementation in a greenfield project.
Shameless plug: You could try our TrueView for .NET framework.
It's based on Domain Driven Design and the Naked Objects pattern. It provides an auto-generated 'explorer' style UI at run-time (no code generation step), but you're free to override forms with your own implementations.
What is the API to the database you will be using? If it's a SOAP web service you could use the Microsoft Smart Client Factory at CodePlex. If it's a local SQL Server database you should consider Entity Framework.