SushiHangover

PowerShell, Learn it or Perish ;-)

master nix
Gitter

Xamarin OS-X Addins Location

In the process of working on an Xamarin Studio Language Addin for PlayScript I needed to to manually find and update some of the installed Addin files. But where are the Addin files?

Within the ~/Library/Application Support directory you will find one based on the version of Xamarin Studio or Monodevelop that you are using:

  • MonoDevelop-4.0
  • MonoDevelop-5.0
  • MonoDevelop-6.0
  • XamarinStudio-4.0
  • XamarinStudio-5.0
  • XamarinStudio-6.0

Within one of those directories you will find:

  • LocalInstall/Addins

So for me, that ended up being:

~/Library/Application Support/XamarinStudio-6.0/LocalInstall/Addins ~/Library/Application Support/MonoDevelop-6.0/LocalInstall/Addins

Playscript | Xamarin / Monodevelop Language Addin (Part 1)

Goal:

In this first part we are going to create an Addin that does the most basic language syntax highlighing using a SyntaxMode xml file.

Prerequisites

You have the MonoDevelop.AddinMaker installed and enabled within Xamarin Studio/MonoDevelop (XS/MD).

Create the Solution/Project

With XS/MD, create a new solution/project. In this example we are using version 1.21 of the Addin Maker.

Add the Syntax files

Language syntax files are XML documents that describe how the visual representation of language will appear within the editor.

i.e.

<Keywords color = "Keyword(Jump)">
    <Word>break</Word>
    <Word>continue</Word>
    <Word>return</Word>
</Keywords>

Note: A definition of the contents of these XML files is out of scope for this posting. The best reference is the files themself. There are quite a number of them in the MonoDevelop ./main/src/core/Mono.Texteditor/SyntaxModes directory, you should start the C# one.

In our case we are adding two syntax mode files, one for ActionScript and one for PlayScript.

Each file contains also has an mime-type attribute that will be used within our addin to provide a reference of the sourcefile extension to its mime type.

i.e.

<SyntaxMode name = "ActionScript" mimeTypes="text/x-actionscript">

<SyntaxMode name = "PlayScript" mimeTypes="text/x-playscript">

Note: Make sure you flag these files as EmbeddedResources so that they are included in the addin assembly.

Mime-type to file ext. linkage

<Extension path = "/MonoDevelop/Core/MimeTypes">
    <MimeType id="text/x-actionscript" _description="ActionScript source code" icon="md-actionscript-file" isText="true">
        <File pattern="*.as" />
    </MimeType>     
    <MimeType id="text/x-playscript" _description="PlayScript source code" icon="md-playscript-file" isText="true">
        <File pattern="*.play" />
    </MimeType>     
</Extension>

Add the File Filter Extension

This will allow the IDE to provide filter options to the various file dialogs.

<Extension path = "/MonoDevelop/Ide/FileFilters">
    <FileFilter id = "ActionScript"
                insertbefore = "Assemblies"
                _label = "ActionScript Files"
                extensions = "*.as"/>
    <FileFilter id = "PlayScript"
                insertbefore = "Assemblies"
                _label = "PlayScript Files"
                extensions = "*.play"/>                                     
</Extension>

If you debug the project you will now find the ActionScript and PlayScript file filters are available:

Add the Syntaxmode Extension

Add the extension templates to the Manifest.addin.xml file.

<Extension path = "/MonoDevelop/SourceEditor2/SyntaxModes">
    <Templates resource="ActionScriptSyntaxMode.xml" />
    <Templates resource="PlayScriptSyntaxMode.xml" />
</Extension>

Add the mime-type resolver extension

Add the resolver extension class to the Manifest.addin.xml file.

<Extension path = "/MonoDevelop/Ide/TextEditorResolver">
    <Resolver class = "MonoDevelop.PlayScript.Resolver.TextEditorResolverProvider" mimeType="text/x-actionscript" />
    <Resolver class = "MonoDevelop.PlayScript.Resolver.TextEditorResolverProvider" mimeType="text/x-playscript" />
</Extension>

ProjectParameters Class

Add a new class called PlayScriptProjectParameters, this class will inherit from MonoDevelop.Projects.ProjectParameters and for now will be completely empty. We will be adding code to it in a future posting, but right now we just need to be able to create the class object.

ActionScriptLanguageBinding Class

