Saturday, September 20, 2014

Persistence framework

Today I am looking for a persistence framework for c#. This is hard because I don't need an OR-Mapper. I need something where I can put in an object and it stores it to database or (and that is the hard thing to find) to an isolated storage or file system.


I found the following list:
   http://csharp-source.net/open-source/persistence


This list is rather disappointing (even if in google top ranked) because most of the projects in here are dead. Some admit, some don't. What I really dislike on this list is that even code generators which will manage the access logic are listed as persistence frameworks. I think they aren't.

Still one of the best solutions are:
- mybatis (only "object to DB" mapping): https://code.google.com/p/mybatisnet/
- Habanero (ORM, but also standard UIs): http://www.chillisoft.co.za/habanero/
- SPF (persistence framework, but only for DBs): http://sisyphuspf.sourceforge.net/home.htm

..and yes of couse, I will not forget to mention NHibernate ( http://nhforge.org/Default.aspx/ ).

Tuesday, September 16, 2014

Document your code, what's next?

Today I have been working on my release version of my project. 

Releasing a project means to me that
  • the features are developed
  • the features are tested
  • the database was adapted
  • the code is re-factored
  • the code is styled
    ... and last and worst
  • the missing comments (I left to the end as always) are added.

To check style and comments I use the tool "StyleCop" which is quite cool but also a pain in the ... hmmm,... neck. This means that at least all summary tags are filled out. After some routine you don't even think of the benefit of doing this. So what is the benefit of the summary tags (and of course there are a lot more tags to mention like the value, returns, param,...)?

In the msdn description of the summary tag ( http://msdn.microsoft.com/en-us/library/2d6dt3kf.aspx ) first of all the object browser window is mentioned, but I don't think that this is THE benefit for most developers. In fact I use the object browser window as good as never... or let's say never.

The article also mentions documentation tools like sandcastle (what is a bad example, because the project is no longer under active development by microsoft ... see http://sandcastle.codeplex.com/ ... even if there is a new open source branch of the project http://shfb.codeplex.com/ ). This project is much too complicated for me. I would like to generate a damn easy chm-file or something which looks great and what makes no troubles at all. 

There are commercial product which seemed to accept my challenge of "creating an easy to use tool" like 
  • vsdocman ( http://www.helixoft.com/vsdocman/overview.html ) or 
  • document X! ( https://www.innovasys.com/product/dx/features_vsnet.html ) or 
  • live documenter ( http://livedocumenter.com/ ) 
did. Other open source project seemed to make a complicated task ( generating a documentation ) more or less impossible (like doxygen). An other approach is to simply provide an xslt file to the generated xml-documentation (out of visual studio).

Finally I decided to use the github project docu ( http://docu.jagregory.com/ ). I downloaded the source, compiled it and it simply worked. I don't really like the template, but this is customizable, so hurray ... I found a solution which generates static and simple web pages. These pages can be opened from inside the visual studio (even if this solution is not yet perfect) using ctrl w + w.

cheers,
Daniel

Sunday, September 7, 2014

Write a great research paper

Hi,

I got a hint about a good youtube video about Professor Simon Peyton Jones, Microsoft Research:

https://www.youtube.com/watch?v=g3dkRsTqdDA


It is about 7 tips of how to write a good research paper (but there are about a hundred more in the video inside of the hints):

- #1 Don't wait: write 0:21
- #2 Identify your key idea 4:16
- #3 Tell a story 7:20
- #4 Nail your contributions to the mast 9:34
- #5 Related work 16:44
- #6 Put your readers first 23:50
- #7 Listen to your readers 28:42

I would highly recommend that video ...

kind regards,
Daniel

Friday, September 5, 2014

Link-List

Hi,

I found a cool list of books and links:

- https://github.com/vhf/free-programming-books/blob/master/free-programming-books.md


I will add items to the list if I find something similar...

cheerio,
Daniel

Tuesday, July 15, 2014

app domains

Hi,

today I wanted to create a launcher application to launch my other wpf applications. This sounds easy but is really hard because you can have only 1 application object in an application domain. The task to do seemed to be clear... I needed a second application domain. But first I researched a little bit about application domains and want to show here some quotes to this:

Operating systems and runtime environments typically provide some form of isolation between applications. For example, Windows uses processes to isolate applications. This isolation is necessary to ensure that code running in one application cannot adversely affect other, unrelated applications.
Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies. Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run.
http://msdn.microsoft.com/en-us/library/cxk374d9.aspx
AppDomains best visualized as a very light weight process.
There can be N AppDomains per .Net Process but generally speaking there is only one. The real advantage of AppDomains is they provide an isolation boundary within your process. Objects can only talk to each other across an AppDomain boundary via remoting or serialization.
It's also possible to run 2 AppDomains at completely different security levels within a process. This can allow you to run your main application at Full Trust while running Untrusted Plugins at a much lower trust level.
It's hard to blanket say yes or no to whether or not a thread respects an AppDomain. It's possible for a single thread to be in N different AppDomains. Such a situation is possible if an object in one AppDomain makes a remote call to an object in another AppDomain. The thread will have to transition between the AppDomains in order to complete.
The disadvantage of AppDomains is mainly complexity. Remoting can take a little bit of time to get your head around and properly setting up an AppDomain can be a non-trivial process.
You may want to take a peek through the MSDN documentation on AppDomains. It's hard to find a sucint tutorial that describes them because they have a variety of complex features. This provides a nice overview which if it doesn't answer your question directly will at least point you in the right place.
http://stackoverflow.com/questions/622516/i-dont-understand-application-domains by JaredPar

JaredPar's answer is good, except he doesn't note the raison d'etre for AppDomains - which is that you can only UNLOAD an Assembly by unloading its AppDomain. If you are a long-running OS process, and you expect to have to load and then later unload assemblies for whatever reason then you need an AppDomain. The prototypical example here is ASP.NET, which loads app code assemblies on demand and then can unload them later, when the apps are no longer being actively used.
The cost you pay for the ability to unload is that independence - you need to communicate across the AppDomain boundary, Can't make a simple method call. You need to manage the AppDomain lifecycle. Etc.
If you just need to dynamically load Assemblies and don't think you'll need to unload them during the life of a single process then you probably don't need to run multiple AppDomains. A good example here might be a rich app that supports a plug-in model, where it sniffs out plug-in assemblies in a "etc" directory and loads 'em all up. However, if the plug-in model calls for unloading the plug-ins ... well.
There are outlyer scenarios. Like, suppose you want to load 2 different versions of an Assembly at the same time. You can run into pitfalls if you don't segregate them with AppDomains. But that will be fairly rare.
The core scenario that justifies the existence of AppDomains is the long running process that must be able to unload assemblies.
Of course, applications could rely on the OS process when you want to unload an assembly. In other words, you could have 3 or 4 cooperating processes running, each with its own set of Assemblies, and when you want to unload an assembly, just shut down the process that hosts that assembly. But the AppDomain offers a higher-perf mechanism to do that, without requiring process stop/start or cross-process comms, which is heavier still than the cross-AppDomain comms described previously. I mean it's still remoting but it is slower and more context switching.
http://stackoverflow.com/questions/622516/i-dont-understand-application-domains by Cheeso

and now a solution how to run more appdomains in C#. ( http://blog.lab49.com/archives/2355 )

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Threading;
 
namespace WPFDomainLab
{
  class Startup
  {
    [STAThread()]
    static void Main()
    {
      var domain1 = AppDomain.CreateDomain(
        "first dedicated domain");
      var domain2 = AppDomain.CreateDomain(
        "second dedicated domain");
 
      CrossAppDomainDelegate action = () =>
      {
        Thread thread = new Thread(() =>
        {
          App app = new App();
          app.MainWindow = new Window1();
          app.MainWindow.Show();
          app.Run();
        });
        thread.SetApartmentState(
          ApartmentState.STA);
        thread.Start();
      };
 
      domain1.DoCallBack(action);
      domain2.DoCallBack(action);
    }
  }
}

please consider to use LoaderOptimization property... (here I would suggest to delete the app file and create your own, because the real main method is hided in the app.g.cs file by the visual studio).

For starting a wpf application it is neccessary to create a domain and then to call


1
newdomain.ExecuteAssembly(path); 

and in a finally block to call:

1
AppDomain.Unload(newdomain); 

What is quite cool in this solution is to be able to pass in some parameters. This communication works over:
 
1
newdomain.SetData(name, valueObject);


Kind regards,
Daniel

Tuesday, July 8, 2014

SSIS Repository

Hi,

today I am working with SSIS and tried to find some 3rd party tasks.

I found the page:

   http://ssisctc.codeplex.com/

It is also a good reference how to build your own SSIS task because some are open source. I will try to build my own soon...

kind regards,
Daniel

Wednesday, June 11, 2014

xp_cmdshell in sql server

Hi,

today I got a request to enable xp_cmdshell on my sql server because an application needed the functionality to list the content of a directory out of a t-sql stored procedure.

The functionality is pretty old (already supported by sql server 2000), but evil referring to sql server security blog entry: http://blogs.msdn.com/b/sqlsecurity/archive/2008/01/10/xp-cmdshell.aspx

If security context is not set with caution enabling this setting enables a user to access a command line to the server with administrator rights. This is bad. (Default is to access the command line with the security context of the sql server service account, but it can be changed to other credentials using: sp_xp_cmdshell_proxy_account )

Syntax:
xp_cmdshell { 'command_string' } [ , no_output ]


Enabled the feature:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
GO
-- To update the currently configured value for advanced options.
RECONFIGURE;
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
GO
-- To update the currently configured value for this feature.
RECONFIGURE;
GO
reference: http://msdn.microsoft.com/en-us/library/ms190693.aspx

Check if it is turned on or off:
1
2
3
4
5
6
7
SELECT 
   name AS [Configuration], 
   CONVERT(INT, ISNULL(value, value_in_use)) AS [IsEnabled]
FROM  
   master.sys.configurations
WHERE  
   name = 'xp_cmdshell'
reference: http://sqltidbits.com/scripts/check-if-xpcmdshell-enabled-across-multiple-servers

... and here an example how it can be used (found in the web):
1
2
3
4
5
6
7
8
9
create table #tmp(result varchar(255))
insert into #tmp exec master.dbo.xp_cmdshell 'ping yahoo.com'
 
if exists(select * from #tmp where result like '%request timed out%')
 print 'timeout'
else
 print 'reply'
 
drop table #tmp
references: http://www.nullskull.com/q/11008/xpcmdshell-output.aspx

and even better:

1
2
3
4
5
6
declare @results table(result varchar(255))

insert into @results
exec sp_executesql N'xp_cmdshell ''ping www.yahoo.com'''

select * from @results
reference: http://stackoverflow.com/questions/1842126/call-tracert-and-ping-from-sql-and-put-the-result-in-sql-table

kind regards,
Daniel