// Copyright (c) The NodeRT Contributors
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the ""License""); you may
// not use this file except in compliance with the License. You may obtain a
// copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing permissions
// and limitations under the License.

// TODO: Verify that this is is still needed..
#define NTDDI_VERSION 0x06010000

#include <v8.h>
#include "nan.h"
#include <string>
#include <ppltasks.h>
#include "CollectionsConverter.h"
#include "CollectionsWrap.h"
#include "node-async.h"
#include "NodeRtUtils.h"
#include "OpaqueWrapper.h"
#include "WrapperBase.h"

#using <Windows.WinMD>

// this undefs fixes the issues of compiling Windows.Data.Json, Windows.Storag.FileProperties, and Windows.Stroage.Search
// Some of the node header files brings windows definitions with the same names as some of the WinRT methods
#undef DocumentProperties
#undef GetObject
#undef CreateEvent
#undef FindText
#undef SendMessage

const char* REGISTRATION_TOKEN_MAP_PROPERTY_NAME = "__registrationTokenMap__";

using v8::Array;
using v8::String;
using v8::Value;
using v8::Boolean;
using v8::Integer;
using v8::FunctionTemplate;
using v8::Object;
using v8::Local;
using v8::Function;
using v8::Date;
using v8::Number;
using v8::PropertyAttribute;
using v8::Primitive;
using Nan::HandleScope;
using Nan::Persistent;
using Nan::Undefined;
using Nan::True;
using Nan::False;
using Nan::Null;
using Nan::MaybeLocal;
using Nan::EscapableHandleScope;
using Nan::HandleScope;
using Nan::TryCatch;
using namespace concurrency;

