// Copyright (c) The NodeRT Contributors
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the ""License""); you may
// not use this file except in compliance with the License. You may obtain a
// copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing permissions
// and limitations under the License.

// TODO: Verify that this is is still needed..
#define NTDDI_VERSION 0x06010000

#include <v8.h>
#include "nan.h"
#include <string>
#include <ppltasks.h>
#include "CollectionsConverter.h"
#include "CollectionsWrap.h"
#include "node-async.h"
#include "NodeRtUtils.h"
#include "OpaqueWrapper.h"
#include "WrapperBase.h"

#using <Windows.WinMD>

// this undefs fixes the issues of compiling Windows.Data.Json, Windows.Storag.FileProperties, and Windows.Stroage.Search
// Some of the node header files brings windows definitions with the same names as some of the WinRT methods
#undef DocumentProperties
#undef GetObject
#undef CreateEvent
#undef FindText
#undef SendMessage

const char* REGISTRATION_TOKEN_MAP_PROPERTY_NAME = "__registrationTokenMap__";

using v8::Array;
using v8::String;
using v8::Value;
using v8::Boolean;
using v8::Integer;
using v8::FunctionTemplate;
using v8::Object;
using v8::Local;
using v8::Function;
using v8::Date;
using v8::Number;
using v8::PropertyAttribute;
using v8::Primitive;
using Nan::HandleScope;
using Nan::Persistent;
using Nan::Undefined;
using Nan::True;
using Nan::False;
using Nan::Null;
using Nan::MaybeLocal;
using Nan::EscapableHandleScope;
using Nan::HandleScope;
using Nan::TryCatch;
using namespace concurrency;

