admin

This user hasn't shared any biographical information


Posts by admin

Get to the point – Code Snippet: Retrieve logged in Terminal Service username & remote host pc name

Use this code snippet to retrieve the username & remote host pc name from a Terminal Service connection.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Principal;
using System.Net;

namespace loginName
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            MessageBox.Show(wp.Identity.Name); // Username
            MessageBox.Show(GetTerminalServerClientNameWTSAPI()); // Remote Host PC Name

        }

        private static string GetTerminalServerClientNameWTSAPI()
        {

            const int WTS_CURRENT_SERVER_HANDLE = -1;

            IntPtr buffer = IntPtr.Zero;
            uint bytesReturned;

            string strReturnValue = "";
            try
            {
                WTSQuerySessionInformation(IntPtr.Zero, WTS_CURRENT_SERVER_HANDLE, WTS_INFO_CLASS.WTSClientName, out buffer, out bytesReturned);
                strReturnValue = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(buffer);
            }

            finally
            {
                buffer = IntPtr.Zero;
            }

            return strReturnValue;
        }

        enum WTS_INFO_CLASS
        {
            WTSInitialProgram,
            WTSApplicationName,
            WTSWorkingDirectory,
            WTSOEMId,
            WTSSessionId,
            WTSUserName,
            WTSWinStationName,
            WTSDomainName,
            WTSConnectState,
            WTSClientBuildNumber,
            WTSClientName,
            WTSClientDirectory,
            WTSClientProductId,
            WTSClientHardwareId,
            WTSClientAddress,
            WTSClientDisplay,
            WTSClientProtocolType

        }

        [System.Runtime.InteropServices.DllImport("Wtsapi32.dll")]
        private static extern bool WTSQuerySessionInformation(System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out System.IntPtr ppBuffer, out uint pBytesReturned);

    }
}

Get to the point: Detect Internet Connection

We will be using Apple’s reachability class to detect the state of the Internet connection. Reachability is freely available from Apple’s website: http://developer.apple.com/iphone/library/samplecode/Reachability/

1- Create a View-based Application and name it InternetConnectionState

2- Download Apple’s Reachability App source code and copy  reachability.h & reachability.m files to your application’s Classes folder.

3- Add these files to your XCode project. Right click the Classes folder and select  Add->Existing Files (see Figure 1). Select the reachability.h & reachability.m files and add them to your XCode project. You should see these file under the Classes folder (see Figure 2).

Figure 1

Figure 2

4- Add the “SystemConfiguration” framework. Right click the Frameworks folder and select Add->Existing Frameworks. Select & Add the SystemConfiguration.framework (see Figure 3).

Figure 3

5- Open the InternetConnectionStateAppDelegate.h and add the following code below the #import <UIKit/UIkit.h> line:

@class Reachability;

Add the following lines inside @interface:

Reachability* hostReach;

Reachability* internetReach;

Reachability* wifiReach;

Finally, add these lines above the @end line:

- (void) updateInterfaceWithReachability: (Reachability*) curReach;

- (void) statusView: (NSString*) statusString;

6- Open the InternetConnectionStateAppDelegate.m and add this line below the last #import:

#import "Reachability.h"

7- Add the following lines of code to the applicationDidFinishLaunching function:

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];

hostReach = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];

[hostReach startNotifer];

[self updateInterfaceWithReachability: hostReach];

internetReach = [[Reachability reachabilityForInternetConnection] retain];

[internetReach startNotifer];

[self updateInterfaceWithReachability: internetReach];

wifiReach = [[Reachability reachabilityForLocalWiFi] retain];

[wifiReach startNotifer];

[self updateInterfaceWithReachability: wifiReach];

8- Copy these functions below the applicationDidFinishLaunching function:

- (void) networkStatusChanged: (Reachability*) curReach

{

NetworkStatus netStatus = [curReach currentReachabilityStatus];

BOOL connectionRequired= [curReach connectionRequired];

NSString* statusString= @"";

switch (netStatus)

{

case NotReachable:

{

statusString = @"Access Not Available";

connectionRequired= NO;

[self statusView:statusString];

break;

}

case ReachableViaWWAN:

{

statusString = @"Reachable WWAN";

[self statusView:statusString];

break;

}

case ReachableViaWiFi:

{

statusString= @"Reachable WiFi";

[self statusView:statusString];

break;

}

}

if(connectionRequired)

{

statusString= [NSString stringWithFormat: @"%@, Connection Required", statusString];

}

}