namespace NodeRT { namespace Windows { namespace Media { namespace Streaming { namespace Adaptive { 
  v8::Local<v8::Value> WrapAdaptiveMediaSource(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ UnwrapAdaptiveMediaSource(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceAdvancedSettings(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ UnwrapAdaptiveMediaSourceAdvancedSettings(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceCorrelatedTimes(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ UnwrapAdaptiveMediaSourceCorrelatedTimes(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceCreationResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ UnwrapAdaptiveMediaSourceCreationResult(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ UnwrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDiagnostics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ UnwrapAdaptiveMediaSourceDiagnostics(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ UnwrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadCompletedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ UnwrapAdaptiveMediaSourceDownloadCompletedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadFailedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ UnwrapAdaptiveMediaSourceDownloadFailedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadRequestedDeferral(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ UnwrapAdaptiveMediaSourceDownloadRequestedDeferral(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadRequestedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ UnwrapAdaptiveMediaSourceDownloadRequestedEventArgs(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ UnwrapAdaptiveMediaSourceDownloadResult(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadStatistics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ UnwrapAdaptiveMediaSourceDownloadStatistics(Local<Value> value);
  
  v8::Local<v8::Value> WrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ wintRtInstance);
  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ UnwrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(Local<Value> value);
  



  static void InitAdaptiveMediaSourceCreationStatusEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceCreationStatus").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("success").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::Success)));
    Nan::Set(enumObject, Nan::New<String>("manifestDownloadFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::ManifestDownloadFailure)));
    Nan::Set(enumObject, Nan::New<String>("manifestParseFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::ManifestParseFailure)));
    Nan::Set(enumObject, Nan::New<String>("unsupportedManifestContentType").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::UnsupportedManifestContentType)));
    Nan::Set(enumObject, Nan::New<String>("unsupportedManifestVersion").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::UnsupportedManifestVersion)));
    Nan::Set(enumObject, Nan::New<String>("unsupportedManifestProfile").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::UnsupportedManifestProfile)));
    Nan::Set(enumObject, Nan::New<String>("unknownFailure").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus::UnknownFailure)));
  }

  static void InitAdaptiveMediaSourceDiagnosticTypeEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDiagnosticType").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("manifestUnchangedUponReload").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::ManifestUnchangedUponReload)));
    Nan::Set(enumObject, Nan::New<String>("manifestMismatchUponReload").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::ManifestMismatchUponReload)));
    Nan::Set(enumObject, Nan::New<String>("manifestSignaledEndOfLiveEventUponReload").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::ManifestSignaledEndOfLiveEventUponReload)));
    Nan::Set(enumObject, Nan::New<String>("mediaSegmentSkipped").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::MediaSegmentSkipped)));
    Nan::Set(enumObject, Nan::New<String>("resourceNotFound").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::ResourceNotFound)));
    Nan::Set(enumObject, Nan::New<String>("resourceTimedOut").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::ResourceTimedOut)));
    Nan::Set(enumObject, Nan::New<String>("resourceParsingError").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::ResourceParsingError)));
    Nan::Set(enumObject, Nan::New<String>("bitrateDisabled").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::BitrateDisabled)));
    Nan::Set(enumObject, Nan::New<String>("fatalMediaSourceError").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType::FatalMediaSourceError)));
  }

  static void InitAdaptiveMediaSourceDownloadBitrateChangedReasonEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadBitrateChangedReason").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("sufficientInboundBitsPerSecond").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::SufficientInboundBitsPerSecond)));
    Nan::Set(enumObject, Nan::New<String>("insufficientInboundBitsPerSecond").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::InsufficientInboundBitsPerSecond)));
    Nan::Set(enumObject, Nan::New<String>("lowBufferLevel").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::LowBufferLevel)));
    Nan::Set(enumObject, Nan::New<String>("positionChanged").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::PositionChanged)));
    Nan::Set(enumObject, Nan::New<String>("trackSelectionChanged").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::TrackSelectionChanged)));
    Nan::Set(enumObject, Nan::New<String>("desiredBitratesChanged").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::DesiredBitratesChanged)));
    Nan::Set(enumObject, Nan::New<String>("errorInPreviousBitrate").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason::ErrorInPreviousBitrate)));
  }

  static void InitAdaptiveMediaSourceResourceTypeEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceResourceType").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("manifest").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType::Manifest)));
    Nan::Set(enumObject, Nan::New<String>("initializationSegment").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType::InitializationSegment)));
    Nan::Set(enumObject, Nan::New<String>("mediaSegment").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType::MediaSegment)));
    Nan::Set(enumObject, Nan::New<String>("key").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType::Key)));
    Nan::Set(enumObject, Nan::New<String>("initializationVector").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType::InitializationVector)));
    Nan::Set(enumObject, Nan::New<String>("mediaSegmentIndex").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType::MediaSegmentIndex)));
  }



  class AdaptiveMediaSource : 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>("AdaptiveMediaSource").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);

        Local<Function> func;
        Local<FunctionTemplate> funcTemplate;

          
            Nan::SetPrototypeMethod(localRef, "getCorrelatedTimes", GetCorrelatedTimes);
            Nan::SetPrototypeMethod(localRef, "close", Close);
          


          
          Nan::SetPrototypeMethod(localRef,"addListener", AddListener);
          Nan::SetPrototypeMethod(localRef,"on", AddListener);
          Nan::SetPrototypeMethod(localRef,"removeListener", RemoveListener);
          Nan::SetPrototypeMethod(localRef, "off", RemoveListener);

          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("initialBitrate").ToLocalChecked(), InitialBitrateGetter, InitialBitrateSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("inboundBitsPerSecondWindow").ToLocalChecked(), InboundBitsPerSecondWindowGetter, InboundBitsPerSecondWindowSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("desiredMaxBitrate").ToLocalChecked(), DesiredMaxBitrateGetter, DesiredMaxBitrateSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("desiredLiveOffset").ToLocalChecked(), DesiredLiveOffsetGetter, DesiredLiveOffsetSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("desiredMinBitrate").ToLocalChecked(), DesiredMinBitrateGetter, DesiredMinBitrateSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("currentPlaybackBitrate").ToLocalChecked(), CurrentPlaybackBitrateGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("audioOnlyPlayback").ToLocalChecked(), AudioOnlyPlaybackGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("inboundBitsPerSecond").ToLocalChecked(), InboundBitsPerSecondGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("availableBitrates").ToLocalChecked(), AvailableBitratesGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("currentDownloadBitrate").ToLocalChecked(), CurrentDownloadBitrateGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("isLive").ToLocalChecked(), IsLiveGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("advancedSettings").ToLocalChecked(), AdvancedSettingsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("desiredSeekableWindowSize").ToLocalChecked(), DesiredSeekableWindowSizeGetter, DesiredSeekableWindowSizeSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("diagnostics").ToLocalChecked(), DiagnosticsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("maxSeekableWindowSize").ToLocalChecked(), MaxSeekableWindowSizeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("minLiveOffset").ToLocalChecked(), MinLiveOffsetGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);

        Nan::SetMethod(constructor, "isContentTypeSupported", IsContentTypeSupported);
        func = Nan::GetFunction(Nan::New<FunctionTemplate>(CreateFromUriAsync)).ToLocalChecked();
        Nan::Set(constructor, Nan::New<String>("createFromUriAsync").ToLocalChecked(), func);
        func = Nan::GetFunction(Nan::New<FunctionTemplate>(CreateFromStreamAsync)).ToLocalChecked();
        Nan::Set(constructor, Nan::New<String>("createFromStreamAsync").ToLocalChecked(), func);


        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSource").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSource(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ 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::Media::Streaming::Adaptive::AdaptiveMediaSource^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^) 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());

      AdaptiveMediaSource *wrapperInstance = new AdaptiveMediaSource(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::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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::Media::Streaming::Adaptive::AdaptiveMediaSource^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSource(winRtInstance));
    }


    static void GetCorrelatedTimes(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ result;
          result = wrapper->_instance->GetCorrelatedTimes();
          info.GetReturnValue().Set(WrapAdaptiveMediaSourceCorrelatedTimes(result));
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void Close(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      if (info.Length() == 0) {
        try {
          delete wrapper->_instance;
          wrapper->_instance = nullptr;
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      } else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }


    static void CreateFromUriAsync(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>^ op;


      if (info.Length() == 2
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::Uri^>(info[0]))
      {
        try
        {
          ::Windows::Foundation::Uri^ arg0 = dynamic_cast<::Windows::Foundation::Uri^>(NodeRT::Utils::GetObjectInstance(info[0]));
            
          op = ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource::CreateFromUriAsync(arg0);
        } catch (Platform::Exception ^exception) {
            NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
            return;
        }
      }
      else if (info.Length() == 3
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::Uri^>(info[0])
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Web::Http::HttpClient^>(info[1]))
      {
        try
        {
          ::Windows::Foundation::Uri^ arg0 = dynamic_cast<::Windows::Foundation::Uri^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::Web::Http::HttpClient^ arg1 = dynamic_cast<::Windows::Web::Http::HttpClient^>(NodeRT::Utils::GetObjectInstance(info[1]));
            
          op = ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource::CreateFromUriAsync(arg0,arg1);
        } catch (Platform::Exception ^exception) {
            NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
            return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }

      auto opTask = create_task(op);
      uv_async_t* asyncToken = NodeUtils::Async::GetAsyncToken(info[info.Length() -1].As<Function>());

      opTask.then( [asyncToken] (task<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^> t)
      {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapAdaptiveMediaSourceCreationResult(result);
              if (tryCatch.HasCaught())
              {
                error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
              }
              else
              {
                error = Undefined();
              }
              if (arg1.IsEmpty()) arg1 = Undefined();
            }
            Local<Value> args[] = {error, arg1};


            invokeCallback(_countof(args), args);
          });
        }
        catch (Platform::Exception^ exception)
        {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {

            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);

            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }
      });
    }

    static void CreateFromStreamAsync(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>^ op;


      if (info.Length() == 4
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Storage::Streams::IInputStream^>(info[0])
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::Uri^>(info[1])
          && info[2]->IsString())
      {
        try
        {
          ::Windows::Storage::Streams::IInputStream^ arg0 = dynamic_cast<::Windows::Storage::Streams::IInputStream^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::Foundation::Uri^ arg1 = dynamic_cast<::Windows::Foundation::Uri^>(NodeRT::Utils::GetObjectInstance(info[1]));
          Platform::String^ arg2 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[2])));
            
          op = ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource::CreateFromStreamAsync(arg0,arg1,arg2);
        } catch (Platform::Exception ^exception) {
            NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
            return;
        }
      }
      else if (info.Length() == 5
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Storage::Streams::IInputStream^>(info[0])
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::Uri^>(info[1])
          && info[2]->IsString()
          && NodeRT::Utils::IsWinRtWrapperOf<::Windows::Web::Http::HttpClient^>(info[3]))
      {
        try
        {
          ::Windows::Storage::Streams::IInputStream^ arg0 = dynamic_cast<::Windows::Storage::Streams::IInputStream^>(NodeRT::Utils::GetObjectInstance(info[0]));
          ::Windows::Foundation::Uri^ arg1 = dynamic_cast<::Windows::Foundation::Uri^>(NodeRT::Utils::GetObjectInstance(info[1]));
          Platform::String^ arg2 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[2])));
          ::Windows::Web::Http::HttpClient^ arg3 = dynamic_cast<::Windows::Web::Http::HttpClient^>(NodeRT::Utils::GetObjectInstance(info[3]));
            
          op = ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource::CreateFromStreamAsync(arg0,arg1,arg2,arg3);
        } 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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^> t)
      {
        try {
          auto result = t.get();
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [result](NodeUtils::InvokeCallbackDelegate invokeCallback) {


            Local<Value> error;
            Local<Value> arg1;
            {
              TryCatch tryCatch;
              arg1 = WrapAdaptiveMediaSourceCreationResult(result);
              if (tryCatch.HasCaught())
              {
                error = Nan::To<Object>(tryCatch.Exception()).ToLocalChecked();
              }
              else
              {
                error = Undefined();
              }
              if (arg1.IsEmpty()) arg1 = Undefined();
            }
            Local<Value> args[] = {error, arg1};


            invokeCallback(_countof(args), args);
          });
        }
        catch (Platform::Exception^ exception)
        {
          NodeUtils::Async::RunCallbackOnMain(asyncToken, [exception](NodeUtils::InvokeCallbackDelegate invokeCallback) {

            Local<Value> error = NodeRT::Utils::WinRtExceptionToJsError(exception);

            Local<Value> args[] = {error};
            invokeCallback(_countof(args), args);
          });
        }
      });
    }


    static void IsContentTypeSupported(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() == 1
        && info[0]->IsString())
      {
        try
        {
          Platform::String^ arg0 = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), info[0])));
          
          bool result;
          result = ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource::IsContentTypeSupported(arg0);
          info.GetReturnValue().Set(Nan::New<Boolean>(result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else  {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }

    static void InitialBitrateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        unsigned int result = wrapper->_instance->InitialBitrate;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void InitialBitrateSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsUint32()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try {

        unsigned int winRtValue = static_cast<unsigned int>(Nan::To<uint32_t>(value).FromMaybe(0));

        wrapper->_instance->InitialBitrate = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void InboundBitsPerSecondWindowGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Windows::Foundation::TimeSpan result = wrapper->_instance->InboundBitsPerSecondWindow;
        info.GetReturnValue().Set(Nan::New<Number>(result.Duration/10000.0));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void InboundBitsPerSecondWindowSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try {

        ::Windows::Foundation::TimeSpan winRtValue = NodeRT::Utils::TimeSpanFromMilli(Nan::To<int64_t>(value).FromMaybe(0));

        wrapper->_instance->InboundBitsPerSecondWindow = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void DesiredMaxBitrateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Platform::IBox<unsigned int>^ result = wrapper->_instance->DesiredMaxBitrate;
        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 DesiredMaxBitrateSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsUint32()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try {

        ::Platform::IBox<unsigned int>^ winRtValue = ref new ::Platform::Box<unsigned int>(static_cast<unsigned int>(Nan::To<uint32_t>(value).FromMaybe(0)));

        wrapper->_instance->DesiredMaxBitrate = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void DesiredLiveOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Windows::Foundation::TimeSpan result = wrapper->_instance->DesiredLiveOffset;
        info.GetReturnValue().Set(Nan::New<Number>(result.Duration/10000.0));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void DesiredLiveOffsetSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try {

        ::Windows::Foundation::TimeSpan winRtValue = NodeRT::Utils::TimeSpanFromMilli(Nan::To<int64_t>(value).FromMaybe(0));

        wrapper->_instance->DesiredLiveOffset = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void DesiredMinBitrateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Platform::IBox<unsigned int>^ result = wrapper->_instance->DesiredMinBitrate;
        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 DesiredMinBitrateSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsUint32()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try {

        ::Platform::IBox<unsigned int>^ winRtValue = ref new ::Platform::Box<unsigned int>(static_cast<unsigned int>(Nan::To<uint32_t>(value).FromMaybe(0)));

        wrapper->_instance->DesiredMinBitrate = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void CurrentPlaybackBitrateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        unsigned int result = wrapper->_instance->CurrentPlaybackBitrate;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void AudioOnlyPlaybackGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        bool result = wrapper->_instance->AudioOnlyPlayback;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void InboundBitsPerSecondGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        unsigned __int64 result = wrapper->_instance->InboundBitsPerSecond;
        info.GetReturnValue().Set(Nan::New<Number>(static_cast<double>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void AvailableBitratesGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Windows::Foundation::Collections::IVectorView<unsigned int>^ result = wrapper->_instance->AvailableBitrates;
        info.GetReturnValue().Set(NodeRT::Collections::VectorViewWrapper<unsigned int>::CreateVectorViewWrapper(result, 
            [](unsigned int val) -> Local<Value> {
              return Nan::New<Integer>(val);
            },
            [](Local<Value> value) -> bool {
              return value->IsUint32();
            },
            [](Local<Value> value) -> unsigned int {
              return static_cast<unsigned int>(Nan::To<uint32_t>(value).FromMaybe(0));
            }
          ));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void CurrentDownloadBitrateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        unsigned int result = wrapper->_instance->CurrentDownloadBitrate;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void IsLiveGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        bool result = wrapper->_instance->IsLive;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void AdvancedSettingsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ result = wrapper->_instance->AdvancedSettings;
        info.GetReturnValue().Set(WrapAdaptiveMediaSourceAdvancedSettings(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void DesiredSeekableWindowSizeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->DesiredSeekableWindowSize;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void DesiredSeekableWindowSizeSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try {

        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ winRtValue = ref new ::Platform::Box<::Windows::Foundation::TimeSpan>(NodeRT::Utils::TimeSpanFromMilli(Nan::To<int64_t>(value).FromMaybe(0)));

        wrapper->_instance->DesiredSeekableWindowSize = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void DiagnosticsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ result = wrapper->_instance->Diagnostics;
        info.GetReturnValue().Set(WrapAdaptiveMediaSourceDiagnostics(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void MaxSeekableWindowSizeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->MaxSeekableWindowSize;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void MinLiveOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(info.This())) {
        return;
      }

      AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->MinLiveOffset;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      Local<Function> callback = info[1].As<Function>();

      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadBitrateChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
        }
        AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(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->DownloadBitrateChanged::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^>(
            [callbackObjPtr](::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ arg0, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapAdaptiveMediaSource(arg0);
                  wrappedArg1 = WrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
      else if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadCompleted", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
        }
        AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(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->DownloadCompleted::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(
            [callbackObjPtr](::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ arg0, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapAdaptiveMediaSource(arg0);
                  wrappedArg1 = WrapAdaptiveMediaSourceDownloadCompletedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
      else if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadFailed", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
        }
        AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(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->DownloadFailed::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(
            [callbackObjPtr](::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ arg0, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapAdaptiveMediaSource(arg0);
                  wrappedArg1 = WrapAdaptiveMediaSourceDownloadFailedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
      else if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadRequested", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
        }
        AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(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->DownloadRequested::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(
            [callbackObjPtr](::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ arg0, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapAdaptiveMediaSource(arg0);
                  wrappedArg1 = WrapAdaptiveMediaSourceDownloadRequestedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
      else if (NodeRT::Utils::CaseInsenstiveEquals(L"playbackBitrateChanged", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
        }
        AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(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->PlaybackBitrateChanged::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^>(
            [callbackObjPtr](::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ arg0, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapAdaptiveMediaSource(arg0);
                  wrappedArg1 = WrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
 else  {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Value> tokenMapVal = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());
      Local<Object> tokenMap;

      if (tokenMapVal.IsEmpty() || Nan::Equals(tokenMapVal, Undefined()).FromMaybe(false)) {
        tokenMap = Nan::New<Object>();
        NodeRT::Utils::SetHiddenValueWithObject(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked(), tokenMap);
      } else {
        tokenMap = Nan::To<Object>(tokenMapVal).ToLocalChecked();
      }

      Nan::Set(tokenMap, info[0], CreateOpaqueWrapper(::Windows::Foundation::PropertyValue::CreateInt64(registrationToken.Value)));
    }

    static void RemoveListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected a string and a callback")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      if ((!NodeRT::Utils::CaseInsenstiveEquals(L"downloadBitrateChanged", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"downloadCompleted", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"downloadFailed", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"downloadRequested", str)) &&(!NodeRT::Utils::CaseInsenstiveEquals(L"playbackBitrateChanged", str))) {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Function> callback = info[1].As<Function>();
      Local<Value> tokenMap = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());

      if (tokenMap.IsEmpty() || Nan::Equals(tokenMap, Undefined()).FromMaybe(false)) {
        return;
      }

      Local<Value> opaqueWrapperObj =  Nan::Get(Nan::To<Object>(tokenMap).ToLocalChecked(), info[0]).ToLocalChecked();

      if (opaqueWrapperObj.IsEmpty() || Nan::Equals(opaqueWrapperObj,Undefined()).FromMaybe(false)) {
        return;
      }

      OpaqueWrapper *opaqueWrapper = OpaqueWrapper::Unwrap<OpaqueWrapper>(opaqueWrapperObj.As<Object>());

      long long tokenValue = (long long) opaqueWrapper->GetObjectInstance();
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      registrationToken.Value = tokenValue;

      try  {
        if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadBitrateChanged", str)) {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
          }
          AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());
          wrapper->_instance->DownloadBitrateChanged::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadCompleted", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
          }
          AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());
          wrapper->_instance->DownloadCompleted::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadFailed", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
          }
          AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());
          wrapper->_instance->DownloadFailed::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"downloadRequested", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
          }
          AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());
          wrapper->_instance->DownloadRequested::remove(registrationToken);
        }
        else if (NodeRT::Utils::CaseInsenstiveEquals(L"playbackBitrateChanged", str))
        {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^>(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;
          }
          AdaptiveMediaSource *wrapper = AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(info.This());
          wrapper->_instance->PlaybackBitrateChanged::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::Media::Streaming::Adaptive::AdaptiveMediaSource^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSource(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ UnwrapAdaptiveMediaSource(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSource::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSource(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ 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>(AdaptiveMediaSource::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ UnwrapAdaptiveMediaSource(Local<Value> value) {
     return AdaptiveMediaSource::Unwrap<AdaptiveMediaSource>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSource(Local<Object> exports) {
    AdaptiveMediaSource::Init(exports);
  }

  class AdaptiveMediaSourceAdvancedSettings : 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>("AdaptiveMediaSourceAdvancedSettings").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("desiredBitrateHeadroomRatio").ToLocalChecked(), DesiredBitrateHeadroomRatioGetter, DesiredBitrateHeadroomRatioSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("bitrateDowngradeTriggerRatio").ToLocalChecked(), BitrateDowngradeTriggerRatioGetter, BitrateDowngradeTriggerRatioSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("allSegmentsIndependent").ToLocalChecked(), AllSegmentsIndependentGetter, AllSegmentsIndependentSetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceAdvancedSettings").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceAdvancedSettings(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^) 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());

      AdaptiveMediaSourceAdvancedSettings *wrapperInstance = new AdaptiveMediaSourceAdvancedSettings(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::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceAdvancedSettings(winRtInstance));
    }





    static void DesiredBitrateHeadroomRatioGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceAdvancedSettings *wrapper = AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(info.This());

      try  {
        ::Platform::IBox<double>^ result = wrapper->_instance->DesiredBitrateHeadroomRatio;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void DesiredBitrateHeadroomRatioSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceAdvancedSettings *wrapper = AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(info.This());

      try {

        ::Platform::IBox<double>^ winRtValue = ref new ::Platform::Box<double>(Nan::To<double>(value).FromMaybe(0.0));

        wrapper->_instance->DesiredBitrateHeadroomRatio = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void BitrateDowngradeTriggerRatioGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceAdvancedSettings *wrapper = AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(info.This());

      try  {
        ::Platform::IBox<double>^ result = wrapper->_instance->BitrateDowngradeTriggerRatio;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void BitrateDowngradeTriggerRatioSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceAdvancedSettings *wrapper = AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(info.This());

      try {

        ::Platform::IBox<double>^ winRtValue = ref new ::Platform::Box<double>(Nan::To<double>(value).FromMaybe(0.0));

        wrapper->_instance->BitrateDowngradeTriggerRatio = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void AllSegmentsIndependentGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceAdvancedSettings *wrapper = AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(info.This());

      try  {
        bool result = wrapper->_instance->AllSegmentsIndependent;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void AllSegmentsIndependentSetter(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::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceAdvancedSettings *wrapper = AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(info.This());

      try {

        bool winRtValue = Nan::To<bool>(value).FromMaybe(false);

        wrapper->_instance->AllSegmentsIndependent = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceAdvancedSettings(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ UnwrapAdaptiveMediaSourceAdvancedSettings(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceAdvancedSettings::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceAdvancedSettings(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ 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>(AdaptiveMediaSourceAdvancedSettings::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceAdvancedSettings^ UnwrapAdaptiveMediaSourceAdvancedSettings(Local<Value> value) {
     return AdaptiveMediaSourceAdvancedSettings::Unwrap<AdaptiveMediaSourceAdvancedSettings>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceAdvancedSettings(Local<Object> exports) {
    AdaptiveMediaSourceAdvancedSettings::Init(exports);
  }

  class AdaptiveMediaSourceCorrelatedTimes : 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>("AdaptiveMediaSourceCorrelatedTimes").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("position").ToLocalChecked(), PositionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("presentationTimeStamp").ToLocalChecked(), PresentationTimeStampGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("programDateTime").ToLocalChecked(), ProgramDateTimeGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceCorrelatedTimes").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceCorrelatedTimes(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^) 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());

      AdaptiveMediaSourceCorrelatedTimes *wrapperInstance = new AdaptiveMediaSourceCorrelatedTimes(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceCorrelatedTimes(winRtInstance));
    }





    static void PositionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCorrelatedTimes *wrapper = AdaptiveMediaSourceCorrelatedTimes::Unwrap<AdaptiveMediaSourceCorrelatedTimes>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->Position;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PresentationTimeStampGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCorrelatedTimes *wrapper = AdaptiveMediaSourceCorrelatedTimes::Unwrap<AdaptiveMediaSourceCorrelatedTimes>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->PresentationTimeStamp;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ProgramDateTimeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCorrelatedTimes *wrapper = AdaptiveMediaSourceCorrelatedTimes::Unwrap<AdaptiveMediaSourceCorrelatedTimes>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::DateTime>^ result = wrapper->_instance->ProgramDateTime;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(NodeRT::Utils::DateTimeToJS(result->Value)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceCorrelatedTimes(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ UnwrapAdaptiveMediaSourceCorrelatedTimes(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceCorrelatedTimes::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceCorrelatedTimes(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ 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>(AdaptiveMediaSourceCorrelatedTimes::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCorrelatedTimes^ UnwrapAdaptiveMediaSourceCorrelatedTimes(Local<Value> value) {
     return AdaptiveMediaSourceCorrelatedTimes::Unwrap<AdaptiveMediaSourceCorrelatedTimes>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceCorrelatedTimes(Local<Object> exports) {
    AdaptiveMediaSourceCorrelatedTimes::Init(exports);
  }

  class AdaptiveMediaSourceCreationResult : 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>("AdaptiveMediaSourceCreationResult").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("httpResponseMessage").ToLocalChecked(), HttpResponseMessageGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("mediaSource").ToLocalChecked(), MediaSourceGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("status").ToLocalChecked(), StatusGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("extendedError").ToLocalChecked(), ExtendedErrorGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceCreationResult").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceCreationResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^) 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());

      AdaptiveMediaSourceCreationResult *wrapperInstance = new AdaptiveMediaSourceCreationResult(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceCreationResult(winRtInstance));
    }





    static void HttpResponseMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCreationResult *wrapper = AdaptiveMediaSourceCreationResult::Unwrap<AdaptiveMediaSourceCreationResult>(info.This());

      try  {
        ::Windows::Web::Http::HttpResponseMessage^ result = wrapper->_instance->HttpResponseMessage;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Web.Http", "HttpResponseMessage", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void MediaSourceGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCreationResult *wrapper = AdaptiveMediaSourceCreationResult::Unwrap<AdaptiveMediaSourceCreationResult>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSource^ result = wrapper->_instance->MediaSource;
        info.GetReturnValue().Set(WrapAdaptiveMediaSource(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::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCreationResult *wrapper = AdaptiveMediaSourceCreationResult::Unwrap<AdaptiveMediaSourceCreationResult>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationStatus 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 ExtendedErrorGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceCreationResult *wrapper = AdaptiveMediaSourceCreationResult::Unwrap<AdaptiveMediaSourceCreationResult>(info.This());

      try  {
        ::Windows::Foundation::HResult result = wrapper->_instance->ExtendedError;
        info.GetReturnValue().Set(Nan::New<Integer>(result.Value));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceCreationResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ UnwrapAdaptiveMediaSourceCreationResult(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceCreationResult::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceCreationResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ 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>(AdaptiveMediaSourceCreationResult::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceCreationResult^ UnwrapAdaptiveMediaSourceCreationResult(Local<Value> value) {
     return AdaptiveMediaSourceCreationResult::Unwrap<AdaptiveMediaSourceCreationResult>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceCreationResult(Local<Object> exports) {
    AdaptiveMediaSourceCreationResult::Init(exports);
  }

  class AdaptiveMediaSourceDiagnosticAvailableEventArgs : 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>("AdaptiveMediaSourceDiagnosticAvailableEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("bitrate").ToLocalChecked(), BitrateGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("diagnosticType").ToLocalChecked(), DiagnosticTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("position").ToLocalChecked(), PositionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("requestId").ToLocalChecked(), RequestIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeLength").ToLocalChecked(), ResourceByteRangeLengthGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeOffset").ToLocalChecked(), ResourceByteRangeOffsetGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceType").ToLocalChecked(), ResourceTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceUri").ToLocalChecked(), ResourceUriGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("segmentId").ToLocalChecked(), SegmentIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("extendedError").ToLocalChecked(), ExtendedErrorGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceContentType").ToLocalChecked(), ResourceContentTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceDuration").ToLocalChecked(), ResourceDurationGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDiagnosticAvailableEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDiagnosticAvailableEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^) 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());

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapperInstance = new AdaptiveMediaSourceDiagnosticAvailableEventArgs(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(winRtInstance));
    }





    static void BitrateGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned int>^ result = wrapper->_instance->Bitrate;
        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 DiagnosticTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticType result = wrapper->_instance->DiagnosticType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PositionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->Position;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void RequestIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<int>^ result = wrapper->_instance->RequestId;
        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 ResourceByteRangeLengthGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeLength;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeOffset;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType>^ result = wrapper->_instance->ResourceType;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Integer>(static_cast<int>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceUriGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Windows::Foundation::Uri^ result = wrapper->_instance->ResourceUri;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void SegmentIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->SegmentId;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ExtendedErrorGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Windows::Foundation::HResult result = wrapper->_instance->ExtendedError;
        info.GetReturnValue().Set(Nan::New<Integer>(result.Value));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceContentTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->ResourceContentType;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceDurationGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDiagnosticAvailableEventArgs *wrapper = AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->ResourceDuration;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ UnwrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDiagnosticAvailableEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ 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>(AdaptiveMediaSourceDiagnosticAvailableEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ UnwrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(Local<Value> value) {
     return AdaptiveMediaSourceDiagnosticAvailableEventArgs::Unwrap<AdaptiveMediaSourceDiagnosticAvailableEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDiagnosticAvailableEventArgs(Local<Object> exports) {
    AdaptiveMediaSourceDiagnosticAvailableEventArgs::Init(exports);
  }

  class AdaptiveMediaSourceDiagnostics : 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>("AdaptiveMediaSourceDiagnostics").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);




          
          Nan::SetPrototypeMethod(localRef,"addListener", AddListener);
          Nan::SetPrototypeMethod(localRef,"on", AddListener);
          Nan::SetPrototypeMethod(localRef,"removeListener", RemoveListener);
          Nan::SetPrototypeMethod(localRef, "off", RemoveListener);


        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDiagnostics").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDiagnostics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^) 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());

      AdaptiveMediaSourceDiagnostics *wrapperInstance = new AdaptiveMediaSourceDiagnostics(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDiagnostics(winRtInstance));
    }







    static void AddListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected arguments are eventName(string),callback(function)")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      Local<Function> callback = info[1].As<Function>();

      ::Windows::Foundation::EventRegistrationToken registrationToken;
      if (NodeRT::Utils::CaseInsenstiveEquals(L"diagnosticAvailable", str))
      {
        if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^>(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;
        }
        AdaptiveMediaSourceDiagnostics *wrapper = AdaptiveMediaSourceDiagnostics::Unwrap<AdaptiveMediaSourceDiagnostics>(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->DiagnosticAvailable::add(
            ref new ::Windows::Foundation::TypedEventHandler<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^>(
            [callbackObjPtr](::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ arg0, ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnosticAvailableEventArgs^ arg1) {
              NodeUtils::Async::RunOnMain([callbackObjPtr , arg0, arg1]() {
                HandleScope scope;


                Local<Value> wrappedArg0;
                Local<Value> wrappedArg1;

                {
                  TryCatch tryCatch;


                  wrappedArg0 = WrapAdaptiveMediaSourceDiagnostics(arg0);
                  wrappedArg1 = WrapAdaptiveMediaSourceDiagnosticAvailableEventArgs(arg1);


                  if (wrappedArg0.IsEmpty()) wrappedArg0 = Undefined();
                  if (wrappedArg1.IsEmpty()) wrappedArg1 = Undefined();
                }

                Local<Value> args[] = { wrappedArg0, wrappedArg1 };
                Local<Object> callbackObjLocalRef = Nan::New<Object>(*callbackObjPtr);
                NodeRT::Utils::CallCallbackInDomain(callbackObjLocalRef, _countof(args), args);
              });
            })
          );
        }
        catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }

      }
 else  {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Value> tokenMapVal = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());
      Local<Object> tokenMap;

      if (tokenMapVal.IsEmpty() || Nan::Equals(tokenMapVal, Undefined()).FromMaybe(false)) {
        tokenMap = Nan::New<Object>();
        NodeRT::Utils::SetHiddenValueWithObject(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked(), tokenMap);
      } else {
        tokenMap = Nan::To<Object>(tokenMapVal).ToLocalChecked();
      }

      Nan::Set(tokenMap, info[0], CreateOpaqueWrapper(::Windows::Foundation::PropertyValue::CreateInt64(registrationToken.Value)));
    }

    static void RemoveListener(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"wrong arguments, expected a string and a callback")));
        return;
      }

      String::Value eventName(v8::Isolate::GetCurrent(), info[0]);
      auto str = *eventName;

      if ((!NodeRT::Utils::CaseInsenstiveEquals(L"diagnosticAvailable", str))) {
        Nan::ThrowError(Nan::Error(String::Concat(v8::Isolate::GetCurrent(), NodeRT::Utils::NewString(L"given event name isn't supported: "), info[0].As<String>())));
        return;
      }

      Local<Function> callback = info[1].As<Function>();
      Local<Value> tokenMap = NodeRT::Utils::GetHiddenValue(callback, Nan::New<String>(REGISTRATION_TOKEN_MAP_PROPERTY_NAME).ToLocalChecked());

      if (tokenMap.IsEmpty() || Nan::Equals(tokenMap, Undefined()).FromMaybe(false)) {
        return;
      }

      Local<Value> opaqueWrapperObj =  Nan::Get(Nan::To<Object>(tokenMap).ToLocalChecked(), info[0]).ToLocalChecked();

      if (opaqueWrapperObj.IsEmpty() || Nan::Equals(opaqueWrapperObj,Undefined()).FromMaybe(false)) {
        return;
      }

      OpaqueWrapper *opaqueWrapper = OpaqueWrapper::Unwrap<OpaqueWrapper>(opaqueWrapperObj.As<Object>());

      long long tokenValue = (long long) opaqueWrapper->GetObjectInstance();
      ::Windows::Foundation::EventRegistrationToken registrationToken;
      registrationToken.Value = tokenValue;

      try  {
        if (NodeRT::Utils::CaseInsenstiveEquals(L"diagnosticAvailable", str)) {
          if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^>(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;
          }
          AdaptiveMediaSourceDiagnostics *wrapper = AdaptiveMediaSourceDiagnostics::Unwrap<AdaptiveMediaSourceDiagnostics>(info.This());
          wrapper->_instance->DiagnosticAvailable::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::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDiagnostics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ UnwrapAdaptiveMediaSourceDiagnostics(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDiagnostics::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDiagnostics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ 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>(AdaptiveMediaSourceDiagnostics::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDiagnostics^ UnwrapAdaptiveMediaSourceDiagnostics(Local<Value> value) {
     return AdaptiveMediaSourceDiagnostics::Unwrap<AdaptiveMediaSourceDiagnostics>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDiagnostics(Local<Object> exports) {
    AdaptiveMediaSourceDiagnostics::Init(exports);
  }

  class AdaptiveMediaSourceDownloadBitrateChangedEventArgs : 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>("AdaptiveMediaSourceDownloadBitrateChangedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("newValue").ToLocalChecked(), NewValueGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("oldValue").ToLocalChecked(), OldValueGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("reason").ToLocalChecked(), ReasonGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadBitrateChangedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^) 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());

      AdaptiveMediaSourceDownloadBitrateChangedEventArgs *wrapperInstance = new AdaptiveMediaSourceDownloadBitrateChangedEventArgs(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(winRtInstance));
    }





    static void NewValueGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadBitrateChangedEventArgs *wrapper = AdaptiveMediaSourceDownloadBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourceDownloadBitrateChangedEventArgs>(info.This());

      try  {
        unsigned int result = wrapper->_instance->NewValue;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void OldValueGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadBitrateChangedEventArgs *wrapper = AdaptiveMediaSourceDownloadBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourceDownloadBitrateChangedEventArgs>(info.This());

      try  {
        unsigned int result = wrapper->_instance->OldValue;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ReasonGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadBitrateChangedEventArgs *wrapper = AdaptiveMediaSourceDownloadBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourceDownloadBitrateChangedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedReason result = wrapper->_instance->Reason;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ UnwrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadBitrateChangedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ 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>(AdaptiveMediaSourceDownloadBitrateChangedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadBitrateChangedEventArgs^ UnwrapAdaptiveMediaSourceDownloadBitrateChangedEventArgs(Local<Value> value) {
     return AdaptiveMediaSourceDownloadBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourceDownloadBitrateChangedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadBitrateChangedEventArgs(Local<Object> exports) {
    AdaptiveMediaSourceDownloadBitrateChangedEventArgs::Init(exports);
  }

  class AdaptiveMediaSourceDownloadCompletedEventArgs : 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>("AdaptiveMediaSourceDownloadCompletedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("httpResponseMessage").ToLocalChecked(), HttpResponseMessageGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeLength").ToLocalChecked(), ResourceByteRangeLengthGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeOffset").ToLocalChecked(), ResourceByteRangeOffsetGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceType").ToLocalChecked(), ResourceTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceUri").ToLocalChecked(), ResourceUriGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("position").ToLocalChecked(), PositionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("requestId").ToLocalChecked(), RequestIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("statistics").ToLocalChecked(), StatisticsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceContentType").ToLocalChecked(), ResourceContentTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceDuration").ToLocalChecked(), ResourceDurationGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadCompletedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadCompletedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^) 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());

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapperInstance = new AdaptiveMediaSourceDownloadCompletedEventArgs(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadCompletedEventArgs(winRtInstance));
    }





    static void HttpResponseMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Windows::Web::Http::HttpResponseMessage^ result = wrapper->_instance->HttpResponseMessage;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Web.Http", "HttpResponseMessage", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeLengthGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeLength;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeOffset;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType result = wrapper->_instance->ResourceType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceUriGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Windows::Foundation::Uri^ result = wrapper->_instance->ResourceUri;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PositionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->Position;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void RequestIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        int result = wrapper->_instance->RequestId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void StatisticsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ result = wrapper->_instance->Statistics;
        info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadStatistics(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceContentTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->ResourceContentType;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceDurationGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadCompletedEventArgs *wrapper = AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->ResourceDuration;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadCompletedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ UnwrapAdaptiveMediaSourceDownloadCompletedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadCompletedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadCompletedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ 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>(AdaptiveMediaSourceDownloadCompletedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadCompletedEventArgs^ UnwrapAdaptiveMediaSourceDownloadCompletedEventArgs(Local<Value> value) {
     return AdaptiveMediaSourceDownloadCompletedEventArgs::Unwrap<AdaptiveMediaSourceDownloadCompletedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadCompletedEventArgs(Local<Object> exports) {
    AdaptiveMediaSourceDownloadCompletedEventArgs::Init(exports);
  }

  class AdaptiveMediaSourceDownloadFailedEventArgs : 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>("AdaptiveMediaSourceDownloadFailedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("httpResponseMessage").ToLocalChecked(), HttpResponseMessageGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeLength").ToLocalChecked(), ResourceByteRangeLengthGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeOffset").ToLocalChecked(), ResourceByteRangeOffsetGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceType").ToLocalChecked(), ResourceTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceUri").ToLocalChecked(), ResourceUriGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("extendedError").ToLocalChecked(), ExtendedErrorGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("position").ToLocalChecked(), PositionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("requestId").ToLocalChecked(), RequestIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("statistics").ToLocalChecked(), StatisticsGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceContentType").ToLocalChecked(), ResourceContentTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceDuration").ToLocalChecked(), ResourceDurationGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadFailedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadFailedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^) 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());

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapperInstance = new AdaptiveMediaSourceDownloadFailedEventArgs(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadFailedEventArgs(winRtInstance));
    }





    static void HttpResponseMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Windows::Web::Http::HttpResponseMessage^ result = wrapper->_instance->HttpResponseMessage;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Web.Http", "HttpResponseMessage", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeLengthGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeLength;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeOffset;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType result = wrapper->_instance->ResourceType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceUriGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Windows::Foundation::Uri^ result = wrapper->_instance->ResourceUri;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ExtendedErrorGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Windows::Foundation::HResult result = wrapper->_instance->ExtendedError;
        info.GetReturnValue().Set(Nan::New<Integer>(result.Value));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PositionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->Position;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void RequestIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        int result = wrapper->_instance->RequestId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void StatisticsGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ result = wrapper->_instance->Statistics;
        info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadStatistics(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceContentTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->ResourceContentType;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceDurationGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadFailedEventArgs *wrapper = AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->ResourceDuration;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadFailedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ UnwrapAdaptiveMediaSourceDownloadFailedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadFailedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadFailedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ 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>(AdaptiveMediaSourceDownloadFailedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadFailedEventArgs^ UnwrapAdaptiveMediaSourceDownloadFailedEventArgs(Local<Value> value) {
     return AdaptiveMediaSourceDownloadFailedEventArgs::Unwrap<AdaptiveMediaSourceDownloadFailedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadFailedEventArgs(Local<Object> exports) {
    AdaptiveMediaSourceDownloadFailedEventArgs::Init(exports);
  }

  class AdaptiveMediaSourceDownloadRequestedDeferral : 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>("AdaptiveMediaSourceDownloadRequestedDeferral").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "complete", Complete);
          




        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadRequestedDeferral").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadRequestedDeferral(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^) 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());

      AdaptiveMediaSourceDownloadRequestedDeferral *wrapperInstance = new AdaptiveMediaSourceDownloadRequestedDeferral(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadRequestedDeferral(winRtInstance));
    }


    static void Complete(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedDeferral *wrapper = AdaptiveMediaSourceDownloadRequestedDeferral::Unwrap<AdaptiveMediaSourceDownloadRequestedDeferral>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          wrapper->_instance->Complete();
          return;
        } catch (Platform::Exception ^exception) {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
 else {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }





    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadRequestedDeferral(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ UnwrapAdaptiveMediaSourceDownloadRequestedDeferral(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadRequestedDeferral::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadRequestedDeferral(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ 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>(AdaptiveMediaSourceDownloadRequestedDeferral::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ UnwrapAdaptiveMediaSourceDownloadRequestedDeferral(Local<Value> value) {
     return AdaptiveMediaSourceDownloadRequestedDeferral::Unwrap<AdaptiveMediaSourceDownloadRequestedDeferral>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadRequestedDeferral(Local<Object> exports) {
    AdaptiveMediaSourceDownloadRequestedDeferral::Init(exports);
  }

  class AdaptiveMediaSourceDownloadRequestedEventArgs : 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>("AdaptiveMediaSourceDownloadRequestedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);


          
            Nan::SetPrototypeMethod(localRef, "getDeferral", GetDeferral);
          



          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeLength").ToLocalChecked(), ResourceByteRangeLengthGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeOffset").ToLocalChecked(), ResourceByteRangeOffsetGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceType").ToLocalChecked(), ResourceTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceUri").ToLocalChecked(), ResourceUriGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("result").ToLocalChecked(), ResultGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("position").ToLocalChecked(), PositionGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("requestId").ToLocalChecked(), RequestIdGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceContentType").ToLocalChecked(), ResourceContentTypeGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceDuration").ToLocalChecked(), ResourceDurationGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadRequestedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadRequestedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^) 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());

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapperInstance = new AdaptiveMediaSourceDownloadRequestedEventArgs(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadRequestedEventArgs(winRtInstance));
    }


    static void GetDeferral(Nan::NAN_METHOD_ARGS_TYPE info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      if (info.Length() == 0)
      {
        try
        {
          ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedDeferral^ result;
          result = wrapper->_instance->GetDeferral();
          info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadRequestedDeferral(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 ResourceByteRangeLengthGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeLength;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeOffset;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceResourceType result = wrapper->_instance->ResourceType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceUriGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Windows::Foundation::Uri^ result = wrapper->_instance->ResourceUri;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResultGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ result = wrapper->_instance->Result;
        info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadResult(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void PositionGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->Position;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void RequestIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        int result = wrapper->_instance->RequestId;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceContentTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        Platform::String^ result = wrapper->_instance->ResourceContentType;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceDurationGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadRequestedEventArgs *wrapper = AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->ResourceDuration;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadRequestedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ UnwrapAdaptiveMediaSourceDownloadRequestedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadRequestedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadRequestedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ 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>(AdaptiveMediaSourceDownloadRequestedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadRequestedEventArgs^ UnwrapAdaptiveMediaSourceDownloadRequestedEventArgs(Local<Value> value) {
     return AdaptiveMediaSourceDownloadRequestedEventArgs::Unwrap<AdaptiveMediaSourceDownloadRequestedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadRequestedEventArgs(Local<Object> exports) {
    AdaptiveMediaSourceDownloadRequestedEventArgs::Init(exports);
  }

  class AdaptiveMediaSourceDownloadResult : 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>("AdaptiveMediaSourceDownloadResult").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceUri").ToLocalChecked(), ResourceUriGetter, ResourceUriSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("inputStream").ToLocalChecked(), InputStreamGetter, InputStreamSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("extendedStatus").ToLocalChecked(), ExtendedStatusGetter, ExtendedStatusSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("contentType").ToLocalChecked(), ContentTypeGetter, ContentTypeSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("buffer").ToLocalChecked(), BufferGetter, BufferSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeOffset").ToLocalChecked(), ResourceByteRangeOffsetGetter, ResourceByteRangeOffsetSetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("resourceByteRangeLength").ToLocalChecked(), ResourceByteRangeLengthGetter, ResourceByteRangeLengthSetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadResult").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^) 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());

      AdaptiveMediaSourceDownloadResult *wrapperInstance = new AdaptiveMediaSourceDownloadResult(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadResult(winRtInstance));
    }





    static void ResourceUriGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try  {
        ::Windows::Foundation::Uri^ result = wrapper->_instance->ResourceUri;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Foundation", "Uri", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceUriSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Foundation::Uri^>(value)) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        ::Windows::Foundation::Uri^ winRtValue = dynamic_cast<::Windows::Foundation::Uri^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->ResourceUri = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void InputStreamGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try  {
        ::Windows::Storage::Streams::IInputStream^ result = wrapper->_instance->InputStream;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Storage.Streams", "IInputStream", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void InputStreamSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Storage::Streams::IInputStream^>(value)) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        ::Windows::Storage::Streams::IInputStream^ winRtValue = dynamic_cast<::Windows::Storage::Streams::IInputStream^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->InputStream = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void ExtendedStatusGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try  {
        unsigned int result = wrapper->_instance->ExtendedStatus;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ExtendedStatusSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsUint32()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        unsigned int winRtValue = static_cast<unsigned int>(Nan::To<uint32_t>(value).FromMaybe(0));

        wrapper->_instance->ExtendedStatus = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void ContentTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(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 ContentTypeSetter(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        Platform::String^ winRtValue = ref new Platform::String(NodeRT::Utils::StringToWchar(v8::String::Value(v8::Isolate::GetCurrent(), value)));

        wrapper->_instance->ContentType = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void BufferGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try  {
        ::Windows::Storage::Streams::IBuffer^ result = wrapper->_instance->Buffer;
        info.GetReturnValue().Set(NodeRT::Utils::CreateExternalWinRTObject("Windows.Storage.Streams", "IBuffer", result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void BufferSetter(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        ::Windows::Storage::Streams::IBuffer^ winRtValue = dynamic_cast<::Windows::Storage::Streams::IBuffer^>(NodeRT::Utils::GetObjectInstance(value));

        wrapper->_instance->Buffer = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void ResourceByteRangeOffsetGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeOffset;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeOffsetSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        ::Platform::IBox<unsigned __int64>^ winRtValue = ref new ::Platform::Box<unsigned __int64>(static_cast<unsigned __int64>(Nan::To<int64_t>(value).FromMaybe(0)));

        wrapper->_instance->ResourceByteRangeOffset = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      
    static void ResourceByteRangeLengthGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try  {
        ::Platform::IBox<unsigned __int64>^ result = wrapper->_instance->ResourceByteRangeLength;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(static_cast<double>(result->Value))) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void ResourceByteRangeLengthSetter(Local<String> property, Local<Value> value, const Nan::PropertyCallbackInfo<void> &info) {
      HandleScope scope;

      if (!value->IsNumber()) {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Value to set is of unexpected type")));
        return;
      }

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadResult *wrapper = AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(info.This());

      try {

        ::Platform::IBox<unsigned __int64>^ winRtValue = ref new ::Platform::Box<unsigned __int64>(static_cast<unsigned __int64>(Nan::To<int64_t>(value).FromMaybe(0)));

        wrapper->_instance->ResourceByteRangeLength = winRtValue;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ UnwrapAdaptiveMediaSourceDownloadResult(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadResult::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadResult(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ 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>(AdaptiveMediaSourceDownloadResult::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadResult^ UnwrapAdaptiveMediaSourceDownloadResult(Local<Value> value) {
     return AdaptiveMediaSourceDownloadResult::Unwrap<AdaptiveMediaSourceDownloadResult>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadResult(Local<Object> exports) {
    AdaptiveMediaSourceDownloadResult::Init(exports);
  }

  class AdaptiveMediaSourceDownloadStatistics : 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>("AdaptiveMediaSourceDownloadStatistics").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("contentBytesReceivedCount").ToLocalChecked(), ContentBytesReceivedCountGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timeToFirstByteReceived").ToLocalChecked(), TimeToFirstByteReceivedGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timeToHeadersReceived").ToLocalChecked(), TimeToHeadersReceivedGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("timeToLastByteReceived").ToLocalChecked(), TimeToLastByteReceivedGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourceDownloadStatistics").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourceDownloadStatistics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^) 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());

      AdaptiveMediaSourceDownloadStatistics *wrapperInstance = new AdaptiveMediaSourceDownloadStatistics(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourceDownloadStatistics(winRtInstance));
    }





    static void ContentBytesReceivedCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadStatistics *wrapper = AdaptiveMediaSourceDownloadStatistics::Unwrap<AdaptiveMediaSourceDownloadStatistics>(info.This());

      try  {
        unsigned __int64 result = wrapper->_instance->ContentBytesReceivedCount;
        info.GetReturnValue().Set(Nan::New<Number>(static_cast<double>(result)));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void TimeToFirstByteReceivedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadStatistics *wrapper = AdaptiveMediaSourceDownloadStatistics::Unwrap<AdaptiveMediaSourceDownloadStatistics>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->TimeToFirstByteReceived;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void TimeToHeadersReceivedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadStatistics *wrapper = AdaptiveMediaSourceDownloadStatistics::Unwrap<AdaptiveMediaSourceDownloadStatistics>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->TimeToHeadersReceived;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void TimeToLastByteReceivedGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^>(info.This())) {
        return;
      }

      AdaptiveMediaSourceDownloadStatistics *wrapper = AdaptiveMediaSourceDownloadStatistics::Unwrap<AdaptiveMediaSourceDownloadStatistics>(info.This());

      try  {
        ::Platform::IBox<::Windows::Foundation::TimeSpan>^ result = wrapper->_instance->TimeToLastByteReceived;
        info.GetReturnValue().Set(result ? static_cast<Local<Value>>(Nan::New<Number>(result->Value.Duration/10000.0)) : Undefined());
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadStatistics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ UnwrapAdaptiveMediaSourceDownloadStatistics(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourceDownloadStatistics::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourceDownloadStatistics(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ 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>(AdaptiveMediaSourceDownloadStatistics::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourceDownloadStatistics^ UnwrapAdaptiveMediaSourceDownloadStatistics(Local<Value> value) {
     return AdaptiveMediaSourceDownloadStatistics::Unwrap<AdaptiveMediaSourceDownloadStatistics>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourceDownloadStatistics(Local<Object> exports) {
    AdaptiveMediaSourceDownloadStatistics::Init(exports);
  }

  class AdaptiveMediaSourcePlaybackBitrateChangedEventArgs : 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>("AdaptiveMediaSourcePlaybackBitrateChangedEventArgs").ToLocalChecked());
        localRef->InstanceTemplate()->SetInternalFieldCount(1);





          
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("audioOnly").ToLocalChecked(), AudioOnlyGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("newValue").ToLocalChecked(), NewValueGetter);
            Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("oldValue").ToLocalChecked(), OldValueGetter);

        Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
        Nan::SetMethod(constructor, "castFrom", CastFrom);



        Nan::Set(exports, Nan::New<String>("AdaptiveMediaSourcePlaybackBitrateChangedEventArgs").ToLocalChecked(), constructor);
      }

      virtual ::Platform::Object^ GetObjectInstance() const override {
        return _instance;
      }

    private:

      AdaptiveMediaSourcePlaybackBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ 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::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^>(info[0])) {
        try {
          winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^) 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());

      AdaptiveMediaSourcePlaybackBitrateChangedEventArgs *wrapperInstance = new AdaptiveMediaSourcePlaybackBitrateChangedEventArgs(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::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^>(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::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ winRtInstance;
      try {
        winRtInstance = (::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^) NodeRT::Utils::GetObjectInstance(info[0]);
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }

      info.GetReturnValue().Set(WrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(winRtInstance));
    }





    static void AudioOnlyGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourcePlaybackBitrateChangedEventArgs *wrapper = AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourcePlaybackBitrateChangedEventArgs>(info.This());

      try  {
        bool result = wrapper->_instance->AudioOnly;
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void NewValueGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourcePlaybackBitrateChangedEventArgs *wrapper = AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourcePlaybackBitrateChangedEventArgs>(info.This());

      try  {
        unsigned int result = wrapper->_instance->NewValue;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      
    static void OldValueGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info) {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^>(info.This())) {
        return;
      }

      AdaptiveMediaSourcePlaybackBitrateChangedEventArgs *wrapper = AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourcePlaybackBitrateChangedEventArgs>(info.This());

      try  {
        unsigned int result = wrapper->_instance->OldValue;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      } catch (Platform::Exception ^exception) {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
      


    private:
      ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ _instance;
      static Persistent<FunctionTemplate> s_constructorTemplate;

      friend v8::Local<v8::Value> WrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ wintRtInstance);
      friend ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ UnwrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(Local<Value> value);
  };

  Persistent<FunctionTemplate> AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::s_constructorTemplate;

  v8::Local<v8::Value> WrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ 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>(AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::Media::Streaming::Adaptive::AdaptiveMediaSourcePlaybackBitrateChangedEventArgs^ UnwrapAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(Local<Value> value) {
     return AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::Unwrap<AdaptiveMediaSourcePlaybackBitrateChangedEventArgs>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(Local<Object> exports) {
    AdaptiveMediaSourcePlaybackBitrateChangedEventArgs::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::Media::Streaming::Adaptive::InitAdaptiveMediaSourceCreationStatusEnum(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDiagnosticTypeEnum(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadBitrateChangedReasonEnum(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceResourceTypeEnum(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSource(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceAdvancedSettings(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceCorrelatedTimes(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceCreationResult(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDiagnosticAvailableEventArgs(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDiagnostics(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadBitrateChangedEventArgs(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadCompletedEventArgs(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadFailedEventArgs(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadRequestedDeferral(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadRequestedEventArgs(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadResult(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourceDownloadStatistics(target);
      NodeRT::Windows::Media::Streaming::Adaptive::InitAdaptiveMediaSourcePlaybackBitrateChangedEventArgs(target);


  NodeRT::Utils::RegisterNameSpace("Windows.Media.Streaming.Adaptive", target);
}



NODE_MODULE(binding, init)
