regular expressions tutorial via C#

Using regular expressions to match a pattern
  1. Start Visual C#.
  2. Create a new Visual C# Console Application.
  3. Specify the using keyword on the Text.RegularExpressions namespace so that you will not be required to qualify declarations in those namespaces later in your code. The using statement must be used prior to any other declarations:

    using System.Text.RegularExpressions;
    					
  4. Define a new regular expression that will use a pattern match to validate an e-mail address. The following regular expression is structured to accomplish three things:
    1. Capture the substring before the @ symbol and put that into the "user" group.
    2. Capture the substring after the @ symbol and put that into the "host" group.
    3. Make sure that the first half of the string does not have an @ symbol.

    Regex emailregex = new Regex("(?<user>[^@]+)@(?<host>.+)");
    					
  5. Define a new string containing a valid e-mail address. This provides a default value if the method's command-line argument is empty:

    String s = jack.niu@jack-fx.com;
    					
  6. Check to see if there are any command-line parameters; if there are, retrieve the first parameter and assign it to the variable "s".

    if ( args.Length > 0 ) {
    	s = args[0];
    }
    					
  7. Use the Match method to pass in the e-mail address variable and return a new Match object. The Match object will return regardless of whether any matches were found in the source string.

    Match m = emailregex.Match(s);
    					
  8. By examining the Success property, we can decide whether to continue processing the Match object or to print an error message. If successful, display the "user" and "host" named groups within the Groups collection of the Match object.

    if ( m.Success ) {
    	Console.WriteLine("User: " + m.Groups["user"].Value);
    	Console.WriteLine("Host: " + m.Groups["host"].Value);
     } else {
    	Console.WriteLine(s + " is not a valid email address");
    }
    Console.WriteLine();
    					
  9. To keep the console window open after running the application, add the following lines of code:

    System.Console.WriteLine("Press Enter to Continue...");
    System.Console.ReadLine();
    					
  10. Build your project.
  11. To run the application in the development environment using the default e-mail address specified in the code, press F5 or select Start from the Debug menu. To start the application with a command-line argument, there are three options:
    • On the Project menu, click Properties, and then click Debug. In the Start Options section in the right pane, specify the e-mail address that you want to test. Press F5, or click Start on the Debug menu to run the application.
      In Visual C# .NET 2005/2008: On the Project menu, click Properties. In the left pane, click the Configuration Properties folder, and then click Debugging. Under Start Options, click Command Line Arguments and specify the e-mail adress that you want to test. Press F5 or select Start from the Debug menu to run the application.
    • Start a command window and navigate to the "bin\debug" folder under the folder in which your project resides. Then type in the name of the executable followed by the e-mail address you wish to test.
    • Locate the executable file for this project, and drag it to the Start...Run window on the taskbar. Add the e-mail address to verify, and click or press OK.
Posted in: programming | Tags: c# programming text.regularexpressions text regularexpressions regex pattern match regular expression symbol groups

Option Strict On disallows implicit conversions

You may receive an error message that resembles the following when you try to compile a Windows Presentation Foundation (WPF) application in Microsoft Visual Basic 2008:

Option Strict On disallows implicit conversions from 'System.Windows.Application' to 'WpfApplication1.Application'.

This issue occurs if the value of the Option Strict statement is "On" at the project level.

To resolve this issue, download an updated WPF template. To obtain the updated template, visit the following Microsoft Web site:

http://go.microsoft.com/fwlink/?LinkId=105130 (http://go.microsoft.com/fwlink/?LinkId=105130)

Important You do not have to unzip the compressed file with a .zip file name extension to install the updated template. To install the updated template, put the .compressed file with a .zip file name extension in the \Visual Studio 2008\Templates\ProjectTemplates\Visual Basic folder, and then restart Visual Studio 2008.
After you install the updated template, the updated template appears in the New Project dialog box in the My Templates section. This section is located under the Visual Studio installed templates section.

Posted in: problems and solutions | Tags: new project visual studio disallows implicit conversions visual basic 2008 visual studio installed templates my templates