- (void) statusView: (NSString *) statusString{

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 320, 50)];

titleLabel.font = [UIFont systemFontOfSize:15];

titleLabel.textColor = [UIColor blackColor];

titleLabel.backgroundColor = [UIColor whiteColor];

titleLabel.opaque = YES;

titleLabel.textAlignment = UITextAlignmentCenter;

titleLabel.text = statusString;

[viewController.view addSubview: titleLabel];

}

- (void) updateInterfaceWithReachability: (Reachability*) curReach

{

if(curReach == hostReach)

{

BOOL connectionRequired= [curReach connectionRequired];

NSString* baseLabel=  @"";

if(connectionRequired)

{

baseLabel=  @"Cellular data network is available.\n  Internet traffic will be routed through it after a connection is established.";

}

else

{

baseLabel=  @"Cellular data network is active.\n  Internet traffic will be routed through it.";

}

}

if(curReach == internetReach)

{

[self networkStatusChanged: curReach];

}

if(curReach == wifiReach)

{

[self networkStatusChanged: curReach];

}

}

- (void) reachabilityChanged: (NSNotification* )note

{

Reachability* curReach = [note object];

NSParameterAssert([curReach isKindOfClass: [Reachability class]]);

[self updateInterfaceWithReachability: curReach];

}

9- Save & Build your application. If there were no errors you should get something similar to Figure 4.

Figure 4

Click here to download the source code.

Get to the point: Understanding Health Level Seven (HL7)

Get to the point: Understanding Health Level Seven (HL7)

This will be the first of a series of tutorials that will guide you to understand what is & how Health Level Seven (HL7 from now on) works.
Learning the HL7 messaging protocol standard can be a bit overwhelming, I will try to make it as easy as possible.

What is HL7?

HL7 is a messaging protocol standard used to exchange information between medical applications. Before HL7 was created, data exchange between medical applications required heavy integration development. The same code could not be used to communicate with other medical applications since there was no messaging protocol standard.

HL7 transmits one record of health-related information at a time. These messages may include patient records, billing info, etc.

How does HL7 work?

Let’s use the following example:

- A patient goes to the hospital and registers at the front desk. A new HL7 message is created and sent to the Hospital’s Information System (HIS).
- Once the doctor evaluates the patient, he decides to reschedule the patient for a next visit. A new HL7 message is created and sent back again to the HIS.

In this simple example we see that for every action a new HL7 message is created & processed. Since the patient has a unique identifier, the HIS can easily save the patient’s medical history.

What does an HL7 message look like?

An HL7 message is just a text message. Many newcomers might think that some sort of software is required to use HL7. HL7 is like any other protocol standard.

You will need to develop an application to receive and interpret the HL7 messages.

Example Message:

MSH|^~\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4
PID|||555-44-4444||EVERYWOMAN^EVE^E^^^^L|JONES|19620320|F|||153 FERNWOOD DR.^^STATESVILLE^OH^35292||(206)3345232|(206)752-121||||AC555444444||67-A4335^OH^20030520
OBR|1|845439^GHH OE|1045813^GHH LAB|15545^GLUCOSE|||200202150730|||||||||555-55-5555^PRIMARY^PATRICIA P^^^^MD^^|||||||||F||||||444-44-4444^HIPPOCRATES^HOWARD H^^^^MD
OBX|1|SN|1554-5^GLUCOSE^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^182|mg/dl|70_105|H|||F

On my next tutorial I will teach you how to read these messages.

Get to the point – Code Snippets: Dialing a number, sending SMS & Email from within your app

These code snippets will allow you to dial a number, send an SMS & send an e-mail from within your application. They will all open up the selected application and close yours.

Dialing a number

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456"]];

Sending an SMS

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:123456"]];

Sending an E-mail

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:amasso@amasso.info?subject=Hello&amp;body=Testing your code snippet."]];

Get to the point: Tab Bar Application – Adding an UITableView to a Navigation Controller

