// 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 UIAutomation { namespace Core { 
  v8::Local<v8::Value> WrapAutomationRemoteOperationResult(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ UnwrapAutomationRemoteOperationResult(Local<Value> value);
  
  v8::Local<v8::Value> WrapCoreAutomationRegistrar(::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ UnwrapCoreAutomationRegistrar(Local<Value> value);
  
  v8::Local<v8::Value> WrapCoreAutomationRemoteOperation(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ UnwrapCoreAutomationRemoteOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapCoreAutomationRemoteOperationContext(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ UnwrapCoreAutomationRemoteOperationContext(Local<Value> value);
  
  v8::Local<v8::Value> WrapICoreAutomationConnectionBoundObjectProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ UnwrapICoreAutomationConnectionBoundObjectProvider(Local<Value> value);
  
  v8::Local<v8::Value> WrapICoreAutomationRemoteOperationExtensionProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ UnwrapICoreAutomationRemoteOperationExtensionProvider(Local<Value> value);
  
  v8::Local<v8::Value> WrapRemoteAutomationClientSession(::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ UnwrapRemoteAutomationClientSession(Local<Value> value);
  
  v8::Local<v8::Value> WrapRemoteAutomationConnectionRequestedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ UnwrapRemoteAutomationConnectionRequestedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapRemoteAutomationDisconnectedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ UnwrapRemoteAutomationDisconnectedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapRemoteAutomationServer(::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ UnwrapRemoteAutomationServer(Local<Value> value);
  
  v8::Local<v8::Value> WrapRemoteAutomationWindow(::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ wintRtInstance);
  ::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ UnwrapRemoteAutomationWindow(Local<Value> value);
  



  static void InitAutomationRemoteOperationStatusEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("AutomationRemoteOperationStatus").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("success").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationStatus::Success)));
    Nan::Set(enumObject, Nan::New<String>("malformedBytecode").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationStatus::MalformedBytecode)));
    Nan::Set(enumObject, Nan::New<String>("instructionLimitExceeded").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationStatus::InstructionLimitExceeded)));
    Nan::Set(enumObject, Nan::New<String>("unhandledException").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationStatus::UnhandledException)));
    Nan::Set(enumObject, Nan::New<String>("executionFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationStatus::ExecutionFailure)));
  }

  static bool IsAutomationAnnotationTypeRegistrationJsObject(Local<Value> value) {
    if (!value->IsObject()) {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    symbol = Nan::New<String>("localId").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false)) {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsInt32()) {
        return false;
      }
    }
    
    return true;
  }

  ::Windows::UI::UIAutomation::Core::AutomationAnnotationTypeRegistration AutomationAnnotationTypeRegistrationFromJsObject(Local<Value> value) {
    HandleScope scope;
    ::Windows::UI::UIAutomation::Core::AutomationAnnotationTypeRegistration 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;

    symbol = Nan::New<String>("localId").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false)) {
      returnValue.LocalId = static_cast<int>(Nan::To<int32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    return returnValue;
  }

  Local<Value> AutomationAnnotationTypeRegistrationToJsObject(::Windows::UI::UIAutomation::Core::AutomationAnnotationTypeRegistration value) {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();

    Nan::Set(obj, Nan::New<String>("localId").ToLocalChecked(), Nan::New<Integer>(value.LocalId));

    return scope.Escape(obj);
  }
  static bool IsAutomationRemoteOperationOperandIdJsObject(Local<Value> value) {
    if (!value->IsObject()) {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    symbol = Nan::New<String>("value").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false)) {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsInt32()) {
        return false;
      }
    }
    
    return true;
  }

  ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId AutomationRemoteOperationOperandIdFromJsObject(Local<Value> value) {
    HandleScope scope;
    ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId 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;

    symbol = Nan::New<String>("value").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false)) {
      returnValue.Value = static_cast<int>(Nan::To<int32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    return returnValue;
  }

  Local<Value> AutomationRemoteOperationOperandIdToJsObject(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId value) {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();

    Nan::Set(obj, Nan::New<String>("value").ToLocalChecked(), Nan::New<Integer>(value.Value));

    return scope.Escape(obj);
  }


  class AutomationRemoteOperationResult : 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>("AutomationRemoteOperationResult").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "hasOperand", HasOperand);
            Nan::SetPrototypeMethod(localRef, "getOperand", GetOperand);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorLocation").ToLocalChecked(), ErrorLocationGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("extendedError").ToLocalChecked(), ExtendedErrorGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AutomationRemoteOperationResult").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AutomationRemoteOperationResult(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ 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::UIAutomation::Core::AutomationRemoteOperationResult^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^) 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());

      AutomationRemoteOperationResult *wrapperInstance = new AutomationRemoteOperationResult(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::UIAutomation::Core::AutomationRemoteOperationResult^>(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::UIAutomation::Core::AutomationRemoteOperationResult^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAutomationRemoteOperationResult(winRtInstance));
    }


    static void HasOperand(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^>(info.This())) {
        return;
      }

      AutomationRemoteOperationResult *wrapper = AutomationRemoteOperationResult::Unwrap<AutomationRemoteOperationResult>(info.This());

      if (info.Length() == 1
        && IsAutomationRemoteOperationOperandIdJsObject(info[0]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          
          bool result;
          result = wrapper->_instance->HasOperand(arg0);
          info.GetReturnValue().Set(Nan::New<Boolean>(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 GetOperand(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^>(info.This())) {
        return;
      }

      AutomationRemoteOperationResult *wrapper = AutomationRemoteOperationResult::Unwrap<AutomationRemoteOperationResult>(info.This());

      if (info.Length() == 1
        && IsAutomationRemoteOperationOperandIdJsObject(info[0]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          
          ::Platform::Object^ result;
          result = wrapper->_instance->GetOperand(arg0);
          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;
      }
    }



    static void ErrorLocationGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^>(info.This())) {
        return;
      }

      AutomationRemoteOperationResult *wrapper = AutomationRemoteOperationResult::Unwrap<AutomationRemoteOperationResult>(info.This());

      try  {
        int result = wrapper->_instance->ErrorLocation;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ExtendedErrorGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^>(info.This())) {
        return;
      }

      AutomationRemoteOperationResult *wrapper = AutomationRemoteOperationResult::Unwrap<AutomationRemoteOperationResult>(info.This());

      try  {
        ::Windows::Foundation::HResult result = wrapper->_instance->ExtendedError;
        info.GetReturnValue().Set(Nan::New<Integer>(result.Value));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^>(info.This())) {
        return;
      }

      AutomationRemoteOperationResult *wrapper = AutomationRemoteOperationResult::Unwrap<AutomationRemoteOperationResult>(info.This());

      try  {
        ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAutomationRemoteOperationResult(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ UnwrapAutomationRemoteOperationResult(Local<Value> value);
  };

  Persistent<FunctionTemplate> AutomationRemoteOperationResult::s_constructorTemplate;

  v8::Local<v8::Value> WrapAutomationRemoteOperationResult(::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ 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>(AutomationRemoteOperationResult::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ UnwrapAutomationRemoteOperationResult(Local<Value> value) {
     return AutomationRemoteOperationResult::Unwrap<AutomationRemoteOperationResult>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAutomationRemoteOperationResult(Local<Object> exports) {
    AutomationRemoteOperationResult::Init(exports);
  }

  class CoreAutomationRegistrar : 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>("CoreAutomationRegistrar").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);






        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "registerAnnotationType", RegisterAnnotationType);
        Nan::SetMethod(constructor, "unregisterAnnotationType", UnregisterAnnotationType);


        Nan::Set(exports, Nan::New<String>("CoreAutomationRegistrar").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      CoreAutomationRegistrar(::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ 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::UIAutomation::Core::CoreAutomationRegistrar^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^) 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());

      CoreAutomationRegistrar *wrapperInstance = new CoreAutomationRegistrar(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::UIAutomation::Core::CoreAutomationRegistrar^>(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::UIAutomation::Core::CoreAutomationRegistrar^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapCoreAutomationRegistrar(winRtInstance));
    }





    static void RegisterAnnotationType(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsGuid(info[0]))
      {
        try
        {
          ::Platform::Guid arg0 = NodeRT::Utils::GuidFromJs(info[0]);
          
          ::Windows::UI::UIAutomation::Core::AutomationAnnotationTypeRegistration result;
          result = ::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar::RegisterAnnotationType(arg0);
          info.GetReturnValue().Set(AutomationAnnotationTypeRegistrationToJsObject(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 UnregisterAnnotationType(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && IsAutomationAnnotationTypeRegistrationJsObject(info[0]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationAnnotationTypeRegistration arg0 = AutomationAnnotationTypeRegistrationFromJsObject(info[0]);
          
          ::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar::UnregisterAnnotationType(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;
      }
    }



    private:
      ::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapCoreAutomationRegistrar(::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ UnwrapCoreAutomationRegistrar(Local<Value> value);
  };

  Persistent<FunctionTemplate> CoreAutomationRegistrar::s_constructorTemplate;

  v8::Local<v8::Value> WrapCoreAutomationRegistrar(::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ 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>(CoreAutomationRegistrar::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::CoreAutomationRegistrar^ UnwrapCoreAutomationRegistrar(Local<Value> value) {
     return CoreAutomationRegistrar::Unwrap<CoreAutomationRegistrar>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitCoreAutomationRegistrar(Local<Object> exports) {
    CoreAutomationRegistrar::Init(exports);
  }

  class CoreAutomationRemoteOperation : 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>("CoreAutomationRemoteOperation").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "isOpcodeSupported", IsOpcodeSupported);
            Nan::SetPrototypeMethod(localRef, "importElement", ImportElement);
            Nan::SetPrototypeMethod(localRef, "importTextRange", ImportTextRange);
            Nan::SetPrototypeMethod(localRef, "addToResults", AddToResults);
            Nan::SetPrototypeMethod(localRef, "execute", Execute);
            Nan::SetPrototypeMethod(localRef, "importConnectionBoundObject", ImportConnectionBoundObject);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("CoreAutomationRemoteOperation").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      CoreAutomationRemoteOperation(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ 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::UIAutomation::Core::CoreAutomationRemoteOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^) 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::UIAutomation::Core::CoreAutomationRemoteOperation();
        } 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());

      CoreAutomationRemoteOperation *wrapperInstance = new CoreAutomationRemoteOperation(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::UIAutomation::Core::CoreAutomationRemoteOperation^>(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::UIAutomation::Core::CoreAutomationRemoteOperation^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapCoreAutomationRemoteOperation(winRtInstance));
    }


    static void IsOpcodeSupported(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperation *wrapper = CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(info.This());

      if (info.Length() == 1
        && info[0]->IsUint32())
      {
        try
        {
          unsigned int arg0 = static_cast<unsigned int>(Nan::To<uint32_t>(info[0]).FromMaybe(0));
          
          bool result;
          result = wrapper->_instance->IsOpcodeSupported(arg0);
          info.GetReturnValue().Set(Nan::New<Boolean>(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 ImportElement(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperation *wrapper = CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(info.This());

      if (info.Length() == 2
        && IsAutomationRemoteOperationOperandIdJsObject(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::AutomationElement^>(info[1]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          ::Windows::UI::UIAutomation::AutomationElement^ arg1 = dynamic_cast<::Windows::UI::UIAutomation::AutomationElement^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          wrapper->_instance->ImportElement(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 ImportTextRange(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperation *wrapper = CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(info.This());

      if (info.Length() == 2
        && IsAutomationRemoteOperationOperandIdJsObject(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::AutomationTextRange^>(info[1]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          ::Windows::UI::UIAutomation::AutomationTextRange^ arg1 = dynamic_cast<::Windows::UI::UIAutomation::AutomationTextRange^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          wrapper->_instance->ImportTextRange(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 AddToResults(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperation *wrapper = CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(info.This());

      if (info.Length() == 1
        && IsAutomationRemoteOperationOperandIdJsObject(info[0]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          
          wrapper->_instance->AddToResults(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 Execute(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperation *wrapper = CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(info.This());

      if (info.Length() == 1
        && (NodeRT::Utils::IsWinRtWrapperOf<::Platform::Array<unsigned char>^>(info[0]) || info[0]->IsArray()))
      {
        try
        {
          ::Platform::Array<unsigned char>^ arg0 = 
            [] (v8::Local<v8::Value> value) -> ::Platform::Array<unsigned char>^
            {
              if (value->IsArray())
              {
                return NodeRT::Collections::JsArrayToWinrtArray<unsigned char>(value.As<Array>(), 
                 [](Local<Value> value) -> bool {
                   return value->IsInt32();
                 },
                 [](Local<Value> value) -> unsigned char {
                   return static_cast<unsigned char>(Nan::To<int32_t>(value).FromMaybe(0));
                 }
                );
              }
              else
              {
                return dynamic_cast<::Platform::Array<unsigned char>^>(NodeRT::Utils::GetObjectInstance(value));
              }
            } (info[0]);
          
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationResult^ result;
          result = wrapper->_instance->Execute(arg0);
          info.GetReturnValue().Set(WrapAutomationRemoteOperationResult(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 ImportConnectionBoundObject(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperation *wrapper = CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(info.This());

      if (info.Length() == 2
        && IsAutomationRemoteOperationOperandIdJsObject(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::AutomationConnectionBoundObject^>(info[1]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          ::Windows::UI::UIAutomation::AutomationConnectionBoundObject^ arg1 = dynamic_cast<::Windows::UI::UIAutomation::AutomationConnectionBoundObject^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          wrapper->_instance->ImportConnectionBoundObject(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;
      }
    }





    private:
      ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapCoreAutomationRemoteOperation(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ UnwrapCoreAutomationRemoteOperation(Local<Value> value);
  };

  Persistent<FunctionTemplate> CoreAutomationRemoteOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapCoreAutomationRemoteOperation(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ 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>(CoreAutomationRemoteOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperation^ UnwrapCoreAutomationRemoteOperation(Local<Value> value) {
     return CoreAutomationRemoteOperation::Unwrap<CoreAutomationRemoteOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitCoreAutomationRemoteOperation(Local<Object> exports) {
    CoreAutomationRemoteOperation::Init(exports);
  }

  class CoreAutomationRemoteOperationContext : 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>("CoreAutomationRemoteOperationContext").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "getOperand", GetOperand);
            Nan::SetPrototypeMethod(localRef, "setOperand", SetOperand);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("CoreAutomationRemoteOperationContext").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      CoreAutomationRemoteOperationContext(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ 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::UIAutomation::Core::CoreAutomationRemoteOperationContext^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^) 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());

      CoreAutomationRemoteOperationContext *wrapperInstance = new CoreAutomationRemoteOperationContext(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::UIAutomation::Core::CoreAutomationRemoteOperationContext^>(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::UIAutomation::Core::CoreAutomationRemoteOperationContext^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapCoreAutomationRemoteOperationContext(winRtInstance));
    }


    static void GetOperand(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperationContext *wrapper = CoreAutomationRemoteOperationContext::Unwrap<CoreAutomationRemoteOperationContext>(info.This());

      if (info.Length() == 1
        && IsAutomationRemoteOperationOperandIdJsObject(info[0]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          
          ::Platform::Object^ result;
          result = wrapper->_instance->GetOperand(arg0);
          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;
      }
    }
    static void SetOperand(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^>(info.This())) {
        return;
      }

      CoreAutomationRemoteOperationContext *wrapper = CoreAutomationRemoteOperationContext::Unwrap<CoreAutomationRemoteOperationContext>(info.This());

      if (info.Length() == 2
        && IsAutomationRemoteOperationOperandIdJsObject(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Platform::Object^>(info[1]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          ::Platform::Object^ arg1 = dynamic_cast<::Platform::Object^>(NodeRT::Utils::GetObjectInstance(info[1]));
          
          wrapper->_instance->SetOperand(arg0, arg1);
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 3
        && IsAutomationRemoteOperationOperandIdJsObject(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Platform::Object^>(info[1])
        && NodeRT::Utils::IsGuid(info[2]))
      {
        try
        {
          ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId arg0 = AutomationRemoteOperationOperandIdFromJsObject(info[0]);
          ::Platform::Object^ arg1 = dynamic_cast<::Platform::Object^>(NodeRT::Utils::GetObjectInstance(info[1]));
          ::Platform::Guid arg2 = NodeRT::Utils::GuidFromJs(info[2]);
          
          wrapper->_instance->SetOperand(arg0, arg1, arg2);
          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::UIAutomation::Core::CoreAutomationRemoteOperationContext^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapCoreAutomationRemoteOperationContext(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ UnwrapCoreAutomationRemoteOperationContext(Local<Value> value);
  };

  Persistent<FunctionTemplate> CoreAutomationRemoteOperationContext::s_constructorTemplate;

  v8::Local<v8::Value> WrapCoreAutomationRemoteOperationContext(::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ 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>(CoreAutomationRemoteOperationContext::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ UnwrapCoreAutomationRemoteOperationContext(Local<Value> value) {
     return CoreAutomationRemoteOperationContext::Unwrap<CoreAutomationRemoteOperationContext>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitCoreAutomationRemoteOperationContext(Local<Object> exports) {
    CoreAutomationRemoteOperationContext::Init(exports);
  }

  class ICoreAutomationConnectionBoundObjectProvider : 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>("ICoreAutomationConnectionBoundObjectProvider").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isComThreadingRequired").ToLocalChecked(), IsComThreadingRequiredGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("ICoreAutomationConnectionBoundObjectProvider").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      ICoreAutomationConnectionBoundObjectProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ 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::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^) 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());

      ICoreAutomationConnectionBoundObjectProvider *wrapperInstance = new ICoreAutomationConnectionBoundObjectProvider(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::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^>(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::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapICoreAutomationConnectionBoundObjectProvider(winRtInstance));
    }





    static void IsComThreadingRequiredGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^>(info.This())) {
        return;
      }

      ICoreAutomationConnectionBoundObjectProvider *wrapper = ICoreAutomationConnectionBoundObjectProvider::Unwrap<ICoreAutomationConnectionBoundObjectProvider>(info.This());

      try  {
        bool result = wrapper->_instance->IsComThreadingRequired;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapICoreAutomationConnectionBoundObjectProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ UnwrapICoreAutomationConnectionBoundObjectProvider(Local<Value> value);
  };

  Persistent<FunctionTemplate> ICoreAutomationConnectionBoundObjectProvider::s_constructorTemplate;

  v8::Local<v8::Value> WrapICoreAutomationConnectionBoundObjectProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ 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>(ICoreAutomationConnectionBoundObjectProvider::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::ICoreAutomationConnectionBoundObjectProvider^ UnwrapICoreAutomationConnectionBoundObjectProvider(Local<Value> value) {
     return ICoreAutomationConnectionBoundObjectProvider::Unwrap<ICoreAutomationConnectionBoundObjectProvider>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitICoreAutomationConnectionBoundObjectProvider(Local<Object> exports) {
    ICoreAutomationConnectionBoundObjectProvider::Init(exports);
  }

  class ICoreAutomationRemoteOperationExtensionProvider : 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>("ICoreAutomationRemoteOperationExtensionProvider").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "callExtension", CallExtension);
            Nan::SetPrototypeMethod(localRef, "isExtensionSupported", IsExtensionSupported);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("ICoreAutomationRemoteOperationExtensionProvider").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      ICoreAutomationRemoteOperationExtensionProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ 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::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^) 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());

      ICoreAutomationRemoteOperationExtensionProvider *wrapperInstance = new ICoreAutomationRemoteOperationExtensionProvider(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::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^>(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::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapICoreAutomationRemoteOperationExtensionProvider(winRtInstance));
    }


    static void CallExtension(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^>(info.This())) {
        return;
      }

      ICoreAutomationRemoteOperationExtensionProvider *wrapper = ICoreAutomationRemoteOperationExtensionProvider::Unwrap<ICoreAutomationRemoteOperationExtensionProvider>(info.This());

      if (info.Length() == 3
        && NodeRT::Utils::IsGuid(info[0])
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^>(info[1])
        && (NodeRT::Utils::IsWinRtWrapperOf<::Platform::Array<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId>^>(info[2]) || info[2]->IsArray()))
      {
        try
        {
          ::Platform::Guid arg0 = NodeRT::Utils::GuidFromJs(info[0]);
          ::Windows::UI::UIAutomation::Core::CoreAutomationRemoteOperationContext^ arg1 = UnwrapCoreAutomationRemoteOperationContext(info[1]);
          ::Platform::Array<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId>^ arg2 = 
            [] (v8::Local<v8::Value> value) -> ::Platform::Array<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId>^
            {
              if (value->IsArray())
              {
                return NodeRT::Collections::JsArrayToWinrtArray<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId>(value.As<Array>(), 
                 [](Local<Value> value) -> bool {
                   return IsAutomationRemoteOperationOperandIdJsObject(value);
                 },
                 [](Local<Value> value) -> ::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId {
                   return AutomationRemoteOperationOperandIdFromJsObject(value);
                 }
                );
              }
              else
              {
                return dynamic_cast<::Platform::Array<::Windows::UI::UIAutomation::Core::AutomationRemoteOperationOperandId>^>(NodeRT::Utils::GetObjectInstance(value));
              }
            } (info[2]);
          
          wrapper->_instance->CallExtension(arg0, arg1, arg2);
          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 IsExtensionSupported(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^>(info.This())) {
        return;
      }

      ICoreAutomationRemoteOperationExtensionProvider *wrapper = ICoreAutomationRemoteOperationExtensionProvider::Unwrap<ICoreAutomationRemoteOperationExtensionProvider>(info.This());

      if (info.Length() == 1
        && NodeRT::Utils::IsGuid(info[0]))
      {
        try
        {
          ::Platform::Guid arg0 = NodeRT::Utils::GuidFromJs(info[0]);
          
          bool result;
          result = wrapper->_instance->IsExtensionSupported(arg0);
          info.GetReturnValue().Set(Nan::New<Boolean>(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::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapICoreAutomationRemoteOperationExtensionProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ UnwrapICoreAutomationRemoteOperationExtensionProvider(Local<Value> value);
  };

  Persistent<FunctionTemplate> ICoreAutomationRemoteOperationExtensionProvider::s_constructorTemplate;

  v8::Local<v8::Value> WrapICoreAutomationRemoteOperationExtensionProvider(::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ 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>(ICoreAutomationRemoteOperationExtensionProvider::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::ICoreAutomationRemoteOperationExtensionProvider^ UnwrapICoreAutomationRemoteOperationExtensionProvider(Local<Value> value) {
     return ICoreAutomationRemoteOperationExtensionProvider::Unwrap<ICoreAutomationRemoteOperationExtensionProvider>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitICoreAutomationRemoteOperationExtensionProvider(Local<Object> exports) {
    ICoreAutomationRemoteOperationExtensionProvider::Init(exports);
  }

  class RemoteAutomationClientSession : 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>("RemoteAutomationClientSession").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;

          
            Nan::SetPrototypeMethod(localRef, "start", Start);
            Nan::SetPrototypeMethod(localRef, "stop", Stop);
          

          
            Nan::SetPrototypeMethod(localRef, "createWindowAsync", CreateWindowAsync);
          

          
          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>("sessionId").ToLocalChecked(), SessionIdGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("RemoteAutomationClientSession").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      RemoteAutomationClientSession(::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ 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::UIAutomation::Core::RemoteAutomationClientSession^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^) 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::UIAutomation::Core::RemoteAutomationClientSession(arg0);
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 2
        && info[0]->IsString()
        && NodeRT::Utils::IsGuid(info[1]))
      {
        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]);
          
          winRtInstance = ref new ::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession(arg0,arg1);
        } 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());

      RemoteAutomationClientSession *wrapperInstance = new RemoteAutomationClientSession(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::UIAutomation::Core::RemoteAutomationClientSession^>(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::UIAutomation::Core::RemoteAutomationClientSession^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapRemoteAutomationClientSession(winRtInstance));
    }

    static void CreateWindowAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(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;
      }

      RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^>^ op;


      if (info.Length() == 4
        && info[0]->IsNumber()
        && info[1]->IsUint32()
        && NodeRT::Utils::IsWinRtWrapperOf<::Platform::Object^>(info[2]))
      {
        try
        {
          unsigned __int64 arg0 = static_cast<unsigned __int64>(Nan::To<int64_t>(info[0]).FromMaybe(0));
          unsigned int arg1 = static_cast<unsigned int>(Nan::To<uint32_t>(info[1]).FromMaybe(0));
          ::Platform::Object^ arg2 = dynamic_cast<::Platform::Object^>(NodeRT::Utils::GetObjectInstance(info[2]));
          
          op = wrapper->_instance->CreateWindowAsync(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<::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^> t) {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapRemoteAutomationWindow(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 Start(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(info.This())) {
        return;
      }

      RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Start();
          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 Stop(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(info.This())) {
        return;
      }

      RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Stop();
          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 SessionIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(info.This())) {
        return;
      }

      RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(info.This());

      try  {
        ::Platform::Guid result = wrapper->_instance->SessionId;
        info.GetReturnValue().Set(NodeRT::Utils::GuidToJs(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"connectionRequested", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(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;
        }
        RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(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->ConnectionRequested::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^, ::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^>(
            [callbackObjPtr](::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ arg0, ::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapRemoteAutomationClientSession(arg0);
                  wrappedArg1 = WrapRemoteAutomationConnectionRequestedEventArgs(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"disconnected", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(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;
        }
        RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(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->Disconnected::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^, ::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^>(
            [callbackObjPtr](::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ arg0, ::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapRemoteAutomationClientSession(arg0);
                  wrappedArg1 = WrapRemoteAutomationDisconnectedEventArgs(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"connectionRequested", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"disconnected", 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"connectionRequested", str)) {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(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;
          }
          RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(info.This());
          wrapper->_instance->ConnectionRequested::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"disconnected", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^>(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;
          }
          RemoteAutomationClientSession *wrapper = RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(info.This());
          wrapper->_instance->Disconnected::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::UIAutomation::Core::RemoteAutomationClientSession^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapRemoteAutomationClientSession(::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ UnwrapRemoteAutomationClientSession(Local<Value> value);
  };

  Persistent<FunctionTemplate> RemoteAutomationClientSession::s_constructorTemplate;

  v8::Local<v8::Value> WrapRemoteAutomationClientSession(::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ 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>(RemoteAutomationClientSession::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::RemoteAutomationClientSession^ UnwrapRemoteAutomationClientSession(Local<Value> value) {
     return RemoteAutomationClientSession::Unwrap<RemoteAutomationClientSession>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitRemoteAutomationClientSession(Local<Object> exports) {
    RemoteAutomationClientSession::Init(exports);
  }

  class RemoteAutomationConnectionRequestedEventArgs : 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>("RemoteAutomationConnectionRequestedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("localPipeName").ToLocalChecked(), LocalPipeNameGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("remoteProcessId").ToLocalChecked(), RemoteProcessIdGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("RemoteAutomationConnectionRequestedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      RemoteAutomationConnectionRequestedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ 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::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^) 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());

      RemoteAutomationConnectionRequestedEventArgs *wrapperInstance = new RemoteAutomationConnectionRequestedEventArgs(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::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^>(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::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapRemoteAutomationConnectionRequestedEventArgs(winRtInstance));
    }





    static void LocalPipeNameGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^>(info.This())) {
        return;
      }

      RemoteAutomationConnectionRequestedEventArgs *wrapper = RemoteAutomationConnectionRequestedEventArgs::Unwrap<RemoteAutomationConnectionRequestedEventArgs>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->LocalPipeName;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void RemoteProcessIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^>(info.This())) {
        return;
      }

      RemoteAutomationConnectionRequestedEventArgs *wrapper = RemoteAutomationConnectionRequestedEventArgs::Unwrap<RemoteAutomationConnectionRequestedEventArgs>(info.This());

      try  {
        unsigned int result = wrapper->_instance->RemoteProcessId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapRemoteAutomationConnectionRequestedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ UnwrapRemoteAutomationConnectionRequestedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> RemoteAutomationConnectionRequestedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapRemoteAutomationConnectionRequestedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ 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>(RemoteAutomationConnectionRequestedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::RemoteAutomationConnectionRequestedEventArgs^ UnwrapRemoteAutomationConnectionRequestedEventArgs(Local<Value> value) {
     return RemoteAutomationConnectionRequestedEventArgs::Unwrap<RemoteAutomationConnectionRequestedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitRemoteAutomationConnectionRequestedEventArgs(Local<Object> exports) {
    RemoteAutomationConnectionRequestedEventArgs::Init(exports);
  }

  class RemoteAutomationDisconnectedEventArgs : 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>("RemoteAutomationDisconnectedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("localPipeName").ToLocalChecked(), LocalPipeNameGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("RemoteAutomationDisconnectedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      RemoteAutomationDisconnectedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ 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::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^) 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());

      RemoteAutomationDisconnectedEventArgs *wrapperInstance = new RemoteAutomationDisconnectedEventArgs(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::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^>(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::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapRemoteAutomationDisconnectedEventArgs(winRtInstance));
    }





    static void LocalPipeNameGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^>(info.This())) {
        return;
      }

      RemoteAutomationDisconnectedEventArgs *wrapper = RemoteAutomationDisconnectedEventArgs::Unwrap<RemoteAutomationDisconnectedEventArgs>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->LocalPipeName;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapRemoteAutomationDisconnectedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ UnwrapRemoteAutomationDisconnectedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> RemoteAutomationDisconnectedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapRemoteAutomationDisconnectedEventArgs(::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ 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>(RemoteAutomationDisconnectedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::RemoteAutomationDisconnectedEventArgs^ UnwrapRemoteAutomationDisconnectedEventArgs(Local<Value> value) {
     return RemoteAutomationDisconnectedEventArgs::Unwrap<RemoteAutomationDisconnectedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitRemoteAutomationDisconnectedEventArgs(Local<Object> exports) {
    RemoteAutomationDisconnectedEventArgs::Init(exports);
  }

  class RemoteAutomationServer : 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>("RemoteAutomationServer").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);






        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "reportSession", ReportSession);


        Nan::Set(exports, Nan::New<String>("RemoteAutomationServer").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      RemoteAutomationServer(::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ 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::UIAutomation::Core::RemoteAutomationServer^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationServer^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationServer^) 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());

      RemoteAutomationServer *wrapperInstance = new RemoteAutomationServer(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::UIAutomation::Core::RemoteAutomationServer^>(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::UIAutomation::Core::RemoteAutomationServer^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationServer^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapRemoteAutomationServer(winRtInstance));
    }





    static void ReportSession(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsGuid(info[0]))
      {
        try
        {
          ::Platform::Guid arg0 = NodeRT::Utils::GuidFromJs(info[0]);
          
          ::Windows::UI::UIAutomation::Core::RemoteAutomationServer::ReportSession(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;
      }
    }



    private:
      ::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapRemoteAutomationServer(::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ UnwrapRemoteAutomationServer(Local<Value> value);
  };

  Persistent<FunctionTemplate> RemoteAutomationServer::s_constructorTemplate;

  v8::Local<v8::Value> WrapRemoteAutomationServer(::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ 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>(RemoteAutomationServer::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::RemoteAutomationServer^ UnwrapRemoteAutomationServer(Local<Value> value) {
     return RemoteAutomationServer::Unwrap<RemoteAutomationServer>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitRemoteAutomationServer(Local<Object> exports) {
    RemoteAutomationServer::Init(exports);
  }

  class RemoteAutomationWindow : 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>("RemoteAutomationWindow").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;


          
            Nan::SetPrototypeMethod(localRef, "unregisterAsync", UnregisterAsync);
          


          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("automationProvider").ToLocalChecked(), AutomationProviderGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("RemoteAutomationWindow").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      RemoteAutomationWindow(::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ 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::UIAutomation::Core::RemoteAutomationWindow^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^>(info[0])) {
        try {
          winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^) 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());

      RemoteAutomationWindow *wrapperInstance = new RemoteAutomationWindow(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::UIAutomation::Core::RemoteAutomationWindow^>(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::UIAutomation::Core::RemoteAutomationWindow^ winRtInstance;
      try {
        winRtInstance = (::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapRemoteAutomationWindow(winRtInstance));
    }

    static void UnregisterAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^>(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;
      }

      RemoteAutomationWindow *wrapper = RemoteAutomationWindow::Unwrap<RemoteAutomationWindow>(info.This());

      ::Windows::Foundation::IAsyncAction^ op;


      if (info.Length() == 1)
      {
        try
        {
          op = wrapper->_instance->UnregisterAsync();
        }
        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 AutomationProviderGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^>(info.This())) {
        return;
      }

      RemoteAutomationWindow *wrapper = RemoteAutomationWindow::Unwrap<RemoteAutomationWindow>(info.This());

      try  {
        ::Platform::Object^ result = wrapper->_instance->AutomationProvider;
        info.GetReturnValue().Set(CreateOpaqueWrapper(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapRemoteAutomationWindow(::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ wintRtInstance);
      friend ::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ UnwrapRemoteAutomationWindow(Local<Value> value);
  };

  Persistent<FunctionTemplate> RemoteAutomationWindow::s_constructorTemplate;

  v8::Local<v8::Value> WrapRemoteAutomationWindow(::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ 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>(RemoteAutomationWindow::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::UI::UIAutomation::Core::RemoteAutomationWindow^ UnwrapRemoteAutomationWindow(Local<Value> value) {
     return RemoteAutomationWindow::Unwrap<RemoteAutomationWindow>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitRemoteAutomationWindow(Local<Object> exports) {
    RemoteAutomationWindow::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::UIAutomation::Core::InitAutomationRemoteOperationStatusEnum(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitAutomationRemoteOperationResult(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitCoreAutomationRegistrar(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitCoreAutomationRemoteOperation(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitCoreAutomationRemoteOperationContext(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitICoreAutomationConnectionBoundObjectProvider(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitICoreAutomationRemoteOperationExtensionProvider(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitRemoteAutomationClientSession(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitRemoteAutomationConnectionRequestedEventArgs(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitRemoteAutomationDisconnectedEventArgs(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitRemoteAutomationServer(target);
      NodeRT::Windows::UI::UIAutomation::Core::InitRemoteAutomationWindow(target);


  NodeRT::Utils::RegisterNameSpace("Windows.UI.UIAutomation.Core", target);
}



NODE_MODULE(binding, init)
