Evgeny Pokhilko's Weblog

Programmer's den

Run a bash script with sudo, nohup and in the background

This command will run script.sh under super user and you can disconnect and come back later:

sudo nohup bash script.sh &

It’s useful if you don’t have Screen or you want the process to close when it finishes without a screen session hanging around.

By default, the output will go to nohup.out. You can change it by redirecting it to a file:

sudo nohup bash script.sh > script.out &

nohup runs a command immune to hangups. It redirects input and output of the process. If you want to connect to the server again and see the output, use tail, as below:

tail -f script.out

The command will  be printing output as your command produces it as if it runs in your terminal session. Ctrl-C will terminate tail but not the nohup command.

If you need to kill the command before it finishes, find the process id first with:

sudo ps -Af | grep “bash script.sh”
sudo kill <process id>

I hope it helps.

February 20, 2012 Posted by | Linux, Networking | | 3 Comments

Contact database with web interface – EVPO Members

I am opening the source of a small project that I made for a charity organisation http://evpomembers.codeplex.com.

This is a web based contact database. The database stores information on individual members with their contact details, general information and how they are connected to each other. The list of features includes:

  • Editable look-ups for most fields
  • Multiple contacts per one address
  • Convenient search for contact names and addresses
  • Log-in support to prevent unauthorized access
  • Customisable export to Excel compatible XML

Minimal Software requirements:

  • Microsoft SQL 2005
  • .NET Framework 3.5


  • AJAXControlToolkit


EVPO Members Copyright © 2012 Evgeny Pokhilko
evpomail@gmail.com http://www.evpo.net

EVPO Members is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