Get to the point: Tab Bar Application – Adding an UITableView to a Navigation Controller

1- Open the previous tutorial sources (Tab Bar Application – Navigation Controller Embedded).

2- Edit the NavigationContentsViewController.h file. Change the source code so it looks like this:

#import &lt;UIKit/UIKit.h&gt;

@interface NavigationContentsViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; {

NSMutableArray *itemsList;

UITableView *myTableView;

}

@property(nonatomic,retain)NSMutableArray *itemsList;

@property(nonatomic,retain)UITableView *myTableView;

@end

Notice the <UITableViewDelegate, UITableViewDataSource> protocols we’ve added.

3- Edit the NavigationContnensViewController.m file and add the following code after the @implementation line:

@synthesize itemsList;
@synthesize myTableView;

4- Add the TableView functions to the NavigationContnensViewController.m file.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [itemsList count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

}

// Set up the cell...

NSString *cellValue = [itemsList objectAtIndex:indexPath.row];

cell.textLabel.text = cellValue;

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *selectedCellItem = [NSString stringWithFormat:@"%d", indexPath.row];

TableViewController *fvController = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:[NSBundle mainBundle]];

fvController.selectedCellItem = selectedCellItem;

[self.navigationController pushViewController:fvController animated:YES];

[fvController release];

fvController = nil;

}

5- Add these lines of code below the previous added code.

-(void)loadView{

myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];

myTableView.delegate = self;

myTableView.dataSource = self;

myTableView.autoresizesSubviews = YES;

itemsList = [[NSMutableArray alloc] init];

[itemsList addObject:@"Item1"];

[itemsList addObject:@"Item2"];

self.navigationItem.title = @"Test List";

self.view = myTableView;

}

6- Remember to release the itemsList array. Do so by adding [itemsList release]; to the dealloc function.

7- We will need a View Controller so go ahead and create it (File->New File ->Cocoa Touch Class->UIViewController subclass) and name it TableViewController (Figure 1). Make sure the “With XIB for user interface” option is marked.

8- Open the TableViewController.h file and change the source code so it looks like this:

#import &lt;UIKit/UIKit.h&gt;

@interface TableViewController : UIViewController {

NSString *selectedCellItem;

}

@property (nonatomic, retain) NSString *selectedCellItem;

@end

9- Now open the TableViewController.m file and add this line of code below the @implementation:

@synthesize selectedCellItem;</pre>
10- Uncomment the viewDidLoad function and add these lines of code:
[sourcecode language="objc"]self.navigationItem.title = @"Selected Item";

CGRect frame = CGRectMake(0, 0, 320, 180);

self.view = [[UIView alloc] initWithFrame:frame];

self.view.backgroundColor = [UIColor whiteColor];

frame = CGRectMake(100, 20, 100, 50);

UILabel *label = [[UILabel alloc] initWithFrame:frame];

label.text = selectedCellItem;

[self.view addSubview:label];

[label release];

[super viewDidLoad];

11- Go back to the NavigationContentsViewController.m file and add this code below the #import “NavigationContentsViewController.h”:

#import "TableViewController.h"

12- That’s it, if you have followed all the previous steps, your project should compile & run without errors.

Download the sources of this tutorial by clicking here.

Get to the point – Code Snippets: NSString to NSInteger & vice versa

NSString to NSInteger code snippet:

NSString *strTest = [NSString stringWithFormat:@"%d", 10];

NSInteger to NSString code snippet:

NSInteger iTest = [strTest integerValue];

Get to the point – iPhone Development: Embed a Navigation controller to a Tab Bar Application

Get to the point – iPhone Development: Embed a Navigation controller to a Tab Bar Application

This tutorial is a continuation of the previous Tab Bar Application tutorial.

1- Open the tabbartest Xcode project. Create a new UIViewController subclass (File->New File) and name it TabBarNavigationController (see Figure 1). Make sure the “With XIB for user interface” option is marked. Three new files will be added to your Xcode project: TabBarNavigationController.h, TabBarNavigationController.m and TabBarNavigationController.xib.


Figure 1

2- Open the TabBarNavigationController.h file and replace the text UIViewController with UINavigationController.

