Friday, October 3, 2014

Two Dead Ends

I suppose I'll offer some notes on two things I've tried to make progress on in the name of offering up real blog postings. In both cases I'm running into brick walls and am hung up, unable to go forward. First I tried to recreate a simple OWIN example as offered up by Reaz Haq in this Austin .NET User Group talk. I recreated his code from a photo of his projection that I took with my phone like so:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Owin;
namespace Whatever
{
   using AppFunc = Func<IDictionary<string, object>, Task>;
   
   public class Startup
   {
      public void Configuration(IAppBuilder appBuilder)
      {
         appBuilder.Use(new Func<AppFunc, AppFunc>(Middleware));
      }
      
      public AppFunc Middleware(AppFunc nextMiddleware)
      {
         AppFunc appFunc = (IDictionary<string, object> environment) =>
         {
            var bytes = Encoding.UTF8.GetBytes("<h1>Hello adnug</h1>");
            var headers = (IDictionary<string, string[]>) environment["owin.ResponseBody"];
            
            headers["Content-Length"] = new[]
                  {bytes.Length.ToString(CultureInfo.CurrentCulture)};
            headers["Content-Type"] = new[] { "text/html" };
            
            var response = (Stream)environment["owin.ResponseBody"];
            response.WriteAsync(bytes, 0, bytes.Length);
            
            return nextMiddleware(environment);
         };
         return appFunc;
      }
   }
}

 
 

If it worked it should just spin up a web page with this HTML in it:

<h1>Hello adnug</h1>

 
 

...adnug being the Austin .NET User Group. Things Reaz did to get this working:

  • install OWIN from Nuget with: Install-Package Owin
  • also get the executable with: Install-Package OwinHost ...perhaps? ...we will need the executable and this Nuget command will put it at C:\yourprojectnamehere\packages\OwinHost.3.0.0\tools\OwinHost.exe
  • create a class library as a project where it is the only project in a solution
  • rename the one .cs file that comes with the project to be "Startup" and change its code to be what I advertise above
  • set it to be the startup project
  • in the project properties, under "Debug" pick "Start external program" under the "Start Action" subsection and here in you will pick the OwinHost.exe executable to run the Katana web server

 
 

Alright, this all works, but then when you debug the application the shell for OwinHost.exe flickers open and then shuts again. In Reaz's example, the shell stayed open and advertised a locale to reach out to to see the HMTL it was crafting at something like http://localhost:5000 and Reaz would pull up a browser and be able to hit the URL, displaying the "Hello adnug" message for the room to see. How do I keep the shell from closing right away? Anyone know? I tried to give -interactive:true -debug:true as command line arguments to no avail. What am I missing? The other thing I've been struggling with is trying to earn myself one of the free, green C# T-shirts by installing Xamarin and then running the dummy Xamarin Store application. As best as I can tell one is supposed to run Xamarin studio side by side with Visual Studio so that one may spin up an Android emulator in Xamarin studio and then debug in Visual Studio to have the debugging manifest in the emulator.

The app comes with two emulators which don’t support version of 19 of Android which you will need. You may install SDKs under the "Open Android SDK Manager..." option under the "Tools" menu in Xamarin Studio and then may create your own emulator under the "Open Android Emulator Manager..." option under the "Tools" menu, but I still can't get things to work. I keep running into an error reading "Deployment failed because the device does not support the package's minimum Android version. You can change the minimum Android version in the Android Application section of the Project Options." ...and as it turns out I cannot just roll back to an earlier version of Android as the Xamarin Store code breaks.

No comments:

Post a Comment