// Copyright (c) Microsoft Corporation
// 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::Handle;
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 Devices { namespace Sms { 

  v8::Local<v8::Value> WrapISmsMessage(::Windows::Devices::Sms::ISmsMessage^ wintRtInstance);
  ::Windows::Devices::Sms::ISmsMessage^ UnwrapISmsMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapISmsBinaryMessage(::Windows::Devices::Sms::ISmsBinaryMessage^ wintRtInstance);
  ::Windows::Devices::Sms::ISmsBinaryMessage^ UnwrapISmsBinaryMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsBinaryMessage(::Windows::Devices::Sms::SmsBinaryMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsBinaryMessage^ UnwrapSmsBinaryMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapISmsTextMessage(::Windows::Devices::Sms::ISmsTextMessage^ wintRtInstance);
  ::Windows::Devices::Sms::ISmsTextMessage^ UnwrapISmsTextMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsTextMessage(::Windows::Devices::Sms::SmsTextMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsTextMessage^ UnwrapSmsTextMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapDeleteSmsMessageOperation(::Windows::Devices::Sms::DeleteSmsMessageOperation^ wintRtInstance);
  ::Windows::Devices::Sms::DeleteSmsMessageOperation^ UnwrapDeleteSmsMessageOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapDeleteSmsMessagesOperation(::Windows::Devices::Sms::DeleteSmsMessagesOperation^ wintRtInstance);
  ::Windows::Devices::Sms::DeleteSmsMessagesOperation^ UnwrapDeleteSmsMessagesOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapGetSmsMessageOperation(::Windows::Devices::Sms::GetSmsMessageOperation^ wintRtInstance);
  ::Windows::Devices::Sms::GetSmsMessageOperation^ UnwrapGetSmsMessageOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapGetSmsMessagesOperation(::Windows::Devices::Sms::GetSmsMessagesOperation^ wintRtInstance);
  ::Windows::Devices::Sms::GetSmsMessagesOperation^ UnwrapGetSmsMessagesOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsDeviceMessageStore(::Windows::Devices::Sms::SmsDeviceMessageStore^ wintRtInstance);
  ::Windows::Devices::Sms::SmsDeviceMessageStore^ UnwrapSmsDeviceMessageStore(Local<Value> value);
  
  v8::Local<v8::Value> WrapSendSmsMessageOperation(::Windows::Devices::Sms::SendSmsMessageOperation^ wintRtInstance);
  ::Windows::Devices::Sms::SendSmsMessageOperation^ UnwrapSendSmsMessageOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsMessageReceivedEventArgs(::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ wintRtInstance);
  ::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ UnwrapSmsMessageReceivedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsDevice(::Windows::Devices::Sms::SmsDevice^ wintRtInstance);
  ::Windows::Devices::Sms::SmsDevice^ UnwrapSmsDevice(Local<Value> value);
  
  v8::Local<v8::Value> WrapGetSmsDeviceOperation(::Windows::Devices::Sms::GetSmsDeviceOperation^ wintRtInstance);
  ::Windows::Devices::Sms::GetSmsDeviceOperation^ UnwrapGetSmsDeviceOperation(Local<Value> value);
  
  v8::Local<v8::Value> WrapISmsDevice(::Windows::Devices::Sms::ISmsDevice^ wintRtInstance);
  ::Windows::Devices::Sms::ISmsDevice^ UnwrapISmsDevice(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsReceivedEventDetails(::Windows::Devices::Sms::SmsReceivedEventDetails^ wintRtInstance);
  ::Windows::Devices::Sms::SmsReceivedEventDetails^ UnwrapSmsReceivedEventDetails(Local<Value> value);
  
  v8::Local<v8::Value> WrapISmsMessageBase(::Windows::Devices::Sms::ISmsMessageBase^ wintRtInstance);
  ::Windows::Devices::Sms::ISmsMessageBase^ UnwrapISmsMessageBase(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsTextMessage2(::Windows::Devices::Sms::SmsTextMessage2^ wintRtInstance);
  ::Windows::Devices::Sms::SmsTextMessage2^ UnwrapSmsTextMessage2(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsWapMessage(::Windows::Devices::Sms::SmsWapMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsWapMessage^ UnwrapSmsWapMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsAppMessage(::Windows::Devices::Sms::SmsAppMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsAppMessage^ UnwrapSmsAppMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsBroadcastMessage(::Windows::Devices::Sms::SmsBroadcastMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsBroadcastMessage^ UnwrapSmsBroadcastMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsVoicemailMessage(::Windows::Devices::Sms::SmsVoicemailMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsVoicemailMessage^ UnwrapSmsVoicemailMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsStatusMessage(::Windows::Devices::Sms::SmsStatusMessage^ wintRtInstance);
  ::Windows::Devices::Sms::SmsStatusMessage^ UnwrapSmsStatusMessage(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsSendMessageResult(::Windows::Devices::Sms::SmsSendMessageResult^ wintRtInstance);
  ::Windows::Devices::Sms::SmsSendMessageResult^ UnwrapSmsSendMessageResult(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsDevice2(::Windows::Devices::Sms::SmsDevice2^ wintRtInstance);
  ::Windows::Devices::Sms::SmsDevice2^ UnwrapSmsDevice2(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsMessageReceivedTriggerDetails(::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ wintRtInstance);
  ::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ UnwrapSmsMessageReceivedTriggerDetails(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsFilterRule(::Windows::Devices::Sms::SmsFilterRule^ wintRtInstance);
  ::Windows::Devices::Sms::SmsFilterRule^ UnwrapSmsFilterRule(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsFilterRules(::Windows::Devices::Sms::SmsFilterRules^ wintRtInstance);
  ::Windows::Devices::Sms::SmsFilterRules^ UnwrapSmsFilterRules(Local<Value> value);
  
  v8::Local<v8::Value> WrapSmsMessageRegistration(::Windows::Devices::Sms::SmsMessageRegistration^ wintRtInstance);
  ::Windows::Devices::Sms::SmsMessageRegistration^ UnwrapSmsMessageRegistration(Local<Value> value);
  


  static void InitSmsMessageFilterEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsMessageFilter").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("all").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageFilter::All)));
	Nan::Set(enumObject, Nan::New<String>("unread").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageFilter::Unread)));
	Nan::Set(enumObject, Nan::New<String>("read").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageFilter::Read)));
	Nan::Set(enumObject, Nan::New<String>("sent").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageFilter::Sent)));
	Nan::Set(enumObject, Nan::New<String>("draft").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageFilter::Draft)));
  }


  static void InitSmsMessageClassEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsMessageClass").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("none").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageClass::None)));
	Nan::Set(enumObject, Nan::New<String>("class0").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageClass::Class0)));
	Nan::Set(enumObject, Nan::New<String>("class1").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageClass::Class1)));
	Nan::Set(enumObject, Nan::New<String>("class2").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageClass::Class2)));
	Nan::Set(enumObject, Nan::New<String>("class3").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageClass::Class3)));
  }


  static void InitSmsMessageTypeEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsMessageType").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("binary").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::Binary)));
	Nan::Set(enumObject, Nan::New<String>("text").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::Text)));
	Nan::Set(enumObject, Nan::New<String>("wap").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::Wap)));
	Nan::Set(enumObject, Nan::New<String>("app").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::App)));
	Nan::Set(enumObject, Nan::New<String>("broadcast").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::Broadcast)));
	Nan::Set(enumObject, Nan::New<String>("voicemail").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::Voicemail)));
	Nan::Set(enumObject, Nan::New<String>("status").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsMessageType::Status)));
  }


  static void InitCellularClassEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("CellularClass").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("none").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::CellularClass::None)));
	Nan::Set(enumObject, Nan::New<String>("gsm").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::CellularClass::Gsm)));
	Nan::Set(enumObject, Nan::New<String>("cdma").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::CellularClass::Cdma)));
  }


  static void InitSmsDataFormatEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsDataFormat").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("unknown").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDataFormat::Unknown)));
	Nan::Set(enumObject, Nan::New<String>("cdmaSubmit").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDataFormat::CdmaSubmit)));
	Nan::Set(enumObject, Nan::New<String>("gsmSubmit").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDataFormat::GsmSubmit)));
	Nan::Set(enumObject, Nan::New<String>("cdmaDeliver").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDataFormat::CdmaDeliver)));
	Nan::Set(enumObject, Nan::New<String>("gsmDeliver").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDataFormat::GsmDeliver)));
  }


  static void InitSmsEncodingEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsEncoding").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("unknown").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::Unknown)));
	Nan::Set(enumObject, Nan::New<String>("optimal").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::Optimal)));
	Nan::Set(enumObject, Nan::New<String>("sevenBitAscii").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::SevenBitAscii)));
	Nan::Set(enumObject, Nan::New<String>("unicode").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::Unicode)));
	Nan::Set(enumObject, Nan::New<String>("gsmSevenBit").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::GsmSevenBit)));
	Nan::Set(enumObject, Nan::New<String>("eightBit").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::EightBit)));
	Nan::Set(enumObject, Nan::New<String>("latin").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::Latin)));
	Nan::Set(enumObject, Nan::New<String>("korean").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::Korean)));
	Nan::Set(enumObject, Nan::New<String>("iA5").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::IA5)));
	Nan::Set(enumObject, Nan::New<String>("shiftJis").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::ShiftJis)));
	Nan::Set(enumObject, Nan::New<String>("latinHebrew").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsEncoding::LatinHebrew)));
  }


  static void InitSmsGeographicalScopeEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsGeographicalScope").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("none").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsGeographicalScope::None)));
	Nan::Set(enumObject, Nan::New<String>("cellWithImmediateDisplay").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsGeographicalScope::CellWithImmediateDisplay)));
	Nan::Set(enumObject, Nan::New<String>("locationArea").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsGeographicalScope::LocationArea)));
	Nan::Set(enumObject, Nan::New<String>("plmn").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsGeographicalScope::Plmn)));
	Nan::Set(enumObject, Nan::New<String>("cell").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsGeographicalScope::Cell)));
  }


  static void InitSmsBroadcastTypeEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsBroadcastType").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("other").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::Other)));
	Nan::Set(enumObject, Nan::New<String>("cmasPresidential").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::CmasPresidential)));
	Nan::Set(enumObject, Nan::New<String>("cmasExtreme").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::CmasExtreme)));
	Nan::Set(enumObject, Nan::New<String>("cmasSevere").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::CmasSevere)));
	Nan::Set(enumObject, Nan::New<String>("cmasAmber").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::CmasAmber)));
	Nan::Set(enumObject, Nan::New<String>("cmasTest").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::CmasTest)));
	Nan::Set(enumObject, Nan::New<String>("eUAlert1").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EUAlert1)));
	Nan::Set(enumObject, Nan::New<String>("eUAlert2").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EUAlert2)));
	Nan::Set(enumObject, Nan::New<String>("eUAlert3").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EUAlert3)));
	Nan::Set(enumObject, Nan::New<String>("eUAlertAmber").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EUAlertAmber)));
	Nan::Set(enumObject, Nan::New<String>("eUAlertInfo").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EUAlertInfo)));
	Nan::Set(enumObject, Nan::New<String>("etwsEarthquake").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EtwsEarthquake)));
	Nan::Set(enumObject, Nan::New<String>("etwsTsunami").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EtwsTsunami)));
	Nan::Set(enumObject, Nan::New<String>("etwsTsunamiAndEarthquake").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::EtwsTsunamiAndEarthquake)));
	Nan::Set(enumObject, Nan::New<String>("latAlertLocal").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsBroadcastType::LatAlertLocal)));
  }


  static void InitSmsDeviceStatusEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsDeviceStatus").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("off").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::Off)));
	Nan::Set(enumObject, Nan::New<String>("ready").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::Ready)));
	Nan::Set(enumObject, Nan::New<String>("simNotInserted").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::SimNotInserted)));
	Nan::Set(enumObject, Nan::New<String>("badSim").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::BadSim)));
	Nan::Set(enumObject, Nan::New<String>("deviceFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::DeviceFailure)));
	Nan::Set(enumObject, Nan::New<String>("subscriptionNotActivated").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::SubscriptionNotActivated)));
	Nan::Set(enumObject, Nan::New<String>("deviceLocked").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::DeviceLocked)));
	Nan::Set(enumObject, Nan::New<String>("deviceBlocked").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsDeviceStatus::DeviceBlocked)));
  }


  static void InitSmsModemErrorCodeEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsModemErrorCode").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("other").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::Other)));
	Nan::Set(enumObject, Nan::New<String>("messagingNetworkError").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::MessagingNetworkError)));
	Nan::Set(enumObject, Nan::New<String>("smsOperationNotSupportedByDevice").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::SmsOperationNotSupportedByDevice)));
	Nan::Set(enumObject, Nan::New<String>("smsServiceNotSupportedByNetwork").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::SmsServiceNotSupportedByNetwork)));
	Nan::Set(enumObject, Nan::New<String>("deviceFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::DeviceFailure)));
	Nan::Set(enumObject, Nan::New<String>("messageNotEncodedProperly").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::MessageNotEncodedProperly)));
	Nan::Set(enumObject, Nan::New<String>("messageTooLarge").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::MessageTooLarge)));
	Nan::Set(enumObject, Nan::New<String>("deviceNotReady").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::DeviceNotReady)));
	Nan::Set(enumObject, Nan::New<String>("networkNotReady").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::NetworkNotReady)));
	Nan::Set(enumObject, Nan::New<String>("invalidSmscAddress").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::InvalidSmscAddress)));
	Nan::Set(enumObject, Nan::New<String>("networkFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::NetworkFailure)));
	Nan::Set(enumObject, Nan::New<String>("fixedDialingNumberRestricted").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsModemErrorCode::FixedDialingNumberRestricted)));
  }


  static void InitSmsFilterActionTypeEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("SmsFilterActionType").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("acceptImmediately").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsFilterActionType::AcceptImmediately)));
	Nan::Set(enumObject, Nan::New<String>("drop").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsFilterActionType::Drop)));
	Nan::Set(enumObject, Nan::New<String>("peek").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsFilterActionType::Peek)));
	Nan::Set(enumObject, Nan::New<String>("accept").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Devices::Sms::SmsFilterActionType::Accept)));
  }



  
  static bool IsLegacySmsApiContractJsObject(Local<Value> value)
  {
    if (!value->IsObject())
    {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    return true;
  }

  ::Windows::Devices::Sms::LegacySmsApiContract LegacySmsApiContractFromJsObject(Local<Value> value)
  {
    HandleScope scope;
    ::Windows::Devices::Sms::LegacySmsApiContract 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> LegacySmsApiContractToJsObject(::Windows::Devices::Sms::LegacySmsApiContract value)
  {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();

    
    return scope.Escape(obj);
  }

  
  static bool IsSmsEncodedLengthJsObject(Local<Value> value)
  {
    if (!value->IsObject())
    {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    symbol = Nan::New<String>("segmentCount").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsUint32())
      {
          return false;
      }
    }
    
    symbol = Nan::New<String>("characterCountLastSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsUint32())
      {
          return false;
      }
    }
    
    symbol = Nan::New<String>("charactersPerSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsUint32())
      {
          return false;
      }
    }
    
    symbol = Nan::New<String>("byteCountLastSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsUint32())
      {
          return false;
      }
    }
    
    symbol = Nan::New<String>("bytesPerSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      if (!Nan::Get(obj,symbol).ToLocalChecked()->IsUint32())
      {
          return false;
      }
    }
    
    return true;
  }

  ::Windows::Devices::Sms::SmsEncodedLength SmsEncodedLengthFromJsObject(Local<Value> value)
  {
    HandleScope scope;
    ::Windows::Devices::Sms::SmsEncodedLength returnValue;
    
    if (!value->IsObject())
    {
      Nan::ThrowError(Nan::TypeError(NodeRT::Utils::NewString(L"Unexpected type, expected an object")));
      return returnValue;
    }

    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
    Local<String> symbol;

    symbol = Nan::New<String>("segmentCount").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      returnValue.SegmentCount = static_cast<unsigned int>(Nan::To<uint32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    symbol = Nan::New<String>("characterCountLastSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      returnValue.CharacterCountLastSegment = static_cast<unsigned int>(Nan::To<uint32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    symbol = Nan::New<String>("charactersPerSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      returnValue.CharactersPerSegment = static_cast<unsigned int>(Nan::To<uint32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    symbol = Nan::New<String>("byteCountLastSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      returnValue.ByteCountLastSegment = static_cast<unsigned int>(Nan::To<uint32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    symbol = Nan::New<String>("bytesPerSegment").ToLocalChecked();
    if (Nan::Has(obj, symbol).FromMaybe(false))
    {
      returnValue.BytesPerSegment = static_cast<unsigned int>(Nan::To<uint32_t>(Nan::Get(obj,symbol).ToLocalChecked()).FromMaybe(0));
    }
    
    return returnValue;
  }

  Local<Value> SmsEncodedLengthToJsObject(::Windows::Devices::Sms::SmsEncodedLength value)
  {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();

    Nan::Set(obj, Nan::New<String>("segmentCount").ToLocalChecked(), Nan::New<Integer>(value.SegmentCount));
    Nan::Set(obj, Nan::New<String>("characterCountLastSegment").ToLocalChecked(), Nan::New<Integer>(value.CharacterCountLastSegment));
    Nan::Set(obj, Nan::New<String>("charactersPerSegment").ToLocalChecked(), Nan::New<Integer>(value.CharactersPerSegment));
    Nan::Set(obj, Nan::New<String>("byteCountLastSegment").ToLocalChecked(), Nan::New<Integer>(value.ByteCountLastSegment));
    Nan::Set(obj, Nan::New<String>("bytesPerSegment").ToLocalChecked(), Nan::New<Integer>(value.BytesPerSegment));
    
    return scope.Escape(obj);
  }

  
  class ISmsMessage : 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>("ISmsMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("ISmsMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    ISmsMessage(::Windows::Devices::Sms::ISmsMessage^ 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::Devices::Sms::ISmsMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::ISmsMessage^) 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());

      ISmsMessage *wrapperInstance = new ISmsMessage(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::Devices::Sms::ISmsMessage^>(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::Devices::Sms::ISmsMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::ISmsMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapISmsMessage(winRtInstance));
    }


  



    static void IdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(info.This()))
      {
        return;
      }

      ISmsMessage *wrapper = ISmsMessage::Unwrap<ISmsMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(info.This()))
      {
        return;
      }

      ISmsMessage *wrapper = ISmsMessage::Unwrap<ISmsMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::ISmsMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapISmsMessage(::Windows::Devices::Sms::ISmsMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::ISmsMessage^ UnwrapISmsMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> ISmsMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapISmsMessage(::Windows::Devices::Sms::ISmsMessage^ 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>(ISmsMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::ISmsMessage^ UnwrapISmsMessage(Local<Value> value)
  {
     return ISmsMessage::Unwrap<ISmsMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitISmsMessage(Local<Object> exports)
  {
    ISmsMessage::Init(exports);
  }

  class ISmsBinaryMessage : 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>("ISmsBinaryMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getData", GetData);
      Nan::SetPrototypeMethod(localRef, "setData", SetData);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("format").ToLocalChecked(), FormatGetter, FormatSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("ISmsBinaryMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    ISmsBinaryMessage(::Windows::Devices::Sms::ISmsBinaryMessage^ 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::Devices::Sms::ISmsBinaryMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::ISmsBinaryMessage^) 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());

      ISmsBinaryMessage *wrapperInstance = new ISmsBinaryMessage(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::Devices::Sms::ISmsBinaryMessage^>(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::Devices::Sms::ISmsBinaryMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::ISmsBinaryMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapISmsBinaryMessage(winRtInstance));
    }


  
    static void GetData(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(info.This()))
      {
        return;
      }

      ISmsBinaryMessage *wrapper = ISmsBinaryMessage::Unwrap<ISmsBinaryMessage>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Platform::Array<unsigned char>^ result;
          result = wrapper->_instance->GetData();
          info.GetReturnValue().Set(NodeRT::Collections::ArrayWrapper<unsigned char>::CreateArrayWrapper(result, 
            [](unsigned char val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> unsigned char {
              return static_cast<unsigned char>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
          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 SetData(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(info.This()))
      {
        return;
      }

      ISmsBinaryMessage *wrapper = ISmsBinaryMessage::Unwrap<ISmsBinaryMessage>(info.This());

      if (info.Length() == 1
        && (NodeRT::Utils::IsWinRtWrapperOf<::Platform::Array<unsigned char>^>(info[0]) || info[0]->IsArray()))
      {
        try
        {
          ::Platform::Array<unsigned char>^ arg0 = 
            [] (v8::Local<v8::Value> value) -> ::Platform::Array<unsigned char>^
            {
              if (value->IsArray())
              {
                return NodeRT::Collections::JsArrayToWinrtArray<unsigned char>(value.As<Array>(), 
                 [](Local<Value> value) -> bool {
                   return value->IsInt32();
                 },
                 [](Local<Value> value) -> unsigned char {
                   return static_cast<unsigned char>(Nan::To<int32_t>(value).FromMaybe(0));
                 }
                );
              }
              else
              {
                return dynamic_cast<::Platform::Array<unsigned char>^>(NodeRT::Utils::GetObjectInstance(value));
              }
            } (info[0]);
          
          wrapper->_instance->SetData(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 FormatGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(info.This()))
      {
        return;
      }

      ISmsBinaryMessage *wrapper = ISmsBinaryMessage::Unwrap<ISmsBinaryMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDataFormat result = wrapper->_instance->Format;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FormatSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(info.This()))
      {
        return;
      }

      ISmsBinaryMessage *wrapper = ISmsBinaryMessage::Unwrap<ISmsBinaryMessage>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::SmsDataFormat winRtValue = static_cast<::Windows::Devices::Sms::SmsDataFormat>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->Format = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::ISmsBinaryMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapISmsBinaryMessage(::Windows::Devices::Sms::ISmsBinaryMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::ISmsBinaryMessage^ UnwrapISmsBinaryMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> ISmsBinaryMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapISmsBinaryMessage(::Windows::Devices::Sms::ISmsBinaryMessage^ 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>(ISmsBinaryMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::ISmsBinaryMessage^ UnwrapISmsBinaryMessage(Local<Value> value)
  {
     return ISmsBinaryMessage::Unwrap<ISmsBinaryMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitISmsBinaryMessage(Local<Object> exports)
  {
    ISmsBinaryMessage::Init(exports);
  }

  class SmsBinaryMessage : 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>("SmsBinaryMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getData", GetData);
      Nan::SetPrototypeMethod(localRef, "setData", SetData);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("format").ToLocalChecked(), FormatGetter, FormatSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsBinaryMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsBinaryMessage(::Windows::Devices::Sms::SmsBinaryMessage^ 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::Devices::Sms::SmsBinaryMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsBinaryMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 0)
      {
        try
        {
          winRtInstance = ref new ::Windows::Devices::Sms::SmsBinaryMessage();
        }
        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());

      SmsBinaryMessage *wrapperInstance = new SmsBinaryMessage(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::Devices::Sms::SmsBinaryMessage^>(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::Devices::Sms::SmsBinaryMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsBinaryMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsBinaryMessage(winRtInstance));
    }


  
    static void GetData(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info.This()))
      {
        return;
      }

      SmsBinaryMessage *wrapper = SmsBinaryMessage::Unwrap<SmsBinaryMessage>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Platform::Array<unsigned char>^ result;
          result = wrapper->_instance->GetData();
          info.GetReturnValue().Set(NodeRT::Collections::ArrayWrapper<unsigned char>::CreateArrayWrapper(result, 
            [](unsigned char val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> unsigned char {
              return static_cast<unsigned char>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
          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 SetData(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info.This()))
      {
        return;
      }

      SmsBinaryMessage *wrapper = SmsBinaryMessage::Unwrap<SmsBinaryMessage>(info.This());

      if (info.Length() == 1
        && (NodeRT::Utils::IsWinRtWrapperOf<::Platform::Array<unsigned char>^>(info[0]) || info[0]->IsArray()))
      {
        try
        {
          ::Platform::Array<unsigned char>^ arg0 = 
            [] (v8::Local<v8::Value> value) -> ::Platform::Array<unsigned char>^
            {
              if (value->IsArray())
              {
                return NodeRT::Collections::JsArrayToWinrtArray<unsigned char>(value.As<Array>(), 
                 [](Local<Value> value) -> bool {
                   return value->IsInt32();
                 },
                 [](Local<Value> value) -> unsigned char {
                   return static_cast<unsigned char>(Nan::To<int32_t>(value).FromMaybe(0));
                 }
                );
              }
              else
              {
                return dynamic_cast<::Platform::Array<unsigned char>^>(NodeRT::Utils::GetObjectInstance(value));
              }
            } (info[0]);
          
          wrapper->_instance->SetData(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 FormatGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info.This()))
      {
        return;
      }

      SmsBinaryMessage *wrapper = SmsBinaryMessage::Unwrap<SmsBinaryMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDataFormat result = wrapper->_instance->Format;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FormatSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info.This()))
      {
        return;
      }

      SmsBinaryMessage *wrapper = SmsBinaryMessage::Unwrap<SmsBinaryMessage>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::SmsDataFormat winRtValue = static_cast<::Windows::Devices::Sms::SmsDataFormat>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->Format = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void IdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info.This()))
      {
        return;
      }

      SmsBinaryMessage *wrapper = SmsBinaryMessage::Unwrap<SmsBinaryMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info.This()))
      {
        return;
      }

      SmsBinaryMessage *wrapper = SmsBinaryMessage::Unwrap<SmsBinaryMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsBinaryMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsBinaryMessage(::Windows::Devices::Sms::SmsBinaryMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsBinaryMessage^ UnwrapSmsBinaryMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsBinaryMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsBinaryMessage(::Windows::Devices::Sms::SmsBinaryMessage^ 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>(SmsBinaryMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsBinaryMessage^ UnwrapSmsBinaryMessage(Local<Value> value)
  {
     return SmsBinaryMessage::Unwrap<SmsBinaryMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsBinaryMessage(Local<Object> exports)
  {
    SmsBinaryMessage::Init(exports);
  }

  class ISmsTextMessage : 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>("ISmsTextMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "toBinaryMessages", ToBinaryMessages);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter, BodySetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("encoding").ToLocalChecked(), EncodingGetter, EncodingSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("from").ToLocalChecked(), FromGetter, FromSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("partCount").ToLocalChecked(), PartCountGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("partNumber").ToLocalChecked(), PartNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("partReferenceId").ToLocalChecked(), PartReferenceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter, ToSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("ISmsTextMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    ISmsTextMessage(::Windows::Devices::Sms::ISmsTextMessage^ 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::Devices::Sms::ISmsTextMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::ISmsTextMessage^) 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());

      ISmsTextMessage *wrapperInstance = new ISmsTextMessage(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::Devices::Sms::ISmsTextMessage^>(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::Devices::Sms::ISmsTextMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::ISmsTextMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapISmsTextMessage(winRtInstance));
    }


  
    static void ToBinaryMessages(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Devices::Sms::SmsDataFormat arg0 = static_cast<::Windows::Devices::Sms::SmsDataFormat>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          ::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsBinaryMessage^>^ result;
          result = wrapper->_instance->ToBinaryMessages(arg0);
          info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Devices::Sms::ISmsBinaryMessage^>::CreateVectorViewWrapper(result, 
            [](::Windows::Devices::Sms::ISmsBinaryMessage^ val) -> Local<Value> {
              return WrapISmsBinaryMessage(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(value);
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::ISmsBinaryMessage^ {
              return UnwrapISmsBinaryMessage(value);
            }
          ));
          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 BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BodySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->Body = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void EncodingGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsEncoding result = wrapper->_instance->Encoding;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void EncodingSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::SmsEncoding winRtValue = static_cast<::Windows::Devices::Sms::SmsEncoding>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->Encoding = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void FromGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->From;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FromSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->From = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void PartCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->PartCount;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PartNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->PartNumber;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PartReferenceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->PartReferenceId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        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::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(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;
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsTextMessage^>(info.This()))
      {
        return;
      }

      ISmsTextMessage *wrapper = ISmsTextMessage::Unwrap<ISmsTextMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->To = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::ISmsTextMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapISmsTextMessage(::Windows::Devices::Sms::ISmsTextMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::ISmsTextMessage^ UnwrapISmsTextMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> ISmsTextMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapISmsTextMessage(::Windows::Devices::Sms::ISmsTextMessage^ 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>(ISmsTextMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::ISmsTextMessage^ UnwrapISmsTextMessage(Local<Value> value)
  {
     return ISmsTextMessage::Unwrap<ISmsTextMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitISmsTextMessage(Local<Object> exports)
  {
    ISmsTextMessage::Init(exports);
  }

  class SmsTextMessage : 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>("SmsTextMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "toBinaryMessages", ToBinaryMessages);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter, ToSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("from").ToLocalChecked(), FromGetter, FromSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("encoding").ToLocalChecked(), EncodingGetter, EncodingSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter, BodySetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("partCount").ToLocalChecked(), PartCountGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("partNumber").ToLocalChecked(), PartNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("partReferenceId").ToLocalChecked(), PartReferenceIdGetter);
      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);

      Nan::SetMethod(constructor, "fromBinaryMessage", FromBinaryMessage);
      Nan::SetMethod(constructor, "fromBinaryData", FromBinaryData);

      Nan::Set(exports, Nan::New<String>("SmsTextMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsTextMessage(::Windows::Devices::Sms::SmsTextMessage^ 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::Devices::Sms::SmsTextMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsTextMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 0)
      {
        try
        {
          winRtInstance = ref new ::Windows::Devices::Sms::SmsTextMessage();
        }
        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());

      SmsTextMessage *wrapperInstance = new SmsTextMessage(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::Devices::Sms::SmsTextMessage^>(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::Devices::Sms::SmsTextMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsTextMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsTextMessage(winRtInstance));
    }


  
    static void ToBinaryMessages(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Devices::Sms::SmsDataFormat arg0 = static_cast<::Windows::Devices::Sms::SmsDataFormat>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          ::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsBinaryMessage^>^ result;
          result = wrapper->_instance->ToBinaryMessages(arg0);
          info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Devices::Sms::ISmsBinaryMessage^>::CreateVectorViewWrapper(result, 
            [](::Windows::Devices::Sms::ISmsBinaryMessage^ val) -> Local<Value> {
              return WrapISmsBinaryMessage(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsBinaryMessage^>(value);
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::ISmsBinaryMessage^ {
              return UnwrapISmsBinaryMessage(value);
            }
          ));
          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 FromBinaryMessage(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBinaryMessage^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::SmsBinaryMessage^ arg0 = UnwrapSmsBinaryMessage(info[0]);
          
          ::Windows::Devices::Sms::SmsTextMessage^ result;
          result = ::Windows::Devices::Sms::SmsTextMessage::FromBinaryMessage(arg0);
          info.GetReturnValue().Set(WrapSmsTextMessage(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 FromBinaryData(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() == 2
        && info[0]->IsInt32()
        && (NodeRT::Utils::IsWinRtWrapperOf<::Platform::Array<unsigned char>^>(info[1]) || info[1]->IsArray()))
      {
        try
        {
          ::Windows::Devices::Sms::SmsDataFormat arg0 = static_cast<::Windows::Devices::Sms::SmsDataFormat>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          ::Platform::Array<unsigned char>^ arg1 = 
            [] (v8::Local<v8::Value> value) -> ::Platform::Array<unsigned char>^
            {
              if (value->IsArray())
              {
                return NodeRT::Collections::JsArrayToWinrtArray<unsigned char>(value.As<Array>(), 
                 [](Local<Value> value) -> bool {
                   return value->IsInt32();
                 },
                 [](Local<Value> value) -> unsigned char {
                   return static_cast<unsigned char>(Nan::To<int32_t>(value).FromMaybe(0));
                 }
                );
              }
              else
              {
                return dynamic_cast<::Platform::Array<unsigned char>^>(NodeRT::Utils::GetObjectInstance(value));
              }
            } (info[1]);
          
          ::Windows::Devices::Sms::SmsTextMessage^ result;
          result = ::Windows::Devices::Sms::SmsTextMessage::FromBinaryData(arg0, arg1);
          info.GetReturnValue().Set(WrapSmsTextMessage(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::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->To = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void FromGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->From;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FromSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->From = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void EncodingGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsEncoding result = wrapper->_instance->Encoding;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void EncodingSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::SmsEncoding winRtValue = static_cast<::Windows::Devices::Sms::SmsEncoding>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->Encoding = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BodySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->Body = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void PartCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->PartCount;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PartNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->PartNumber;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PartReferenceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->PartReferenceId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        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::Devices::Sms::SmsTextMessage^>(info.This()))
      {
        return;
      }

      SmsTextMessage *wrapper = SmsTextMessage::Unwrap<SmsTextMessage>(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::Devices::Sms::SmsTextMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsTextMessage(::Windows::Devices::Sms::SmsTextMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsTextMessage^ UnwrapSmsTextMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsTextMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsTextMessage(::Windows::Devices::Sms::SmsTextMessage^ 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>(SmsTextMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsTextMessage^ UnwrapSmsTextMessage(Local<Value> value)
  {
     return SmsTextMessage::Unwrap<SmsTextMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsTextMessage(Local<Object> exports)
  {
    SmsTextMessage::Init(exports);
  }

  class DeleteSmsMessageOperation : 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>("DeleteSmsMessageOperation").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getResults", GetResults);
      Nan::SetPrototypeMethod(localRef, "cancel", Cancel);
      Nan::SetPrototypeMethod(localRef, "close", Close);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorCode").ToLocalChecked(), ErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("completed").ToLocalChecked(), CompletedGetter, CompletedSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("DeleteSmsMessageOperation").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    DeleteSmsMessageOperation(::Windows::Devices::Sms::DeleteSmsMessageOperation^ 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::Devices::Sms::DeleteSmsMessageOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::DeleteSmsMessageOperation^) 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());

      DeleteSmsMessageOperation *wrapperInstance = new DeleteSmsMessageOperation(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::Devices::Sms::DeleteSmsMessageOperation^>(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::Devices::Sms::DeleteSmsMessageOperation^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::DeleteSmsMessageOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapDeleteSmsMessageOperation(winRtInstance));
    }


  
    static void GetResults(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->GetResults();
          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 Cancel(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Cancel();
          return;   
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Close(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Close();
          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 ErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::HResult result = wrapper->_instance->ErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result.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::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncActionCompletedHandler^ result = wrapper->_instance->Completed;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncActionCompletedHandler", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncActionCompletedHandler^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessageOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessageOperation *wrapper = DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncActionCompletedHandler^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncActionCompletedHandler^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Completed = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::DeleteSmsMessageOperation^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapDeleteSmsMessageOperation(::Windows::Devices::Sms::DeleteSmsMessageOperation^ wintRtInstance);
    friend ::Windows::Devices::Sms::DeleteSmsMessageOperation^ UnwrapDeleteSmsMessageOperation(Local<Value> value);
  };
  Persistent<FunctionTemplate> DeleteSmsMessageOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapDeleteSmsMessageOperation(::Windows::Devices::Sms::DeleteSmsMessageOperation^ 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>(DeleteSmsMessageOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::DeleteSmsMessageOperation^ UnwrapDeleteSmsMessageOperation(Local<Value> value)
  {
     return DeleteSmsMessageOperation::Unwrap<DeleteSmsMessageOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDeleteSmsMessageOperation(Local<Object> exports)
  {
    DeleteSmsMessageOperation::Init(exports);
  }

  class DeleteSmsMessagesOperation : 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>("DeleteSmsMessagesOperation").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getResults", GetResults);
      Nan::SetPrototypeMethod(localRef, "cancel", Cancel);
      Nan::SetPrototypeMethod(localRef, "close", Close);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorCode").ToLocalChecked(), ErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("completed").ToLocalChecked(), CompletedGetter, CompletedSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("DeleteSmsMessagesOperation").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    DeleteSmsMessagesOperation(::Windows::Devices::Sms::DeleteSmsMessagesOperation^ 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::Devices::Sms::DeleteSmsMessagesOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::DeleteSmsMessagesOperation^) 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());

      DeleteSmsMessagesOperation *wrapperInstance = new DeleteSmsMessagesOperation(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::Devices::Sms::DeleteSmsMessagesOperation^>(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::Devices::Sms::DeleteSmsMessagesOperation^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::DeleteSmsMessagesOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapDeleteSmsMessagesOperation(winRtInstance));
    }


  
    static void GetResults(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->GetResults();
          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 Cancel(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Cancel();
          return;   
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Close(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Close();
          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 ErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::HResult result = wrapper->_instance->ErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result.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::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncActionCompletedHandler^ result = wrapper->_instance->Completed;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncActionCompletedHandler", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncActionCompletedHandler^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::DeleteSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      DeleteSmsMessagesOperation *wrapper = DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncActionCompletedHandler^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncActionCompletedHandler^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Completed = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::DeleteSmsMessagesOperation^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapDeleteSmsMessagesOperation(::Windows::Devices::Sms::DeleteSmsMessagesOperation^ wintRtInstance);
    friend ::Windows::Devices::Sms::DeleteSmsMessagesOperation^ UnwrapDeleteSmsMessagesOperation(Local<Value> value);
  };
  Persistent<FunctionTemplate> DeleteSmsMessagesOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapDeleteSmsMessagesOperation(::Windows::Devices::Sms::DeleteSmsMessagesOperation^ 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>(DeleteSmsMessagesOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::DeleteSmsMessagesOperation^ UnwrapDeleteSmsMessagesOperation(Local<Value> value)
  {
     return DeleteSmsMessagesOperation::Unwrap<DeleteSmsMessagesOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitDeleteSmsMessagesOperation(Local<Object> exports)
  {
    DeleteSmsMessagesOperation::Init(exports);
  }

  class GetSmsMessageOperation : 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>("GetSmsMessageOperation").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getResults", GetResults);
      Nan::SetPrototypeMethod(localRef, "cancel", Cancel);
      Nan::SetPrototypeMethod(localRef, "close", Close);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorCode").ToLocalChecked(), ErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("completed").ToLocalChecked(), CompletedGetter, CompletedSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("GetSmsMessageOperation").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    GetSmsMessageOperation(::Windows::Devices::Sms::GetSmsMessageOperation^ 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::Devices::Sms::GetSmsMessageOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::GetSmsMessageOperation^) 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());

      GetSmsMessageOperation *wrapperInstance = new GetSmsMessageOperation(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::Devices::Sms::GetSmsMessageOperation^>(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::Devices::Sms::GetSmsMessageOperation^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::GetSmsMessageOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapGetSmsMessageOperation(winRtInstance));
    }


  
    static void GetResults(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Devices::Sms::ISmsMessage^ result;
          result = wrapper->_instance->GetResults();
          info.GetReturnValue().Set(WrapISmsMessage(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 Cancel(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Cancel();
          return;   
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Close(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Close();
          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 ErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::HResult result = wrapper->_instance->ErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result.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::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::ISmsMessage^>^ result = wrapper->_instance->Completed;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncOperationCompletedHandler`1", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::ISmsMessage^>^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessageOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessageOperation *wrapper = GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::ISmsMessage^>^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::ISmsMessage^>^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Completed = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::GetSmsMessageOperation^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapGetSmsMessageOperation(::Windows::Devices::Sms::GetSmsMessageOperation^ wintRtInstance);
    friend ::Windows::Devices::Sms::GetSmsMessageOperation^ UnwrapGetSmsMessageOperation(Local<Value> value);
  };
  Persistent<FunctionTemplate> GetSmsMessageOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapGetSmsMessageOperation(::Windows::Devices::Sms::GetSmsMessageOperation^ 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>(GetSmsMessageOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::GetSmsMessageOperation^ UnwrapGetSmsMessageOperation(Local<Value> value)
  {
     return GetSmsMessageOperation::Unwrap<GetSmsMessageOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitGetSmsMessageOperation(Local<Object> exports)
  {
    GetSmsMessageOperation::Init(exports);
  }

  class GetSmsMessagesOperation : 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>("GetSmsMessagesOperation").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getResults", GetResults);
      Nan::SetPrototypeMethod(localRef, "cancel", Cancel);
      Nan::SetPrototypeMethod(localRef, "close", Close);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorCode").ToLocalChecked(), ErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("progress").ToLocalChecked(), ProgressGetter, ProgressSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("completed").ToLocalChecked(), CompletedGetter, CompletedSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("GetSmsMessagesOperation").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    GetSmsMessagesOperation(::Windows::Devices::Sms::GetSmsMessagesOperation^ 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::Devices::Sms::GetSmsMessagesOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::GetSmsMessagesOperation^) 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());

      GetSmsMessagesOperation *wrapperInstance = new GetSmsMessagesOperation(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::Devices::Sms::GetSmsMessagesOperation^>(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::Devices::Sms::GetSmsMessagesOperation^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::GetSmsMessagesOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapGetSmsMessagesOperation(winRtInstance));
    }


  
    static void GetResults(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^ result;
          result = wrapper->_instance->GetResults();
          info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Devices::Sms::ISmsMessage^>::CreateVectorViewWrapper(result, 
            [](::Windows::Devices::Sms::ISmsMessage^ val) -> Local<Value> {
              return WrapISmsMessage(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(value);
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::ISmsMessage^ {
              return UnwrapISmsMessage(value);
            }
          ));
          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 Cancel(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Cancel();
          return;   
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Close(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Close();
          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 ErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::HResult result = wrapper->_instance->ErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result.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::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ProgressGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncOperationProgressHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^ result = wrapper->_instance->Progress;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncOperationProgressHandler`2", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ProgressSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncOperationProgressHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncOperationProgressHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncOperationProgressHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Progress = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void CompletedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncOperationWithProgressCompletedHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^ result = wrapper->_instance->Completed;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncOperationWithProgressCompletedHandler`2", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncOperationWithProgressCompletedHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsMessagesOperation^>(info.This()))
      {
        return;
      }

      GetSmsMessagesOperation *wrapper = GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncOperationWithProgressCompletedHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncOperationWithProgressCompletedHandler<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Completed = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::GetSmsMessagesOperation^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapGetSmsMessagesOperation(::Windows::Devices::Sms::GetSmsMessagesOperation^ wintRtInstance);
    friend ::Windows::Devices::Sms::GetSmsMessagesOperation^ UnwrapGetSmsMessagesOperation(Local<Value> value);
  };
  Persistent<FunctionTemplate> GetSmsMessagesOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapGetSmsMessagesOperation(::Windows::Devices::Sms::GetSmsMessagesOperation^ 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>(GetSmsMessagesOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::GetSmsMessagesOperation^ UnwrapGetSmsMessagesOperation(Local<Value> value)
  {
     return GetSmsMessagesOperation::Unwrap<GetSmsMessagesOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitGetSmsMessagesOperation(Local<Object> exports)
  {
    GetSmsMessagesOperation::Init(exports);
  }

  class SmsDeviceMessageStore : 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>("SmsDeviceMessageStore").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
      Local<Function> func;
      Local<FunctionTemplate> funcTemplate;
                  
      Nan::SetPrototypeMethod(localRef, "deleteMessageAsync", DeleteMessageAsync);
      Nan::SetPrototypeMethod(localRef, "deleteMessagesAsync", DeleteMessagesAsync);
      Nan::SetPrototypeMethod(localRef, "getMessageAsync", GetMessageAsync);
      Nan::SetPrototypeMethod(localRef, "getMessagesAsync", GetMessagesAsync);
      
                  
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("maxMessages").ToLocalChecked(), MaxMessagesGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsDeviceMessageStore").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsDeviceMessageStore(::Windows::Devices::Sms::SmsDeviceMessageStore^ 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::Devices::Sms::SmsDeviceMessageStore^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDeviceMessageStore^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsDeviceMessageStore^) 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());

      SmsDeviceMessageStore *wrapperInstance = new SmsDeviceMessageStore(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::Devices::Sms::SmsDeviceMessageStore^>(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::Devices::Sms::SmsDeviceMessageStore^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsDeviceMessageStore^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsDeviceMessageStore(winRtInstance));
    }


    static void DeleteMessageAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDeviceMessageStore^>(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;
      }

      SmsDeviceMessageStore *wrapper = SmsDeviceMessageStore::Unwrap<SmsDeviceMessageStore>(info.This());

      ::Windows::Foundation::IAsyncAction^ op;
    

      if (info.Length() == 2
        && info[0]->IsUint32())
      {
        try
        {
          unsigned int arg0 = static_cast<unsigned int>(Nan::To<uint32_t>(info[0]).FromMaybe(0));
          
          op = wrapper->_instance->DeleteMessageAsync(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<void> t) 
      {	
        try
        {
          t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> args[] = {Undefined()};

		    
            invokeCallback(_countof(args), args);
          });
        }
        catch (Platform::Exception^ exception)
        {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
             
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);
        
            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }  		
      });
    }
    static void DeleteMessagesAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDeviceMessageStore^>(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;
      }

      SmsDeviceMessageStore *wrapper = SmsDeviceMessageStore::Unwrap<SmsDeviceMessageStore>(info.This());

      ::Windows::Foundation::IAsyncAction^ op;
    

      if (info.Length() == 2
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Devices::Sms::SmsMessageFilter arg0 = static_cast<::Windows::Devices::Sms::SmsMessageFilter>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          op = wrapper->_instance->DeleteMessagesAsync(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<void> t) 
      {	
        try
        {
          t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> args[] = {Undefined()};

		    
            invokeCallback(_countof(args), args);
          });
        }
        catch (Platform::Exception^ exception)
        {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
             
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);
        
            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }  		
      });
    }
    static void GetMessageAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDeviceMessageStore^>(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;
      }

      SmsDeviceMessageStore *wrapper = SmsDeviceMessageStore::Unwrap<SmsDeviceMessageStore>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::Devices::Sms::ISmsMessage^>^ op;
    

      if (info.Length() == 2
        && info[0]->IsUint32())
      {
        try
        {
          unsigned int arg0 = static_cast<unsigned int>(Nan::To<uint32_t>(info[0]).FromMaybe(0));
          
          op = wrapper->_instance->GetMessageAsync(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::Devices::Sms::ISmsMessage^> t) 
      {	
        try
        {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            TryCatch tryCatch;
            Local<Value> error; 
            Local<Value> arg1 = WrapISmsMessage(result);
            if (tryCatch.HasCaught())
            {
              error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
            }
            else 
            {
              error = Undefined();
            }
            if (arg1.IsEmpty()) arg1 = Undefined();
            Local<Value> args[] = {error, arg1};
			// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
			// can be fixed by wrapping the conversion code in a function and calling it on the fly
			// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
			tryCatch.~TryCatch();

		    
            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 GetMessagesAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDeviceMessageStore^>(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;
      }

      SmsDeviceMessageStore *wrapper = SmsDeviceMessageStore::Unwrap<SmsDeviceMessageStore>(info.This());

      ::Windows::Foundation::IAsyncOperationWithProgress<::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^, int>^ op;
    

      if (info.Length() == 2
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Devices::Sms::SmsMessageFilter arg0 = static_cast<::Windows::Devices::Sms::SmsMessageFilter>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          op = wrapper->_instance->GetMessagesAsync(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::Foundation::Collections::IVectorView<::Windows::Devices::Sms::ISmsMessage^>^> t) 
      {	
        try
        {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            TryCatch tryCatch;
            Local<Value> error; 
            Local<Value> arg1 = NodeRT::Collections::VectorViewWrapper<::Windows::Devices::Sms::ISmsMessage^>::CreateVectorViewWrapper(result, 
            [](::Windows::Devices::Sms::ISmsMessage^ val) -> Local<Value> {
              return WrapISmsMessage(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(value);
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::ISmsMessage^ {
              return UnwrapISmsMessage(value);
            }
          );
            if (tryCatch.HasCaught())
            {
              error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
            }
            else 
            {
              error = Undefined();
            }
            if (arg1.IsEmpty()) arg1 = Undefined();
            Local<Value> args[] = {error, arg1};
			// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
			// can be fixed by wrapping the conversion code in a function and calling it on the fly
			// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
			tryCatch.~TryCatch();

		    
            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 MaxMessagesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDeviceMessageStore^>(info.This()))
      {
        return;
      }

      SmsDeviceMessageStore *wrapper = SmsDeviceMessageStore::Unwrap<SmsDeviceMessageStore>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->MaxMessages;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsDeviceMessageStore^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsDeviceMessageStore(::Windows::Devices::Sms::SmsDeviceMessageStore^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsDeviceMessageStore^ UnwrapSmsDeviceMessageStore(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsDeviceMessageStore::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsDeviceMessageStore(::Windows::Devices::Sms::SmsDeviceMessageStore^ 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>(SmsDeviceMessageStore::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsDeviceMessageStore^ UnwrapSmsDeviceMessageStore(Local<Value> value)
  {
     return SmsDeviceMessageStore::Unwrap<SmsDeviceMessageStore>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsDeviceMessageStore(Local<Object> exports)
  {
    SmsDeviceMessageStore::Init(exports);
  }

  class SendSmsMessageOperation : 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>("SendSmsMessageOperation").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getResults", GetResults);
      Nan::SetPrototypeMethod(localRef, "cancel", Cancel);
      Nan::SetPrototypeMethod(localRef, "close", Close);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorCode").ToLocalChecked(), ErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("completed").ToLocalChecked(), CompletedGetter, CompletedSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SendSmsMessageOperation").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SendSmsMessageOperation(::Windows::Devices::Sms::SendSmsMessageOperation^ 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::Devices::Sms::SendSmsMessageOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SendSmsMessageOperation^) 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());

      SendSmsMessageOperation *wrapperInstance = new SendSmsMessageOperation(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::Devices::Sms::SendSmsMessageOperation^>(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::Devices::Sms::SendSmsMessageOperation^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SendSmsMessageOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSendSmsMessageOperation(winRtInstance));
    }


  
    static void GetResults(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->GetResults();
          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 Cancel(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Cancel();
          return;   
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Close(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Close();
          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 ErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::HResult result = wrapper->_instance->ErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result.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::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncActionCompletedHandler^ result = wrapper->_instance->Completed;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncActionCompletedHandler", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncActionCompletedHandler^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SendSmsMessageOperation^>(info.This()))
      {
        return;
      }

      SendSmsMessageOperation *wrapper = SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncActionCompletedHandler^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncActionCompletedHandler^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Completed = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::SendSmsMessageOperation^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSendSmsMessageOperation(::Windows::Devices::Sms::SendSmsMessageOperation^ wintRtInstance);
    friend ::Windows::Devices::Sms::SendSmsMessageOperation^ UnwrapSendSmsMessageOperation(Local<Value> value);
  };
  Persistent<FunctionTemplate> SendSmsMessageOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapSendSmsMessageOperation(::Windows::Devices::Sms::SendSmsMessageOperation^ 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>(SendSmsMessageOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SendSmsMessageOperation^ UnwrapSendSmsMessageOperation(Local<Value> value)
  {
     return SendSmsMessageOperation::Unwrap<SendSmsMessageOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSendSmsMessageOperation(Local<Object> exports)
  {
    SendSmsMessageOperation::Init(exports);
  }

  class SmsMessageReceivedEventArgs : 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>("SmsMessageReceivedEventArgs").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("binaryMessage").ToLocalChecked(), BinaryMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("textMessage").ToLocalChecked(), TextMessageGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsMessageReceivedEventArgs").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsMessageReceivedEventArgs(::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ 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::Devices::Sms::SmsMessageReceivedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedEventArgs^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsMessageReceivedEventArgs^) 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());

      SmsMessageReceivedEventArgs *wrapperInstance = new SmsMessageReceivedEventArgs(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::Devices::Sms::SmsMessageReceivedEventArgs^>(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::Devices::Sms::SmsMessageReceivedEventArgs^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsMessageReceivedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsMessageReceivedEventArgs(winRtInstance));
    }


  



    static void BinaryMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedEventArgs^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedEventArgs *wrapper = SmsMessageReceivedEventArgs::Unwrap<SmsMessageReceivedEventArgs>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsBinaryMessage^ result = wrapper->_instance->BinaryMessage;
        info.GetReturnValue().Set(WrapSmsBinaryMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void TextMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedEventArgs^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedEventArgs *wrapper = SmsMessageReceivedEventArgs::Unwrap<SmsMessageReceivedEventArgs>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsTextMessage^ result = wrapper->_instance->TextMessage;
        info.GetReturnValue().Set(WrapSmsTextMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsMessageReceivedEventArgs(::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ UnwrapSmsMessageReceivedEventArgs(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsMessageReceivedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsMessageReceivedEventArgs(::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ 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>(SmsMessageReceivedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ UnwrapSmsMessageReceivedEventArgs(Local<Value> value)
  {
     return SmsMessageReceivedEventArgs::Unwrap<SmsMessageReceivedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsMessageReceivedEventArgs(Local<Object> exports)
  {
    SmsMessageReceivedEventArgs::Init(exports);
  }

  class SmsDevice : 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>("SmsDevice").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
      Local<Function> func;
      Local<FunctionTemplate> funcTemplate;
            
      Nan::SetPrototypeMethod(localRef, "calculateLength", CalculateLength);
      
            
      Nan::SetPrototypeMethod(localRef, "sendMessageAsync", SendMessageAsync);
      
            
      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>("accountPhoneNumber").ToLocalChecked(), AccountPhoneNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceStatus").ToLocalChecked(), DeviceStatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageStore").ToLocalChecked(), MessageStoreGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);

      Nan::SetMethod(constructor, "getDeviceSelector", GetDeviceSelector);
      func = Nan::GetFunction(Nan::New<FunctionTemplate>(FromNetworkAccountIdAsync)).ToLocalChecked();
      Nan::Set(constructor, Nan::New<String>("fromNetworkAccountIdAsync").ToLocalChecked(), func);
      func = Nan::GetFunction(Nan::New<FunctionTemplate>(FromIdAsync)).ToLocalChecked();
      Nan::Set(constructor, Nan::New<String>("fromIdAsync").ToLocalChecked(), func);
      func = Nan::GetFunction(Nan::New<FunctionTemplate>(GetDefaultAsync)).ToLocalChecked();
      Nan::Set(constructor, Nan::New<String>("getDefaultAsync").ToLocalChecked(), func);

      Nan::Set(exports, Nan::New<String>("SmsDevice").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsDevice(::Windows::Devices::Sms::SmsDevice^ 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::Devices::Sms::SmsDevice^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsDevice^) 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());

      SmsDevice *wrapperInstance = new SmsDevice(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::Devices::Sms::SmsDevice^>(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::Devices::Sms::SmsDevice^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsDevice^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsDevice(winRtInstance));
    }


    static void SendMessageAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(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;
      }

      SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());

      ::Windows::Devices::Sms::SendSmsMessageOperation^ op;
    

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::ISmsMessage^ arg0 = UnwrapISmsMessage(info[0]);
          
          op = wrapper->_instance->SendMessageAsync(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<void> t) 
      {	
        try
        {
          t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> args[] = {Undefined()};

		    
            invokeCallback(_countof(args), args);
          });
        }
        catch (Platform::Exception^ exception)
        {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
             
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);
        
            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }  		
      });
    }
  
    static void CalculateLength(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(info.This()))
      {
        return;
      }

      SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::SmsTextMessage^ arg0 = UnwrapSmsTextMessage(info[0]);
          
          ::Windows::Devices::Sms::SmsEncodedLength result;
          result = wrapper->_instance->CalculateLength(arg0);
          info.GetReturnValue().Set(SmsEncodedLengthToJsObject(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 FromNetworkAccountIdAsync(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::Devices::Sms::SmsDevice^>^ op;
      

      if (info.Length() == 2
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(info[0])));
          
          op = ::Windows::Devices::Sms::SmsDevice::FromNetworkAccountIdAsync(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::Devices::Sms::SmsDevice^> t) 
      {	
        try
        {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {

            
            TryCatch tryCatch;
            Local<Value> error; 
            Local<Value> arg1 = WrapSmsDevice(result);
            if (tryCatch.HasCaught())
            {
              error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
            }
            else 
            {
              error = Undefined();
            }
            if (arg1.IsEmpty()) arg1 = Undefined();
            Local<Value> args[] = {error, arg1};
			// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
			// can be fixed by wrapping the conversion code in a function and calling it on the fly
			// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
			tryCatch.~TryCatch();

	  	    
            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 FromIdAsync(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::Devices::Sms::SmsDevice^>^ op;
      

      if (info.Length() == 2
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(info[0])));
          
          op = ::Windows::Devices::Sms::SmsDevice::FromIdAsync(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::Devices::Sms::SmsDevice^> t) 
      {	
        try
        {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {

            
            TryCatch tryCatch;
            Local<Value> error; 
            Local<Value> arg1 = WrapSmsDevice(result);
            if (tryCatch.HasCaught())
            {
              error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
            }
            else 
            {
              error = Undefined();
            }
            if (arg1.IsEmpty()) arg1 = Undefined();
            Local<Value> args[] = {error, arg1};
			// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
			// can be fixed by wrapping the conversion code in a function and calling it on the fly
			// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
			tryCatch.~TryCatch();

	  	    
            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 GetDefaultAsync(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::Devices::Sms::SmsDevice^>^ op;
      

      if (info.Length() == 1)
      {
        try
        {
          op = ::Windows::Devices::Sms::SmsDevice::GetDefaultAsync();
        }
        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::Devices::Sms::SmsDevice^> t) 
      {	
        try
        {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {

            
            TryCatch tryCatch;
            Local<Value> error; 
            Local<Value> arg1 = WrapSmsDevice(result);
            if (tryCatch.HasCaught())
            {
              error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
            }
            else 
            {
              error = Undefined();
            }
            if (arg1.IsEmpty()) arg1 = Undefined();
            Local<Value> args[] = {error, arg1};
			// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
			// can be fixed by wrapping the conversion code in a function and calling it on the fly
			// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
			tryCatch.~TryCatch();

	  	    
            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 GetDeviceSelector(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() == 0)
      {
        try
        {
          Platform::String^ result;
          result = ::Windows::Devices::Sms::SmsDevice::GetDeviceSelector();
          info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void AccountPhoneNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(info.This()))
      {
        return;
      }

      SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->AccountPhoneNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(info.This()))
      {
        return;
      }

      SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceStatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(info.This()))
      {
        return;
      }

      SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDeviceStatus result = wrapper->_instance->DeviceStatus;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageStoreGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(info.This()))
      {
        return;
      }

      SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDeviceMessageStore^ result = wrapper->_instance->MessageStore;
        info.GetReturnValue().Set(WrapSmsDeviceMessageStore(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
		return;
      }

      String::Value eventName(info[0]);
      auto str = *eventName;
      
      Local<Function> callback = info[1].As<Function>();
      
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"smsDeviceStatusChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(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;
        }
        SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(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->SmsDeviceStatusChanged::add(
            ref new ::Windows::Devices::Sms::SmsDeviceStatusChangedEventHandler(
            [callbackObjPtr](::Windows::Devices::Sms::SmsDevice^ arg0) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0]() {
           	    HandleScope scope;
                TryCatch tryCatch;
              
                Local<Value> error;

                Local<Value> wrappedArg0 = WrapSmsDevice(arg0);

                if (tryCatch.HasCaught())
                {
                  error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
                }
                else 
                {
                  error = Undefined();
                }

				// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
				// can be fixed by wrapping the conversion code in a function and calling it on the fly
				// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
				tryCatch.~TryCatch();


                if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();

                Local<Value> args[] = { wrappedArg0 };
                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"smsMessageReceived", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(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;
        }
        SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(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->SmsMessageReceived::add(
            ref new ::Windows::Devices::Sms::SmsMessageReceivedEventHandler(
            [callbackObjPtr](::Windows::Devices::Sms::SmsDevice^ arg0, ::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
           	    HandleScope scope;
                TryCatch tryCatch;
              
                Local<Value> error;

                Local<Value> wrappedArg0 = WrapSmsDevice(arg0);
                Local<Value> wrappedArg1 = WrapSmsMessageReceivedEventArgs(arg1);

                if (tryCatch.HasCaught())
                {
                  error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
                }
                else 
                {
                  error = Undefined();
                }

				// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
				// can be fixed by wrapping the conversion code in a function and calling it on the fly
				// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
				tryCatch.~TryCatch();


                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(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(info[0]);
      auto str = *eventName;

      if ((NodeRT::Utils::CaseInsenstiveEquals(L"smsDeviceStatusChanged", str)) &&(NodeRT::Utils::CaseInsenstiveEquals(L"smsMessageReceived", str)))
      {
        Nan::ThrowError(Nan::Error(String::Concat(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"smsDeviceStatusChanged", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(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;
          }
          SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());
          wrapper->_instance->SmsDeviceStatusChanged::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"smsMessageReceived", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice^>(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;
          }
          SmsDevice *wrapper = SmsDevice::Unwrap<SmsDevice>(info.This());
          wrapper->_instance->SmsMessageReceived::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::Devices::Sms::SmsDevice^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsDevice(::Windows::Devices::Sms::SmsDevice^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsDevice^ UnwrapSmsDevice(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsDevice::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsDevice(::Windows::Devices::Sms::SmsDevice^ 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>(SmsDevice::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsDevice^ UnwrapSmsDevice(Local<Value> value)
  {
     return SmsDevice::Unwrap<SmsDevice>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsDevice(Local<Object> exports)
  {
    SmsDevice::Init(exports);
  }

  class GetSmsDeviceOperation : 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>("GetSmsDeviceOperation").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "getResults", GetResults);
      Nan::SetPrototypeMethod(localRef, "cancel", Cancel);
      Nan::SetPrototypeMethod(localRef, "close", Close);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("errorCode").ToLocalChecked(), ErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("id").ToLocalChecked(), IdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("completed").ToLocalChecked(), CompletedGetter, CompletedSetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("GetSmsDeviceOperation").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    GetSmsDeviceOperation(::Windows::Devices::Sms::GetSmsDeviceOperation^ 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::Devices::Sms::GetSmsDeviceOperation^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::GetSmsDeviceOperation^) 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());

      GetSmsDeviceOperation *wrapperInstance = new GetSmsDeviceOperation(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::Devices::Sms::GetSmsDeviceOperation^>(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::Devices::Sms::GetSmsDeviceOperation^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::GetSmsDeviceOperation^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapGetSmsDeviceOperation(winRtInstance));
    }


  
    static void GetResults(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Devices::Sms::SmsDevice^ result;
          result = wrapper->_instance->GetResults();
          info.GetReturnValue().Set(WrapSmsDevice(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 Cancel(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Cancel();
          return;   
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void Close(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Close();
          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 ErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      try 
      {
        ::Windows::Foundation::HResult result = wrapper->_instance->ErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result.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::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->Id;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncStatus result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      try 
      {
        ::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::SmsDevice^>^ result = wrapper->_instance->Completed;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "AsyncOperationCompletedHandler`1", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CompletedSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::SmsDevice^>^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::GetSmsDeviceOperation^>(info.This()))
      {
        return;
      }

      GetSmsDeviceOperation *wrapper = GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(info.This());

      try 
      {
        
        ::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::SmsDevice^>^ winRtValue = dynamic_cast<::Windows::Foundation::AsyncOperationCompletedHandler<::Windows::Devices::Sms::SmsDevice^>^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Completed = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    


  private:
    ::Windows::Devices::Sms::GetSmsDeviceOperation^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapGetSmsDeviceOperation(::Windows::Devices::Sms::GetSmsDeviceOperation^ wintRtInstance);
    friend ::Windows::Devices::Sms::GetSmsDeviceOperation^ UnwrapGetSmsDeviceOperation(Local<Value> value);
  };
  Persistent<FunctionTemplate> GetSmsDeviceOperation::s_constructorTemplate;

  v8::Local<v8::Value> WrapGetSmsDeviceOperation(::Windows::Devices::Sms::GetSmsDeviceOperation^ 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>(GetSmsDeviceOperation::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::GetSmsDeviceOperation^ UnwrapGetSmsDeviceOperation(Local<Value> value)
  {
     return GetSmsDeviceOperation::Unwrap<GetSmsDeviceOperation>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitGetSmsDeviceOperation(Local<Object> exports)
  {
    GetSmsDeviceOperation::Init(exports);
  }

  class ISmsDevice : 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>("ISmsDevice").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
      Local<Function> func;
      Local<FunctionTemplate> funcTemplate;
            
      Nan::SetPrototypeMethod(localRef, "calculateLength", CalculateLength);
      
            
      Nan::SetPrototypeMethod(localRef, "sendMessageAsync", SendMessageAsync);
      
            
      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>("accountPhoneNumber").ToLocalChecked(), AccountPhoneNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceStatus").ToLocalChecked(), DeviceStatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageStore").ToLocalChecked(), MessageStoreGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("ISmsDevice").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    ISmsDevice(::Windows::Devices::Sms::ISmsDevice^ 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::Devices::Sms::ISmsDevice^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::ISmsDevice^) 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());

      ISmsDevice *wrapperInstance = new ISmsDevice(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::Devices::Sms::ISmsDevice^>(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::Devices::Sms::ISmsDevice^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::ISmsDevice^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapISmsDevice(winRtInstance));
    }


    static void SendMessageAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(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;
      }

      ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());

      ::Windows::Devices::Sms::SendSmsMessageOperation^ op;
    

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessage^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::ISmsMessage^ arg0 = UnwrapISmsMessage(info[0]);
          
          op = wrapper->_instance->SendMessageAsync(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<void> t) 
      {	
        try
        {
          t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> args[] = {Undefined()};

		    
            invokeCallback(_countof(args), args);
          });
        }
        catch (Platform::Exception^ exception)
        {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {
             
            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);
        
            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }  		
      });
    }
  
    static void CalculateLength(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(info.This()))
      {
        return;
      }

      ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::SmsTextMessage^ arg0 = UnwrapSmsTextMessage(info[0]);
          
          ::Windows::Devices::Sms::SmsEncodedLength result;
          result = wrapper->_instance->CalculateLength(arg0);
          info.GetReturnValue().Set(SmsEncodedLengthToJsObject(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 AccountPhoneNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(info.This()))
      {
        return;
      }

      ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->AccountPhoneNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(info.This()))
      {
        return;
      }

      ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceStatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(info.This()))
      {
        return;
      }

      ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDeviceStatus result = wrapper->_instance->DeviceStatus;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageStoreGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(info.This()))
      {
        return;
      }

      ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDeviceMessageStore^ result = wrapper->_instance->MessageStore;
        info.GetReturnValue().Set(WrapSmsDeviceMessageStore(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
		return;
      }

      String::Value eventName(info[0]);
      auto str = *eventName;
      
      Local<Function> callback = info[1].As<Function>();
      
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"smsDeviceStatusChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(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;
        }
        ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(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->SmsDeviceStatusChanged::add(
            ref new ::Windows::Devices::Sms::SmsDeviceStatusChangedEventHandler(
            [callbackObjPtr](::Windows::Devices::Sms::SmsDevice^ arg0) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0]() {
           	    HandleScope scope;
                TryCatch tryCatch;
              
                Local<Value> error;

                Local<Value> wrappedArg0 = WrapSmsDevice(arg0);

                if (tryCatch.HasCaught())
                {
                  error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
                }
                else 
                {
                  error = Undefined();
                }

				// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
				// can be fixed by wrapping the conversion code in a function and calling it on the fly
				// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
				tryCatch.~TryCatch();


                if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();

                Local<Value> args[] = { wrappedArg0 };
                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"smsMessageReceived", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(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;
        }
        ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(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->SmsMessageReceived::add(
            ref new ::Windows::Devices::Sms::SmsMessageReceivedEventHandler(
            [callbackObjPtr](::Windows::Devices::Sms::SmsDevice^ arg0, ::Windows::Devices::Sms::SmsMessageReceivedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
           	    HandleScope scope;
                TryCatch tryCatch;
              
                Local<Value> error;

                Local<Value> wrappedArg0 = WrapSmsDevice(arg0);
                Local<Value> wrappedArg1 = WrapSmsMessageReceivedEventArgs(arg1);

                if (tryCatch.HasCaught())
                {
                  error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
                }
                else 
                {
                  error = Undefined();
                }

				// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
				// can be fixed by wrapping the conversion code in a function and calling it on the fly
				// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
				tryCatch.~TryCatch();


                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(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(info[0]);
      auto str = *eventName;

      if ((NodeRT::Utils::CaseInsenstiveEquals(L"smsDeviceStatusChanged", str)) &&(NodeRT::Utils::CaseInsenstiveEquals(L"smsMessageReceived", str)))
      {
        Nan::ThrowError(Nan::Error(String::Concat(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"smsDeviceStatusChanged", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(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;
          }
          ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());
          wrapper->_instance->SmsDeviceStatusChanged::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"smsMessageReceived", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsDevice^>(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;
          }
          ISmsDevice *wrapper = ISmsDevice::Unwrap<ISmsDevice>(info.This());
          wrapper->_instance->SmsMessageReceived::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::Devices::Sms::ISmsDevice^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapISmsDevice(::Windows::Devices::Sms::ISmsDevice^ wintRtInstance);
    friend ::Windows::Devices::Sms::ISmsDevice^ UnwrapISmsDevice(Local<Value> value);
  };
  Persistent<FunctionTemplate> ISmsDevice::s_constructorTemplate;

  v8::Local<v8::Value> WrapISmsDevice(::Windows::Devices::Sms::ISmsDevice^ 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>(ISmsDevice::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::ISmsDevice^ UnwrapISmsDevice(Local<Value> value)
  {
     return ISmsDevice::Unwrap<ISmsDevice>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitISmsDevice(Local<Object> exports)
  {
    ISmsDevice::Init(exports);
  }

  class SmsReceivedEventDetails : 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>("SmsReceivedEventDetails").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageIndex").ToLocalChecked(), MessageIndexGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("binaryMessage").ToLocalChecked(), BinaryMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsReceivedEventDetails").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsReceivedEventDetails(::Windows::Devices::Sms::SmsReceivedEventDetails^ 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::Devices::Sms::SmsReceivedEventDetails^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsReceivedEventDetails^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsReceivedEventDetails^) 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());

      SmsReceivedEventDetails *wrapperInstance = new SmsReceivedEventDetails(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::Devices::Sms::SmsReceivedEventDetails^>(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::Devices::Sms::SmsReceivedEventDetails^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsReceivedEventDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsReceivedEventDetails(winRtInstance));
    }


  



    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsReceivedEventDetails^>(info.This()))
      {
        return;
      }

      SmsReceivedEventDetails *wrapper = SmsReceivedEventDetails::Unwrap<SmsReceivedEventDetails>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageIndexGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsReceivedEventDetails^>(info.This()))
      {
        return;
      }

      SmsReceivedEventDetails *wrapper = SmsReceivedEventDetails::Unwrap<SmsReceivedEventDetails>(info.This());

      try 
      {
        unsigned int result = wrapper->_instance->MessageIndex;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BinaryMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsReceivedEventDetails^>(info.This()))
      {
        return;
      }

      SmsReceivedEventDetails *wrapper = SmsReceivedEventDetails::Unwrap<SmsReceivedEventDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsBinaryMessage^ result = wrapper->_instance->BinaryMessage;
        info.GetReturnValue().Set(WrapSmsBinaryMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsReceivedEventDetails^>(info.This()))
      {
        return;
      }

      SmsReceivedEventDetails *wrapper = SmsReceivedEventDetails::Unwrap<SmsReceivedEventDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsReceivedEventDetails^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsReceivedEventDetails(::Windows::Devices::Sms::SmsReceivedEventDetails^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsReceivedEventDetails^ UnwrapSmsReceivedEventDetails(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsReceivedEventDetails::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsReceivedEventDetails(::Windows::Devices::Sms::SmsReceivedEventDetails^ 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>(SmsReceivedEventDetails::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsReceivedEventDetails^ UnwrapSmsReceivedEventDetails(Local<Value> value)
  {
     return SmsReceivedEventDetails::Unwrap<SmsReceivedEventDetails>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsReceivedEventDetails(Local<Object> exports)
  {
    SmsReceivedEventDetails::Init(exports);
  }

  class ISmsMessageBase : 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>("ISmsMessageBase").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("ISmsMessageBase").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    ISmsMessageBase(::Windows::Devices::Sms::ISmsMessageBase^ 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::Devices::Sms::ISmsMessageBase^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::ISmsMessageBase^) 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());

      ISmsMessageBase *wrapperInstance = new ISmsMessageBase(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::Devices::Sms::ISmsMessageBase^>(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::Devices::Sms::ISmsMessageBase^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::ISmsMessageBase^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapISmsMessageBase(winRtInstance));
    }


  



    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info.This()))
      {
        return;
      }

      ISmsMessageBase *wrapper = ISmsMessageBase::Unwrap<ISmsMessageBase>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info.This()))
      {
        return;
      }

      ISmsMessageBase *wrapper = ISmsMessageBase::Unwrap<ISmsMessageBase>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info.This()))
      {
        return;
      }

      ISmsMessageBase *wrapper = ISmsMessageBase::Unwrap<ISmsMessageBase>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info.This()))
      {
        return;
      }

      ISmsMessageBase *wrapper = ISmsMessageBase::Unwrap<ISmsMessageBase>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info.This()))
      {
        return;
      }

      ISmsMessageBase *wrapper = ISmsMessageBase::Unwrap<ISmsMessageBase>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::ISmsMessageBase^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapISmsMessageBase(::Windows::Devices::Sms::ISmsMessageBase^ wintRtInstance);
    friend ::Windows::Devices::Sms::ISmsMessageBase^ UnwrapISmsMessageBase(Local<Value> value);
  };
  Persistent<FunctionTemplate> ISmsMessageBase::s_constructorTemplate;

  v8::Local<v8::Value> WrapISmsMessageBase(::Windows::Devices::Sms::ISmsMessageBase^ 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>(ISmsMessageBase::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::ISmsMessageBase^ UnwrapISmsMessageBase(Local<Value> value)
  {
     return ISmsMessageBase::Unwrap<ISmsMessageBase>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitISmsMessageBase(Local<Object> exports)
  {
    ISmsMessageBase::Init(exports);
  }

  class SmsTextMessage2 : 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>("SmsTextMessage2").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("retryAttemptCount").ToLocalChecked(), RetryAttemptCountGetter, RetryAttemptCountSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter, ToSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isDeliveryNotificationEnabled").ToLocalChecked(), IsDeliveryNotificationEnabledGetter, IsDeliveryNotificationEnabledSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("encoding").ToLocalChecked(), EncodingGetter, EncodingSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("callbackNumber").ToLocalChecked(), CallbackNumberGetter, CallbackNumberSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter, BodySetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("protocolId").ToLocalChecked(), ProtocolIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("from").ToLocalChecked(), FromGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("teleserviceId").ToLocalChecked(), TeleserviceIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsTextMessage2").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsTextMessage2(::Windows::Devices::Sms::SmsTextMessage2^ 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::Devices::Sms::SmsTextMessage2^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsTextMessage2^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 0)
      {
        try
        {
          winRtInstance = ref new ::Windows::Devices::Sms::SmsTextMessage2();
        }
        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());

      SmsTextMessage2 *wrapperInstance = new SmsTextMessage2(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::Devices::Sms::SmsTextMessage2^>(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::Devices::Sms::SmsTextMessage2^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsTextMessage2^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsTextMessage2(winRtInstance));
    }


  



    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void RetryAttemptCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        int result = wrapper->_instance->RetryAttemptCount;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void RetryAttemptCountSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        
        int winRtValue = static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->RetryAttemptCount = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->To = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void IsDeliveryNotificationEnabledGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        bool result = wrapper->_instance->IsDeliveryNotificationEnabled;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void IsDeliveryNotificationEnabledSetter(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::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        
        bool winRtValue = Nan::To<bool>(value).FromMaybe(false);

        wrapper->_instance->IsDeliveryNotificationEnabled = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void EncodingGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsEncoding result = wrapper->_instance->Encoding;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void EncodingSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::SmsEncoding winRtValue = static_cast<::Windows::Devices::Sms::SmsEncoding>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->Encoding = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void CallbackNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->CallbackNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CallbackNumberSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->CallbackNumber = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BodySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->Body = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void ProtocolIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        int result = wrapper->_instance->ProtocolId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FromGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->From;
        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::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(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;
      }
    }
    
    static void TeleserviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsTextMessage2^>(info.This()))
      {
        return;
      }

      SmsTextMessage2 *wrapper = SmsTextMessage2::Unwrap<SmsTextMessage2>(info.This());

      try 
      {
        int result = wrapper->_instance->TeleserviceId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsTextMessage2^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsTextMessage2(::Windows::Devices::Sms::SmsTextMessage2^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsTextMessage2^ UnwrapSmsTextMessage2(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsTextMessage2::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsTextMessage2(::Windows::Devices::Sms::SmsTextMessage2^ 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>(SmsTextMessage2::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsTextMessage2^ UnwrapSmsTextMessage2(Local<Value> value)
  {
     return SmsTextMessage2::Unwrap<SmsTextMessage2>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsTextMessage2(Local<Object> exports)
  {
    SmsTextMessage2::Init(exports);
  }

  class SmsWapMessage : 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>("SmsWapMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("applicationId").ToLocalChecked(), ApplicationIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("binaryBody").ToLocalChecked(), BinaryBodyGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("contentType").ToLocalChecked(), ContentTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("from").ToLocalChecked(), FromGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("headers").ToLocalChecked(), HeadersGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsWapMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsWapMessage(::Windows::Devices::Sms::SmsWapMessage^ 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::Devices::Sms::SmsWapMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsWapMessage^) 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());

      SmsWapMessage *wrapperInstance = new SmsWapMessage(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::Devices::Sms::SmsWapMessage^>(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::Devices::Sms::SmsWapMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsWapMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsWapMessage(winRtInstance));
    }


  



    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        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::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(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;
      }
    }
    
    static void ApplicationIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->ApplicationId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BinaryBodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        ::Windows::Storage::Streams::IBuffer^ result = wrapper->_instance->BinaryBody;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Storage.Streams", "IBuffer", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ContentTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->ContentType;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FromGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->From;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void HeadersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IMap<::Platform::String^, ::Platform::String^>^ result = wrapper->_instance->Headers;
        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(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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsWapMessage^>(info.This()))
      {
        return;
      }

      SmsWapMessage *wrapper = SmsWapMessage::Unwrap<SmsWapMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsWapMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsWapMessage(::Windows::Devices::Sms::SmsWapMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsWapMessage^ UnwrapSmsWapMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsWapMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsWapMessage(::Windows::Devices::Sms::SmsWapMessage^ 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>(SmsWapMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsWapMessage^ UnwrapSmsWapMessage(Local<Value> value)
  {
     return SmsWapMessage::Unwrap<SmsWapMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsWapMessage(Local<Object> exports)
  {
    SmsWapMessage::Init(exports);
  }

  class SmsAppMessage : 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>("SmsAppMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("protocolId").ToLocalChecked(), ProtocolIdGetter, ProtocolIdSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("portNumber").ToLocalChecked(), PortNumberGetter, PortNumberSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isDeliveryNotificationEnabled").ToLocalChecked(), IsDeliveryNotificationEnabledGetter, IsDeliveryNotificationEnabledSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("retryAttemptCount").ToLocalChecked(), RetryAttemptCountGetter, RetryAttemptCountSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("encoding").ToLocalChecked(), EncodingGetter, EncodingSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("callbackNumber").ToLocalChecked(), CallbackNumberGetter, CallbackNumberSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter, BodySetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("binaryBody").ToLocalChecked(), BinaryBodyGetter, BinaryBodySetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter, ToSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("teleserviceId").ToLocalChecked(), TeleserviceIdGetter, TeleserviceIdSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("from").ToLocalChecked(), FromGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsAppMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsAppMessage(::Windows::Devices::Sms::SmsAppMessage^ 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::Devices::Sms::SmsAppMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsAppMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 0)
      {
        try
        {
          winRtInstance = ref new ::Windows::Devices::Sms::SmsAppMessage();
        }
        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());

      SmsAppMessage *wrapperInstance = new SmsAppMessage(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::Devices::Sms::SmsAppMessage^>(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::Devices::Sms::SmsAppMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsAppMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsAppMessage(winRtInstance));
    }


  



    static void ProtocolIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->ProtocolId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ProtocolIdSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        int winRtValue = static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->ProtocolId = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void PortNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->PortNumber;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PortNumberSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        int winRtValue = static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->PortNumber = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void IsDeliveryNotificationEnabledGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        bool result = wrapper->_instance->IsDeliveryNotificationEnabled;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void IsDeliveryNotificationEnabledSetter(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::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        bool winRtValue = Nan::To<bool>(value).FromMaybe(false);

        wrapper->_instance->IsDeliveryNotificationEnabled = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void RetryAttemptCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->RetryAttemptCount;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void RetryAttemptCountSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        int winRtValue = static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->RetryAttemptCount = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void EncodingGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsEncoding result = wrapper->_instance->Encoding;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void EncodingSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::SmsEncoding winRtValue = static_cast<::Windows::Devices::Sms::SmsEncoding>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->Encoding = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void CallbackNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->CallbackNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CallbackNumberSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->CallbackNumber = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BodySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->Body = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void BinaryBodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        ::Windows::Storage::Streams::IBuffer^ result = wrapper->_instance->BinaryBody;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Storage.Streams", "IBuffer", result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BinaryBodySetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Storage::Streams::IBuffer^>(value))
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        ::Windows::Storage::Streams::IBuffer^ winRtValue = dynamic_cast<::Windows::Storage::Streams::IBuffer^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->BinaryBody = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->To = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void TeleserviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->TeleserviceId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void TeleserviceIdSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        
        int winRtValue = static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->TeleserviceId = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void FromGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->From;
        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::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(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;
      }
    }
    
    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsAppMessage^>(info.This()))
      {
        return;
      }

      SmsAppMessage *wrapper = SmsAppMessage::Unwrap<SmsAppMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsAppMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsAppMessage(::Windows::Devices::Sms::SmsAppMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsAppMessage^ UnwrapSmsAppMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsAppMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsAppMessage(::Windows::Devices::Sms::SmsAppMessage^ 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>(SmsAppMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsAppMessage^ UnwrapSmsAppMessage(Local<Value> value)
  {
     return SmsAppMessage::Unwrap<SmsAppMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsAppMessage(Local<Object> exports)
  {
    SmsAppMessage::Init(exports);
  }

  class SmsBroadcastMessage : 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>("SmsBroadcastMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("broadcastType").ToLocalChecked(), BroadcastTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("channel").ToLocalChecked(), ChannelGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("geographicalScope").ToLocalChecked(), GeographicalScopeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isEmergencyAlert").ToLocalChecked(), IsEmergencyAlertGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isUserPopupRequested").ToLocalChecked(), IsUserPopupRequestedGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageCode").ToLocalChecked(), MessageCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("updateNumber").ToLocalChecked(), UpdateNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsBroadcastMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsBroadcastMessage(::Windows::Devices::Sms::SmsBroadcastMessage^ 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::Devices::Sms::SmsBroadcastMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsBroadcastMessage^) 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());

      SmsBroadcastMessage *wrapperInstance = new SmsBroadcastMessage(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::Devices::Sms::SmsBroadcastMessage^>(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::Devices::Sms::SmsBroadcastMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsBroadcastMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsBroadcastMessage(winRtInstance));
    }


  



    static void BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BroadcastTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsBroadcastType result = wrapper->_instance->BroadcastType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ChannelGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->Channel;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void GeographicalScopeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsGeographicalScope result = wrapper->_instance->GeographicalScope;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void IsEmergencyAlertGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        bool result = wrapper->_instance->IsEmergencyAlert;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void IsUserPopupRequestedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        bool result = wrapper->_instance->IsUserPopupRequested;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->MessageCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        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::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(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;
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void UpdateNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->UpdateNumber;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsBroadcastMessage^>(info.This()))
      {
        return;
      }

      SmsBroadcastMessage *wrapper = SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsBroadcastMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsBroadcastMessage(::Windows::Devices::Sms::SmsBroadcastMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsBroadcastMessage^ UnwrapSmsBroadcastMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsBroadcastMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsBroadcastMessage(::Windows::Devices::Sms::SmsBroadcastMessage^ 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>(SmsBroadcastMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsBroadcastMessage^ UnwrapSmsBroadcastMessage(Local<Value> value)
  {
     return SmsBroadcastMessage::Unwrap<SmsBroadcastMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsBroadcastMessage(Local<Object> exports)
  {
    SmsBroadcastMessage::Init(exports);
  }

  class SmsVoicemailMessage : 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>("SmsVoicemailMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageCount").ToLocalChecked(), MessageCountGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timestamp").ToLocalChecked(), TimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsVoicemailMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsVoicemailMessage(::Windows::Devices::Sms::SmsVoicemailMessage^ 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::Devices::Sms::SmsVoicemailMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsVoicemailMessage^) 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());

      SmsVoicemailMessage *wrapperInstance = new SmsVoicemailMessage(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::Devices::Sms::SmsVoicemailMessage^>(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::Devices::Sms::SmsVoicemailMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsVoicemailMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsVoicemailMessage(winRtInstance));
    }


  



    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        ::Platform::IBox<int>^ result = wrapper->_instance->MessageCount;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Integer>(result->Value)) : Undefined());
        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::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(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;
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsVoicemailMessage^>(info.This()))
      {
        return;
      }

      SmsVoicemailMessage *wrapper = SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsVoicemailMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsVoicemailMessage(::Windows::Devices::Sms::SmsVoicemailMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsVoicemailMessage^ UnwrapSmsVoicemailMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsVoicemailMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsVoicemailMessage(::Windows::Devices::Sms::SmsVoicemailMessage^ 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>(SmsVoicemailMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsVoicemailMessage^ UnwrapSmsVoicemailMessage(Local<Value> value)
  {
     return SmsVoicemailMessage::Unwrap<SmsVoicemailMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsVoicemailMessage(Local<Object> exports)
  {
    SmsVoicemailMessage::Init(exports);
  }

  class SmsStatusMessage : 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>("SmsStatusMessage").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageClass").ToLocalChecked(), MessageClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("simIccId").ToLocalChecked(), SimIccIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("body").ToLocalChecked(), BodyGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("dischargeTime").ToLocalChecked(), DischargeTimeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("from").ToLocalChecked(), FromGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageReferenceNumber").ToLocalChecked(), MessageReferenceNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("serviceCenterTimestamp").ToLocalChecked(), ServiceCenterTimestampGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("to").ToLocalChecked(), ToGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsStatusMessage").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsStatusMessage(::Windows::Devices::Sms::SmsStatusMessage^ 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::Devices::Sms::SmsStatusMessage^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsStatusMessage^) 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());

      SmsStatusMessage *wrapperInstance = new SmsStatusMessage(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::Devices::Sms::SmsStatusMessage^>(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::Devices::Sms::SmsStatusMessage^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsStatusMessage^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsStatusMessage(winRtInstance));
    }


  



    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageClass result = wrapper->_instance->MessageClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SimIccIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SimIccId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->Status;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BodyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->Body;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DischargeTimeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        ::Windows::Foundation::DateTime result = wrapper->_instance->DischargeTime;
        info.GetReturnValue().Set(NodeRT::Utils::DateTimeToJS(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void FromGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->From;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageReferenceNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        int result = wrapper->_instance->MessageReferenceNumber;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ServiceCenterTimestampGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        ::Windows::Foundation::DateTime result = wrapper->_instance->ServiceCenterTimestamp;
        info.GetReturnValue().Set(NodeRT::Utils::DateTimeToJS(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ToGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsStatusMessage^>(info.This()))
      {
        return;
      }

      SmsStatusMessage *wrapper = SmsStatusMessage::Unwrap<SmsStatusMessage>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->To;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsStatusMessage^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsStatusMessage(::Windows::Devices::Sms::SmsStatusMessage^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsStatusMessage^ UnwrapSmsStatusMessage(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsStatusMessage::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsStatusMessage(::Windows::Devices::Sms::SmsStatusMessage^ 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>(SmsStatusMessage::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsStatusMessage^ UnwrapSmsStatusMessage(Local<Value> value)
  {
     return SmsStatusMessage::Unwrap<SmsStatusMessage>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsStatusMessage(Local<Object> exports)
  {
    SmsStatusMessage::Init(exports);
  }

  class SmsSendMessageResult : 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>("SmsSendMessageResult").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isErrorTransient").ToLocalChecked(), IsErrorTransientGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isSuccessful").ToLocalChecked(), IsSuccessfulGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageReferenceNumbers").ToLocalChecked(), MessageReferenceNumbersGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("modemErrorCode").ToLocalChecked(), ModemErrorCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("networkCauseCode").ToLocalChecked(), NetworkCauseCodeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("transportFailureCause").ToLocalChecked(), TransportFailureCauseGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsSendMessageResult").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsSendMessageResult(::Windows::Devices::Sms::SmsSendMessageResult^ 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::Devices::Sms::SmsSendMessageResult^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsSendMessageResult^) 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());

      SmsSendMessageResult *wrapperInstance = new SmsSendMessageResult(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::Devices::Sms::SmsSendMessageResult^>(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::Devices::Sms::SmsSendMessageResult^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsSendMessageResult^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsSendMessageResult(winRtInstance));
    }


  



    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void IsErrorTransientGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        bool result = wrapper->_instance->IsErrorTransient;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void IsSuccessfulGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        bool result = wrapper->_instance->IsSuccessful;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageReferenceNumbersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVectorView<int>^ result = wrapper->_instance->MessageReferenceNumbers;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<int>::CreateVectorViewWrapper(result, 
            [](int val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> int {
              return static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ModemErrorCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsModemErrorCode result = wrapper->_instance->ModemErrorCode;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void NetworkCauseCodeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        int result = wrapper->_instance->NetworkCauseCode;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void TransportFailureCauseGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsSendMessageResult^>(info.This()))
      {
        return;
      }

      SmsSendMessageResult *wrapper = SmsSendMessageResult::Unwrap<SmsSendMessageResult>(info.This());

      try 
      {
        int result = wrapper->_instance->TransportFailureCause;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsSendMessageResult^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsSendMessageResult(::Windows::Devices::Sms::SmsSendMessageResult^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsSendMessageResult^ UnwrapSmsSendMessageResult(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsSendMessageResult::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsSendMessageResult(::Windows::Devices::Sms::SmsSendMessageResult^ 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>(SmsSendMessageResult::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsSendMessageResult^ UnwrapSmsSendMessageResult(Local<Value> value)
  {
     return SmsSendMessageResult::Unwrap<SmsSendMessageResult>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsSendMessageResult(Local<Object> exports)
  {
    SmsSendMessageResult::Init(exports);
  }

  class SmsDevice2 : 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>("SmsDevice2").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
      Local<Function> func;
      Local<FunctionTemplate> funcTemplate;
            
      Nan::SetPrototypeMethod(localRef, "calculateLength", CalculateLength);
      
            
      Nan::SetPrototypeMethod(localRef, "sendMessageAndGetResultAsync", SendMessageAndGetResultAsync);
      
            
      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>("smscAddress").ToLocalChecked(), SmscAddressGetter, SmscAddressSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("accountPhoneNumber").ToLocalChecked(), AccountPhoneNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceId").ToLocalChecked(), DeviceIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceStatus").ToLocalChecked(), DeviceStatusGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("parentDeviceId").ToLocalChecked(), ParentDeviceIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);

      Nan::SetMethod(constructor, "getDeviceSelector", GetDeviceSelector);
      Nan::SetMethod(constructor, "fromId", FromId);
      Nan::SetMethod(constructor, "getDefault", GetDefault);
      Nan::SetMethod(constructor, "fromParentId", FromParentId);

      Nan::Set(exports, Nan::New<String>("SmsDevice2").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsDevice2(::Windows::Devices::Sms::SmsDevice2^ 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::Devices::Sms::SmsDevice2^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsDevice2^) 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());

      SmsDevice2 *wrapperInstance = new SmsDevice2(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::Devices::Sms::SmsDevice2^>(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::Devices::Sms::SmsDevice2^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsDevice2^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsDevice2(winRtInstance));
    }


    static void SendMessageAndGetResultAsync(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(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;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      ::Windows::Foundation::IAsyncOperation<::Windows::Devices::Sms::SmsSendMessageResult^>^ op;
    

      if (info.Length() == 2
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::ISmsMessageBase^ arg0 = UnwrapISmsMessageBase(info[0]);
          
          op = wrapper->_instance->SendMessageAndGetResultAsync(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::Devices::Sms::SmsSendMessageResult^> t) 
      {	
        try
        {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            TryCatch tryCatch;
            Local<Value> error; 
            Local<Value> arg1 = WrapSmsSendMessageResult(result);
            if (tryCatch.HasCaught())
            {
              error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
            }
            else 
            {
              error = Undefined();
            }
            if (arg1.IsEmpty()) arg1 = Undefined();
            Local<Value> args[] = {error, arg1};
			// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
			// can be fixed by wrapping the conversion code in a function and calling it on the fly
			// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
			tryCatch.~TryCatch();

		    
            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 CalculateLength(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      if (info.Length() == 1
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::ISmsMessageBase^>(info[0]))
      {
        try
        {
          ::Windows::Devices::Sms::ISmsMessageBase^ arg0 = UnwrapISmsMessageBase(info[0]);
          
          ::Windows::Devices::Sms::SmsEncodedLength result;
          result = wrapper->_instance->CalculateLength(arg0);
          info.GetReturnValue().Set(SmsEncodedLengthToJsObject(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 GetDeviceSelector(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() == 0)
      {
        try
        {
          Platform::String^ result;
          result = ::Windows::Devices::Sms::SmsDevice2::GetDeviceSelector();
          info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }
    static void FromId(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(info[0])));
          
          ::Windows::Devices::Sms::SmsDevice2^ result;
          result = ::Windows::Devices::Sms::SmsDevice2::FromId(arg0);
          info.GetReturnValue().Set(WrapSmsDevice2(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 GetDefault(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Devices::Sms::SmsDevice2^ result;
          result = ::Windows::Devices::Sms::SmsDevice2::GetDefault();
          info.GetReturnValue().Set(WrapSmsDevice2(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 FromParentId(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(info[0])));
          
          ::Windows::Devices::Sms::SmsDevice2^ result;
          result = ::Windows::Devices::Sms::SmsDevice2::FromParentId(arg0);
          info.GetReturnValue().Set(WrapSmsDevice2(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 SmscAddressGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->SmscAddress;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SmscAddressSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsString())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        
        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(value)));

        wrapper->_instance->SmscAddress = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void AccountPhoneNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->AccountPhoneNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->DeviceId;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceStatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsDeviceStatus result = wrapper->_instance->DeviceStatus;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ParentDeviceIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(info.This()))
      {
        return;
      }

      SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->ParentDeviceId;
        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(info[0]);
      auto str = *eventName;
      
      Local<Function> callback = info[1].As<Function>();
      
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"deviceStatusChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(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;
        }
        SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(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->DeviceStatusChanged::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Devices::Sms::SmsDevice2^, ::Platform::Object^>(
            [callbackObjPtr](::Windows::Devices::Sms::SmsDevice2^ arg0, ::Platform::Object^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
           	    HandleScope scope;
                TryCatch tryCatch;
              
                Local<Value> error;

                Local<Value> wrappedArg0 = WrapSmsDevice2(arg0);
                Local<Value> wrappedArg1 = CreateOpaqueWrapper(arg1);

                if (tryCatch.HasCaught())
                {
                  error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
                }
                else 
                {
                  error = Undefined();
                }

				// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
				// can be fixed by wrapping the conversion code in a function and calling it on the fly
				// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
				tryCatch.~TryCatch();


                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(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(info[0]);
      auto str = *eventName;

      if ((NodeRT::Utils::CaseInsenstiveEquals(L"deviceStatusChanged", str)))
      {
        Nan::ThrowError(Nan::Error(String::Concat(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"deviceStatusChanged", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsDevice2^>(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;
          }
          SmsDevice2 *wrapper = SmsDevice2::Unwrap<SmsDevice2>(info.This());
          wrapper->_instance->DeviceStatusChanged::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::Devices::Sms::SmsDevice2^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsDevice2(::Windows::Devices::Sms::SmsDevice2^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsDevice2^ UnwrapSmsDevice2(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsDevice2::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsDevice2(::Windows::Devices::Sms::SmsDevice2^ 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>(SmsDevice2::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsDevice2^ UnwrapSmsDevice2(Local<Value> value)
  {
     return SmsDevice2::Unwrap<SmsDevice2>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsDevice2(Local<Object> exports)
  {
    SmsDevice2::Init(exports);
  }

  class SmsMessageReceivedTriggerDetails : 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>("SmsMessageReceivedTriggerDetails").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "drop", Drop);
      Nan::SetPrototypeMethod(localRef, "accept", Accept);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("appMessage").ToLocalChecked(), AppMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("broadcastMessage").ToLocalChecked(), BroadcastMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("statusMessage").ToLocalChecked(), StatusMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("textMessage").ToLocalChecked(), TextMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("voicemailMessage").ToLocalChecked(), VoicemailMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("wapMessage").ToLocalChecked(), WapMessageGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsMessageReceivedTriggerDetails").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsMessageReceivedTriggerDetails(::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ 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::Devices::Sms::SmsMessageReceivedTriggerDetails^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^) 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());

      SmsMessageReceivedTriggerDetails *wrapperInstance = new SmsMessageReceivedTriggerDetails(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::Devices::Sms::SmsMessageReceivedTriggerDetails^>(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::Devices::Sms::SmsMessageReceivedTriggerDetails^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsMessageReceivedTriggerDetails(winRtInstance));
    }


  
    static void Drop(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Drop();
          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 Accept(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Accept();
          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 AppMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsAppMessage^ result = wrapper->_instance->AppMessage;
        info.GetReturnValue().Set(WrapSmsAppMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BroadcastMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsBroadcastMessage^ result = wrapper->_instance->BroadcastMessage;
        info.GetReturnValue().Set(WrapSmsBroadcastMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void StatusMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsStatusMessage^ result = wrapper->_instance->StatusMessage;
        info.GetReturnValue().Set(WrapSmsStatusMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void TextMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsTextMessage2^ result = wrapper->_instance->TextMessage;
        info.GetReturnValue().Set(WrapSmsTextMessage2(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void VoicemailMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsVoicemailMessage^ result = wrapper->_instance->VoicemailMessage;
        info.GetReturnValue().Set(WrapSmsVoicemailMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void WapMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(info.This()))
      {
        return;
      }

      SmsMessageReceivedTriggerDetails *wrapper = SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsWapMessage^ result = wrapper->_instance->WapMessage;
        info.GetReturnValue().Set(WrapSmsWapMessage(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsMessageReceivedTriggerDetails(::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ UnwrapSmsMessageReceivedTriggerDetails(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsMessageReceivedTriggerDetails::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsMessageReceivedTriggerDetails(::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ 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>(SmsMessageReceivedTriggerDetails::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ UnwrapSmsMessageReceivedTriggerDetails(Local<Value> value)
  {
     return SmsMessageReceivedTriggerDetails::Unwrap<SmsMessageReceivedTriggerDetails>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsMessageReceivedTriggerDetails(Local<Object> exports)
  {
    SmsMessageReceivedTriggerDetails::Init(exports);
  }

  class SmsFilterRule : 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>("SmsFilterRule").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("cellularClass").ToLocalChecked(), CellularClassGetter, CellularClassSetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("broadcastChannels").ToLocalChecked(), BroadcastChannelsGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("broadcastTypes").ToLocalChecked(), BroadcastTypesGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("deviceIds").ToLocalChecked(), DeviceIdsGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("imsiPrefixes").ToLocalChecked(), ImsiPrefixesGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("messageType").ToLocalChecked(), MessageTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("portNumbers").ToLocalChecked(), PortNumbersGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("protocolIds").ToLocalChecked(), ProtocolIdsGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("senderNumbers").ToLocalChecked(), SenderNumbersGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("teleserviceIds").ToLocalChecked(), TeleserviceIdsGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("textMessagePrefixes").ToLocalChecked(), TextMessagePrefixesGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("wapApplicationIds").ToLocalChecked(), WapApplicationIdsGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("wapContentTypes").ToLocalChecked(), WapContentTypesGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsFilterRule").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsFilterRule(::Windows::Devices::Sms::SmsFilterRule^ 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::Devices::Sms::SmsFilterRule^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsFilterRule^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Devices::Sms::SmsMessageType arg0 = static_cast<::Windows::Devices::Sms::SmsMessageType>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          winRtInstance = ref new ::Windows::Devices::Sms::SmsFilterRule(arg0);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
	    	return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      SmsFilterRule *wrapperInstance = new SmsFilterRule(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::Devices::Sms::SmsFilterRule^>(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::Devices::Sms::SmsFilterRule^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsFilterRule^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsFilterRule(winRtInstance));
    }


  



    static void CellularClassGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Devices::Sms::CellularClass result = wrapper->_instance->CellularClass;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void CellularClassSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info)
    {
      HandleScope scope;
      
      if (!value->IsInt32())
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        
        ::Windows::Devices::Sms::CellularClass winRtValue = static_cast<::Windows::Devices::Sms::CellularClass>(Nan::To<int32_t>(value).FromMaybe(0));

        wrapper->_instance->CellularClass = winRtValue;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
    
    static void BroadcastChannelsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<int>^ result = wrapper->_instance->BroadcastChannels;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<int>::CreateVectorWrapper(result, 
            [](int val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> int {
              return static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void BroadcastTypesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Windows::Devices::Sms::SmsBroadcastType>^ result = wrapper->_instance->BroadcastTypes;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<::Windows::Devices::Sms::SmsBroadcastType>::CreateVectorWrapper(result, 
            [](::Windows::Devices::Sms::SmsBroadcastType val) -> Local<Value> {
              return Nan::New<Integer>(static_cast<int>(val));
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::SmsBroadcastType {
              return static_cast<::Windows::Devices::Sms::SmsBroadcastType>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void DeviceIdsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->DeviceIds;
        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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ImsiPrefixesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->ImsiPrefixes;
        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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void MessageTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsMessageType result = wrapper->_instance->MessageType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PortNumbersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<int>^ result = wrapper->_instance->PortNumbers;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<int>::CreateVectorWrapper(result, 
            [](int val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> int {
              return static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void ProtocolIdsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<int>^ result = wrapper->_instance->ProtocolIds;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<int>::CreateVectorWrapper(result, 
            [](int val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> int {
              return static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void SenderNumbersGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->SenderNumbers;
        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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void TeleserviceIdsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<int>^ result = wrapper->_instance->TeleserviceIds;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<int>::CreateVectorWrapper(result, 
            [](int val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsInt32();
            },
            [](Local<Value> value) -> int {
              return static_cast<int>(Nan::To<int32_t>(value).FromMaybe(0));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void TextMessagePrefixesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->TextMessagePrefixes;
        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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void WapApplicationIdsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->WapApplicationIds;
        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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void WapContentTypesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(info.This()))
      {
        return;
      }

      SmsFilterRule *wrapper = SmsFilterRule::Unwrap<SmsFilterRule>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Platform::String^>^ result = wrapper->_instance->WapContentTypes;
        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(value)));
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsFilterRule^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsFilterRule(::Windows::Devices::Sms::SmsFilterRule^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsFilterRule^ UnwrapSmsFilterRule(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsFilterRule::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsFilterRule(::Windows::Devices::Sms::SmsFilterRule^ 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>(SmsFilterRule::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsFilterRule^ UnwrapSmsFilterRule(Local<Value> value)
  {
     return SmsFilterRule::Unwrap<SmsFilterRule>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsFilterRule(Local<Object> exports)
  {
    SmsFilterRule::Init(exports);
  }

  class SmsFilterRules : 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>("SmsFilterRules").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("actionType").ToLocalChecked(), ActionTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("rules").ToLocalChecked(), RulesGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("SmsFilterRules").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsFilterRules(::Windows::Devices::Sms::SmsFilterRules^ 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::Devices::Sms::SmsFilterRules^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRules^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsFilterRules^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::Devices::Sms::SmsFilterActionType arg0 = static_cast<::Windows::Devices::Sms::SmsFilterActionType>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          winRtInstance = ref new ::Windows::Devices::Sms::SmsFilterRules(arg0);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
	    	return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      SmsFilterRules *wrapperInstance = new SmsFilterRules(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::Devices::Sms::SmsFilterRules^>(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::Devices::Sms::SmsFilterRules^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsFilterRules^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsFilterRules(winRtInstance));
    }


  



    static void ActionTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRules^>(info.This()))
      {
        return;
      }

      SmsFilterRules *wrapper = SmsFilterRules::Unwrap<SmsFilterRules>(info.This());

      try 
      {
        ::Windows::Devices::Sms::SmsFilterActionType result = wrapper->_instance->ActionType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void RulesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRules^>(info.This()))
      {
        return;
      }

      SmsFilterRules *wrapper = SmsFilterRules::Unwrap<SmsFilterRules>(info.This());

      try 
      {
        ::Windows::Foundation::Collections::IVector<::Windows::Devices::Sms::SmsFilterRule^>^ result = wrapper->_instance->Rules;
        info.GetReturnValue().Set(NodeRT::Collections::VectorWrapper<::Windows::Devices::Sms::SmsFilterRule^>::CreateVectorWrapper(result, 
            [](::Windows::Devices::Sms::SmsFilterRule^ val) -> Local<Value> {
              return WrapSmsFilterRule(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRule^>(value);
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::SmsFilterRule^ {
              return UnwrapSmsFilterRule(value);
            }
          ));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::Devices::Sms::SmsFilterRules^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsFilterRules(::Windows::Devices::Sms::SmsFilterRules^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsFilterRules^ UnwrapSmsFilterRules(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsFilterRules::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsFilterRules(::Windows::Devices::Sms::SmsFilterRules^ 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>(SmsFilterRules::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsFilterRules^ UnwrapSmsFilterRules(Local<Value> value)
  {
     return SmsFilterRules::Unwrap<SmsFilterRules>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsFilterRules(Local<Object> exports)
  {
    SmsFilterRules::Init(exports);
  }

  class SmsMessageRegistration : 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>("SmsMessageRegistration").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "unregister", Unregister);
      
                  
      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, "register", Register);
      Nan::SetAccessor(constructor, Nan::New<String>("allRegistrations").ToLocalChecked(), AllRegistrationsGetter);

      Nan::Set(exports, Nan::New<String>("SmsMessageRegistration").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    SmsMessageRegistration(::Windows::Devices::Sms::SmsMessageRegistration^ 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::Devices::Sms::SmsMessageRegistration^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageRegistration^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::Devices::Sms::SmsMessageRegistration^) 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());

      SmsMessageRegistration *wrapperInstance = new SmsMessageRegistration(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::Devices::Sms::SmsMessageRegistration^>(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::Devices::Sms::SmsMessageRegistration^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::Devices::Sms::SmsMessageRegistration^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapSmsMessageRegistration(winRtInstance));
    }


  
    static void Unregister(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageRegistration^>(info.This()))
      {
        return;
      }

      SmsMessageRegistration *wrapper = SmsMessageRegistration::Unwrap<SmsMessageRegistration>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Unregister();
          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 Register(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (info.Length() == 2
        && info[0]->IsString()
        && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsFilterRules^>(info[1]))
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(info[0])));
          ::Windows::Devices::Sms::SmsFilterRules^ arg1 = UnwrapSmsFilterRules(info[1]);
          
          ::Windows::Devices::Sms::SmsMessageRegistration^ result;
          result = ::Windows::Devices::Sms::SmsMessageRegistration::Register(arg0, arg1);
          info.GetReturnValue().Set(WrapSmsMessageRegistration(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::Devices::Sms::SmsMessageRegistration^>(info.This()))
      {
        return;
      }

      SmsMessageRegistration *wrapper = SmsMessageRegistration::Unwrap<SmsMessageRegistration>(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 AllRegistrationsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;

      try 
      {
        ::Windows::Foundation::Collections::IVectorView<::Windows::Devices::Sms::SmsMessageRegistration^>^ result = ::Windows::Devices::Sms::SmsMessageRegistration::AllRegistrations;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<::Windows::Devices::Sms::SmsMessageRegistration^>::CreateVectorViewWrapper(result, 
            [](::Windows::Devices::Sms::SmsMessageRegistration^ val) -> Local<Value> {
              return WrapSmsMessageRegistration(val);
            },
            [](Local<Value> value) -> bool {
              return NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageRegistration^>(value);
            },
            [](Local<Value> value) -> ::Windows::Devices::Sms::SmsMessageRegistration^ {
              return UnwrapSmsMessageRegistration(value);
            }
          ));
        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(info[0]);
      auto str = *eventName;
      
      Local<Function> callback = info[1].As<Function>();
      
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"messageReceived", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageRegistration^>(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;
        }
        SmsMessageRegistration *wrapper = SmsMessageRegistration::Unwrap<SmsMessageRegistration>(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->MessageReceived::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Devices::Sms::SmsMessageRegistration^, ::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^>(
            [callbackObjPtr](::Windows::Devices::Sms::SmsMessageRegistration^ arg0, ::Windows::Devices::Sms::SmsMessageReceivedTriggerDetails^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
           	    HandleScope scope;
                TryCatch tryCatch;
              
                Local<Value> error;

                Local<Value> wrappedArg0 = WrapSmsMessageRegistration(arg0);
                Local<Value> wrappedArg1 = WrapSmsMessageReceivedTriggerDetails(arg1);

                if (tryCatch.HasCaught())
                {
                  error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
                }
                else 
                {
                  error = Undefined();
                }

				// TODO: this is ugly! Needed due to the possibility of expception occuring inside object convertors
				// can be fixed by wrapping the conversion code in a function and calling it on the fly
				// we must clear the try catch block here so the invoked inner method exception won't get swollen (issue #52) 
				tryCatch.~TryCatch();


                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(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(info[0]);
      auto str = *eventName;

      if ((NodeRT::Utils::CaseInsenstiveEquals(L"messageReceived", str)))
      {
        Nan::ThrowError(Nan::Error(String::Concat(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"messageReceived", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Devices::Sms::SmsMessageRegistration^>(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;
          }
          SmsMessageRegistration *wrapper = SmsMessageRegistration::Unwrap<SmsMessageRegistration>(info.This());
          wrapper->_instance->MessageReceived::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::Devices::Sms::SmsMessageRegistration^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapSmsMessageRegistration(::Windows::Devices::Sms::SmsMessageRegistration^ wintRtInstance);
    friend ::Windows::Devices::Sms::SmsMessageRegistration^ UnwrapSmsMessageRegistration(Local<Value> value);
  };
  Persistent<FunctionTemplate> SmsMessageRegistration::s_constructorTemplate;

  v8::Local<v8::Value> WrapSmsMessageRegistration(::Windows::Devices::Sms::SmsMessageRegistration^ 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>(SmsMessageRegistration::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Devices::Sms::SmsMessageRegistration^ UnwrapSmsMessageRegistration(Local<Value> value)
  {
     return SmsMessageRegistration::Unwrap<SmsMessageRegistration>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitSmsMessageRegistration(Local<Object> exports)
  {
    SmsMessageRegistration::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::Devices::Sms::InitSmsMessageFilterEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsMessageClassEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsMessageTypeEnum(target);
  NodeRT::Windows::Devices::Sms::InitCellularClassEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsDataFormatEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsEncodingEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsGeographicalScopeEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsBroadcastTypeEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsDeviceStatusEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsModemErrorCodeEnum(target);
  NodeRT::Windows::Devices::Sms::InitSmsFilterActionTypeEnum(target);
  NodeRT::Windows::Devices::Sms::InitISmsMessage(target);
  NodeRT::Windows::Devices::Sms::InitISmsBinaryMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsBinaryMessage(target);
  NodeRT::Windows::Devices::Sms::InitISmsTextMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsTextMessage(target);
  NodeRT::Windows::Devices::Sms::InitDeleteSmsMessageOperation(target);
  NodeRT::Windows::Devices::Sms::InitDeleteSmsMessagesOperation(target);
  NodeRT::Windows::Devices::Sms::InitGetSmsMessageOperation(target);
  NodeRT::Windows::Devices::Sms::InitGetSmsMessagesOperation(target);
  NodeRT::Windows::Devices::Sms::InitSmsDeviceMessageStore(target);
  NodeRT::Windows::Devices::Sms::InitSendSmsMessageOperation(target);
  NodeRT::Windows::Devices::Sms::InitSmsMessageReceivedEventArgs(target);
  NodeRT::Windows::Devices::Sms::InitSmsDevice(target);
  NodeRT::Windows::Devices::Sms::InitGetSmsDeviceOperation(target);
  NodeRT::Windows::Devices::Sms::InitISmsDevice(target);
  NodeRT::Windows::Devices::Sms::InitSmsReceivedEventDetails(target);
  NodeRT::Windows::Devices::Sms::InitISmsMessageBase(target);
  NodeRT::Windows::Devices::Sms::InitSmsTextMessage2(target);
  NodeRT::Windows::Devices::Sms::InitSmsWapMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsAppMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsBroadcastMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsVoicemailMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsStatusMessage(target);
  NodeRT::Windows::Devices::Sms::InitSmsSendMessageResult(target);
  NodeRT::Windows::Devices::Sms::InitSmsDevice2(target);
  NodeRT::Windows::Devices::Sms::InitSmsMessageReceivedTriggerDetails(target);
  NodeRT::Windows::Devices::Sms::InitSmsFilterRule(target);
  NodeRT::Windows::Devices::Sms::InitSmsFilterRules(target);
  NodeRT::Windows::Devices::Sms::InitSmsMessageRegistration(target);

  NodeRT::Utils::RegisterNameSpace("Windows.Devices.Sms", target);
}


NODE_MODULE(binding, init)