protected override HandlerManifest BuildHandlerManifest(bool useTPM)
        {
            HandlerManifest manifest = new HandlerManifest();

            manifest.PackageReferences.Add(new NuGetReference("Newtonsoft.Json", "9.0.1"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.Amqp", "1.1.5"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.Devices.Client", "1.0.16"));
            manifest.PackageReferences.Add(new NuGetReference("PCLCrypto", "2.0.147"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.BCrypt", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.Kernel32", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.NCrypt", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.Windows.Core", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("Validation", "2.3.5"));

            if (useTPM)
            {
                manifest.PackageReferences.Add(new NuGetReference("Microsoft.Devices.Tpm", "1.0.0"));
                manifest.PackageReferences.Add(new NuGetReference("Microsoft.TSS", "1.0.3"));
            }

            if (useTPM)
            {
                manifest.Files.Add(new FileToAdd("CSharp/Tpm/AzureIoTHub.cs"));
            }
            else
            {
                manifest.Files.Add(new FileToAdd("CSharp/AzureIoTHub.cs"));
            }

            return(manifest);
        }
Exemplo n.º 2
0
        protected override HandlerManifest BuildHandlerManifest(bool useTPM)
        {
            if (useTPM)
            {
                throw new NotSupportedException("TPM support for this project type is not yet supported");
            }

            HandlerManifest manifest = new HandlerManifest();

            manifest.PackageReferences.Add(new NuGetReference("Newtonsoft.Json", "9.0.1"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.Amqp", "1.1.6"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.Devices.Client", "1.0.16"));

            manifest.Files.Add(new FileToAdd("CPP/WAC/azure_iot_hub.cpp"));
            manifest.Files.Add(new FileToAdd("CPP/WAC/azure_iot_hub.h"));

            return(manifest);
        }
Exemplo n.º 3
0
        protected override HandlerManifest BuildHandlerManifest(bool useTPM)
        {
            if (useTPM)
            {
                throw new NotSupportedException("TPM support for this project type is not yet supported");
            }

            HandlerManifest manifest = new HandlerManifest();

            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.C.SharedUtility", "1.0.14"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.IoTHub.AmqpTransport", "1.0.14"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.IoTHub.IoTHubClient", "1.0.14"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.uamqp", "1.0.15"));

            manifest.Files.Add(new FileToAdd("CPP/NonWAC/azure_iot_hub.cpp"));
            manifest.Files.Add(new FileToAdd("CPP/NonWAC/azure_iot_hub.h"));

            return(manifest);
        }