EVPO Members is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with EVPO Members. If not, see http://www.gnu.org/licenses.


  1. Download the source from the SVN repository.
  2. Create ContactData database in SQL and restore empty.bak
  3. Run apsnet_regsql from Visual Studio command line and install aspnetdb. Leave default settings mostly in the wizard.
  4. Create a SQL log-in (ContactDataUser for example with password 1).
  5. Grant access to the log-in to the ContactData and aspnetdb databases.
  6. Download AjaxControlToolkit (http://ajaxcontroltoolkit.codeplex.com/,go to All Downloads and download the package for .NET 3.5 !!!) for .NET 3.5 and unzip it to the AjaxControlToolkit directory.
  7. Open the solution and rebuild it.
  8. Open UI\web.config
  9. Update the two connection strings making them valid for the ContactData and aspnetdb databases respectively.
  10. In Visual Studio go to Project/ASP.NET Configuration
  11. On the opened web page go to Security/Create User
  12. Specify any user name and password so you can log in to the web app
  13. Ctrl+F5 in Visual Studio
  14. You should see the home page of the web app in your browser


1. Address



2. Contact Form



3. Export



4. Relationships



5. Summary



6. Lookups



February 11, 2012 Posted by | .NET, ASP.NET, SQL | , , | Leave a comment

Measure Size Of Rendered Text In WPF

Problem: Get the size that arbitrary text will take to adjust width, height of a control or control wrapping.


FormattedText formattedText = new FormattedText(text, 
  new Typeface(fontFamilyName), 
return formattedText.Width;

October 20, 2010 Posted by | .NET, WPF | , | Leave a comment

Suse 11 workstation as a router

My task was to connect to my office through VPN from a SUSE workstation and allow another Windows machine to use office network resources. In this scenario SUSE acts as a router forwarding ip packets from the Windows machine to the office network.

I am using NetworkManager for VPN on my SUSE machine. In one of the previous articles I wrote about establishing VPN connection to a windows server from SUSE.

IP forwarding is disabled by default. You can check it with the following command:

cat /proc/sys/net/ipv4/ip_forward

It returns either 1 or 0. 1 means IP forwarding is enabled. I suppose you will see 0. Otherwise you wouldn’t read this article. But use this command later to verify that ip forwarding is enabled.

In my configuration I need to change settings of the SUSE firewall to allow IP forwarding. The settings you see in YAST are not comprehensive and they are not enough for the task.

Instead open /etc/sysconfig/SuSEfirewall2 in gedit. Add your VPN network interface name (run/sbin/ifconfig after connecting to VPN to get all active interfaces) to FW_DEV_EXT. It will make your office network external for the SUSE router. Add your internal network (where the packets will be coming from) to FW_DEV_INT. As a result SUSE knows that your internal network is your home network and your office network is external.

Change FW_ROUTE to yes. This will allow IP forwarding. I also changed FW_MASQUERADE to yes. Not sure it was necessary for my task. By the way masquerading can be configured in YAST GUI tool unlike IP forwarding.

Now if you invoke cat /proc/sys/net/ipv4/ip_forward, you should see 1 returned.

Forwarding will be performed according to your routing table. To see the routing table invoke

/sbin/route -n

Now go to your Windows machine. Say your office network is 111.222.333.0 ( and the SUSE machine IP address is 193.333.222.1.

route add mask

This will send packets going to your office network to the SUSE router.

February 24, 2010 Posted by | Networking, SUSE | , | Leave a comment

Remote desktop via VPN from SUSE 11.1

I needed to work at weekends and connected to my machine at work. VPN + Remote Desktop

I used this guide to install VPN:


“sudo apt-get install network-manager-pptp” didn’t work in suse. I had to find the rpm packages. There were two I had to install:



I installed them running one command:

rpm -ivh <package1> <package2>

Then I installed rdesktop. I connect from command prompt:

rdesktop <full DNS address> -f

-f switch is full screen

There is another switch for setting the resolution:

-g 1024×768

May 30, 2009 Posted by | Networking, SUSE | , | Leave a comment

EVPO DC project structure

Project in VS

The picture above is the solution in VS. The application contains three layers: Data Layer, Business Layer and UI.

Evpo.DocCirc.MySqlDL, Evpo.DocCirc.MySqlDL.Update

Data layer. All database access operations are in the MySqlDl project. The Update project contains the changes of the database schema have made from the first version. The MySqlDl project is only accessed by Evpo.DocCirc.Biz. According to the principles UI cannot access the data layer directly. The following picture shows the project files:

MySqlDl files

The Resources folder contains the scripts run during the installation. CreateDatabase creates a new database and all the schema objects. In addition it populates some tables. CreateUsers creates users needed for working with the database. It is run once at setup time as well.

The purpose of the files with Access suffix is to access the database and change its state or obtain business objects from it. In this application business objects are simple and their purpose is only to store data. They don’t do anything. Access suffixed classes work with them. They load and save them from the database. Besides, access objects run queries and change the database state. For example DocCardAccess loads and saves DocCardItem from the database. DocCardItem is the business object representing Document Card.


Common project files

This is the project that all other projects reference. Mostly it contains data storage classes like buisiness objects, global settings and so on. Most classes do not do anything, just store data. The project have common classes that all the layers operate with. For example, DocCardItem class mentioned above is loaded from the database in the data layer and can be processed in the business layer. Then DocCardItem objects are displayed in the UI.


Biz project files

The business layer. It contains all the business logic. It also serves as an intermediate layer between the Data Layer and UI because, as I said above, UI cannot access Data Layer directly. Classes with suffix Data are wrappers providing access to the data layer. An important class in this project is DocCardMovementController. It provides workflow control such as moves the document card to the next stage.


UI project files

The classes in this project comprise the UI layer. Originaly the code in the classes was extracted from asp.net web pages for unit testing, but now I think it is a good idea to move as much as possible from the web pages because they must be as thin as possible and they are not covered by the unit tests.


Messaging project files

As you see in the picture, it’s purpose is to compose and send notification messages such as Action Is Required or event notifications to the users. There are two ways of notification Email messages and instant messages. EmailMessanger and InstantMessanger are for those purposes accordingly. Note that InstantMessager doesn’t send notifications by itself. Instead, it accesses a web service specified in the configuration that sends the actual notification to the users. The web service is not included in this solution.


EDCWeb project files

It contains the web pages. The project references Common, Biz, UI and resources. “G” folder contains pictures that are used in the UI. The “Settings” folder stores configuration files e. g. evpodc.config.  The most important file in the project is AppCode\Global.asax.cs. Inside this file the action starts. It is worth starting from for developers who study the application.

Note that the web pages don’t contain language specific data. The words and sentences are stored in the satelite resource assemblies Evpo.DocCirc.Resources and Evpo.DocCirc.Resources.ru-RU. Their description follows.

Evpo.DocCirc.Resources, Evpo.DocCirc.Resources.RU-ru

Resource project files

Each web page file has a resource file in this project. There are two assemblies at the moment: english and russian. They are used depending on the culture of the project set in web.config. Other languages can be added.

Other projects

EvpoDCUTest – all the unit tests and mock objects live here

EvpoDocCircSetup – the project creating the setup package

May 9, 2009 Posted by | .NET, ASP.NET, Workflow | , , | 3 Comments

EVPODC Getting Started Part 2 (Configuration)

When you first enter the application, you see the Queries menu (Figure 1). However it’s too early for making queries because we don’t have data yet.

configuration-01Figure 1

For the working system we need to create users, folders and routes. Then we’ll be able to create documents.

To create users we click Administration, then Users. We see that there are three existing users. They are builtin users. Don’t delete them. Unfortunately, the system allows you to delete anyone. Although the application behavior is unpredictable if you do so.

Say this is a development company and we have a team containing 2 developers, a requirement writer, a tester and a team leader. Please, note that the only field required is Login. You also need to fill in the email address if you want to use notifications. I am going to use them for this sample. So I created 5 new users as you can see in the DropDown list. (figure 2)

configuration-02Figure 2

Now we need to add the users to different security roles to restrict access because we don’t want all to see everything. We go to Administration / Roles. There are two builtin roles: Administrators and Users. All the new created users are included in the group Users by default. We can leave them as they are and add new roles. I want to create the following roles:

  • Requirement Department: Bill Johnson (requirement writer)
  • Quality Assurance: John Mayer (tester)
  • Developers: Kevin Black (developer), Stephen Smith (developer)
  • Managers: Dexter Brown (team leader)

See figure 3

configuration-03Figure 3

You might be asking: where are the permissions? The answer is that it’s too early for permissions. You confugure them for each folder and document type and we haven’t created neither. That’s what we are going to do now.

Go to Administration / Document Folders

This interface is easy to understand. When you input Folder Name and click Create New Folder, a subfolder is added in the folder that is selected on the left. For our scenario I create a complex folder structure (see figure 4) for the purposes of our sample.

configuration-04Figure 4

That’s how it looks like in the app (figure 5)



Figure 5

Now you see where permissions are. These are default permissions for Development Team folder. I assume I need to give you a clue about security settings in the app because it’s flexible but not clear at first sight. The security system is similar to the NTFS folder security and other known applications. Each security object, a folder in this case, has security settings for many security roles. In figure 5 we have settings for Administrators and Users because they are builtin roles. Each security role defined in the folder has a set of settings you can see under Users. I clicked href Users. That’s why we are viewing the settings for this role. As you can see Users have all permissions in new folders by default. Note that if a role is not in the role list, it doesn’t have access to the folders at all. So our new roles don’t have any permissions in the folder we look at but don’t forget that our users are members of the Users role. That’s why they can do eveyithing at the moment.

Let’s start from configuring the root folder Documents. For that you need to click the link at the very bottom of the page Root folder permissions…

In the root folder our team is going to store annual leave requests and equipment requests. These document types are useful for everybody. Therefore the rule is that everybody can create a document in this folder. People can also read documents of their collegues in the folder because we need them to plan vacations together. We don’t want to give access to equipment requests, but we’ll talk about that later because I am going to configure that in the document type permissions specifically for equipment requests. So the settings for the role Users in the Documents folder will be as in the figure 6.


Figure 6

According to the settings:

members of Users can:

  • create new documents (Create checkbox)
  • read other users’ documents (Read checkbox) including their own (Read own checkbox)
  • update their own documents (Update own)
  • see the folder on the list of folders (Browse). However, it is not applicable to the root folder because it’s never on the list of folders. You are always within in.


  • udate others’ document (Update)
  • delete documents (Delete) including their own (Delete own).

The reason why we don’t allow the users to delete their own documents is because we want to guaranty that no annual leave request was deleted by a malicious employee.

It’s time to configure a role that is responsible for these documents and has more permissions. They are Managers. We add the role to the list and set the settings (see figure 7).

configuration-08Figure 7

These settings say that Managers can do everything in the folder. In fact they update when they accept request or reject it. They might delete document if it’s no longer needed. You got the idea of the folder security configuration.

Next thing we have to do is to create the document types equipment requests and annual leave requests. We need to go to Folders/DocumentTypes and click Create document type. The first tab of the document type form for equipment requests you can see in Figure 8.

configuration-09Figure 8

Note Prefix and Next number fields. Each document has a unique number. When you create the first document of this type, its number is going to be EQ00001. After that the next document of this type is going to be EQ00002 etc.

Next we fill in the route tab.

… the docs end here, I got bored of writing these and haven’t touched these since then. Let me know if you are interested in the continuation.

November 19, 2008 Posted by | .NET, ASP.NET, Workflow | , , | 2 Comments

EVPO Document Circulation – getting started part 1 (installation)

EVPO Document Circulation (http://evpodc.codeplex.com) Installation

The installation is easy because the application comes with a lightweight web server. All you need is run the installer and find the “EVPO Document Circulation” shortcut in your Start/All Programs. You also need a running instance of MySql server. You can install it after this installer.


  • MySql Server needs to be available in your network and you need its machine name and the port number (if not default).
  • Windows machine with .NET Framework 2.0.

When you run the shortcut, the configuration wizard will start. When the configuration is finished, the same short cut will be opening the application normally (picture 1).


Picture 1

The system needs administrative access to the MySql database server to create its database and two accounts. The wizard doesn’t create or modify anything at this step yet. However, it checks the access to the database server.

In step 2 you will be asked the name of the database. If you install the application for the second time and already have the database, only enter its name and untick “Create new database”. If you don’t, your existing database will be lost as it says on the page.


Picture 2

In step 3 of the wizard two accounts will be created in MySql server. EVPO DC will use them to access the database. You don’t need to remember the passwords. They will be written to the application configuration files later (Warning: they will be in the config file in plain text).

Step 4 (see picture 3): The web application needs permissions to write in that directory. The ASP.NET account set by default cannot modify files in directories. This is not the case when you use the installer. The server is run in Utildev cassini web server. It uses the NT AUTHORITY\SYSTEM account that have all the necessary permissions. Click next. The directory will be created.


Picture 3.

In Step 5 the wizard needs to know SMTP server details to send email notifications to users. They will be also saved in the settings file (Warning: in plain text) (see Figure 2)


Picture 4.

Most accounts require SSL. Google Main is one of them.

In step 6 (Picture 5) the wizard will save everything you have entered to the specified configuration file (evpodc.config) (Warning: all entered information and passwords will be in the file in plain text).


Then the application will open. The default password for DocCircAdmin is 1

November 18, 2008 Posted by | .NET, ASP.NET, Workflow | , | 8 Comments

Customize property editor in the VS designer

Sometimes, the VS property grid in the XAML designer (the code name is Cider) is not enough for custom WPF controls. Once, I needed to update a property of my control automatically depending on a value of another property. First, I searched for an example of such an action in WPF controls of the framework. I found nothing similar. The property grid in VS is plain and one property never depends on another. However the property grid in Expression Blend is much more interesting. Therefore, there should be a way to extend the designer. The way starts from the CategoryAttribute and EditorAttribute atributes. Let’s see an example of a custom WPF control that extends Label. The extended control renders Content and adds prefix before the content and suffix after the content. So our control has two additional properties: Prefix and Suffix. The control is for names. Therefore, Prefix can only be “Mr” or “King”. When the user selects Prefix, Suffix gets an initial value depending on the selected Prefix. Then the user can edit Suffix if she is not happy with the value set automatically. Say the prefix “Mr” correspons to the suffix “Junior” and the prefix “King” corresponds to the suffix “III”. So if the user inputs “Arthur” to Content and selects the prefix “King”, the suffix will be set to “III” automatically. See the picture of the control at runtime below:

It looks identically in the designer. The following picture is the part of the property grid containing Content, Prefix and Suffix:

Note, Suffix can be edited after selecting Prefix because the king is not necessary III. He can be I, II or even IV. But if you set the prefix to Mr, the edited value of suffix will be overriden with Junior.

Let’s see the class declaration of the custom control (Control1).

 [Editor(typeof(ExtCategoryEditor), typeof(ExtCategoryEditor))]
    public class Control1 : Label

The Editor attribute says that we provide a editor that can be embedded into the VS property grid for the control. In fact the part of the property grid under “Ext” is a grid that ExtCategoryEditor provides. Our editor is only for the Ext category. In Control1 class we also need to say which properties correspond to “Ext ” category, so that they may get into our editor. We simply mark properties with CategoryAttribute for this:

        public string Prefix
            get { return (string)GetValue(PrefixProperty); }
            set { SetValue(PrefixProperty, value); }

You probably think that ExtCategoryEditor is the class that contains the Grid control we see in the property grid. That’s not right. ExtCategoryEditor is a class derived from CategoryEditor that has a set of methods. One of them gives DataTemplate containing the Grid control. Look at the ExtCategoryEditor class:

    internal class ExtCategoryEditor : CategoryEditor
        public override bool ConsumesProperty(PropertyEntry property)
            string[] properties = new string[]

            if (properties.Contains(property.PropertyName))
                return true;
                return false;

        public override DataTemplate EditorTemplate
                return (DataTemplate)EditorTempaleForExt.Current["ExtDataTemplate"];

        public override object GetImage(System.Windows.Size desiredSize)
            return null;

        public override string TargetCategory
            get { return "Ext"; }

EditorTemplate is the method giving Grid, which is in EditorTemplate. The Editor template is declared in ResourceDictionary EditorTemplateForExt. Its XAML declaration is below:

    <DataTemplate x:Key="ExtDataTemplate">
            <TextBlock Grid.Row="0" Grid.Column="0" Text="Prefix"/>
            <ComboBox Grid.Row="0" Grid.Column="1"
                      SelectedValue="{Binding Prefix, ElementName=uiPropertyCourier}"
                    <TextBlock Text="King"/>
                    <TextBlock Text="Mr"/>

            <TextBlock Grid.Row="1" Grid.Column="0" Text="Suffix"/>
            <TextBox Name="uiSuffix" Grid.Row="1" Grid.Column="1" Text="{Binding Suffix, ElementName=uiPropertyCourier}" />

            <local:PropertyCourier  x:Name="uiPropertyCourier"
                Prefix="{Binding [Prefix].PropertyValue.Value}"
                Suffix="{Binding [Suffix].PropertyValue.Value}">



You can see that “Binding [<Property name>].PropertyValue.Value” in Microsoft’s examples. It means that DataContext of your DataTemplate and the elements inside it is an instance of some internal Microsoft class. The class has an Indexer that receives string as a parameter. It actually gets the property name. I won’t write the names of those Microsoft classes because they declared with internal keyword and are not supposed to be used by developers outside Microsoft. However you can see them in the debugger. Just add watch to the DataContext property.

This is ComboBox_SelectionChanged method:

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            ComboBox comboBox = (ComboBox)sender;
            PropertyCourier propertyCourier =
            string value = (string)comboBox.SelectedValue;
            switch (value)
                case "King":
                    propertyCourier.Suffix = "III";
                case "Mr":
                    propertyCourier.Suffix = "Junior";

PropertyCourier is an empty FrameworkElement with two dependency properties: Prefix and Suffix. It is just an intermediate object that pass over values from our controls to the instances of the internal microsoft classes. The point is that you can not update properties in Control1 directly because of two reasons. Firstly, It is not convenient to get access to the Control1 object from the method. Secondly, the values won’t be serialized. Values should pass through internal Cider classes to be serialized. I use PropertyCourier as a convenient way to update values through Cider classes.

For more details download the code.

June 29, 2008 Posted by | .NET, WPF | , , , , , | Leave a comment

How to load referenced assemblies from any place you want

This is HowTo for those who need it. The app.config file below defines rules for the main assembly. It sets where the referenced assemblies could be found at runtime. The main assembly references other two assemblies and gets one of them from network (\\someserver\shared\Summator.dll) and another one from the local machine in a subdirectory.

Application config file is below:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            culture="neutral" />
      <probing privatePath="SUB1\SUB2\SUB3\">

If you reference an assembly from your local machine, you are not limited by subdirectories of the main application because you can use the following method to mount your drives to one of the subdirectories:


PS: Configuration files can be conveniently edited by the mscorcfg.msc tool (Control Panel – Administrative Tools – Microsoft .NET Framework 2.0 Configuration, MyComputer, Application, Right click, Add…).

June 25, 2008 Posted by | .NET | | Leave a comment