This class inherits from IDotNetLanguageBinding and other then stubbing out some methods and assigning the file extension that this class is related to (.as), the other thing that we need to do it call the static method SyntaxModeService.LoadStylesAndModes in the constructor in other for the Editor to load and parse the embedded xml file that contains our language’s syntax:

    public ActionScriptLanguageBinding() {
        SyntaxModeService.LoadStylesAndModes (Assembly.GetExecutingAssembly ());
    }

    public string Language {
        get {
            return "ActionScript";
        }
    }

    public string ProjectStockIcon {
        get { 
            return "md-project";
        }
    }

    public FilePath GetFileName (FilePath baseName)
    {
        return baseName + ".as";
    }

    public bool IsSourceCodeFile (FilePath fileName)
    {
        return StringComparer.OrdinalIgnoreCase.Equals (Path.GetExtension (fileName), ".as");
    }

PlayScriptScriptLanguageBinding Class

This is a repeat of the ActionScriptLanguageBinding class, but updated for the PlayScript .play extension.

    public string Language {
        get {
            return "PlayScript";
        }
    }

    public string ProjectStockIcon {
        get { 
            return "md-project";
        }
    }

    public FilePath GetFileName (FilePath baseName)
    {
        return baseName + ".play";
    }

    public bool IsSourceCodeFile (FilePath fileName)
    {
        return StringComparer.OrdinalIgnoreCase.Equals (Path.GetExtension (fileName), ".play");
    }

Running this and you will have very basic language highlighting in any .as and .play that you add to Xamarin Studio or MonoDevelop.

Addition Required Reading:

Michael Hutchinson’s MonoDevelop.AddinMaker References:

Creating a Simple Add-in

MonoDevelop.AddinMaker 1.2

MonoDevelop.AddinMaker 1.2.1

MonoDevelop.AddinMaker 1.2

Source : mhutch/MonoDevelop.AddinMaker

Mono.Addin References:

Documentation : Mono.Addins

Source : mono/mono-addins

apt~file | Finding packages by searching headers

When you need a file or package and can’t find it:

Use apt-file

First, install apt-file and update it.

sudo apt-get install apt-file
sudo apt-file update

You can search with apt-file needed files or packages.

apt-file search curses.h
apt-file search panel.h
apt-file search iconv.h

Mono | Ubuntu Broken Packages

I do not normally use a Linux Desktop, more of a CLI kind-of guy, but in trying to support some C# projects that are using MonoDevelop, I needed to get the beta/alpha Mono builds installed… It turns out to be a P.I.T.A. to do it from packages and not source.

Broken packages always seem to be a problem when dealing with pre-built Linux software and I usually build from source so I do not see them, but installing the mono-devel package fails due to libjpeg62-turbo and libjpeg62 not being avialable in the normal Ubuntu repos. They have been replaced by bundle 8 of libraries but libgdiplus that Mono references is pinned to libjpeg6* packages…

So the errors:

sudo apt-get install mono-devel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
The following packages have unmet dependencies:
 mono-devel : Depends: libgdiplus (>= 2.6.7) but it is not going to be installed
              Depends: libmono-system-design4.0-cil (>= 1.0) but it is not going to be installed
              Depends: libmono-system-drawing4.0-cil (>= 3.0.6) but it is not going to be installed
              Depends: libmono-system-messaging4.0-cil (>= 2.10.1) but it is not going to be installed
              Depends: libmono-system-runtime4.0-cil (>= 2.10.1) but it is not going to be installed
              Depends: libmono-system-servicemodel-activation4.0-cil (>= 1.0) but it is not going to be installed
              Depends: libmono-system-servicemodel-web4.0-cil (>= 3.2.1) but it is not going to be installed
              Depends: libmono-system-servicemodel4.0a-cil (>= 3.2.3) but it is not going to be installed
              Depends: libmono-system-web-extensions4.0-cil (>= 2.10.3) but it is not going to be installed
              Depends: libmono-system-web-services4.0-cil (>= 1.0) but it is not going to be installed
              Depends: libmono-system-web4.0-cil (>= 2.10.3) but it is not going to be installed
              Depends: libmono-system-windows-forms4.0-cil (>= 1.0) but it is not going to be installed
              Depends: libmono-cil-dev (= 4.2.1.91-0xamarin1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
sudo apt-get install libgdiplus
1
2
3
4
5
6
7
8
9
10
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libgdiplus : Depends: libjpeg62-turbo (>= 1.3.1) but it is not installable
E: Unable to correct problems, you have held broken packages.
sudo apt-get install libjpeg62-turbo
1
2
3
4
5
6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package libjpeg62-turbo is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or is only available from another source E: 
Package 'libjpeg62-turbo' has no installation candidate

The Fix:

Get the older libjpeg62-turbo package:

libjpeg62-turbo - libjpeg-turbo JPEG runtime library

 wget http://ftp.br.debian.org/debian/pool/main/libj/libjpeg-turbo/libjpeg62-turbo_1.4.1-2_amd64.deb

Get the older libjpeg62 package:

libjpeg62 - Independent JPEG Group’s JPEG runtime library (version 6.2)

 wget http://ftp.br.debian.org/debian/pool/main/libj/libjpeg6b/libjpeg62_6b2-2_amd64.deb

Install the deb packages:

sudo dpkg --install --recursive --auto-deconfigure libjpeg62-turbo_1.4.1-2_amd64.deb 

Update and fix the ‘now broken’ dependencies:

apt-get update
sudo apt-get -f install

Finally, install mono (and monodevelop) from package:

sudo apt-get install mono-devel
sudo apt-get isntall monodevelop

Ahhh, mono 4.2.1 is now installed:

1
2
3
4
5
6
7
8
9
10
11
mono --version
Mono JIT compiler version 4.2.1 (Stable 4.2.1.91/8862921 Fri Oct 30 17:04:13 UTC 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
  TLS:           __thread
  SIGSEGV:       altstack
  Notifications: epoll
  Architecture:  amd64
  Disabled:      none
  Misc:          softdebug 
  LLVM:          supported, not enabled.
  GC:            sgen

Almost would be easier to install from source ;-)

Have fun.

PlayScript | Optimizing psc/mcs

Eric Lippert has a couple of recent posts that I have been reviewing in conjuction with the PlayScript version of Mono’s mcs (psc) as some of the things devs do in ActionScript 3.0 are targeted to making Flash’s AVM run efficiently does not always make the cut for a C#/CLR oriented compiler. Many of these items revolve around arrays and vector and misuse of the generic (dynamic) Object types, but strings, associative operations, and nulls need some love also and his posts are very insightful as how C# is optimized in certain areas.

Great reading for any C#/CLR devs, including PowerShell DevOps that are bundling their custom C# written assemblies to speed up their PS modules.

Optimizing associative operations

String concatenation behind the scenes, part one

String concatenation behind the scenes, part two

He also has a great series on Nullable micro-optimizations that start here:

Nullable micro-optimizations, part one

PlayScript Github repo is here check it out now!

Mono's new TLS Provider

Great news, the new pluggable TLS provider is available for security review.

Mono’s new TLS provider

Hello,

As described by Miguel in the “State of Tls in Mono” [1] we have been working on a new TLS implementation for Mono, one that would upgrade our TLS stack, and one that would allow us to reuse some of the higher level pieces from Microsoft’s networking stack, read that post for more details on the scope of the project.

Mono’s master branch now has the ability to load alternative TLS implementations. We added this code so we can start testing our new TLS implementation side-by-side the code that is in use today, and also so that we can provide both platform-specific backends or allow developers to choose a different TLS implementation (like BoringSSL, OpenSSL or Amazon’s s2n).

This is achieved by making our SSL transport pluggable, this allows HttpWebRequest and other classes to use the new TLS stack.

Today, a regular Mono checkout will default to the existing Mono SSL/TLS implementation which supports a number of ciphers and TLS levels up to 1.0, so nothing has changed and we have one alternative implementation available: mono-tls.

mono-tls is a purely managed implementation of TLS 1.0, 1.1 and 1.2 (filling the gap that we had). To use it, you need to build the mono-tls [2] module, once this is build, you will have to reference the following libraries: Mono.Security.NewTls, Mono.Security.NewTls.Interface, Mono.Security.Providers.NewTls.

Once you have these, you should add this code to your main program:

  MonoTlsProviderFactory.InstallProvider (new NewTlsProvider ());

Then uses of HttpWebRequest, FtpWebRequest and the Smtp client will all use the new TLS stack.

More details are available in the architecture document [3].

TLS State While we have added an extensive test suite to this new TLS implementation and tested this against a wide variety of TLS servers and configurations, we have not completed a security audit of its implementation. While we have taken every step to ensure that we follow all the best practices when implementing a security stack, we want to get this code reviewed by third parties, and we want to complete a comprehensive security audit of the code before we would even consider transitioning this as the default.

Future Work - Pluggability/SslStream We are going to be making the SslStream the proxy endpoint, for two reasons: (a) it would make SslStream usable with the new provider interface and (b) it would simplify some of the special code that lives in different places in the class libraries to use the new TLS implementation.

We will also likely introduce a MONO_TLS_PROVIDER environment variable that controls the implementation, so that we make it easier to test the implementations during the testing phase.

Future Work - Other Providers We are currently developing a provider for Apple platforms that will use Apple’s unmanaged SSL implementation, and we will be adding an implementation that use Google’s BoringSSL. The idea being that on Apple, you get to use the system provided implementation, and on other platforms, we use the Google maintained one.

Please let me know if you have any questions, comments, feedback. In particular, we would like to get you to find security holes in the implementation. We can offer a Xamarin shirt or a Xamarin monkey as a prize for finding holes in the new implementation.

References [1] http://tirania.org/blog/archive/2015/Aug-27.html [2] http://github.com/mono/mono-tls [3] https://github.com/mono/mono-tls/blob/master/ARCHITECTURE.md

Star Wars: The Force Awakens Trailer | Official HD

Get your first look at the new Star Wars: The Force Awakens trailer! Lucasfilm and visionary director J.J. Abrams join forces to take you back again to a galaxy far, far away as “Star Wars” returns to the big screen with “Star Wars: The Force Awakens.” Episode VII in the Star Wars Saga, Star Wars: The Force Awakens, opens in cinemas December 17, 2015. Official Site: http://starwarsunitedkingdom.co.uk Subscribe to Star Wars on YouTube for more videos: https://www.youtube.com/StarWarsUK Like Star Wars on Facebook: https://www.facebook.com/StarWars.UK Follow @StarWars on Twitter: @StarWarsUK Follow @StarWars on Instagram: http://instagram.com/starwars Follow Star Wars on Tumblr: http://starwars.tumblr.com/ Star Wars: The Force Awakens, directed by J.J. Abrams from a screenplay by Lawrence Kasdan & Abrams, features a cast including actors John Boyega, Daisy Ridley, Adam Driver, Oscar Isaac, Andy Serkis, Academy Award winner Lupita Nyong’o, Gwendoline Christie, Crystal Clarke, Pip Andersen, Domhnall Gleeson, and Max von Sydow. They will join the original stars of the saga, Harrison Ford, Carrie Fisher, Mark Hamill, Anthony Daniels, Peter Mayhew, and Kenny Baker. The film is being produced by Kathleen Kennedy, J.J. Abrams, and Bryan Burk, and John Williams returns as the composer.

Get your first look at the new Star Wars: The Force Awakens trailer!

Lucasfilm and visionary director J.J. Abrams join forces to take you back again to a galaxy far, far away as “Star Wars” returns to the big screen with “Star Wars: The Force Awakens.”

Episode VII in the Star Wars Saga, Star Wars: The Force Awakens, opens in cinemas December 17, 2015.

Official Site: http://starwarsunitedkingdom.co.uk

Subscribe to Star Wars on YouTube for more videos: https://www.youtube.com/StarWarsUK Like Star Wars on Facebook: https://www.facebook.com/StarWars.UK Follow @StarWars on Twitter: @StarWarsUK Follow @StarWars on Instagram: http://instagram.com/starwars Follow Star Wars on Tumblr: http://starwars.tumblr.com/

Star Wars: The Force Awakens, directed by J.J. Abrams from a screenplay by Lawrence Kasdan & Abrams, features a cast including actors John Boyega, Daisy Ridley, Adam Driver, Oscar Isaac, Andy Serkis, Academy Award winner Lupita Nyong’o, Gwendoline Christie, Crystal Clarke, Pip Andersen, Domhnall Gleeson, and Max von Sydow. They will join the original stars of the saga, Harrison Ford, Carrie Fisher, Mark Hamill, Anthony Daniels, Peter Mayhew, and Kenny Baker.

The film is being produced by Kathleen Kennedy, J.J. Abrams, and Bryan Burk, and John Williams returns as the composer.

OSX 10.11 El Capitan, Which Mono version?

Moving to El Capitan? Then you need Mono version 4.2.x or 4.0.4.4.

From the Mono mailing list:

What is the difference between the latest Mono 4.0.4.4 package for Mac and the 4.2.1 El Capitan Preview? The changelog of 4.0.4.4 includes “33585: El Capitan System Integrity Protection support.” so i suppose that the 4.0.4.4 also works on El Capitan?.

Reply from Miguel de Icaza:

One is based on Mono 4.0 series, with minimal changes just to enable the support on El Capitan; The 4.2 has the same changes, on top of the latest Mono 4.2, available on Alpha and the release candidate.