Web Application Instructions of VistAWeb

Install the VistAWeb application on the server following steps 1-5 below

1 Remove prior versions of VW (and vwContext, if it exists.)

2 Unzip vistaweb_<version>.<date>.zip into the target VW folder.

3 Unzip vistawebcontext_<version>.<date>.zip into the target folder created in step 3 of the one-time BSE configuration mentioned above.

4 Change the <vistaweb>/resources/xml/log4net.xml file to add the login ID and password from step 2 above. Strip out the text “Provider=SQLOLEDB” from the connection string.

5 Change the <vistawebcontext>/resources/xml/log4net.xml to add the login ID and password from step 2 above. Strip out the text “Provider=SQLOLEDB” from the connection string.

6 Change the <vistaweb>/web.config file

a. Change userActivity.connectionString to specify the SQL Server database.

b. Change version.useFullVersion to “false”.

c. Change allowViewLog to “false”.

d. Change excludeChemHem to “true”.

7 Change the <vistawebcontext>/web.config file to specify the SQL Server database (set it to the same value as what’s in 6.a.)

8 For Production purposes, a domain address was established for VistAWeb (https://vistaweb.med.va.gov/), with VistAWeb configured as its own website.

9 Set the default VistAWeb content page to “loginframeset.htm.”

10 Grant Write permission to the NETWORK SERVICE user on the Windows 2003 server to the folder ~/resources/images/temp.

11 Start the vistawebcontext application pool and the vistaweb web application, then start the vistaweb application pool.

12 Start the vistawebcontext web application, then start the vistaweb application.

13 Copy vhasites.xml file from the prior VistAWeb instance into <vistaweb>/resources/xml.

14 Start <vistawebcontext>

15 Start <vistaweb>

The configuration in steps 4 – 7 can be done by using the script and properties file provided in Appendix B.

SQL Server Database Schema Instructions

A database schema is required for maintaining the VistAWeb log files and identity of sites from which a user can perform patient lookups. Appendix A contains the database specifications (written for SQL Server 2000). For security purposes, the user account and password that is needed by the VistAWeb application will not be included in this document.

1. Create a database called EMR, or something similar.

2. Run the SQL scripts in Appendix A.

3. Add the user account used by VistAWeb (contact the VA Service Desk for information regarding the account/password at 1-888-596-4357 or by e-mail at VASD@va.gov.)

4. Grant the provided user account “dbowner” rights to the EMR database.

VistA Security

VistAWeb can optionally handle VistA security similarly to the way CPRS does, by requiring the user to have CPRS patient selection and/or CPRS GUI tab access in order to gain access to patient reports through VistAWeb.  This setup is global in nature; that is, if set up, all users would have to have one or both of these settings in order to be able to login to VistAWeb.

You can see a user’s CPRS tabs and patient selection settings in the user management area of VistA FileMan.

Posted in: Others | Tags:

Introduction of VistAWeb

Veterans Health Information Systems and Technology Architecture (VistA) VistAWeb is an intranet web application used to review remote patient information found in VistA, the Federal Health Information Exchange (FHIE) system, and the Health Data Repository (HDR) databases. To a large extent, VistAWeb mirrors the reports behavior of the Computerized Patient Record System (CPRS) and Remote Data View (RDV). However, by permitting a more robust and timely retrieval of remote-site patient data, VistAWeb is also an enhancement to CPRS/RDV.

There are three ways to access VistAWeb. VistAWeb can be made available by adding it to the CPRS Tools Menu, and it can be selected as the default method of retrieving data from the Remote Data Available button in CPRS. These two methods are referred to as CPRS-spawned versions of VistAWeb. They are compliant with the Health Level 7 (HL7) Clinical Context Object Workgroup (CCOW) standards and therefore maintain context with the patient selected in CPRS. As a third option, VistAWeb can be accessed in a standalone mode by entering the uniform resource locator (URL) link (https://vistaweb.med.va.gov/) in the Internet Explorer address bar.

Note: Some links found in this installation guide go to sites or pages found on the VA intranet. These sites or pages are not accessible from outside the VA network.

The standalone version of VistAWeb is connected to neither CPRS nor the clinical context management application. Standalone VistAWeb serves an important function for users who have been granted special access to multiple sites, such as for National Programs, Veterans Administration (VA) researchers, and others. VistAWeb was also made available more broadly, though temporarily, to assist clinical staff with the retrieval of patient information from the sites affected by damage caused by hurricane Katrina.

Refer to the VistAWeb User Manual for a detailed description on access and use of VistAWeb from CPRS and as a standalone application process.

Assumptions

This installation guide is intended for system administrators (specifically, web administrators) who are assumed to possess the technical knowledge of how to configure and interact with application servers. This document also assumes the necessary security hardening guidelines have already been implemented. (Refer to the Office of Cyber and Information Security link below for information pertaining to security requirements.)

https://vaww.infoprotection.va.gov/portal/server.pt?open=17&objID=4283&DirMode=1&parentname=Dir&parentid=3&mode=2&in_hi_userid=2&cached=true

VistAWeb is not installed at each local site; it is installed on an application server. A link to the application may be incorporated into the existing CPRS Tools Menu at the local site. The instructions provided in this guide identify the required configuration settings for VistAWeb use from the CPRS Tools Menu. Additional reference material may be viewed in the CPRS GUI Technical Manual by selecting the following link:

http://www.va.gov/vdl/documents/Clinical/Comp_Patient_Recrd_Sys_(CPRS)/cprsguitm.pdf

Posted in: Others | Tags:

Standalone Application Process

· User launches the web browser application (e.g., Internet Explorer).

· User enters the URL of VistAWeb (https://vistaweb.med.va.gov) in the address bar and presses the Enter key or clicks the mouse cursor on the “Go” button adjacent to the address bar.

· VistAWeb loads into the user’s web browser.

· User must select a login site link on the left of the display screen by clicking the mouse cursor on the desired site where the user has access.

· User is provided with the VistA Login screen.

· User enters his or her CPRS access/verify codes in the spaces provided and presses the Enter key or clicks the mouse cursor on the Login button.

· Once the user’s account is authenticated against CPRS, the user’s remote site patient selection permissions are verified from a SQL Server database. The permissible sites for the user to choose patients from are then displayed.

· User must select a site from which to select a patient if selecting a site other than his or her default site.

· User is presented a Patient Selection screen for entering the desired patient name (last name, comma, first name, and middle initial), portion of name, first initial of last name and last 4 digits of Social Security number, similar to patient selection in CPRS. User then clicks the mouse cursor on the “Find” button (or presses the Enter key) to find a list of patients matching the criteria. With the appropriate patient highlighted, user then clicks on OK (or presses the Enter key).

· The Sites and Notices screen is displayed, which identifies the sites where the patient has been seen.

· User can look at different elements of the patient record by selecting a desired report from the list of available reports on the left side of the displayed screen.

By default, a VistAWeb user is permitted to select patients that are in the local VistA system where the user logs in. VistAWeb will retrieve data for these patients from all sites where the patients have visited. Some users (researchers or referral coordinators, for example) may need to select patients that are not in the local VistA. These users must be granted Special User access. Special User access can be granted for one site in addition to the login site, several sites, an entire VISN, or all sites nationally. The process for requesting special user permission is documented in the VistAWeb User Manual.

Note that regardless of which site is selected for a patient (local or remote), once a patient has been selected, VistAWeb uses the Master Patient Index (MPI) at the selected site to determine at what other sites the patient has remote data and establishes the connections to each of those sites to retrieve data requested by the user.

Note: Users who regularly only use the standalone version of VistAWeb will be required to update their verify codes periodically, just as they would if logging into CPRS. When this happens, the login screen will display the message, “User must enter a new Verify code at this time.”

Posted in: Others | Tags:

How to build a Private Assembly in Rainbow (Module Plug-in)

What is a Private Assembly?

I like to relate a private assembly to a module plug-in. A lot of Rainbow development seems to happen by opening the Rainbow Solution file in VS.Net and proceeding to add your custom code for your own modules. When you build the result, it ends up being part of the Rainbow.DLL file; hence you’ve added your changes to the Rainbow Core. When using a Private Assembly, all of the building of your module takes place outside of the Rainbow Project; because you create a new VS.Net solution file and reference the Rainbow.DLL file from within your new solution file. After building your solution it can be added to Rainbow by copying the YourSolution.DLL file to the Rainbow BIN folder, and adding your ASCX, and ASPX files to the DesktopModules\YourSolution\ folder. Lastly you tell Rainbow about your solution using an Install XML file or by adding it directly to the database. The result is a Plug-in that you can deploy to any rainbow installation with ease. When you make changes to your plug-in, simply XCOPY install them over to Rainbow again, and your changes are in place.

This document will refer to a Private Module Assembly as a Plug-In.

One clear advantage to this way of developing modules for rainbow is that you don’t ever have to rebuild the Rainbow Core, so you only have to rebuild your particular module, and it results in saving time for you as a developer.

Another advantage is that your code is separate from the Rainbow Core and can be installed in most any Rainbow Installation that exists.

I can’t think of any other reasons at the moment but if you do… feel free to add them.

Requirements
  • Visual Studio .Net 2003
  • You should have Rainbow installed and running on your development machine. Refer to **** Rainbow Install Instructions **** for help on installing Rainbow.

The instructions in this document have been tested with VS.Net 2003. I am fairly certain that they will also work in earlier versions of VS.Net as well.

Creating your Plug-in

Follow these instructions exactly, and when you get the general idea you can modify them to your specific situation.

Create a default project to host your plugin.

  1. Start VS.Net
  2. Select New Project from the File Menu.
  3. Click on Visual C# Projects, and then on ASP.Net Web Application.
  4. In the Location field, change the name from http://localhost/WebApplication1 to http://localhost/MyRainbowPlugin.

Add a Reference to the Rainbow.DLL and other dependencies.

  1. Right click on “MyRainbowPlugin” project from the VS.Net Solution Explorer and choose “Add Reference”.
  2. From the “Add Reference” window, click the “Browse” button.
  3. Navigate to the location of your Rainbow Bin folder. If you installed the Rainbow Portal on your C: drive then the location should be c:\Rainbow\bin\. Change the location depending on where you installed Rainbow.
  4. Click on the file named Rainbow.dll and then click “Open”.
  5. Leaving the “Add Reference” window open, select Brows again and add the following DLL files… Esperantus.dll and log4net.dll. Note: When I failed to load the last two dll files I got miscellaneous errors when VS.Net tried to load my ascx, and the result was that I could only see the html code and not the form designer.
  6. Click on the “OK” button to close the window and add the references.

Creating the Module

  1. Go ahead and close (or even delete) the WebForm1.aspx file that VS.Net automatically created for you.
  2. From the “Project” menu, click on “Add Web User Control”.
  3. In the “Add New Item” dialog, type in the name “MyHelloWorldPlugin.ascx”.
  4. This is where you begin to add content to your control. For our example, just type the words “Hello World!” on the “MyHelloWorldPlugin.ascx” page.
  5. Click on the “View” menu and select “Code”.
  6. We need to make some changes to make sure we create a Rainbow Portal Module and not just a default ASCX control.
  7. After the last using statement, create a new line and type in the following code…

using Rainbow.UI;

using Rainbow.UI.WebControls;

  1. Move down to the line that starts with…

public class MyHelloWorldPlugin : System.Web.UI.UserControl

and change it to read

public class MyHelloWorldPlugin : PortalModuleControl

  1. Move down to the section that reads… “Web Form Designer generated code” and expand the section.
  2. Type the following code between the lines that read…

InitializeComponent();

base.OnInit(e);

so that it reads like this…

InitializeComponent();

ModuleTitle = new DesktopModuleTitle();

Controls.AddAt(0, ModuleTitle);

base.OnInit(e);

  1. Create new line after the #endregion code and type in the following…

public override Guid GuidID

{

get

{

return new Guid("{38536E21-A815-4499-97B8-9D8F755CE3D8}");

}

}

  1. Make sure not to use the GUID code supplied in this document, instead follow these instructions to create your own GUID.
    1. Highlight the GUID that appears on code… it is on the line that reads… return new Guid(“{38536E21-A815-4499-97B8-9D8F755CE3D8}”);
    2. Click on the “Tools” menu and select “Create GUID”.
    3. Select option “4. Registry Format…”
    4. Click on the “Copy” button, and then click on the “Exit” button to close the “Create GUID” dialog box.
    5. Select the “Edit” menu and click “Paste”.
    6. Your new GUID should overwrite the one mentioned in this document.
  1. Build your project by selecting “Build Solution” from the “Build” menu.

Congratulations, you just made your very own rainbow plug-in module. Now we can use XCOPY deployment and deploy the files from our module folder to the Rainbow Folder.

Installing your Module Files
  1. Open up windows explorer and copy the MyRainbowPlugin.dll and the MyRainbowPlugin.pdb from your applications bin folder into the Rainbow\bin folder. Note: Your application should have been created, by default, in the <drive>\inetpub\wwwroot folder.
  2. Navigate to your Rainbow installation and under Rainbow\DesktopModules\ create a new folder called MyRainbowPlugin.
  3. Copy the MyRainbowPlugin.ascx file from your application folder into the \Rainbow\DesktopModules\MyRainbowPlugin folder that you created in the previous step.
Telling Rainbow about your new module

There are probably easier ways to do this, but I am doing to show you the method I use to hook the module up to rainbow after you’ve physically moved all the necessary files into the right locations.

The table that contains the module information is called rb_GeneralModuleDefinitions and is in the Raibow database. You need to create a new entry in this database for your module. Below is a SQL Insert Statement that you can use as a template. Just fill in the blanks with the specifics of your module and add run the query against the Rainbow database using something like Query Analyzer.

INSERT INTO [Rainbow].[dbo].[rb_GeneralModuleDefinitions]

(

[GeneralModDefID],

[FriendlyName],

[DesktopSrc],

[MobileSrc],

[AssemblyName],

[ClassName],

[Admin],

[Searchable]

)

VALUES

(

'{5D4D00B8-9D81-485d-B04A-04DD6802BC8D}', --GUID

'MyHelloWorldPlugin', --FriendlyName

'DesktopModules/MyRainbowPlugin/MyHelloWorldPlugin.ascx', --DesktopSrc

' ', --MobileSrc

'MyRainbowPlugin.DLL', --AssemblyName

'MyRainbowPlugin.MyHelloWorldPlugin', --ClassName

0, --Admin

0 --Searchable

)

Rainbow should now recognize your module, but there are just a few more steps before we add to your home page so we can test it out completely.

  1. Launch Rainbow in your web browser.
  2. Select the “Admin All” tab.
  3. Click the “Edit this item…” edit icon next to the “MyHelloWorldPlugin”. The icon usually looks like a pencil.
  4. In the next screen choose “Select All” to make the module available in all portals. Alternatively, if you only want the module available for a few portals select them individually.
  5. Select “Apply Changes”.

Now let’s add the module to our home page

  1. Select “Admin This”.
  2. Scroll down to the “Tabs” Section.
  3. Click the “Home”.
  4. Click the “Edit this item…” edit icon.
  5. Click the “Module Type” drop down list and choose “MyHelloWorldPlugin”.
  6. Change the “Module Name” to “Hello World”.
  7. Click “Add to “Organize Modules” Below”.
  8. Click “Apply Changes”.
  9. Navigate to the Rainbow “Home” page.

Congratulations! You should now see your module as one of the modules on the home page. From here you can start creating your own new modules without having to build from the rainbow core.

Debugging your “Plug-in” Modules

Normally modules developed within the Rainbow core are debugged by starting Rainbow from within VS.Net in Debug Mode. How then do you debug Private Assemblies?

The answer is simple…

  1. Start your web browser and make sure you have the Rainbow Portal Home page loaded.
  2. Switch to your VS.Net project and open your Plug-in Module.
  3. From the “Tools” menu in VS.Net, Choose “Debug Process”.
  4. In the “Processes” dialog box, select “aspnet_wp.exe”.
  5. Click the “Attach” button.
  6. A new window called “Attach to Process” pops up. In this window make sure the check mark next to “Common Language Runtime” is selected.
  7. Click “OK” and the “Attach to Process” pop up closes.
  8. Click “Close” in the “Processes” window.
  9. You are now attached to the debugger in order to debug your newly developed Plug-in Module. Any break points you select will jump you to the code when you navigate to the part of the web page that contains your module.
Tips…
  • Create a batch file to move your files from your inetpub\yourmodule and inetpub\yourmodule\bin file into their Rainbow locations. It will make it much easier for you to load new versions between testing.
  • To test your module, follow the tip above and just restart the web browser. Technically you don’t even have to restart the web browser, just refresh or navigate to the portal tab that hosts your module.
Posted in: C# Programming | Tags:

Additional Adapters in Spring - log4net

As log4net is a widely using logging framework, there are 2 additional adapters for log4net:

  • Common.Logging.Log4Net
    is linked against log4net 1.2.10.0
  • Common.Logging.Log4Net129
    is linked against log4net 1.2.9.0

2 different Adapters are necessary because log4net unfortunately changed it's public key from 1.2.9.0 to 1.2.10.0 (which was the primary reason for introducing Common.Logging)

Both Adapters accept the following configuration properties:

Key

Possible Value(s)

Description

configType

FILE
FILE-WATCH
INLINE
EXTERNAL

INLINE will simply call XmlConfigurator.Configure()

EXTERNAL expects log4net being configured somewhere else in your code and does nothing.

FILE, FILE-WATCH: see property "configFile" below.

configFile

<path to your log4net.config file>

if configType is FILE or FILE-WATCH, the value of "configFile" is passed to XmlConfigurator.Configure (FileInfo) / ConfigureAndWatch(FileInfo) method.

Example:

<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="~/log4net.config" />
</factoryAdapter>
</logging>
</common>

will configure log4net 1.2.10.0 using the file log4net.config from your application's root directory by calling XmlConfigurator.ConfigureAndWatch().

Advanced Logging Tasks

Implementing your own FactoryAdapter

If you need to implement your own FactoryAdapter, you need to implement the Common.Logging.ILoggerFactoryAdapter interface. An implementation must provide a public constructor accepting a NameValueCollection parameter:

public class MyLoggingFactoryAdapter : ILoggerFactoryAdapter
{
public MyLoggingFactoryAdapter(NameValueCollection properties)
{
// configure according to properties
}
public ILog GetLogger(Type type) { ... }
public ILog GetLogger(string name) { ... }
}

Posted in: programming | Tags: log4net spring factoryadapter adapters common.logging common.logging.log4net configtype configfile xmlconfigurator

Adapters available in Common.Logging in .NET

All standard FactoryAdapters provided by the Common.Logging library accept the following optional configuration properties (use <arg> for declarative configuration):

Key

Possible Value(s)

Description

level

All
Debug
Info
Warn
Error
Fatal
Off

Defines the global maximum level of logging.

showDateTime

true|false

output timestamp?

showLogName

true|false

output logger name?

dateTimeFormat

any formatstring accepted by DateTime.ToString()

defines the format to be used for output the timestamp.
If no format is specified DateTime.ToString() will be used.

NoOpLoggerFactoryAdapter

This is the default FactoryAdapter if logging is not configured. It simply does nothing.

ConsoleOutLoggerFactoryAdapter

ConsoleOutLoggerFactoryAdapter uses Console.Out for logging output.

TraceLoggerFactoryAdapter

TraceLoggerFactoryAdapter uses System.Diagnostics.Trace for logging output.

Posted in: programming | Tags: c# spring adapters common.logging showdatetime showlogname datetimeformat nooploggerfactoryadapter consoleoutloggerfactoryadapter traceloggerfactoryadapter traceloggerfactoryadapter