namespace NodeRT { namespace Windows { namespace UI { namespace Xaml { namespace Hosting { 
  v8::Local<v8::Value> WrapDesignerAppExitedEventArgs(::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ UnwrapDesignerAppExitedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapDesignerAppManager(::Windows::UI::Xaml::Hosting::DesignerAppManager^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::DesignerAppManager^ UnwrapDesignerAppManager(Local<Value> value);
  
  v8::Local<v8::Value> WrapDesignerAppView(::Windows::UI::Xaml::Hosting::DesignerAppView^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::DesignerAppView^ UnwrapDesignerAppView(Local<Value> value);
  
  v8::Local<v8::Value> WrapDesktopWindowXamlSource(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ UnwrapDesktopWindowXamlSource(Local<Value> value);
  
  v8::Local<v8::Value> WrapDesktopWindowXamlSourceGotFocusEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ UnwrapDesktopWindowXamlSourceGotFocusEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ UnwrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapElementCompositionPreview(::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ UnwrapElementCompositionPreview(Local<Value> value);
  
  v8::Local<v8::Value> WrapIXamlUIPresenterHost(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ UnwrapIXamlUIPresenterHost(Local<Value> value);
  
  v8::Local<v8::Value> WrapIXamlUIPresenterHost2(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ UnwrapIXamlUIPresenterHost2(Local<Value> value);
  
  v8::Local<v8::Value> WrapIXamlUIPresenterHost3(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ UnwrapIXamlUIPresenterHost3(Local<Value> value);
  
  v8::Local<v8::Value> WrapWindowsXamlManager(::Windows::UI::Xaml::Hosting::WindowsXamlManager^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ UnwrapWindowsXamlManager(Local<Value> value);
  
  v8::Local<v8::Value> WrapXamlSourceFocusNavigationRequest(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ UnwrapXamlSourceFocusNavigationRequest(Local<Value> value);
  
  v8::Local<v8::Value> WrapXamlSourceFocusNavigationResult(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ UnwrapXamlSourceFocusNavigationResult(Local<Value> value);
  
  v8::Local<v8::Value> WrapXamlUIPresenter(::Windows::UI::Xaml::Hosting::XamlUIPresenter^ wintRtInstance);
  ::Windows::UI::Xaml::Hosting::XamlUIPresenter^ UnwrapXamlUIPresenter(Local<Value> value);
  



  static void InitDesignerAppViewStateEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("DesignerAppViewState").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("visible").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::DesignerAppViewState::Visible)));
    Nan::Set(enumObject, Nan::New<String>("hidden").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::DesignerAppViewState::Hidden)));
  }

  static void InitXamlSourceFocusNavigationReasonEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("XamlSourceFocusNavigationReason").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("programmatic").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Programmatic)));
    Nan::Set(enumObject, Nan::New<String>("restore").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Restore)));
    Nan::Set(enumObject, Nan::New<String>("first").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::First)));
    Nan::Set(enumObject, Nan::New<String>("last").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Last)));
    Nan::Set(enumObject, Nan::New<String>("left").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Left)));
    Nan::Set(enumObject, Nan::New<String>("up").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Up)));
    Nan::Set(enumObject, Nan::New<String>("right").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Right)));
    Nan::Set(enumObject, Nan::New<String>("down").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Down)));
  }

  static bool IsHostingContractJsObject(Local<Value> value) {
    if (!value->IsObject()) {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    return true;
  }

  ::Windows::UI::Xaml::Hosting::HostingContract HostingContractFromJsObject(Local<Value> value) {
    HandleScope scope;
    ::Windows::UI::Xaml::Hosting::HostingContract returnValue;

    if (!value->IsObject()) {
      Nan::ThrowError(Nan::TypeError(NodeRT::Utils::NewString(L"Unexpected type, expected an object")));
      return returnValue;
    }

    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
    Local<String> symbol;

    return returnValue;
  }

  Local<Value> HostingContractToJsObject(::Windows::UI::Xaml::Hosting::HostingContract value) {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();


    return scope.Escape(obj);
  }

  static bool IsSizeJsObject(Local<Value> value) {
    if (!value->IsObject()) {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    return true;
  }

  ::Windows::Foundation::Size SizeFromJsObject(Local<Value> value) {
    HandleScope scope;
    ::Windows::Foundation::Size returnValue;

    if (!value->IsObject()) {
      Nan::ThrowError(Nan::TypeError(NodeRT::Utils::NewString(L"Unexpected type, expected an object")));
      return returnValue;
    }

    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
    Local<String> symbol;

    return returnValue;
  }

  Local<Value> SizeToJsObject(::Windows::Foundation::Size value) {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();


    return scope.Escape(obj);
  }
  static bool IsRectJsObject(Local<Value> value) {
    if (!value->IsObject()) {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    return true;
  }

  ::Windows::Foundation::Rect RectFromJsObject(Local<Value> value) {
    HandleScope scope;
    ::Windows::Foundation::Rect returnValue;

    if (!value->IsObject()) {
      Nan::ThrowError(Nan::TypeError(NodeRT::Utils::NewString(L"Unexpected type, expected an object")));
      return returnValue;
    }

    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
    Local<String> symbol;

    return returnValue;
  }

  Local<Value> RectToJsObject(::Windows::Foundation::Rect value) {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();


    return scope.Escape(obj);
  }

  class DesignerAppExitedEventArgs : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("DesignerAppExitedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("exitCode").ToLocalChecked(), ExitCodeGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("DesignerAppExitedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      DesignerAppExitedEventArgs(::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      DesignerAppExitedEventArgs *wrapperInstance = new DesignerAppExitedEventArgs(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapDesignerAppExitedEventArgs(winRtInstance));
    }





    static void ExitCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^>(info.This())) {
        return;
      }

      DesignerAppExitedEventArgs *wrapper = DesignerAppExitedEventArgs::Unwrap<DesignerAppExitedEventArgs>(info.This());

      try  {
        unsigned int result = wrapper->_instance->ExitCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapDesignerAppExitedEventArgs(::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ UnwrapDesignerAppExitedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> DesignerAppExitedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapDesignerAppExitedEventArgs(::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(DesignerAppExitedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ UnwrapDesignerAppExitedEventArgs(Local<Value> value) {
     return DesignerAppExitedEventArgs::Unwrap<DesignerAppExitedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDesignerAppExitedEventArgs(Local<Object> exports) {
    DesignerAppExitedEventArgs::Init(exports);
  }

  class DesignerAppManager : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("DesignerAppManager").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;

          
            Nan::SetPrototypeMethod(localRef, "close", Close);
          

          
            Nan::SetPrototypeMethod(localRef, "createNewViewAsync", CreateNewViewAsync);
            Nan::SetPrototypeMethod(localRef, "loadObjectIntoAppAsync", LoadObjectIntoAppAsync);
          

          
          Nan::SetPrototypeMethod(localRef,"addListener", AddListener);
          Nan::SetPrototypeMethod(localRef,"on", AddListener);
          Nan::SetPrototypeMethod(localRef,"removeListener", RemoveListener);
          Nan::SetPrototypeMethod(localRef, "off", RemoveListener);

          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("appUserModelId").ToLocalChecked(), AppUserModelIdGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("DesignerAppManager").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      DesignerAppManager(::Windows::UI::Xaml::Hosting::DesignerAppManager^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::DesignerAppManager^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::DesignerAppManager^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 1
        && info[0]->IsString())
      {
        try {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          
          winRtInstance = ref new ::Windows::UI::Xaml::Hosting::DesignerAppManager(arg0);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      DesignerAppManager *wrapperInstance = new DesignerAppManager(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::DesignerAppManager^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::DesignerAppManager^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapDesignerAppManager(winRtInstance));
    }

    static void CreateNewViewAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info.This())) {
        return;
      }

      if (info.Length() == 0 || !info[info.Length() -1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: No callback was given")));
        return;
      }

      DesignerAppManager *wrapper = DesignerAppManager::Unwrap<DesignerAppManager>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::UI::Xaml::Hosting::DesignerAppView^>^ op;


      if (info.Length() == 3
        && info[0]->IsInt32()
        && NodeRT::Utils::IsSize(info[1]))
      {
        try
        {
          ::Windows::UI::Xaml::Hosting::DesignerAppViewState arg0 = static_cast<::Windows::UI::Xaml::Hosting::DesignerAppViewState>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          ::Windows::Foundation::Size arg1 = NodeRT::Utils::SizeFromJs(info[1]);
          
          op = wrapper->_instance->CreateNewViewAsync(arg0,arg1);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }

      auto opTask = create_task(op);
      uv_async_t* asyncToken = NodeUtils::Async::GetAsyncToken(info[info.Length() -1].As<Function>());

      opTask.then( [asyncToken] (task<::Windows::UI::Xaml::Hosting::DesignerAppView^> t) {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapDesignerAppView(result);
              if (tryCatch.HasCaught())
              {
                error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
              }
              else
              {
                error = Undefined();
              }
              if (arg1.IsEmpty()) arg1 = Undefined();
            }
            Local<Value> args[] = {error, arg1};


            invokeCallback(_countof(args), args);
          });
        } catch (Platform::Exception^ exception) {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);

            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }
      });
    }
    static void LoadObjectIntoAppAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info.This())) {
        return;
      }

      if (info.Length() == 0 || !info[info.Length() -1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: No callback was given")));
        return;
      }

      DesignerAppManager *wrapper = DesignerAppManager::Unwrap<DesignerAppManager>(info.This());

      ::Windows::Foundation::IAsyncAction^ op;


      if (info.Length() == 4
        && info[0]->IsString()
        && NodeRT::Utils::IsGuid(info[1])
        && info[2]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          ::Platform::Guid arg1 = NodeRT::Utils::GuidFromJs(info[1]);
          Platform::String^ arg2 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[2])));
          
          op = wrapper->_instance->LoadObjectIntoAppAsync(arg0,arg1,arg2);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }

      auto opTask = create_task(op);
      uv_async_t* asyncToken = NodeUtils::Async::GetAsyncToken(info[info.Length() -1].As<Function>());

      opTask.then( [asyncToken] (task<void> t) {
        try {
          t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> args[] = {Undefined()};


            invokeCallback(_countof(args), args);
          });
        } catch (Platform::Exception^ exception) {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);

            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }
      });
    }


    static void Close(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info.This())) {
        return;
      }

      DesignerAppManager *wrapper = DesignerAppManager::Unwrap<DesignerAppManager>(info.This());

      if (info.Length() == 0) {
        try {
          delete wrapper->_instance;
          wrapper->_instance = nullptr;
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      } else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    static void AppUserModelIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info.This())) {
        return;
      }

      DesignerAppManager *wrapper = DesignerAppManager::Unwrap<DesignerAppManager>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->AppUserModelId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      Local<Function> callback = info[1].As<Function>();

      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"designerAppExited", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info.This()))
        {
          Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"The caller of this method isn't of the expected type or internal WinRt object was disposed")));
      return;
        }
        DesignerAppManager *wrapper = DesignerAppManager::Unwrap<DesignerAppManager>(info.This());
      
        try {
          Persistent<Object>* perstPtr = new Persistent<Object>();
          perstPtr->Reset(NodeRT::Utils::CreateCallbackObjectInDomain(callback));
          std::shared_ptr<Persistent<Object>> callbackObjPtr(perstPtr,
            [] (Persistent<Object> *ptr ) {
              NodeUtils::Async::RunOnMain([ptr]() {
                ptr->Reset();
                delete ptr;
            });
          });

          registrationToken = wrapper->_instance->DesignerAppExited::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::UI::Xaml::Hosting::DesignerAppManager^, ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^>(
            [callbackObjPtr](::Windows::UI::Xaml::Hosting::DesignerAppManager^ arg0, ::Windows::UI::Xaml::Hosting::DesignerAppExitedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapDesignerAppManager(arg0);
                  wrappedArg1 = WrapDesignerAppExitedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
 else  {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Value> tokenMapVal = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());
      Local<Object> tokenMap;

      if (tokenMapVal.IsEmpty() || Nan::Equals(tokenMapVal, Undefined()).FromMaybe(false)) {
        tokenMap = Nan::New<Object>();
        NodeRT::Utils::SetHiddenValueWithObject(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked(), tokenMap);
      } else {
        tokenMap = Nan::To<Object>(tokenMapVal).ToLocalChecked();
      }

      Nan::Set(tokenMap, info[0], CreateOpaqueWrapper(::Windows::Foundation::PropertyValue::CreateInt64(registrationToken.Value)));
    }

    static void RemoveListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected a string and a callback")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      if ((!NodeRT::Utils::CaseInsenstiveEquals(L"designerAppExited", str))) {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Function> callback = info[1].As<Function>();
      Local<Value> tokenMap = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());

      if (tokenMap.IsEmpty() || Nan::Equals(tokenMap, Undefined()).FromMaybe(false)) {
        return;
      }

      Local<Value> opaqueWrapperObj =  Nan::Get(Nan::To<Object>(tokenMap).ToLocalChecked(), info[0]).ToLocalChecked();

      if (opaqueWrapperObj.IsEmpty() || Nan::Equals(opaqueWrapperObj,Undefined()).FromMaybe(false)) {
        return;
      }

      OpaqueWrapper *opaqueWrapper = OpaqueWrapper::Unwrap<OpaqueWrapper>(opaqueWrapperObj.As<Object>());

      long long tokenValue = (long long) opaqueWrapper->GetObjectInstance();
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      registrationToken.Value = tokenValue;

      try  {
        if (NodeRT::Utils::CaseInsenstiveEquals(L"designerAppExited", str)) {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppManager^>(info.This()))
          {
            Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"The caller of this method isn't of the expected type or internal WinRt object was disposed")));
            return;
          }
          DesignerAppManager *wrapper = DesignerAppManager::Unwrap<DesignerAppManager>(info.This());
          wrapper->_instance->DesignerAppExited::remove(registrationToken);
        }
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }

      Nan::Delete(Nan::To<Object>(tokenMap).ToLocalChecked(), Nan::To<String>(info[0]).ToLocalChecked());
    }
    private:
      ::Windows::UI::Xaml::Hosting::DesignerAppManager^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapDesignerAppManager(::Windows::UI::Xaml::Hosting::DesignerAppManager^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::DesignerAppManager^ UnwrapDesignerAppManager(Local<Value> value);
  };

  Persistent<FunctionTemplate> DesignerAppManager::s_constructorTemplate;

  v8::Local<v8::Value> WrapDesignerAppManager(::Windows::UI::Xaml::Hosting::DesignerAppManager^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(DesignerAppManager::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::DesignerAppManager^ UnwrapDesignerAppManager(Local<Value> value) {
     return DesignerAppManager::Unwrap<DesignerAppManager>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDesignerAppManager(Local<Object> exports) {
    DesignerAppManager::Init(exports);
  }

  class DesignerAppView : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("DesignerAppView").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;

          
            Nan::SetPrototypeMethod(localRef, "close", Close);
          

          
            Nan::SetPrototypeMethod(localRef, "updateViewAsync", UpdateViewAsync);
          


          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("appUserModelId").ToLocalChecked(), AppUserModelIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("applicationViewId").ToLocalChecked(), ApplicationViewIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("viewSize").ToLocalChecked(), ViewSizeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("viewState").ToLocalChecked(), ViewStateGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("DesignerAppView").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      DesignerAppView(::Windows::UI::Xaml::Hosting::DesignerAppView^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::DesignerAppView^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::DesignerAppView^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      DesignerAppView *wrapperInstance = new DesignerAppView(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::DesignerAppView^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::DesignerAppView^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapDesignerAppView(winRtInstance));
    }

    static void UpdateViewAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info.This())) {
        return;
      }

      if (info.Length() == 0 || !info[info.Length() -1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: No callback was given")));
        return;
      }

      DesignerAppView *wrapper = DesignerAppView::Unwrap<DesignerAppView>(info.This());

      ::Windows::Foundation::IAsyncAction^ op;


      if (info.Length() == 3
        && info[0]->IsInt32()
        && NodeRT::Utils::IsSize(info[1]))
      {
        try
        {
          ::Windows::UI::Xaml::Hosting::DesignerAppViewState arg0 = static_cast<::Windows::UI::Xaml::Hosting::DesignerAppViewState>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          ::Windows::Foundation::Size arg1 = NodeRT::Utils::SizeFromJs(info[1]);
          
          op = wrapper->_instance->UpdateViewAsync(arg0,arg1);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }

      auto opTask = create_task(op);
      uv_async_t* asyncToken = NodeUtils::Async::GetAsyncToken(info[info.Length() -1].As<Function>());

      opTask.then( [asyncToken] (task<void> t) {
        try {
          t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> args[] = {Undefined()};


            invokeCallback(_countof(args), args);
          });
        } catch (Platform::Exception^ exception) {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);

            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }
      });
    }


    static void Close(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info.This())) {
        return;
      }

      DesignerAppView *wrapper = DesignerAppView::Unwrap<DesignerAppView>(info.This());

      if (info.Length() == 0) {
        try {
          delete wrapper->_instance;
          wrapper->_instance = nullptr;
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      } else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    static void AppUserModelIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info.This())) {
        return;
      }

      DesignerAppView *wrapper = DesignerAppView::Unwrap<DesignerAppView>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->AppUserModelId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ApplicationViewIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info.This())) {
        return;
      }

      DesignerAppView *wrapper = DesignerAppView::Unwrap<DesignerAppView>(info.This());

      try  {
        int result = wrapper->_instance->ApplicationViewId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ViewSizeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info.This())) {
        return;
      }

      DesignerAppView *wrapper = DesignerAppView::Unwrap<DesignerAppView>(info.This());

      try  {
        ::Windows::Foundation::Size result = wrapper->_instance->ViewSize;
        info.GetReturnValue().Set(NodeRT::Utils::SizeToJs(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ViewStateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesignerAppView^>(info.This())) {
        return;
      }

      DesignerAppView *wrapper = DesignerAppView::Unwrap<DesignerAppView>(info.This());

      try  {
        ::Windows::UI::Xaml::Hosting::DesignerAppViewState result = wrapper->_instance->ViewState;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::Xaml::Hosting::DesignerAppView^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapDesignerAppView(::Windows::UI::Xaml::Hosting::DesignerAppView^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::DesignerAppView^ UnwrapDesignerAppView(Local<Value> value);
  };

  Persistent<FunctionTemplate> DesignerAppView::s_constructorTemplate;

  v8::Local<v8::Value> WrapDesignerAppView(::Windows::UI::Xaml::Hosting::DesignerAppView^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(DesignerAppView::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::DesignerAppView^ UnwrapDesignerAppView(Local<Value> value) {
     return DesignerAppView::Unwrap<DesignerAppView>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDesignerAppView(Local<Object> exports) {
    DesignerAppView::Init(exports);
  }

  class DesktopWindowXamlSource : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("DesktopWindowXamlSource").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "navigateFocus", NavigateFocus);
            Nan::SetPrototypeMethod(localRef, "close", Close);
          


          
          Nan::SetPrototypeMethod(localRef,"addListener", AddListener);
          Nan::SetPrototypeMethod(localRef,"on", AddListener);
          Nan::SetPrototypeMethod(localRef,"removeListener", RemoveListener);
          Nan::SetPrototypeMethod(localRef, "off", RemoveListener);

          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("content").ToLocalChecked(), ContentGetter, ContentSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("hasFocus").ToLocalChecked(), HasFocusGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("DesktopWindowXamlSource").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      DesktopWindowXamlSource(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 0)
      {
        try {
          winRtInstance = ref new ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource();
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      DesktopWindowXamlSource *wrapperInstance = new DesktopWindowXamlSource(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapDesktopWindowXamlSource(winRtInstance));
    }


    static void NavigateFocus(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This())) {
        return;
      }

      DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^>(info[0]))
      {
        try
        {
          ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ arg0 = UnwrapXamlSourceFocusNavigationRequest(info[0]);
          
          ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ result;
          result = wrapper->_instance->NavigateFocus(arg0);
          info.GetReturnValue().Set(WrapXamlSourceFocusNavigationResult(result));
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void Close(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This())) {
        return;
      }

      DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());

      if (info.Length() == 0) {
        try {
          delete wrapper->_instance;
          wrapper->_instance = nullptr;
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      } else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    static void ContentGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This())) {
        return;
      }

      DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());

      try  {
        ::Windows::UI::Xaml::UIElement^ result = wrapper->_instance->Content;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Xaml", "UIElement", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ContentSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(value)) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This())) {
        return;
      }

      DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());

      try {

        ::Windows::UI::Xaml::UIElement^ winRtValue = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Content = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void HasFocusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This())) {
        return;
      }

      DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());

      try  {
        bool result = wrapper->_instance->HasFocus;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      Local<Function> callback = info[1].As<Function>();

      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"gotFocus", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This()))
        {
          Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"The caller of this method isn't of the expected type or internal WinRt object was disposed")));
      return;
        }
        DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());
      
        try {
          Persistent<Object>* perstPtr = new Persistent<Object>();
          perstPtr->Reset(NodeRT::Utils::CreateCallbackObjectInDomain(callback));
          std::shared_ptr<Persistent<Object>> callbackObjPtr(perstPtr,
            [] (Persistent<Object> *ptr ) {
              NodeUtils::Async::RunOnMain([ptr]() {
                ptr->Reset();
                delete ptr;
            });
          });

          registrationToken = wrapper->_instance->GotFocus::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^, ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^>(
            [callbackObjPtr](::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ arg0, ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapDesktopWindowXamlSource(arg0);
                  wrappedArg1 = WrapDesktopWindowXamlSourceGotFocusEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
      else if (NodeRT::Utils::CaseInsenstiveEquals(L"takeFocusRequested", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This()))
        {
          Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"The caller of this method isn't of the expected type or internal WinRt object was disposed")));
      return;
        }
        DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());
      
        try {
          Persistent<Object>* perstPtr = new Persistent<Object>();
          perstPtr->Reset(NodeRT::Utils::CreateCallbackObjectInDomain(callback));
          std::shared_ptr<Persistent<Object>> callbackObjPtr(perstPtr,
            [] (Persistent<Object> *ptr ) {
              NodeUtils::Async::RunOnMain([ptr]() {
                ptr->Reset();
                delete ptr;
            });
          });

          registrationToken = wrapper->_instance->TakeFocusRequested::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^, ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^>(
            [callbackObjPtr](::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ arg0, ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapDesktopWindowXamlSource(arg0);
                  wrappedArg1 = WrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
 else  {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Value> tokenMapVal = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());
      Local<Object> tokenMap;

      if (tokenMapVal.IsEmpty() || Nan::Equals(tokenMapVal, Undefined()).FromMaybe(false)) {
        tokenMap = Nan::New<Object>();
        NodeRT::Utils::SetHiddenValueWithObject(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked(), tokenMap);
      } else {
        tokenMap = Nan::To<Object>(tokenMapVal).ToLocalChecked();
      }

      Nan::Set(tokenMap, info[0], CreateOpaqueWrapper(::Windows::Foundation::PropertyValue::CreateInt64(registrationToken.Value)));
    }

    static void RemoveListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected a string and a callback")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      if ((!NodeRT::Utils::CaseInsenstiveEquals(L"gotFocus", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"takeFocusRequested", str))) {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Function> callback = info[1].As<Function>();
      Local<Value> tokenMap = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());

      if (tokenMap.IsEmpty() || Nan::Equals(tokenMap, Undefined()).FromMaybe(false)) {
        return;
      }

      Local<Value> opaqueWrapperObj =  Nan::Get(Nan::To<Object>(tokenMap).ToLocalChecked(), info[0]).ToLocalChecked();

      if (opaqueWrapperObj.IsEmpty() || Nan::Equals(opaqueWrapperObj,Undefined()).FromMaybe(false)) {
        return;
      }

      OpaqueWrapper *opaqueWrapper = OpaqueWrapper::Unwrap<OpaqueWrapper>(opaqueWrapperObj.As<Object>());

      long long tokenValue = (long long) opaqueWrapper->GetObjectInstance();
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      registrationToken.Value = tokenValue;

      try  {
        if (NodeRT::Utils::CaseInsenstiveEquals(L"gotFocus", str)) {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This()))
          {
            Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"The caller of this method isn't of the expected type or internal WinRt object was disposed")));
            return;
          }
          DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());
          wrapper->_instance->GotFocus::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"takeFocusRequested", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^>(info.This()))
          {
            Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"The caller of this method isn't of the expected type or internal WinRt object was disposed")));
            return;
          }
          DesktopWindowXamlSource *wrapper = DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(info.This());
          wrapper->_instance->TakeFocusRequested::remove(registrationToken);
        }
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }

      Nan::Delete(Nan::To<Object>(tokenMap).ToLocalChecked(), Nan::To<String>(info[0]).ToLocalChecked());
    }
    private:
      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapDesktopWindowXamlSource(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ UnwrapDesktopWindowXamlSource(Local<Value> value);
  };

  Persistent<FunctionTemplate> DesktopWindowXamlSource::s_constructorTemplate;

  v8::Local<v8::Value> WrapDesktopWindowXamlSource(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(DesktopWindowXamlSource::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource^ UnwrapDesktopWindowXamlSource(Local<Value> value) {
     return DesktopWindowXamlSource::Unwrap<DesktopWindowXamlSource>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDesktopWindowXamlSource(Local<Object> exports) {
    DesktopWindowXamlSource::Init(exports);
  }

  class DesktopWindowXamlSourceGotFocusEventArgs : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("DesktopWindowXamlSourceGotFocusEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("request").ToLocalChecked(), RequestGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("DesktopWindowXamlSourceGotFocusEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      DesktopWindowXamlSourceGotFocusEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      DesktopWindowXamlSourceGotFocusEventArgs *wrapperInstance = new DesktopWindowXamlSourceGotFocusEventArgs(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapDesktopWindowXamlSourceGotFocusEventArgs(winRtInstance));
    }





    static void RequestGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^>(info.This())) {
        return;
      }

      DesktopWindowXamlSourceGotFocusEventArgs *wrapper = DesktopWindowXamlSourceGotFocusEventArgs::Unwrap<DesktopWindowXamlSourceGotFocusEventArgs>(info.This());

      try  {
        ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ result = wrapper->_instance->Request;
        info.GetReturnValue().Set(WrapXamlSourceFocusNavigationRequest(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapDesktopWindowXamlSourceGotFocusEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ UnwrapDesktopWindowXamlSourceGotFocusEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> DesktopWindowXamlSourceGotFocusEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapDesktopWindowXamlSourceGotFocusEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(DesktopWindowXamlSourceGotFocusEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceGotFocusEventArgs^ UnwrapDesktopWindowXamlSourceGotFocusEventArgs(Local<Value> value) {
     return DesktopWindowXamlSourceGotFocusEventArgs::Unwrap<DesktopWindowXamlSourceGotFocusEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDesktopWindowXamlSourceGotFocusEventArgs(Local<Object> exports) {
    DesktopWindowXamlSourceGotFocusEventArgs::Init(exports);
  }

  class DesktopWindowXamlSourceTakeFocusRequestedEventArgs : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("DesktopWindowXamlSourceTakeFocusRequestedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("request").ToLocalChecked(), RequestGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("DesktopWindowXamlSourceTakeFocusRequestedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      DesktopWindowXamlSourceTakeFocusRequestedEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      DesktopWindowXamlSourceTakeFocusRequestedEventArgs *wrapperInstance = new DesktopWindowXamlSourceTakeFocusRequestedEventArgs(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(winRtInstance));
    }





    static void RequestGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^>(info.This())) {
        return;
      }

      DesktopWindowXamlSourceTakeFocusRequestedEventArgs *wrapper = DesktopWindowXamlSourceTakeFocusRequestedEventArgs::Unwrap<DesktopWindowXamlSourceTakeFocusRequestedEventArgs>(info.This());

      try  {
        ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ result = wrapper->_instance->Request;
        info.GetReturnValue().Set(WrapXamlSourceFocusNavigationRequest(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ UnwrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> DesktopWindowXamlSourceTakeFocusRequestedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(DesktopWindowXamlSourceTakeFocusRequestedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs^ UnwrapDesktopWindowXamlSourceTakeFocusRequestedEventArgs(Local<Value> value) {
     return DesktopWindowXamlSourceTakeFocusRequestedEventArgs::Unwrap<DesktopWindowXamlSourceTakeFocusRequestedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDesktopWindowXamlSourceTakeFocusRequestedEventArgs(Local<Object> exports) {
    DesktopWindowXamlSourceTakeFocusRequestedEventArgs::Init(exports);
  }

  class ElementCompositionPreview : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("ElementCompositionPreview").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);






        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "setAppWindowContent", SetAppWindowContent);
        Nan::SetMethod(constructor, "getAppWindowContent", GetAppWindowContent);
        Nan::SetMethod(constructor, "setImplicitShowAnimation", SetImplicitShowAnimation);
        Nan::SetMethod(constructor, "setImplicitHideAnimation", SetImplicitHideAnimation);
        Nan::SetMethod(constructor, "setIsTranslationEnabled", SetIsTranslationEnabled);
        Nan::SetMethod(constructor, "getPointerPositionPropertySet", GetPointerPositionPropertySet);
        Nan::SetMethod(constructor, "getElementVisual", GetElementVisual);
        Nan::SetMethod(constructor, "getElementChildVisual", GetElementChildVisual);
        Nan::SetMethod(constructor, "setElementChildVisual", SetElementChildVisual);
        Nan::SetMethod(constructor, "getScrollViewerManipulationPropertySet", GetScrollViewerManipulationPropertySet);


        Nan::Set(exports, Nan::New<String>("ElementCompositionPreview").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      ElementCompositionPreview(::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::ElementCompositionPreview^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::ElementCompositionPreview^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      ElementCompositionPreview *wrapperInstance = new ElementCompositionPreview(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::ElementCompositionPreview^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::ElementCompositionPreview^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapElementCompositionPreview(winRtInstance));
    }





    static void SetAppWindowContent(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::WindowManagement::AppWindow^>(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[1]))
      {
        try
        {
          ::Windows::UI::WindowManagement::AppWindow^ arg0 = dynamic_cast<::Windows::UI::WindowManagement::AppWindow^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::UI::Xaml::UIElement^ arg1 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::SetAppWindowContent(arg0, arg1);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void GetAppWindowContent(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::WindowManagement::AppWindow^>(info[0]))
      {
        try
        {
          ::Windows::UI::WindowManagement::AppWindow^ arg0 = dynamic_cast<::Windows::UI::WindowManagement::AppWindow^>(NodeRT::Utils::GetObjectInstance(info[0]));
          
          ::Windows::UI::Xaml::UIElement^ result;
          result = ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetAppWindowContent(arg0);
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Xaml", "UIElement", result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void SetImplicitShowAnimation(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Composition::ICompositionAnimationBase^>(info[1]))
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::UI::Composition::ICompositionAnimationBase^ arg1 = dynamic_cast<::Windows::UI::Composition::ICompositionAnimationBase^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::SetImplicitShowAnimation(arg0, arg1);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void SetImplicitHideAnimation(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Composition::ICompositionAnimationBase^>(info[1]))
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::UI::Composition::ICompositionAnimationBase^ arg1 = dynamic_cast<::Windows::UI::Composition::ICompositionAnimationBase^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::SetImplicitHideAnimation(arg0, arg1);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void SetIsTranslationEnabled(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0])
        && info[1]->IsBoolean())
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          bool arg1 = Nan::To<bool>(info[1]).FromMaybe(false);
          
          ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(arg0, arg1);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void GetPointerPositionPropertySet(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0]))
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          
          ::Windows::UI::Composition::CompositionPropertySet^ result;
          result = ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetPointerPositionPropertySet(arg0);
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Composition", "CompositionPropertySet", result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void GetElementVisual(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0]))
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          
          ::Windows::UI::Composition::Visual^ result;
          result = ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(arg0);
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Composition", "Visual", result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void GetElementChildVisual(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0]))
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          
          ::Windows::UI::Composition::Visual^ result;
          result = ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetElementChildVisual(arg0);
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Composition", "Visual", result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void SetElementChildVisual(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Composition::Visual^>(info[1]))
      {
        try
        {
          ::Windows::UI::Xaml::UIElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::UI::Composition::Visual^ arg1 = dynamic_cast<::Windows::UI::Composition::Visual^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::SetElementChildVisual(arg0, arg1);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void GetScrollViewerManipulationPropertySet(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Controls::ScrollViewer^>(info[0]))
      {
        try
        {
          ::Windows::UI::Xaml::Controls::ScrollViewer^ arg0 = dynamic_cast<::Windows::UI::Xaml::Controls::ScrollViewer^>(NodeRT::Utils::GetObjectInstance(info[0]));
          
          ::Windows::UI::Composition::CompositionPropertySet^ result;
          result = ::Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetScrollViewerManipulationPropertySet(arg0);
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Composition", "CompositionPropertySet", result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    private:
      ::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapElementCompositionPreview(::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ UnwrapElementCompositionPreview(Local<Value> value);
  };

  Persistent<FunctionTemplate> ElementCompositionPreview::s_constructorTemplate;

  v8::Local<v8::Value> WrapElementCompositionPreview(::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(ElementCompositionPreview::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::ElementCompositionPreview^ UnwrapElementCompositionPreview(Local<Value> value) {
     return ElementCompositionPreview::Unwrap<ElementCompositionPreview>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitElementCompositionPreview(Local<Object> exports) {
    ElementCompositionPreview::Init(exports);
  }

  class IXamlUIPresenterHost : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("IXamlUIPresenterHost").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "resolveFileResource", ResolveFileResource);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("IXamlUIPresenterHost").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      IXamlUIPresenterHost(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      IXamlUIPresenterHost *wrapperInstance = new IXamlUIPresenterHost(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapIXamlUIPresenterHost(winRtInstance));
    }


    static void ResolveFileResource(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^>(info.This())) {
        return;
      }

      IXamlUIPresenterHost *wrapper = IXamlUIPresenterHost::Unwrap<IXamlUIPresenterHost>(info.This());

      if (info.Length() == 1
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          
          Platform::String^ result;
          result = wrapper->_instance->ResolveFileResource(arg0);
          info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }





    private:
      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapIXamlUIPresenterHost(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ UnwrapIXamlUIPresenterHost(Local<Value> value);
  };

  Persistent<FunctionTemplate> IXamlUIPresenterHost::s_constructorTemplate;

  v8::Local<v8::Value> WrapIXamlUIPresenterHost(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(IXamlUIPresenterHost::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ UnwrapIXamlUIPresenterHost(Local<Value> value) {
     return IXamlUIPresenterHost::Unwrap<IXamlUIPresenterHost>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitIXamlUIPresenterHost(Local<Object> exports) {
    IXamlUIPresenterHost::Init(exports);
  }

  class IXamlUIPresenterHost2 : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("IXamlUIPresenterHost2").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "getGenericXamlFilePath", GetGenericXamlFilePath);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("IXamlUIPresenterHost2").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      IXamlUIPresenterHost2(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      IXamlUIPresenterHost2 *wrapperInstance = new IXamlUIPresenterHost2(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapIXamlUIPresenterHost2(winRtInstance));
    }


    static void GetGenericXamlFilePath(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^>(info.This())) {
        return;
      }

      IXamlUIPresenterHost2 *wrapper = IXamlUIPresenterHost2::Unwrap<IXamlUIPresenterHost2>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          Platform::String^ result;
          result = wrapper->_instance->GetGenericXamlFilePath();
          info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }





    private:
      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapIXamlUIPresenterHost2(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ UnwrapIXamlUIPresenterHost2(Local<Value> value);
  };

  Persistent<FunctionTemplate> IXamlUIPresenterHost2::s_constructorTemplate;

  v8::Local<v8::Value> WrapIXamlUIPresenterHost2(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(IXamlUIPresenterHost2::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost2^ UnwrapIXamlUIPresenterHost2(Local<Value> value) {
     return IXamlUIPresenterHost2::Unwrap<IXamlUIPresenterHost2>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitIXamlUIPresenterHost2(Local<Object> exports) {
    IXamlUIPresenterHost2::Init(exports);
  }

  class IXamlUIPresenterHost3 : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("IXamlUIPresenterHost3").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "resolveDictionaryResource", ResolveDictionaryResource);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("IXamlUIPresenterHost3").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      IXamlUIPresenterHost3(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      IXamlUIPresenterHost3 *wrapperInstance = new IXamlUIPresenterHost3(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapIXamlUIPresenterHost3(winRtInstance));
    }


    static void ResolveDictionaryResource(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^>(info.This())) {
        return;
      }

      IXamlUIPresenterHost3 *wrapper = IXamlUIPresenterHost3::Unwrap<IXamlUIPresenterHost3>(info.This());

      if (info.Length() == 3
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::ResourceDictionary^>(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Platform::Object^>(info[1])
        && NodeRT::Utils::IsWinRtWrapperOf<::Platform::Object^>(info[2]))
      {
        try
        {
          ::Windows::UI::Xaml::ResourceDictionary^ arg0 = dynamic_cast<::Windows::UI::Xaml::ResourceDictionary^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Platform::Object^ arg1 = dynamic_cast<::Platform::Object^>(NodeRT::Utils::GetObjectInstance(info[1]));
          ::Platform::Object^ arg2 = dynamic_cast<::Platform::Object^>(NodeRT::Utils::GetObjectInstance(info[2]));
          
          ::Platform::Object^ result;
          result = wrapper->_instance->ResolveDictionaryResource(arg0, arg1, arg2);
          info.GetReturnValue().Set(CreateOpaqueWrapper(result));
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }





    private:
      ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapIXamlUIPresenterHost3(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ UnwrapIXamlUIPresenterHost3(Local<Value> value);
  };

  Persistent<FunctionTemplate> IXamlUIPresenterHost3::s_constructorTemplate;

  v8::Local<v8::Value> WrapIXamlUIPresenterHost3(::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(IXamlUIPresenterHost3::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost3^ UnwrapIXamlUIPresenterHost3(Local<Value> value) {
     return IXamlUIPresenterHost3::Unwrap<IXamlUIPresenterHost3>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitIXamlUIPresenterHost3(Local<Object> exports) {
    IXamlUIPresenterHost3::Init(exports);
  }

  class WindowsXamlManager : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("WindowsXamlManager").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "close", Close);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "initializeForCurrentThread", InitializeForCurrentThread);


        Nan::Set(exports, Nan::New<String>("WindowsXamlManager").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      WindowsXamlManager(::Windows::UI::Xaml::Hosting::WindowsXamlManager^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::WindowsXamlManager^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::WindowsXamlManager^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      WindowsXamlManager *wrapperInstance = new WindowsXamlManager(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::WindowsXamlManager^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::WindowsXamlManager^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapWindowsXamlManager(winRtInstance));
    }



    static void Close(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::WindowsXamlManager^>(info.This())) {
        return;
      }

      WindowsXamlManager *wrapper = WindowsXamlManager::Unwrap<WindowsXamlManager>(info.This());

      if (info.Length() == 0) {
        try {
          delete wrapper->_instance;
          wrapper->_instance = nullptr;
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      } else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    static void InitializeForCurrentThread(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ result;
          result = ::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
          info.GetReturnValue().Set(WrapWindowsXamlManager(result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    private:
      ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapWindowsXamlManager(::Windows::UI::Xaml::Hosting::WindowsXamlManager^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ UnwrapWindowsXamlManager(Local<Value> value);
  };

  Persistent<FunctionTemplate> WindowsXamlManager::s_constructorTemplate;

  v8::Local<v8::Value> WrapWindowsXamlManager(::Windows::UI::Xaml::Hosting::WindowsXamlManager^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(WindowsXamlManager::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::WindowsXamlManager^ UnwrapWindowsXamlManager(Local<Value> value) {
     return WindowsXamlManager::Unwrap<WindowsXamlManager>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitWindowsXamlManager(Local<Object> exports) {
    WindowsXamlManager::Init(exports);
  }

  class XamlSourceFocusNavigationRequest : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("XamlSourceFocusNavigationRequest").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("correlationId").ToLocalChecked(), CorrelationIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("hintRect").ToLocalChecked(), HintRectGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("reason").ToLocalChecked(), ReasonGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("XamlSourceFocusNavigationRequest").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      XamlSourceFocusNavigationRequest(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try {
          ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason arg0 = static_cast<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          winRtInstance = ref new ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest(arg0);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 2
        && info[0]->IsInt32()
        && NodeRT::Utils::IsRect(info[1]))
      {
        try {
          ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason arg0 = static_cast<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          ::Windows::Foundation::Rect arg1 = NodeRT::Utils::RectFromJs(info[1]);
          
          winRtInstance = ref new ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest(arg0,arg1);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 3
        && info[0]->IsInt32()
        && NodeRT::Utils::IsRect(info[1])
        && NodeRT::Utils::IsGuid(info[2]))
      {
        try {
          ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason arg0 = static_cast<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          ::Windows::Foundation::Rect arg1 = NodeRT::Utils::RectFromJs(info[1]);
          ::Platform::Guid arg2 = NodeRT::Utils::GuidFromJs(info[2]);
          
          winRtInstance = ref new ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest(arg0,arg1,arg2);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      XamlSourceFocusNavigationRequest *wrapperInstance = new XamlSourceFocusNavigationRequest(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapXamlSourceFocusNavigationRequest(winRtInstance));
    }





    static void CorrelationIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^>(info.This())) {
        return;
      }

      XamlSourceFocusNavigationRequest *wrapper = XamlSourceFocusNavigationRequest::Unwrap<XamlSourceFocusNavigationRequest>(info.This());

      try  {
        ::Platform::Guid result = wrapper->_instance->CorrelationId;
        info.GetReturnValue().Set(NodeRT::Utils::GuidToJs(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void HintRectGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^>(info.This())) {
        return;
      }

      XamlSourceFocusNavigationRequest *wrapper = XamlSourceFocusNavigationRequest::Unwrap<XamlSourceFocusNavigationRequest>(info.This());

      try  {
        ::Windows::Foundation::Rect result = wrapper->_instance->HintRect;
        info.GetReturnValue().Set(NodeRT::Utils::RectToJs(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ReasonGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^>(info.This())) {
        return;
      }

      XamlSourceFocusNavigationRequest *wrapper = XamlSourceFocusNavigationRequest::Unwrap<XamlSourceFocusNavigationRequest>(info.This());

      try  {
        ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason result = wrapper->_instance->Reason;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapXamlSourceFocusNavigationRequest(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ UnwrapXamlSourceFocusNavigationRequest(Local<Value> value);
  };

  Persistent<FunctionTemplate> XamlSourceFocusNavigationRequest::s_constructorTemplate;

  v8::Local<v8::Value> WrapXamlSourceFocusNavigationRequest(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(XamlSourceFocusNavigationRequest::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationRequest^ UnwrapXamlSourceFocusNavigationRequest(Local<Value> value) {
     return XamlSourceFocusNavigationRequest::Unwrap<XamlSourceFocusNavigationRequest>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitXamlSourceFocusNavigationRequest(Local<Object> exports) {
    XamlSourceFocusNavigationRequest::Init(exports);
  }

  class XamlSourceFocusNavigationResult : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("XamlSourceFocusNavigationResult").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("wasFocusMoved").ToLocalChecked(), WasFocusMovedGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("XamlSourceFocusNavigationResult").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      XamlSourceFocusNavigationResult(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 1
        && info[0]->IsBoolean())
      {
        try {
          bool arg0 = Nan::To<bool>(info[0]).FromMaybe(false);
          
          winRtInstance = ref new ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult(arg0);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      XamlSourceFocusNavigationResult *wrapperInstance = new XamlSourceFocusNavigationResult(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapXamlSourceFocusNavigationResult(winRtInstance));
    }





    static void WasFocusMovedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^>(info.This())) {
        return;
      }

      XamlSourceFocusNavigationResult *wrapper = XamlSourceFocusNavigationResult::Unwrap<XamlSourceFocusNavigationResult>(info.This());

      try  {
        bool result = wrapper->_instance->WasFocusMoved;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapXamlSourceFocusNavigationResult(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ UnwrapXamlSourceFocusNavigationResult(Local<Value> value);
  };

  Persistent<FunctionTemplate> XamlSourceFocusNavigationResult::s_constructorTemplate;

  v8::Local<v8::Value> WrapXamlSourceFocusNavigationResult(::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(XamlSourceFocusNavigationResult::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationResult^ UnwrapXamlSourceFocusNavigationResult(Local<Value> value) {
     return XamlSourceFocusNavigationResult::Unwrap<XamlSourceFocusNavigationResult>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitXamlSourceFocusNavigationResult(Local<Object> exports) {
    XamlSourceFocusNavigationResult::Init(exports);
  }

  class XamlUIPresenter : public WrapperBase {
    public:
      
      static void Init(const Local<Object> exports) {
        HandleScope scope;

        Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
        s_constructorTemplate.Reset(localRef);
        localRef->SetClassName(Nan::New<String>("XamlUIPresenter").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "setSize", SetSize);
            Nan::SetPrototypeMethod(localRef, "render", Render);
            Nan::SetPrototypeMethod(localRef, "present", Present);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("themeResourcesXaml").ToLocalChecked(), ThemeResourcesXamlGetter, ThemeResourcesXamlSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("themeKey").ToLocalChecked(), ThemeKeyGetter, ThemeKeySetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("rootElement").ToLocalChecked(), RootElementGetter, RootElementSetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "getFlyoutPlacementTargetInfo", GetFlyoutPlacementTargetInfo);
        Nan::SetMethod(constructor, "getFlyoutPlacement", GetFlyoutPlacement);
        Nan::SetMethod(constructor, "setHost", SetHost);
        Nan::SetMethod(constructor, "notifyWindowSizeChanged", NotifyWindowSizeChanged);
        Nan::SetAccessor(constructor, Nan::New<String>("completeTimelinesAutomatically").ToLocalChecked(), CompleteTimelinesAutomaticallyGetter, CompleteTimelinesAutomaticallySetter);


        Nan::Set(exports, Nan::New<String>("XamlUIPresenter").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      XamlUIPresenter(::Windows::UI::Xaml::Hosting::XamlUIPresenter^ instance) {
        _instance = instance;
      }

      
    static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This())) {
        if (info.Length() > 0) {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++) {
            argsPtr[i] = info[i];
          }

          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        } else {
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);

          if (res.IsEmpty()) {
            return;
          }

          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }

      ::Windows::UI::Xaml::Hosting::XamlUIPresenter^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::Xaml::Hosting::XamlUIPresenter^) NodeRT::Utils::GetObjectInstance(info[0]);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
        return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      XamlUIPresenter *wrapperInstance = new XamlUIPresenter(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


      
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;
      if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info[0])) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
        return;
      }

      ::Windows::UI::Xaml::Hosting::XamlUIPresenter^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::Xaml::Hosting::XamlUIPresenter^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapXamlUIPresenter(winRtInstance));
    }


    static void SetSize(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      if (info.Length() == 2
        && info[0]->IsInt32()
        && info[1]->IsInt32())
      {
        try
        {
          int arg0 = static_cast<int>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          int arg1 = static_cast<int>(Nan::To<int32_t>(info[1]).FromMaybe(0));
          
          wrapper->_instance->SetSize(arg0, arg1);
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Render(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Render();
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Present(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Present();
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    static void GetFlyoutPlacementTargetInfo(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::FrameworkElement^>(info[0])
        && info[1]->IsInt32())
      {
        try
        {
          ::Windows::UI::Xaml::FrameworkElement^ arg0 = dynamic_cast<::Windows::UI::Xaml::FrameworkElement^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::UI::Xaml::Controls::Primitives::FlyoutPlacementMode arg1 = static_cast<::Windows::UI::Xaml::Controls::Primitives::FlyoutPlacementMode>(Nan::To<int32_t>(info[1]).FromMaybe(0));
          ::Windows::UI::Xaml::Controls::Primitives::FlyoutPlacementMode arg2;  
          bool arg3;  
          
          ::Windows::Foundation::Rect result;
          result = ::Windows::UI::Xaml::Hosting::XamlUIPresenter::GetFlyoutPlacementTargetInfo(arg0, arg1, &arg2, &arg3);
          Local<Object> resObj = Nan::New<Object>();
          Nan::Set(resObj, Nan::New<String>("rect").ToLocalChecked(), NodeRT::Utils::RectToJs(result));
          Nan::Set(resObj, Nan::New<String>("targetPreferredPlacement").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(arg2)));
          Nan::Set(resObj, Nan::New<String>("allowFallbacks").ToLocalChecked(), Nan::New<Boolean>(arg3));
          info.GetReturnValue().Set(resObj);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void GetFlyoutPlacement(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 6
        && NodeRT::Utils::IsRect(info[0])
        && NodeRT::Utils::IsSize(info[1])
        && NodeRT::Utils::IsSize(info[2])
        && NodeRT::Utils::IsRect(info[3])
        && info[4]->IsInt32()
        && info[5]->IsBoolean())
      {
        try
        {
          ::Windows::Foundation::Rect arg0 = NodeRT::Utils::RectFromJs(info[0]);
          ::Windows::Foundation::Size arg1 = NodeRT::Utils::SizeFromJs(info[1]);
          ::Windows::Foundation::Size arg2 = NodeRT::Utils::SizeFromJs(info[2]);
          ::Windows::Foundation::Rect arg3 = NodeRT::Utils::RectFromJs(info[3]);
          ::Windows::UI::Xaml::Controls::Primitives::FlyoutPlacementMode arg4 = static_cast<::Windows::UI::Xaml::Controls::Primitives::FlyoutPlacementMode>(Nan::To<int32_t>(info[4]).FromMaybe(0));
          bool arg5 = Nan::To<bool>(info[5]).FromMaybe(false);
          ::Windows::UI::Xaml::Controls::Primitives::FlyoutPlacementMode arg6;  
          
          ::Windows::Foundation::Rect result;
          result = ::Windows::UI::Xaml::Hosting::XamlUIPresenter::GetFlyoutPlacement(arg0, arg1, arg2, arg3, arg4, arg5, &arg6);
          Local<Object> resObj = Nan::New<Object>();
          Nan::Set(resObj, Nan::New<String>("rect").ToLocalChecked(), NodeRT::Utils::RectToJs(result));
          Nan::Set(resObj, Nan::New<String>("chosenPlacement").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(arg6)));
          info.GetReturnValue().Set(resObj);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void SetHost(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^>(info[0]))
      {
        try
        {
          ::Windows::UI::Xaml::Hosting::IXamlUIPresenterHost^ arg0 = UnwrapIXamlUIPresenterHost(info[0]);
          
          ::Windows::UI::Xaml::Hosting::XamlUIPresenter::SetHost(arg0);
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void NotifyWindowSizeChanged(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::UI::Xaml::Hosting::XamlUIPresenter::NotifyWindowSizeChanged();
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void ThemeResourcesXamlGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->ThemeResourcesXaml;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ThemeResourcesXamlSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsString()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      try {

        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));

        wrapper->_instance->ThemeResourcesXaml = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void ThemeKeyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->ThemeKey;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ThemeKeySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsString()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      try {

        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));

        wrapper->_instance->ThemeKey = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void RootElementGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      try  {
        ::Windows::UI::Xaml::UIElement^ result = wrapper->_instance->RootElement;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.UI.Xaml", "UIElement", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void RootElementSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::UIElement^>(value)) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::Xaml::Hosting::XamlUIPresenter^>(info.This())) {
        return;
      }

      XamlUIPresenter *wrapper = XamlUIPresenter::Unwrap<XamlUIPresenter>(info.This());

      try {

        ::Windows::UI::Xaml::UIElement^ winRtValue = dynamic_cast<::Windows::UI::Xaml::UIElement^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->RootElement = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      


    static void CompleteTimelinesAutomaticallyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      try
      {
        bool result = ::Windows::UI::Xaml::Hosting::XamlUIPresenter::CompleteTimelinesAutomatically;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      

    static void CompleteTimelinesAutomaticallySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsBoolean()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      try {


        bool winRtValue = Nan::To<bool>(value).FromMaybe(false);

        ::Windows::UI::Xaml::Hosting::XamlUIPresenter::CompleteTimelinesAutomatically = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      

    private:
      ::Windows::UI::Xaml::Hosting::XamlUIPresenter^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapXamlUIPresenter(::Windows::UI::Xaml::Hosting::XamlUIPresenter^ wintRtInstance);
      friend ::Windows::UI::Xaml::Hosting::XamlUIPresenter^ UnwrapXamlUIPresenter(Local<Value> value);
  };

  Persistent<FunctionTemplate> XamlUIPresenter::s_constructorTemplate;

  v8::Local<v8::Value> WrapXamlUIPresenter(::Windows::UI::Xaml::Hosting::XamlUIPresenter^ winRtInstance) {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr) {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(XamlUIPresenter::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::Xaml::Hosting::XamlUIPresenter^ UnwrapXamlUIPresenter(Local<Value> value) {
     return XamlUIPresenter::Unwrap<XamlUIPresenter>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitXamlUIPresenter(Local<Object> exports) {
    XamlUIPresenter::Init(exports);
  }


} } } } } 

NAN_MODULE_INIT(init) {
  // We ignore failures for now since it probably means that
  // the initialization already happened for STA, and that's cool

  CoInitializeEx(nullptr, COINIT_MULTITHREADED);

  /*
  if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) {
    Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"error in CoInitializeEx()")));
    return;
  }
  */

      NodeRT::Windows::UI::Xaml::Hosting::InitDesignerAppViewStateEnum(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitXamlSourceFocusNavigationReasonEnum(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitDesignerAppExitedEventArgs(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitDesignerAppManager(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitDesignerAppView(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitDesktopWindowXamlSource(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitDesktopWindowXamlSourceGotFocusEventArgs(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitDesktopWindowXamlSourceTakeFocusRequestedEventArgs(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitElementCompositionPreview(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitIXamlUIPresenterHost(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitIXamlUIPresenterHost2(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitIXamlUIPresenterHost3(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitWindowsXamlManager(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitXamlSourceFocusNavigationRequest(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitXamlSourceFocusNavigationResult(target);
      NodeRT::Windows::UI::Xaml::Hosting::InitXamlUIPresenter(target);


  NodeRT::Utils::RegisterNameSpace("Windows.UI.Xaml.Hosting", target);
}



NODE_MODULE(binding, init)
