Wednesday, September 17, 2014

How to install a Windows service from the command prompt

Installing a Windows service from the command prompt is a fairly simple task, only a few steps to follow.


  1. Build the project in Release mode
  2. Go to the Release folder and copy the full address from the address bar
  3. Open Visual Studio Command Prompt (On Windows 7 you can find it under Start - All programs - Visual Studio - Visual Studio Tools; on Windows 8 click start and start typing Visual Studio Command Prompt )*
  4. Install the service using the command installUtil and passing the path you copied at step 2: installUtil pathToFolder

If the service is already installed you will need to uninstall it first:
installUtil /u pathToFolder

*If on the machine where you need to install it you don't have Visual Studio, you will have to find the executable installUtil. On my Windows 8 (but I believe it is the same on Windows 7) it is in C:\Windows\Microsoft.NET\Framework\v4.0.30319


Monday, September 8, 2014

Creating a custom setter and getter for a property in Objective C


When creating the mobile application Jano I had to show different statistics in a special menu. It had to appear in a label (of course) and I wanted to format it according to the phone's style.

The best solution for me was to add a string property to the model that would return the NSNumber property formatted accordingly.

In the .h file I defined the public properties as follows:


@property (nonatomic, strong) NSString *ValueAsString;

@property (nonatomic, strong) NSNumber *Value;


In the .m file, the code appear like this:
@synthesize Value = _value, ValueAsString = _valueAsString; 


//Getter for ValueAsString
-(NSString*) ValueAsString
{
NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setGroupingSeparator:[[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator]];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *result = [formatter stringFromNumber:_value];

    return result;
}

-(void)setValueAsString:(NSString*)value
{
_valueAsString = value;
}
Although I had no use for the setter, I added it here so that it would be a full example.