Exemplo n.º 4
0
        protected override HandlerManifest BuildHandlerManifest(bool useTPM)
        {
            HandlerManifest manifest = new HandlerManifest();

            manifest.PackageReferences.Add(new NuGetReference("DotNetty.Buffers-signed", "0.3.2"));
            manifest.PackageReferences.Add(new NuGetReference("DotNetty.Codecs.Mqtt-signed", "0.3.2"));
            manifest.PackageReferences.Add(new NuGetReference("DotNetty.Codecs-signed", "0.3.2"));
            manifest.PackageReferences.Add(new NuGetReference("DotNetty.Common-signed", "0.3.2"));
            manifest.PackageReferences.Add(new NuGetReference("DotNetty.Handlers-signed", "0.3.2"));
            manifest.PackageReferences.Add(new NuGetReference("DotNetty.Transport-signed", "0.3.2"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.AspNet.WebApi.Client", "5.2.3"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.Amqp", "1.1.5"));
            manifest.PackageReferences.Add(new NuGetReference("EnterpriseLibrary.TransientFaultHandling", "6.0.1304.0"));
            manifest.PackageReferences.Add(new NuGetReference("Microsoft.Azure.Devices.Client", "1.0.16"));
            manifest.PackageReferences.Add(new NuGetReference("Newtonsoft.Json", "9.0.1"));
            manifest.PackageReferences.Add(new NuGetReference("PCLCrypto", "2.0.147"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.BCrypt", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.Kernel32", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.NCrypt", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("PInvoke.Windows.Core", "0.3.90"));
            manifest.PackageReferences.Add(new NuGetReference("Validation", "2.3.5"));

            if (useTPM)
            {
                manifest.PackageReferences.Add(new NuGetReference("Microsoft.Devices.Tpm", "1.0.0"));
                manifest.PackageReferences.Add(new NuGetReference("Microsoft.TSS", "1.0.3"));
            }

            if (useTPM)
            {
                manifest.Files.Add(new FileToAdd("CSharp/Tpm/AzureIoTHub.cs"));
            }
            else
            {
                manifest.Files.Add(new FileToAdd("CSharp/AzureIoTHub.cs"));
            }

            return(manifest);
        }
Exemplo n.º 5
0
        public override async Task <AddServiceInstanceResult> AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct)
        {
            var cancel = context.ServiceInstance.Metadata["Cancel"];

            if (cancel != null)
            {
                if ((bool)cancel)
                {
                    // Cancellation
                    throw new OperationCanceledException();
                }
            }

            // Once C++ is officially supported, we can switch this to context.HandlerHelper, removing AzureIoTHubConnectedServiceHandlerHelper
            var handlerHelper = GetConnectedServiceHandlerHelper(context);

            bool bUseTPM = (bool)context.ServiceInstance.Metadata["TPM"];

            if (bUseTPM)
            {
                handlerHelper.TokenReplacementValues.Add("TPMSlot", "0");
            }
            else
            {
                IAzureIoTHub iotHubAccount = context.ServiceInstance.Metadata["IoTHubAccount"] as IAzureIoTHub;
                var          primaryKeys   = await iotHubAccount.GetPrimaryKeysAsync(ct);

                var ioTHubUri = context.ServiceInstance.Metadata["iotHubUri"] as string;

                handlerHelper.TokenReplacementValues.Add("iotHubUri", ioTHubUri);

                var device = GetSelectedDevice(context, ioTHubUri, primaryKeys.IoTHubOwner);
                if (device == null)
                {
                    throw new OperationCanceledException();
                }
                else
                {
                    handlerHelper.TokenReplacementValues.Add("deviceId", device.Id);
                    handlerHelper.TokenReplacementValues.Add("deviceKey", device.Key);
                    handlerHelper.TokenReplacementValues.Add("iotHubOwnerPrimaryKey", primaryKeys.IoTHubOwner);
                    handlerHelper.TokenReplacementValues.Add("servicePrimaryKey", primaryKeys.Service);
                }
            }

            HandlerManifest configuration = this.BuildHandlerManifest(bUseTPM);

            await this.AddSdkReferenceAsync(context, configuration, ct);

            foreach (var fileToAdd in configuration.Files)
            {
                var    file       = this.CopyResourceToTemporaryPath(fileToAdd.Path, handlerHelper);
                string targetPath = Path.GetFileName(fileToAdd.Path); // Use the same name
                string addedFile  = await handlerHelper.AddFileAsync(file, targetPath);
            }

            AddServiceInstanceResult result = this.CreateAddServiceInstanceResult(context);

            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "New service instance {0} created", context.ServiceInstance.Name);

            return(result);
        }
Exemplo n.º 6
0
        private async Task AddSdkReferenceAsync(ConnectedServiceHandlerContext context, HandlerManifest manifest, CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();

            foreach (var nuget in manifest.PackageReferences)
            {
                Dictionary <string, string> packages = new Dictionary <string, string>();

                packages.Add(nuget.Id, nuget.Version);

                try
                {
                    await NuGetUtilities.InstallPackagesAsync(
                        packages,
                        "ConnectedServiceForAzureIoTHub.9e26cafb-e929-4d85-a8af-42c42f72f771",
                        context.Logger,
                        ProjectUtilities.GetDteProject(context.ProjectHierarchy),
                        this.PackageInstallerServices,
                        this.PackageInstaller);
                }
                catch (Exception ex)
                {
                    var status = string.Format("Package {0} installation failed. Exception: '{1}'. WARNING: The project might not compile!", nuget.Id, ex.Message);
                    await context.Logger.WriteMessageAsync(LoggerMessageCategory.Warning, status);
                }
            }
        }