3- We need to add a view controller to display contents. Create a new UIViewController subclass named NavigationContentsViewController (File->New File->UIViewController subclass).

4- Create a new view to add to the newly created UIViewController (File->New file->View XIB). This is not a Cocoa Touch Class file, be sure to select User Interface. Name the view FirstNavigationView. Open the file FirstNavigationView.xib and select File’s Owner. In the Identity tab of the Inspector, change the class to NavigationContentsViewController. Go to the “View Connection” tab, click on the view outlet, then drag & release it on the view canvas.

5- Open the MainWindow.xib file and add a new Tab Bar Item. Be sure the new Tab Bar Item is selected. Open the Inspector window (Tools->Inspector if it’s not already opened). On the Identity tab change the selected Class to TabBarNavigationController (see Figure 2).


Figure 2

6- Select the Tab Bar Controller (see Figure 3). Select the attributes tab from the Inspector Window. Select the second item in the View Controllers list. Choose the Navigation Controller class (see Figure 4).


Figure 3


Figure 4

7- Expand the “Tab Bar Controller” and expand the “Selected Navigation Controller (Item)”. Select the “View Controller (Item)” and change the class to NavigationContentsViewController (see Figure 5). You’ll see the name has changed to “Navigation Contents View Controller (Item)”. Click on the Attributes tab and set the NIB Name to FirstNavigationView in the Inspector window.


Figure 5

8- Save all files, click on the “Build and Run” button from Xcode, your app will be executed (see Figure 6).


Figure 6

TabBarEmbeddedNavigation source code

Get to the point – iPhone Development: Tab Bar Application

Get to the point, iPhone development tutorials for those programmers who want concise step by step tutorials, but do not have the time to watch a 30 min video tutorial.

Get to the point – iPhone Development: Tab Bar Application (Adding new views)

1- Open Xcode and create a new “Tab Bar Application” (see Figure 1). Name it tabbartest (see Figure 2).


Figure 1


Figure 2

2- Xcode will create the necessary files for a basic Tab Bar Application (see Figure 3).


Figure 3

3- By double clicking the MainWindow.xib file Interface Builder will show up (see Figure 4). If the Inspector and Library windows don’t appear, open them (Tools->Library, Tools->Inspector).


Figure 4

4- Go back to Xcode and create a new file (File->New File). From the User Interface menu list select “View XIB” (see Figure 5). Name this view as ThirdView.xib (see Figure 6).


Figure 5


Figure 6

5- From Xcode double click the ThirdView.xib file. Interface Builder will show up again (see Figure 7).


Figure 7

6- Click on the File’s Owner icon. Go to the Inspector window and click on the “View Identity” icon. From the Class list select FirstViewController (see Figure 8).


Figure 8

7- Click on the “View Connection” menu option. Click on the view outlet, then drag & release it on the view canvas (see Figure 9). If you do this correctly the “View Connection” window should look like Figure 10.


Figure 9


Figure 10

8- Go back to Xcode and open the MainWindow.xib file. Add a new Tab Bar Item (see Figure 11) by selecting it from the Library. Drag the Tab Bar Item to the Tab Bar Controller (see Figure 12).


Figure 11


Figure 12

9- Click on the newly added Tab Bar Item and select the “View Controller Attributes” from the Inspector Window (see Figure 13). Set the NIB Name parameter to ThirdView (see Figure 14). Once the NIB Name is set, your MainWindow file should show the text “Loaded From ThirdView” (see Figure 15).


Figure 13


Figure 14


Figure 15

10- Save all your Xcode & Interface Builder files. Click “Build and Run” from Xcode. The Tab Bar Application will show up on the iPhone Simulator with a third Tab Bar Item (see Figure 16).


Figure 16

Tab Bar Application – Source Code

iPhone App: SitcmSounds

Developed a new iPhone app: SitcmSounds (awaiting approval).

SitcmSounds

SitcmSounds

Follow me on Twitter

clouding.me beta launched!

The beta version of www.clouding.me is online. Register to beta test this new clouding service. I will soon add an iPhone web version. The iPhone app version is on its way, hopefully Apple will approve it.

clouding.me
Follow me on Twitter

Get Adobe Flash playerPlugin by wpburn.com wordpress themes