Friday, October 03, 2014

Configure app which requires admin rights to run at startup with task scheduler

 

App which requires elevated admin rights can’t just be set to run at startup by adding it to the registry key (HKLM\Software\Microsoft\Windows\CurrentVersion\Run) because it mail fail to start since it requires the UAC prompt. Windows will silently fail to display the UAC prompt.

One solution is to make the app a Windows Service, but depending on the technology used, this might not be possible. For example, a .NET Windows Service which is using .NET API printing (System.Printing) is not recommended (see http://blogs.msdn.com/b/dsui_team/archive/2013/06/24/printing-from-a-windows-service.aspx or see ‘Caution’ in http://msdn.microsoft.com/en-us/library/system.drawing.aspx).

So another solution is to use task scheduler.

When configuring the scheduled task, you need to make sure:

1. In the task properties popup, "Run with highest privileges" option is checked.

2. In the "Edit Action" popup, "Start in" is filled with the directory path (Do not include quotation marks or a trailing slash)

http://social.technet.microsoft.com/Forums/windows/en-US/7167bb31-f375-4f77-b430-0339092e16b9/how-does-run-with-the-highest-privileges-really-work-in-task-scheduler-?forum=w7itprogeneral

Tuesday, September 02, 2014

Duplicate folders issue with MvvmCross by NuGet

 

EDIT: Issue is fixed in MVVMCROSS v3.2.1 !

With the current NuGet version of MvvmCross, when adding it to the project you get duplicate folders (‘Layout’ and ‘layout’, ‘Values’ and ‘values’)

To fix this, right click on the project and choose ‘Tools \ Edit File’ in Xamarin Studio. In Visual Studio, there’s a similar way.

In the .csproj, you just need to replace the first upper case letter with lower case letter, so replace ‘Layout’ with ‘layout’ and ’Values’ with ‘values’ and save the file.

image

Tuesday, August 05, 2014

Auto binding of outlets in Xamarin iOS and MvvmCross

 

If you are like me and you don’t like doing the bindings in code, you start thinking about solutions.

So I’m experimenting with the idea of creating the bindings at runtime, based on a simple name convention:

  • An UIButton outlet with the name 'btnXXX' is bound to the view-model 'XXXCommand' property.
  • An UITextField outlet with the name 'txtXXX' is bound to the view-model 'XXX' property.
  • An UILabel outlet with the name 'lblXXX' is bound to the view-model 'XXX' property.

For example, if you have a UIButton outlet called btnLogin, it's bound to view-model LoginCommand property.

I uploaded the code here;

https://github.com/nitescua/AutoBinding/

This can be done for other platforms as well.

Tuesday, July 29, 2014

Xamarin HttpClient NameResolutionFailure exception

 

If you look on internet there are plenty of people reporting this error.

Xamarin is somehow aware of this error, and it marked it as fixed but it doesn’t seem like it is.

Fortunately, this exception appears only in debug mode, not in release mode.

Android–deployment error - INSTALL_FAILED_UPDATE_INCOMPATIBLE

 

When trying to deploy on device I got this error:

Deployment failed because of an internal error: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]

Deployment failed. Internal error.

To fix it, run:

C:\Users\[YourUserName]\AppData\Local\Android\android-sdk\platform-tools>adb uninstall com.xxx.yyy

Don’t include the .apk file extension

Monday, May 26, 2014

Publish empty folders

 

If you need to include an empty folder when deploying using MSDeploy (either manually from Visual Studio or calling msdeploy from scripts) you can do that by:

1. create a Web Publishing Pipeline file (.wpp.targets)

   Create a new XML file in the project folder (the same folder that holds the .csproj or .vbproj file) and name it <projectname>.wpp.targets.

2. Add the following

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="
http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AfterAddIisSettingAndFileContentsToSourceManifest>MakeEmptyFolders</AfterAddIisSettingAndFileContentsToSourceManifest>
  </PropertyGroup>
  <Target Name="MakeEmptyFolders">
    <Message Text="Adding empty folder to hold downloads" />
    <MakeDir Directories="$(_MSDeployDirPath_FullPath)\Survey\responses"/>
  </Target>
</Project>

In my case I needed an empty folder called ‘responses’ inside an existing ‘Survey’ folder.

The folder will be created no matter which configuration or publishing profile is run.

More info:

http://msdn.microsoft.com/en-us/library/ff398069(v=vs.110).aspx

http://blog.alanta.nl/2011/02/web-deploy-customizing-deployment.html

Monday, April 07, 2014

A busy MvxViewController for MvvmCross + iOS

In my MVVMCross apps, in the shared PCL core library, I usually have a MvxViewModel derived class called ViewModelBase with a IsBusy property:


public class ViewModelBase : MvxViewModel
{
bool isBusy;
public bool IsBusy
{
get { return this.isBusy; }
set { if (this.isBusy != value) { this.isBusy = value; this.RaisePropertyChanged("IsBusy"); } }
}

// other base stuff in ViewModelBase
}
The property is to update a progress indicator control in the view.
For iOS the control can be UIActivityIndicatorView.

But instead of placing a UIActivityIndicatorView on each view, we can dynamically create it at run-time when IsBusy property changes to true.
We can have this implemented in a ViewController base class like this:

using System;
using System.ComponentModel;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
using Cirrious.MvvmCross.Touch.Views;
using Cirrious.CrossCore.WeakSubscription;
using YourApp.Core.ViewModels;

namespace YourApp.Touch
{
public abstract class MvxViewControllerBase : MvxViewController
{
// weak subscription to NotifyProperty event
IDisposable npSubscription;

public override void ViewDidLoad()
{
base.ViewDidLoad();

// subscribe to view-model's PropertyChanged
this.npSubscription = ((INotifyPropertyChanged)this.ViewModel).WeakSubscribe<bool>("IsBusy", (s, e) => { this.UpdateActivityIndicatorView(); });

// at this point view-model exists, so update the indicator view
this.UpdateActivityIndicatorView();

// add other common UIViewController stuff
}

protected override void Dispose(bool disposing)
{
if (disposing && this.npSubscription != null)
{
this.npSubscription.Dispose();
this.npSubscription = null;
}
base.Dispose(disposing);
}

void UpdateActivityIndicatorView()
{
// get the activity indicator
var activityIndicatorView = (UIActivityIndicatorView)this.View.ViewWithTag(1000);

var vm
= (ViewModelBase)this.ViewModel;
if (vm.IsBusy)
{
// show busy indicator. create it first if it doesn't already exists
if (activityIndicatorView == null)
{
activityIndicatorView
= new UIActivityIndicatorView(this.View.Frame)
{
ActivityIndicatorViewStyle
= UIActivityIndicatorViewStyle.Gray,
Tag
= 1000
};

this.Add(activityIndicatorView);
this.View.BringSubviewToFront(activityIndicatorView);
activityIndicatorView.StartAnimating();
}

// show the activity indicator
activityIndicatorView.Hidden = false;
}
else
{
// hide the activity indicator
if (activityIndicatorView != null)
{
activityIndicatorView.Hidden
= true;
}
}
}
}
}
Instead of having a base class we can delegate the implementation to an extension class which has the same implementation.

Please let me know if you see any possible issues.

I am thinking to do a similar implementation for other platforms as well.
Maybe MVVMCross could support out of the box a similar implementation. A built in implementation in MVVMCross would probably require to be able to override the style for the indicator.