// 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 Services { namespace TargetedContent { 
  v8::Local<v8::Value> WrapTargetedContentAction(::Windows::Services::TargetedContent::TargetedContentAction^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentAction^ UnwrapTargetedContentAction(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentAvailabilityChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ UnwrapTargetedContentAvailabilityChangedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ UnwrapTargetedContentChangedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentCollection(::Windows::Services::TargetedContent::TargetedContentCollection^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentCollection^ UnwrapTargetedContentCollection(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentContainer(::Windows::Services::TargetedContent::TargetedContentContainer^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentContainer^ UnwrapTargetedContentContainer(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentFile(::Windows::Services::TargetedContent::TargetedContentFile^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentFile^ UnwrapTargetedContentFile(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentImage(::Windows::Services::TargetedContent::TargetedContentImage^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentImage^ UnwrapTargetedContentImage(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentItem(::Windows::Services::TargetedContent::TargetedContentItem^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentItem^ UnwrapTargetedContentItem(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentItemState(::Windows::Services::TargetedContent::TargetedContentItemState^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentItemState^ UnwrapTargetedContentItemState(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentObject(::Windows::Services::TargetedContent::TargetedContentObject^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentObject^ UnwrapTargetedContentObject(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentStateChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ UnwrapTargetedContentStateChangedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentSubscription(::Windows::Services::TargetedContent::TargetedContentSubscription^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentSubscription^ UnwrapTargetedContentSubscription(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentSubscriptionOptions(::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ UnwrapTargetedContentSubscriptionOptions(Local<Value> value);
  
  v8::Local<v8::Value> WrapTargetedContentValue(::Windows::Services::TargetedContent::TargetedContentValue^ wintRtInstance);
  ::Windows::Services::TargetedContent::TargetedContentValue^ UnwrapTargetedContentValue(Local<Value> value);
  



  static void InitTargetedContentAppInstallationStateEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("TargetedContentAppInstallationState").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("notApplicable").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentAppInstallationState::NotApplicable)));
    Nan::Set(enumObject, Nan::New<String>("notInstalled").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentAppInstallationState::NotInstalled)));
    Nan::Set(enumObject, Nan::New<String>("installed").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentAppInstallationState::Installed)));
  }

  static void InitTargetedContentAvailabilityEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("TargetedContentAvailability").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("none").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentAvailability::None)));
    Nan::Set(enumObject, Nan::New<String>("partial").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentAvailability::Partial)));
    Nan::Set(enumObject, Nan::New<String>("all").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentAvailability::All)));
  }

  static void InitTargetedContentInteractionEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("TargetedContentInteraction").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("impression").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Impression)));
    Nan::Set(enumObject, Nan::New<String>("clickThrough").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::ClickThrough)));
    Nan::Set(enumObject, Nan::New<String>("hover").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Hover)));
    Nan::Set(enumObject, Nan::New<String>("like").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Like)));
    Nan::Set(enumObject, Nan::New<String>("dislike").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Dislike)));
    Nan::Set(enumObject, Nan::New<String>("dismiss").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Dismiss)));
    Nan::Set(enumObject, Nan::New<String>("ineligible").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Ineligible)));
    Nan::Set(enumObject, Nan::New<String>("accept").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Accept)));
    Nan::Set(enumObject, Nan::New<String>("decline").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Decline)));
    Nan::Set(enumObject, Nan::New<String>("defer").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Defer)));
    Nan::Set(enumObject, Nan::New<String>("canceled").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Canceled)));
    Nan::Set(enumObject, Nan::New<String>("conversion").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Conversion)));
    Nan::Set(enumObject, Nan::New<String>("opportunity").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentInteraction::Opportunity)));
  }

  static void InitTargetedContentObjectKindEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("TargetedContentObjectKind").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("collection").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentObjectKind::Collection)));
    Nan::Set(enumObject, Nan::New<String>("item").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentObjectKind::Item)));
    Nan::Set(enumObject, Nan::New<String>("value").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentObjectKind::Value)));
  }

  static void InitTargetedContentValueKindEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("TargetedContentValueKind").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("string").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::String)));
    Nan::Set(enumObject, Nan::New<String>("uri").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Uri)));
    Nan::Set(enumObject, Nan::New<String>("number").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Number)));
    Nan::Set(enumObject, Nan::New<String>("boolean").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Boolean)));
    Nan::Set(enumObject, Nan::New<String>("file").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::File)));
    Nan::Set(enumObject, Nan::New<String>("imageFile").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::ImageFile)));
    Nan::Set(enumObject, Nan::New<String>("action").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Action)));
    Nan::Set(enumObject, Nan::New<String>("strings").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Strings)));
    Nan::Set(enumObject, Nan::New<String>("uris").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Uris)));
    Nan::Set(enumObject, Nan::New<String>("numbers").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Numbers)));
    Nan::Set(enumObject, Nan::New<String>("booleans").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Booleans)));
    Nan::Set(enumObject, Nan::New<String>("files").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Files)));
    Nan::Set(enumObject, Nan::New<String>("imageFiles").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::ImageFiles)));
    Nan::Set(enumObject, Nan::New<String>("actions").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Services::TargetedContent::TargetedContentValueKind::Actions)));
  }

  static bool IsTargetedContentContractJsObject(Local<Value> value) {
    if (!value->IsObject()) {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    return true;
  }

  ::Windows::Services::TargetedContent::TargetedContentContract TargetedContentContractFromJsObject(Local<Value> value) {
    HandleScope scope;
    ::Windows::Services::TargetedContent::TargetedContentContract returnValue;

    if (!value->IsObject()) {
      Nan::ThrowError(Nan::TypeError(NodeRT::Utils::NewString(L"Unexpected type, expected an object")));
      return returnValue;
    }

    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
    Local<String> symbol;

    return returnValue;
  }

  Local<Value> TargetedContentContractToJsObject(::Windows::Services::TargetedContent::TargetedContentContract value) {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();


    return scope.Escape(obj);
  }


  class TargetedContentAction : 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>("TargetedContentAction").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;


          
            Nan::SetPrototypeMethod(localRef, "invokeAsync", InvokeAsync);
          



        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentAction").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentAction(::Windows::Services::TargetedContent::TargetedContentAction^ 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::Services::TargetedContent::TargetedContentAction^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentAction^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentAction^) 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());

      TargetedContentAction *wrapperInstance = new TargetedContentAction(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::Services::TargetedContent::TargetedContentAction^>(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::Services::TargetedContent::TargetedContentAction^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentAction^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentAction(winRtInstance));
    }

    static void InvokeAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentAction^>(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;
      }

      TargetedContentAction *wrapper = TargetedContentAction::Unwrap<TargetedContentAction>(info.This());

      ::Windows::Foundation::IAsyncAction^ op;


      if (info.Length() == 1)
      {
        try
        {
          op = wrapper->_instance->InvokeAsync();
        }
        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);
          });
        }
      });
    }






    private:
      ::Windows::Services::TargetedContent::TargetedContentAction^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentAction(::Windows::Services::TargetedContent::TargetedContentAction^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentAction^ UnwrapTargetedContentAction(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentAction::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentAction(::Windows::Services::TargetedContent::TargetedContentAction^ 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>(TargetedContentAction::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentAction^ UnwrapTargetedContentAction(Local<Value> value) {
     return TargetedContentAction::Unwrap<TargetedContentAction>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentAction(Local<Object> exports) {
    TargetedContentAction::Init(exports);
  }

  class TargetedContentAvailabilityChangedEventArgs : 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>("TargetedContentAvailabilityChangedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "getDeferral", GetDeferral);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentAvailabilityChangedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentAvailabilityChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ 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::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^) 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());

      TargetedContentAvailabilityChangedEventArgs *wrapperInstance = new TargetedContentAvailabilityChangedEventArgs(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::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^>(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::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentAvailabilityChangedEventArgs(winRtInstance));
    }


    static void GetDeferral(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^>(info.This())) {
        return;
      }

      TargetedContentAvailabilityChangedEventArgs *wrapper = TargetedContentAvailabilityChangedEventArgs::Unwrap<TargetedContentAvailabilityChangedEventArgs>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Foundation::Deferral^ result;
          result = wrapper->_instance->GetDeferral();
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Deferral", 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::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentAvailabilityChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ UnwrapTargetedContentAvailabilityChangedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentAvailabilityChangedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentAvailabilityChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ 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>(TargetedContentAvailabilityChangedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ UnwrapTargetedContentAvailabilityChangedEventArgs(Local<Value> value) {
     return TargetedContentAvailabilityChangedEventArgs::Unwrap<TargetedContentAvailabilityChangedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentAvailabilityChangedEventArgs(Local<Object> exports) {
    TargetedContentAvailabilityChangedEventArgs::Init(exports);
  }

  class TargetedContentChangedEventArgs : 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>("TargetedContentChangedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "getDeferral", GetDeferral);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("hasPreviousContentExpired").ToLocalChecked(), HasPreviousContentExpiredGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentChangedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ 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::Services::TargetedContent::TargetedContentChangedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^) 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());

      TargetedContentChangedEventArgs *wrapperInstance = new TargetedContentChangedEventArgs(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::Services::TargetedContent::TargetedContentChangedEventArgs^>(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::Services::TargetedContent::TargetedContentChangedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentChangedEventArgs(winRtInstance));
    }


    static void GetDeferral(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^>(info.This())) {
        return;
      }

      TargetedContentChangedEventArgs *wrapper = TargetedContentChangedEventArgs::Unwrap<TargetedContentChangedEventArgs>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Foundation::Deferral^ result;
          result = wrapper->_instance->GetDeferral();
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Deferral", 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 HasPreviousContentExpiredGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^>(info.This())) {
        return;
      }

      TargetedContentChangedEventArgs *wrapper = TargetedContentChangedEventArgs::Unwrap<TargetedContentChangedEventArgs>(info.This());

      try  {
        bool result = wrapper->_instance->HasPreviousContentExpired;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ UnwrapTargetedContentChangedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentChangedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ 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>(TargetedContentChangedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ UnwrapTargetedContentChangedEventArgs(Local<Value> value) {
     return TargetedContentChangedEventArgs::Unwrap<TargetedContentChangedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentChangedEventArgs(Local<Object> exports) {
    TargetedContentChangedEventArgs::Init(exports);
  }

  class TargetedContentCollection : 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>("TargetedContentCollection").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "reportInteraction", ReportInteraction);
            Nan::SetPrototypeMethod(localRef, "reportCustomInteraction", ReportCustomInteraction);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("collections").ToLocalChecked(), CollectionsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("items").ToLocalChecked(), ItemsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("path").ToLocalChecked(), PathGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("properties").ToLocalChecked(), PropertiesGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentCollection").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentCollection(::Windows::Services::TargetedContent::TargetedContentCollection^ 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::Services::TargetedContent::TargetedContentCollection^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentCollection^) 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());

      TargetedContentCollection *wrapperInstance = new TargetedContentCollection(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::Services::TargetedContent::TargetedContentCollection^>(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::Services::TargetedContent::TargetedContentCollection^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentCollection^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentCollection(winRtInstance));
    }


    static void ReportInteraction(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Services::TargetedContent::TargetedContentInteraction arg0 = static_cast<::Windows::Services::TargetedContent::TargetedContentInteraction>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          wrapper->_instance->ReportInteraction(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 ReportCustomInteraction(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      if (info.Length() == 1
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          
          wrapper->_instance->ReportCustomInteraction(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 CollectionsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Services::TargetedContent::TargetedContentCollection^>^ result = wrapper->_instance->Collections;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Services::TargetedContent::TargetedContentCollection^>::CreateVectorViewWrapper(result, 
            [](::Windows::Services::TargetedContent::TargetedContentCollection^ val) -> Local<Value> {
              return WrapTargetedContentCollection(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(value);
            },
            [](Local<Value> value) -> ::Windows::Services::TargetedContent::TargetedContentCollection^ {
              return UnwrapTargetedContentCollection(value);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void IdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->Id;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ItemsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Services::TargetedContent::TargetedContentItem^>^ result = wrapper->_instance->Items;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Services::TargetedContent::TargetedContentItem^>::CreateVectorViewWrapper(result, 
            [](::Windows::Services::TargetedContent::TargetedContentItem^ val) -> Local<Value> {
              return WrapTargetedContentItem(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(value);
            },
            [](Local<Value> value) -> ::Windows::Services::TargetedContent::TargetedContentItem^ {
              return UnwrapTargetedContentItem(value);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PathGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->Path;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PropertiesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(info.This())) {
        return;
      }

      TargetedContentCollection *wrapper = TargetedContentCollection::Unwrap<TargetedContentCollection>(info.This());

      try  {
        ::Windows::Foundation::Collections::IMapView<::Platform::String^, ::Windows::Services::TargetedContent::TargetedContentValue^>^ result = wrapper->_instance->Properties;
        info.GetReturnValue().Set(NodeRT::Collections::MapViewWrapper<::Platform::String^,::Windows::Services::TargetedContent::TargetedContentValue^>::CreateMapViewWrapper(result, 
            [](::Platform::String^ val) -> Local<Value> {
              return NodeRT::Utils::NewString(val->Data());
            },
            [](Local<Value> value) -> bool {
              return value->IsString();
            },
            [](Local<Value> value) -> ::Platform::String^ {
              return ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));
            },
            [](::Windows::Services::TargetedContent::TargetedContentValue^ val) -> Local<Value> {
              return WrapTargetedContentValue(val);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentCollection^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentCollection(::Windows::Services::TargetedContent::TargetedContentCollection^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentCollection^ UnwrapTargetedContentCollection(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentCollection::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentCollection(::Windows::Services::TargetedContent::TargetedContentCollection^ 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>(TargetedContentCollection::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentCollection^ UnwrapTargetedContentCollection(Local<Value> value) {
     return TargetedContentCollection::Unwrap<TargetedContentCollection>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentCollection(Local<Object> exports) {
    TargetedContentCollection::Init(exports);
  }

  class TargetedContentContainer : 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>("TargetedContentContainer").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;

          
            Nan::SetPrototypeMethod(localRef, "selectSingleObject", SelectSingleObject);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("availability").ToLocalChecked(), AvailabilityGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("content").ToLocalChecked(), ContentGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        func = Nan::GetFunction(Nan::New<FunctionTemplate>(GetAsync)).ToLocalChecked();
        Nan::Set(constructor, Nan::New<String>("getAsync").ToLocalChecked(), func);


        Nan::Set(exports, Nan::New<String>("TargetedContentContainer").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentContainer(::Windows::Services::TargetedContent::TargetedContentContainer^ 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::Services::TargetedContent::TargetedContentContainer^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentContainer^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentContainer^) 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());

      TargetedContentContainer *wrapperInstance = new TargetedContentContainer(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::Services::TargetedContent::TargetedContentContainer^>(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::Services::TargetedContent::TargetedContentContainer^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentContainer^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentContainer(winRtInstance));
    }


    static void SelectSingleObject(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentContainer^>(info.This())) {
        return;
      }

      TargetedContentContainer *wrapper = TargetedContentContainer::Unwrap<TargetedContentContainer>(info.This());

      if (info.Length() == 1
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          
          ::Windows::Services::TargetedContent::TargetedContentObject^ result;
          result = wrapper->_instance->SelectSingleObject(arg0);
          info.GetReturnValue().Set(WrapTargetedContentObject(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 GetAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 0 || !info[info.Length() -1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: No callback was given")));
        return;
      }

      ::Windows::Foundation::IAsyncOperation<::Windows::Services::TargetedContent::TargetedContentContainer^>^ op;


      if (info.Length() == 2
          && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
            
          op = ::Windows::Services::TargetedContent::TargetedContentContainer::GetAsync(arg0);
        } 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::Services::TargetedContent::TargetedContentContainer^> t)
      {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapTargetedContentContainer(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 AvailabilityGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentContainer^>(info.This())) {
        return;
      }

      TargetedContentContainer *wrapper = TargetedContentContainer::Unwrap<TargetedContentContainer>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentAvailability result = wrapper->_instance->Availability;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ContentGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentContainer^>(info.This())) {
        return;
      }

      TargetedContentContainer *wrapper = TargetedContentContainer::Unwrap<TargetedContentContainer>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentCollection^ result = wrapper->_instance->Content;
        info.GetReturnValue().Set(WrapTargetedContentCollection(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void IdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentContainer^>(info.This())) {
        return;
      }

      TargetedContentContainer *wrapper = TargetedContentContainer::Unwrap<TargetedContentContainer>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->Id;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void TimestampGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentContainer^>(info.This())) {
        return;
      }

      TargetedContentContainer *wrapper = TargetedContentContainer::Unwrap<TargetedContentContainer>(info.This());

      try  {
        ::Windows::Foundation::DateTime result = wrapper->_instance->Timestamp;
        info.GetReturnValue().Set(NodeRT::Utils::DateTimeToJS(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentContainer^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentContainer(::Windows::Services::TargetedContent::TargetedContentContainer^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentContainer^ UnwrapTargetedContentContainer(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentContainer::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentContainer(::Windows::Services::TargetedContent::TargetedContentContainer^ 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>(TargetedContentContainer::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentContainer^ UnwrapTargetedContentContainer(Local<Value> value) {
     return TargetedContentContainer::Unwrap<TargetedContentContainer>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentContainer(Local<Object> exports) {
    TargetedContentContainer::Init(exports);
  }

  class TargetedContentFile : 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>("TargetedContentFile").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;


          
            Nan::SetPrototypeMethod(localRef, "openReadAsync", OpenReadAsync);
          



        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentFile").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentFile(::Windows::Services::TargetedContent::TargetedContentFile^ 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::Services::TargetedContent::TargetedContentFile^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentFile^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentFile^) 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());

      TargetedContentFile *wrapperInstance = new TargetedContentFile(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::Services::TargetedContent::TargetedContentFile^>(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::Services::TargetedContent::TargetedContentFile^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentFile^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentFile(winRtInstance));
    }

    static void OpenReadAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentFile^>(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;
      }

      TargetedContentFile *wrapper = TargetedContentFile::Unwrap<TargetedContentFile>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::Storage::Streams::IRandomAccessStreamWithContentType^>^ op;


      if (info.Length() == 1)
      {
        try
        {
          op = wrapper->_instance->OpenReadAsync();
        }
        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::Storage::Streams::IRandomAccessStreamWithContentType^> t) {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = NodeRT::Utils::CreateExternalWinRTObject("Windows.Storage.Streams", "IRandomAccessStreamWithContentType", 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);
          });
        }
      });
    }






    private:
      ::Windows::Services::TargetedContent::TargetedContentFile^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentFile(::Windows::Services::TargetedContent::TargetedContentFile^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentFile^ UnwrapTargetedContentFile(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentFile::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentFile(::Windows::Services::TargetedContent::TargetedContentFile^ 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>(TargetedContentFile::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentFile^ UnwrapTargetedContentFile(Local<Value> value) {
     return TargetedContentFile::Unwrap<TargetedContentFile>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentFile(Local<Object> exports) {
    TargetedContentFile::Init(exports);
  }

  class TargetedContentImage : 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>("TargetedContentImage").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;


          
            Nan::SetPrototypeMethod(localRef, "openReadAsync", OpenReadAsync);
          


          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("height").ToLocalChecked(), HeightGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("width").ToLocalChecked(), WidthGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentImage").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentImage(::Windows::Services::TargetedContent::TargetedContentImage^ 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::Services::TargetedContent::TargetedContentImage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentImage^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentImage^) 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());

      TargetedContentImage *wrapperInstance = new TargetedContentImage(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::Services::TargetedContent::TargetedContentImage^>(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::Services::TargetedContent::TargetedContentImage^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentImage^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentImage(winRtInstance));
    }

    static void OpenReadAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentImage^>(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;
      }

      TargetedContentImage *wrapper = TargetedContentImage::Unwrap<TargetedContentImage>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::Storage::Streams::IRandomAccessStreamWithContentType^>^ op;


      if (info.Length() == 1)
      {
        try
        {
          op = wrapper->_instance->OpenReadAsync();
        }
        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::Storage::Streams::IRandomAccessStreamWithContentType^> t) {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = NodeRT::Utils::CreateExternalWinRTObject("Windows.Storage.Streams", "IRandomAccessStreamWithContentType", 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 HeightGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentImage^>(info.This())) {
        return;
      }

      TargetedContentImage *wrapper = TargetedContentImage::Unwrap<TargetedContentImage>(info.This());

      try  {
        unsigned int result = wrapper->_instance->Height;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void WidthGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentImage^>(info.This())) {
        return;
      }

      TargetedContentImage *wrapper = TargetedContentImage::Unwrap<TargetedContentImage>(info.This());

      try  {
        unsigned int result = wrapper->_instance->Width;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentImage^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentImage(::Windows::Services::TargetedContent::TargetedContentImage^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentImage^ UnwrapTargetedContentImage(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentImage::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentImage(::Windows::Services::TargetedContent::TargetedContentImage^ 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>(TargetedContentImage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentImage^ UnwrapTargetedContentImage(Local<Value> value) {
     return TargetedContentImage::Unwrap<TargetedContentImage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentImage(Local<Object> exports) {
    TargetedContentImage::Init(exports);
  }

  class TargetedContentItem : 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>("TargetedContentItem").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "reportInteraction", ReportInteraction);
            Nan::SetPrototypeMethod(localRef, "reportCustomInteraction", ReportCustomInteraction);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("collections").ToLocalChecked(), CollectionsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("path").ToLocalChecked(), PathGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("properties").ToLocalChecked(), PropertiesGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("state").ToLocalChecked(), StateGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentItem").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentItem(::Windows::Services::TargetedContent::TargetedContentItem^ 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::Services::TargetedContent::TargetedContentItem^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentItem^) 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());

      TargetedContentItem *wrapperInstance = new TargetedContentItem(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::Services::TargetedContent::TargetedContentItem^>(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::Services::TargetedContent::TargetedContentItem^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentItem^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentItem(winRtInstance));
    }


    static void ReportInteraction(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info.This())) {
        return;
      }

      TargetedContentItem *wrapper = TargetedContentItem::Unwrap<TargetedContentItem>(info.This());

      if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Services::TargetedContent::TargetedContentInteraction arg0 = static_cast<::Windows::Services::TargetedContent::TargetedContentInteraction>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          wrapper->_instance->ReportInteraction(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 ReportCustomInteraction(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info.This())) {
        return;
      }

      TargetedContentItem *wrapper = TargetedContentItem::Unwrap<TargetedContentItem>(info.This());

      if (info.Length() == 1
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          
          wrapper->_instance->ReportCustomInteraction(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 CollectionsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info.This())) {
        return;
      }

      TargetedContentItem *wrapper = TargetedContentItem::Unwrap<TargetedContentItem>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Services::TargetedContent::TargetedContentCollection^>^ result = wrapper->_instance->Collections;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Services::TargetedContent::TargetedContentCollection^>::CreateVectorViewWrapper(result, 
            [](::Windows::Services::TargetedContent::TargetedContentCollection^ val) -> Local<Value> {
              return WrapTargetedContentCollection(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentCollection^>(value);
            },
            [](Local<Value> value) -> ::Windows::Services::TargetedContent::TargetedContentCollection^ {
              return UnwrapTargetedContentCollection(value);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PathGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info.This())) {
        return;
      }

      TargetedContentItem *wrapper = TargetedContentItem::Unwrap<TargetedContentItem>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->Path;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PropertiesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info.This())) {
        return;
      }

      TargetedContentItem *wrapper = TargetedContentItem::Unwrap<TargetedContentItem>(info.This());

      try  {
        ::Windows::Foundation::Collections::IMapView<::Platform::String^, ::Windows::Services::TargetedContent::TargetedContentValue^>^ result = wrapper->_instance->Properties;
        info.GetReturnValue().Set(NodeRT::Collections::MapViewWrapper<::Platform::String^,::Windows::Services::TargetedContent::TargetedContentValue^>::CreateMapViewWrapper(result, 
            [](::Platform::String^ val) -> Local<Value> {
              return NodeRT::Utils::NewString(val->Data());
            },
            [](Local<Value> value) -> bool {
              return value->IsString();
            },
            [](Local<Value> value) -> ::Platform::String^ {
              return ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));
            },
            [](::Windows::Services::TargetedContent::TargetedContentValue^ val) -> Local<Value> {
              return WrapTargetedContentValue(val);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void StateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItem^>(info.This())) {
        return;
      }

      TargetedContentItem *wrapper = TargetedContentItem::Unwrap<TargetedContentItem>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentItemState^ result = wrapper->_instance->State;
        info.GetReturnValue().Set(WrapTargetedContentItemState(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentItem^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentItem(::Windows::Services::TargetedContent::TargetedContentItem^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentItem^ UnwrapTargetedContentItem(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentItem::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentItem(::Windows::Services::TargetedContent::TargetedContentItem^ 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>(TargetedContentItem::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentItem^ UnwrapTargetedContentItem(Local<Value> value) {
     return TargetedContentItem::Unwrap<TargetedContentItem>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentItem(Local<Object> exports) {
    TargetedContentItem::Init(exports);
  }

  class TargetedContentItemState : 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>("TargetedContentItemState").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("appInstallationState").ToLocalChecked(), AppInstallationStateGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("shouldDisplay").ToLocalChecked(), ShouldDisplayGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentItemState").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentItemState(::Windows::Services::TargetedContent::TargetedContentItemState^ 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::Services::TargetedContent::TargetedContentItemState^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItemState^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentItemState^) 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());

      TargetedContentItemState *wrapperInstance = new TargetedContentItemState(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::Services::TargetedContent::TargetedContentItemState^>(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::Services::TargetedContent::TargetedContentItemState^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentItemState^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentItemState(winRtInstance));
    }





    static void AppInstallationStateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItemState^>(info.This())) {
        return;
      }

      TargetedContentItemState *wrapper = TargetedContentItemState::Unwrap<TargetedContentItemState>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentAppInstallationState result = wrapper->_instance->AppInstallationState;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ShouldDisplayGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentItemState^>(info.This())) {
        return;
      }

      TargetedContentItemState *wrapper = TargetedContentItemState::Unwrap<TargetedContentItemState>(info.This());

      try  {
        bool result = wrapper->_instance->ShouldDisplay;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentItemState^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentItemState(::Windows::Services::TargetedContent::TargetedContentItemState^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentItemState^ UnwrapTargetedContentItemState(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentItemState::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentItemState(::Windows::Services::TargetedContent::TargetedContentItemState^ 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>(TargetedContentItemState::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentItemState^ UnwrapTargetedContentItemState(Local<Value> value) {
     return TargetedContentItemState::Unwrap<TargetedContentItemState>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentItemState(Local<Object> exports) {
    TargetedContentItemState::Init(exports);
  }

  class TargetedContentObject : 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>("TargetedContentObject").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("collection").ToLocalChecked(), CollectionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("item").ToLocalChecked(), ItemGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("objectKind").ToLocalChecked(), ObjectKindGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("value").ToLocalChecked(), ValueGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentObject").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentObject(::Windows::Services::TargetedContent::TargetedContentObject^ 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::Services::TargetedContent::TargetedContentObject^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentObject^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentObject^) 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());

      TargetedContentObject *wrapperInstance = new TargetedContentObject(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::Services::TargetedContent::TargetedContentObject^>(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::Services::TargetedContent::TargetedContentObject^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentObject^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentObject(winRtInstance));
    }





    static void CollectionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentObject^>(info.This())) {
        return;
      }

      TargetedContentObject *wrapper = TargetedContentObject::Unwrap<TargetedContentObject>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentCollection^ result = wrapper->_instance->Collection;
        info.GetReturnValue().Set(WrapTargetedContentCollection(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ItemGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentObject^>(info.This())) {
        return;
      }

      TargetedContentObject *wrapper = TargetedContentObject::Unwrap<TargetedContentObject>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentItem^ result = wrapper->_instance->Item;
        info.GetReturnValue().Set(WrapTargetedContentItem(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ObjectKindGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentObject^>(info.This())) {
        return;
      }

      TargetedContentObject *wrapper = TargetedContentObject::Unwrap<TargetedContentObject>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentObjectKind result = wrapper->_instance->ObjectKind;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ValueGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentObject^>(info.This())) {
        return;
      }

      TargetedContentObject *wrapper = TargetedContentObject::Unwrap<TargetedContentObject>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentValue^ result = wrapper->_instance->Value;
        info.GetReturnValue().Set(WrapTargetedContentValue(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentObject^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentObject(::Windows::Services::TargetedContent::TargetedContentObject^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentObject^ UnwrapTargetedContentObject(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentObject::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentObject(::Windows::Services::TargetedContent::TargetedContentObject^ 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>(TargetedContentObject::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentObject^ UnwrapTargetedContentObject(Local<Value> value) {
     return TargetedContentObject::Unwrap<TargetedContentObject>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentObject(Local<Object> exports) {
    TargetedContentObject::Init(exports);
  }

  class TargetedContentStateChangedEventArgs : 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>("TargetedContentStateChangedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "getDeferral", GetDeferral);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentStateChangedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentStateChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ 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::Services::TargetedContent::TargetedContentStateChangedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^) 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());

      TargetedContentStateChangedEventArgs *wrapperInstance = new TargetedContentStateChangedEventArgs(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::Services::TargetedContent::TargetedContentStateChangedEventArgs^>(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::Services::TargetedContent::TargetedContentStateChangedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentStateChangedEventArgs(winRtInstance));
    }


    static void GetDeferral(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^>(info.This())) {
        return;
      }

      TargetedContentStateChangedEventArgs *wrapper = TargetedContentStateChangedEventArgs::Unwrap<TargetedContentStateChangedEventArgs>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Foundation::Deferral^ result;
          result = wrapper->_instance->GetDeferral();
          info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Deferral", 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::Services::TargetedContent::TargetedContentStateChangedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentStateChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ UnwrapTargetedContentStateChangedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentStateChangedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentStateChangedEventArgs(::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ 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>(TargetedContentStateChangedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ UnwrapTargetedContentStateChangedEventArgs(Local<Value> value) {
     return TargetedContentStateChangedEventArgs::Unwrap<TargetedContentStateChangedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentStateChangedEventArgs(Local<Object> exports) {
    TargetedContentStateChangedEventArgs::Init(exports);
  }

  class TargetedContentSubscription : 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>("TargetedContentSubscription").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;


          
            Nan::SetPrototypeMethod(localRef, "getContentContainerAsync", GetContentContainerAsync);
          

          
          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>("id").ToLocalChecked(), IdGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "getOptions", GetOptions);
        func = Nan::GetFunction(Nan::New<FunctionTemplate>(GetAsync)).ToLocalChecked();
        Nan::Set(constructor, Nan::New<String>("getAsync").ToLocalChecked(), func);


        Nan::Set(exports, Nan::New<String>("TargetedContentSubscription").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentSubscription(::Windows::Services::TargetedContent::TargetedContentSubscription^ 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::Services::TargetedContent::TargetedContentSubscription^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentSubscription^) 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());

      TargetedContentSubscription *wrapperInstance = new TargetedContentSubscription(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::Services::TargetedContent::TargetedContentSubscription^>(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::Services::TargetedContent::TargetedContentSubscription^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentSubscription^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentSubscription(winRtInstance));
    }

    static void GetContentContainerAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
      }

      TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::Services::TargetedContent::TargetedContentContainer^>^ op;


      if (info.Length() == 1)
      {
        try
        {
          op = wrapper->_instance->GetContentContainerAsync();
        }
        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::Services::TargetedContent::TargetedContentContainer^> t) {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapTargetedContentContainer(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 GetAsync(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 0 || !info[info.Length() -1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: No callback was given")));
        return;
      }

      ::Windows::Foundation::IAsyncOperation<::Windows::Services::TargetedContent::TargetedContentSubscription^>^ op;


      if (info.Length() == 2
          && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
            
          op = ::Windows::Services::TargetedContent::TargetedContentSubscription::GetAsync(arg0);
        } 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::Services::TargetedContent::TargetedContentSubscription^> t)
      {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapTargetedContentSubscription(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 GetOptions(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      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])));
          
          ::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ result;
          result = ::Windows::Services::TargetedContent::TargetedContentSubscription::GetOptions(arg0);
          info.GetReturnValue().Set(WrapTargetedContentSubscriptionOptions(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 IdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(info.This())) {
        return;
      }

      TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->Id;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      Local<Function> callback = info[1].As<Function>();

      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"availabilityChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
        }
        TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(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->AvailabilityChanged::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Services::TargetedContent::TargetedContentSubscription^, ::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^>(
            [callbackObjPtr](::Windows::Services::TargetedContent::TargetedContentSubscription^ arg0, ::Windows::Services::TargetedContent::TargetedContentAvailabilityChangedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapTargetedContentSubscription(arg0);
                  wrappedArg1 = WrapTargetedContentAvailabilityChangedEventArgs(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"contentChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
        }
        TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(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->ContentChanged::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Services::TargetedContent::TargetedContentSubscription^, ::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^>(
            [callbackObjPtr](::Windows::Services::TargetedContent::TargetedContentSubscription^ arg0, ::Windows::Services::TargetedContent::TargetedContentChangedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapTargetedContentSubscription(arg0);
                  wrappedArg1 = WrapTargetedContentChangedEventArgs(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"stateChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
        }
        TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(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->StateChanged::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Services::TargetedContent::TargetedContentSubscription^, ::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^>(
            [callbackObjPtr](::Windows::Services::TargetedContent::TargetedContentSubscription^ arg0, ::Windows::Services::TargetedContent::TargetedContentStateChangedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapTargetedContentSubscription(arg0);
                  wrappedArg1 = WrapTargetedContentStateChangedEventArgs(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"availabilityChanged", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"contentChanged", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"stateChanged", 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"availabilityChanged", str)) {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
          }
          TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(info.This());
          wrapper->_instance->AvailabilityChanged::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"contentChanged", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
          }
          TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(info.This());
          wrapper->_instance->ContentChanged::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"stateChanged", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscription^>(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;
          }
          TargetedContentSubscription *wrapper = TargetedContentSubscription::Unwrap<TargetedContentSubscription>(info.This());
          wrapper->_instance->StateChanged::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::Services::TargetedContent::TargetedContentSubscription^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentSubscription(::Windows::Services::TargetedContent::TargetedContentSubscription^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentSubscription^ UnwrapTargetedContentSubscription(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentSubscription::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentSubscription(::Windows::Services::TargetedContent::TargetedContentSubscription^ 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>(TargetedContentSubscription::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentSubscription^ UnwrapTargetedContentSubscription(Local<Value> value) {
     return TargetedContentSubscription::Unwrap<TargetedContentSubscription>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentSubscription(Local<Object> exports) {
    TargetedContentSubscription::Init(exports);
  }

  class TargetedContentSubscriptionOptions : 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>("TargetedContentSubscriptionOptions").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "update", Update);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("allowPartialContentAvailability").ToLocalChecked(), AllowPartialContentAvailabilityGetter, AllowPartialContentAvailabilitySetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cloudQueryParameters").ToLocalChecked(), CloudQueryParametersGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("localFilters").ToLocalChecked(), LocalFiltersGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("subscriptionId").ToLocalChecked(), SubscriptionIdGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentSubscriptionOptions").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentSubscriptionOptions(::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ 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::Services::TargetedContent::TargetedContentSubscriptionOptions^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^) 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());

      TargetedContentSubscriptionOptions *wrapperInstance = new TargetedContentSubscriptionOptions(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::Services::TargetedContent::TargetedContentSubscriptionOptions^>(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::Services::TargetedContent::TargetedContentSubscriptionOptions^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentSubscriptionOptions(winRtInstance));
    }


    static void Update(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info.This())) {
        return;
      }

      TargetedContentSubscriptionOptions *wrapper = TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Update();
          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 AllowPartialContentAvailabilityGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info.This())) {
        return;
      }

      TargetedContentSubscriptionOptions *wrapper = TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(info.This());

      try  {
        bool result = wrapper->_instance->AllowPartialContentAvailability;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void AllowPartialContentAvailabilitySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsBoolean()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info.This())) {
        return;
      }

      TargetedContentSubscriptionOptions *wrapper = TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(info.This());

      try {

        bool winRtValue = Nan::To<bool>(value).FromMaybe(false);

        wrapper->_instance->AllowPartialContentAvailability = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void CloudQueryParametersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info.This())) {
        return;
      }

      TargetedContentSubscriptionOptions *wrapper = TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(info.This());

      try  {
        ::Windows::Foundation::Collections::IMap<::Platform::String^, ::Platform::String^>^ result = wrapper->_instance->CloudQueryParameters;
        info.GetReturnValue().Set(NodeRT::Collections::MapWrapper<::Platform::String^,::Platform::String^>::CreateMapWrapper(result, 
            [](::Platform::String^ val) -> Local<Value> {
              return NodeRT::Utils::NewString(val->Data());
            },
            [](Local<Value> value) -> bool {
              return value->IsString();
            },
            [](Local<Value> value) -> ::Platform::String^ {
              return ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));
            },
            [](::Platform::String^ val) -> Local<Value> {
              return NodeRT::Utils::NewString(val->Data());
            },
            [](Local<Value> value) -> bool {
              return value->IsString();
            },
            [](Local<Value> value) -> ::Platform::String^ {
              return ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void LocalFiltersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info.This())) {
        return;
      }

      TargetedContentSubscriptionOptions *wrapper = TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->LocalFilters;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<::Platform::String^>::CreateVectorWrapper(result, 
            [](::Platform::String^ val) -> Local<Value> {
              return NodeRT::Utils::NewString(val->Data());
            },
            [](Local<Value> value) -> bool {
              return value->IsString();
            },
            [](Local<Value> value) -> ::Platform::String^ {
              return ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void SubscriptionIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^>(info.This())) {
        return;
      }

      TargetedContentSubscriptionOptions *wrapper = TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->SubscriptionId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentSubscriptionOptions(::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ UnwrapTargetedContentSubscriptionOptions(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentSubscriptionOptions::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentSubscriptionOptions(::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ 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>(TargetedContentSubscriptionOptions::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentSubscriptionOptions^ UnwrapTargetedContentSubscriptionOptions(Local<Value> value) {
     return TargetedContentSubscriptionOptions::Unwrap<TargetedContentSubscriptionOptions>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentSubscriptionOptions(Local<Object> exports) {
    TargetedContentSubscriptionOptions::Init(exports);
  }

  class TargetedContentValue : 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>("TargetedContentValue").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("action").ToLocalChecked(), ActionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("actions").ToLocalChecked(), ActionsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("boolean").ToLocalChecked(), BooleanGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("booleans").ToLocalChecked(), BooleansGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("file").ToLocalChecked(), FileGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("files").ToLocalChecked(), FilesGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("imageFile").ToLocalChecked(), ImageFileGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("imageFiles").ToLocalChecked(), ImageFilesGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("number").ToLocalChecked(), NumberGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("numbers").ToLocalChecked(), NumbersGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("path").ToLocalChecked(), PathGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("string").ToLocalChecked(), StringGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("strings").ToLocalChecked(), StringsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("uri").ToLocalChecked(), UriGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("uris").ToLocalChecked(), UrisGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("valueKind").ToLocalChecked(), ValueKindGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("TargetedContentValue").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      TargetedContentValue(::Windows::Services::TargetedContent::TargetedContentValue^ 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::Services::TargetedContent::TargetedContentValue^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info[0])) {
        try {
          winRtInstance = (::Windows::Services::TargetedContent::TargetedContentValue^) 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());

      TargetedContentValue *wrapperInstance = new TargetedContentValue(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::Services::TargetedContent::TargetedContentValue^>(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::Services::TargetedContent::TargetedContentValue^ winRtInstance;
      try {
        winRtInstance = (::Windows::Services::TargetedContent::TargetedContentValue^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapTargetedContentValue(winRtInstance));
    }





    static void ActionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentAction^ result = wrapper->_instance->Action;
        info.GetReturnValue().Set(WrapTargetedContentAction(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ActionsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Services::TargetedContent::TargetedContentAction^>^ result = wrapper->_instance->Actions;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Services::TargetedContent::TargetedContentAction^>::CreateVectorViewWrapper(result, 
            [](::Windows::Services::TargetedContent::TargetedContentAction^ val) -> Local<Value> {
              return WrapTargetedContentAction(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentAction^>(value);
            },
            [](Local<Value> value) -> ::Windows::Services::TargetedContent::TargetedContentAction^ {
              return UnwrapTargetedContentAction(value);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void BooleanGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        bool result = wrapper->_instance->Boolean;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void BooleansGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<bool>^ result = wrapper->_instance->Booleans;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<bool>::CreateVectorViewWrapper(result, 
            [](bool val) -> Local<Value> {
              return Nan::New<Boolean>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsBoolean();
            },
            [](Local<Value> value) -> bool {
              return Nan::To<bool>(value).FromMaybe(false);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void FileGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentFile^ result = wrapper->_instance->File;
        info.GetReturnValue().Set(WrapTargetedContentFile(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void FilesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Services::TargetedContent::TargetedContentFile^>^ result = wrapper->_instance->Files;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Services::TargetedContent::TargetedContentFile^>::CreateVectorViewWrapper(result, 
            [](::Windows::Services::TargetedContent::TargetedContentFile^ val) -> Local<Value> {
              return WrapTargetedContentFile(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentFile^>(value);
            },
            [](Local<Value> value) -> ::Windows::Services::TargetedContent::TargetedContentFile^ {
              return UnwrapTargetedContentFile(value);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ImageFileGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentImage^ result = wrapper->_instance->ImageFile;
        info.GetReturnValue().Set(WrapTargetedContentImage(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ImageFilesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Services::TargetedContent::TargetedContentImage^>^ result = wrapper->_instance->ImageFiles;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Services::TargetedContent::TargetedContentImage^>::CreateVectorViewWrapper(result, 
            [](::Windows::Services::TargetedContent::TargetedContentImage^ val) -> Local<Value> {
              return WrapTargetedContentImage(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentImage^>(value);
            },
            [](Local<Value> value) -> ::Windows::Services::TargetedContent::TargetedContentImage^ {
              return UnwrapTargetedContentImage(value);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void NumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        double result = wrapper->_instance->Number;
        info.GetReturnValue().Set(Nan::New<Number>(static_cast<double>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void NumbersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<double>^ result = wrapper->_instance->Numbers;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<double>::CreateVectorViewWrapper(result, 
            [](double val) -> Local<Value> {
              return Nan::New<Number>(static_cast<double>(val));
            },
            [](Local<Value> value) -> bool {
              return value->IsNumber();
            },
            [](Local<Value> value) -> double {
              return Nan::To<double>(value).FromMaybe(0.0);
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PathGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->Path;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void StringGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->String;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void StringsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Platform::String^>^ result = wrapper->_instance->Strings;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Platform::String^>::CreateVectorViewWrapper(result, 
            [](::Platform::String^ val) -> Local<Value> {
              return NodeRT::Utils::NewString(val->Data());
            },
            [](Local<Value> value) -> bool {
              return value->IsString();
            },
            [](Local<Value> value) -> ::Platform::String^ {
              return ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void UriGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Uri^ result = wrapper->_instance->Uri;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void UrisGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Foundation::Uri^>^ result = wrapper->_instance->Uris;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Foundation::Uri^>::CreateVectorViewWrapper(result, 
            [](::Windows::Foundation::Uri^ val) -> Local<Value> {
              return NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::Uri^>(value);
            },
            [](Local<Value> value) -> ::Windows::Foundation::Uri^ {
              return dynamic_cast<::Windows::Foundation::Uri^>(NodeRT::Utils::GetObjectInstance(value));
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ValueKindGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Services::TargetedContent::TargetedContentValue^>(info.This())) {
        return;
      }

      TargetedContentValue *wrapper = TargetedContentValue::Unwrap<TargetedContentValue>(info.This());

      try  {
        ::Windows::Services::TargetedContent::TargetedContentValueKind result = wrapper->_instance->ValueKind;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Services::TargetedContent::TargetedContentValue^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapTargetedContentValue(::Windows::Services::TargetedContent::TargetedContentValue^ wintRtInstance);
      friend ::Windows::Services::TargetedContent::TargetedContentValue^ UnwrapTargetedContentValue(Local<Value> value);
  };

  Persistent<FunctionTemplate> TargetedContentValue::s_constructorTemplate;

  v8::Local<v8::Value> WrapTargetedContentValue(::Windows::Services::TargetedContent::TargetedContentValue^ 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>(TargetedContentValue::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Services::TargetedContent::TargetedContentValue^ UnwrapTargetedContentValue(Local<Value> value) {
     return TargetedContentValue::Unwrap<TargetedContentValue>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitTargetedContentValue(Local<Object> exports) {
    TargetedContentValue::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::Services::TargetedContent::InitTargetedContentAppInstallationStateEnum(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentAvailabilityEnum(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentInteractionEnum(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentObjectKindEnum(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentValueKindEnum(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentAction(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentAvailabilityChangedEventArgs(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentChangedEventArgs(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentCollection(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentContainer(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentFile(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentImage(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentItem(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentItemState(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentObject(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentStateChangedEventArgs(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentSubscription(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentSubscriptionOptions(target);
      NodeRT::Windows::Services::TargetedContent::InitTargetedContentValue(target);


  NodeRT::Utils::RegisterNameSpace("Windows.Services.TargetedContent", target);
}



NODE_MODULE(binding, init)
