Esempio n. 1
0
        private void _sendImage(PSImage image, Stream outputStream, BinaryWriter writer)
        {
            var transferSyntax = TransferSyntaxes.Lookup(image.TransferSyntaxID);

            if (transferSyntax.Compression != DICOMSharp.Data.Compression.CompressionInfo.None)
            {
                // Need to decompress
                var data = new DICOMData();
                data.ParseFile(PSUtils.GetParsedFilePath(image.Path), true, PSUtils.GetLogger());
                data.Uncompress();

                var memStream = new MemoryStream();
                data.WriteToStreamAsPart10File(memStream, PSUtils.GetLogger());

                writer.Write((UInt32)(memStream.Length + 4));
                memStream.Position = 0;
                memStream.CopyTo(outputStream);
            }
            else
            {
                // Write the file out directly.
                var fileInfo = new FileInfo(PSUtils.GetParsedFilePath(image.Path));
                var size     = fileInfo.Length;
                writer.Write((UInt32)(size + 4));
                fileInfo.OpenRead().CopyTo(outputStream);
            }
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName = this.ResourceGroupName;
                string imageName         = this.ImageName;
                string expand            = this.Expand;

                if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(imageName))
                {
                    var result   = ImagesClient.Get(resourceGroupName, imageName, expand);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
                else if (!string.IsNullOrEmpty(resourceGroupName))
                {
                    var result       = ImagesClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = ImagesClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSImageList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImageList>(r));
                    }
                    WriteObject(psObject, true);
                }
                else
                {
                    var result       = ImagesClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = ImagesClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSImageList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImageList>(r));
                    }
                    WriteObject(psObject, true);
                }
            });
        }
Esempio n. 3
0
        protected void ExecuteImageGetMethod(object[] invokeMethodInputParameters)
        {
            string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]);
            string imageName         = (string)ParseParameter(invokeMethodInputParameters[1]);
            string expand            = (string)ParseParameter(invokeMethodInputParameters[2]);

            if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(imageName))
            {
                var result   = ImagesClient.Get(resourceGroupName, imageName, expand);
                var psObject = new PSImage();
                Mapper.Map <Image, PSImage>(result, psObject);
                WriteObject(psObject);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName))
            {
                var result       = ImagesClient.ListByResourceGroup(resourceGroupName);
                var resultList   = result.ToList();
                var nextPageLink = result.NextPageLink;
                while (!string.IsNullOrEmpty(nextPageLink))
                {
                    var pageResult = ImagesClient.ListByResourceGroupNext(nextPageLink);
                    foreach (var pageItem in pageResult)
                    {
                        resultList.Add(pageItem);
                    }
                    nextPageLink = pageResult.NextPageLink;
                }
                var psObject = new List <PSImageList>();
                foreach (var r in resultList)
                {
                    psObject.Add(Mapper.Map <Image, PSImageList>(r));
                }
                WriteObject(psObject);
            }
            else
            {
                var result       = ImagesClient.List();
                var resultList   = result.ToList();
                var nextPageLink = result.NextPageLink;
                while (!string.IsNullOrEmpty(nextPageLink))
                {
                    var pageResult = ImagesClient.ListNext(nextPageLink);
                    foreach (var pageItem in pageResult)
                    {
                        resultList.Add(pageItem);
                    }
                    nextPageLink = pageResult.NextPageLink;
                }
                var psObject = new List <PSImageList>();
                foreach (var r in resultList)
                {
                    psObject.Add(Mapper.Map <Image, PSImageList>(r));
                }
                WriteObject(psObject);
            }
        }
        private void Run()
        {
            WriteWarning("New-AzureRmImageConfig: A property of the output of this cmdlet will change in an upcoming breaking change release. " +
                         "The StorageAccountType property for a DataDisk will return Standard_LRS and Premium_LRS");

            // SourceVirtualMachine
            Microsoft.Azure.Management.Compute.Models.SubResource vSourceVirtualMachine = null;

            // StorageProfile
            Microsoft.Azure.Management.Compute.Models.ImageStorageProfile vStorageProfile = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("SourceVirtualMachineId"))
            {
                if (vSourceVirtualMachine == null)
                {
                    vSourceVirtualMachine = new Microsoft.Azure.Management.Compute.Models.SubResource();
                }
                vSourceVirtualMachine.Id = this.SourceVirtualMachineId;
            }

            if (this.MyInvocation.BoundParameters.ContainsKey("OsDisk"))
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
                }
                vStorageProfile.OsDisk = this.OsDisk;
            }

            if (this.MyInvocation.BoundParameters.ContainsKey("DataDisk"))
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
                }
                vStorageProfile.DataDisks = this.DataDisk;
            }

            if (vStorageProfile == null)
            {
                vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
            }
            vStorageProfile.ZoneResilient = this.ZoneResilient.IsPresent;

            var vImage = new PSImage
            {
                Location             = this.MyInvocation.BoundParameters.ContainsKey("Location") ? this.Location : null,
                Tags                 = this.MyInvocation.BoundParameters.ContainsKey("Tag") ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
                SourceVirtualMachine = vSourceVirtualMachine,
                StorageProfile       = vStorageProfile,
            };

            WriteObject(vImage);
        }
Esempio n. 5
0
        private void Run()
        {
            // SourceVirtualMachine
            SubResource vSourceVirtualMachine = null;

            // StorageProfile
            ImageStorageProfile vStorageProfile = null;

            if (this.IsParameterBound(c => c.SourceVirtualMachineId))
            {
                if (vSourceVirtualMachine == null)
                {
                    vSourceVirtualMachine = new SubResource();
                }
                vSourceVirtualMachine.Id = this.SourceVirtualMachineId;
            }

            if (this.IsParameterBound(c => c.OsDisk))
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new ImageStorageProfile();
                }
                vStorageProfile.OsDisk = this.OsDisk;
            }

            if (this.IsParameterBound(c => c.DataDisk))
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new ImageStorageProfile();
                }
                vStorageProfile.DataDisks = this.DataDisk;
            }

            if (vStorageProfile == null)
            {
                vStorageProfile = new ImageStorageProfile();
            }
            vStorageProfile.ZoneResilient = this.ZoneResilient.IsPresent;

            var vImage = new PSImage
            {
                HyperVGeneration     = this.IsParameterBound(c => c.HyperVGeneration) ? this.HyperVGeneration : "V1",
                Location             = this.IsParameterBound(c => c.Location) ? this.Location : null,
                Tags                 = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
                SourceVirtualMachine = vSourceVirtualMachine,
                StorageProfile       = vStorageProfile,
            };

            WriteObject(vImage);
        }
Esempio n. 6
0
        private void Run()
        {
            // SourceVirtualMachine
            Microsoft.Azure.Management.Compute.Models.SubResource vSourceVirtualMachine = null;

            // StorageProfile
            Microsoft.Azure.Management.Compute.Models.ImageStorageProfile vStorageProfile = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("SourceVirtualMachineId"))
            {
                if (vSourceVirtualMachine == null)
                {
                    vSourceVirtualMachine = new Microsoft.Azure.Management.Compute.Models.SubResource();
                }
                vSourceVirtualMachine.Id = this.SourceVirtualMachineId;
            }

            if (this.MyInvocation.BoundParameters.ContainsKey("OsDisk"))
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
                }
                vStorageProfile.OsDisk = this.OsDisk;
            }

            if (this.MyInvocation.BoundParameters.ContainsKey("DataDisk"))
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
                }
                vStorageProfile.DataDisks = this.DataDisk;
            }

            if (vStorageProfile == null)
            {
                vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
            }
            vStorageProfile.ZoneResilient = this.ZoneResilient.IsPresent;

            var vImage = new PSImage
            {
                Location             = this.MyInvocation.BoundParameters.ContainsKey("Location") ? this.Location : null,
                Tags                 = this.MyInvocation.BoundParameters.ContainsKey("Tag") ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
                SourceVirtualMachine = vSourceVirtualMachine,
                StorageProfile       = vStorageProfile,
            };

            WriteObject(vImage);
        }
        private void Run()
        {
            // SourceVirtualMachine
            Microsoft.Azure.Management.Compute.Models.SubResource vSourceVirtualMachine = null;

            // StorageProfile
            Microsoft.Azure.Management.Compute.Models.ImageStorageProfile vStorageProfile = null;

            if (this.SourceVirtualMachineId != null)
            {
                if (vSourceVirtualMachine == null)
                {
                    vSourceVirtualMachine = new Microsoft.Azure.Management.Compute.Models.SubResource();
                }
                vSourceVirtualMachine.Id = this.SourceVirtualMachineId;
            }

            if (this.OsDisk != null)
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
                }
                vStorageProfile.OsDisk = this.OsDisk;
            }

            if (this.DataDisk != null)
            {
                if (vStorageProfile == null)
                {
                    vStorageProfile = new Microsoft.Azure.Management.Compute.Models.ImageStorageProfile();
                }
                vStorageProfile.DataDisks = this.DataDisk;
            }


            var vImage = new PSImage
            {
                Location             = this.Location,
                Tags                 = (this.Tag == null) ? null : this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value),
                SourceVirtualMachine = vSourceVirtualMachine,
                StorageProfile       = vStorageProfile,
            };

            WriteObject(vImage);
        }
        public override void ExecuteCmdlet()
        {
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ImageName, VerbsData.Update))
                {
                    string resourceGroupName = this.ResourceGroupName;
                    string imageName         = this.ImageName;
                    Image parameters         = new Image();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSImage, Image>(this.Image, parameters);

                    var result   = ImagesClient.CreateOrUpdate(resourceGroupName, imageName, parameters);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        protected override void ProcessRecord()
        {
            AutoMapper.Mapper.AddProfile <ComputeAutomationAutoMapperProfile>();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ImageName, VerbsCommon.New))
                {
                    string resourceGroupName = this.ResourceGroupName;
                    string imageName         = this.ImageName;
                    Image parameters         = new Image();
                    Mapper.Map <PSImage, Image>(this.Image, parameters);

                    var result   = ImagesClient.CreateOrUpdate(resourceGroupName, imageName, parameters);
                    var psObject = new PSImage();
                    Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Esempio n. 10
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ImageName, VerbsData.Update))
                {
                    string resourceGroupName;
                    string imageName;
                    switch (this.ParameterSetName)
                    {
                    case "ResourceIdParameter":
                        resourceGroupName = GetResourceGroupName(this.ResourceId);
                        imageName         = GetResourceName(this.ResourceId, "Microsoft.Compute/images");
                        break;

                    case "ObjectParameter":
                        resourceGroupName = GetResourceGroupName(this.Image.Id);
                        imageName         = GetResourceName(this.Image.Id, "Microsoft.Compute/images");
                        break;

                    default:
                        resourceGroupName = this.ResourceGroupName;
                        imageName         = this.ImageName;
                        break;
                    }

                    var parameters  = ImagesClient.Get(resourceGroupName, imageName);
                    parameters.Tags = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null;

                    if (string.IsNullOrEmpty(parameters.HyperVGeneration))
                    {
                        parameters.HyperVGeneration = HyperVGenerationTypes.V1; // temporarily unblock create image until this parameter is added.
                    }

                    var result   = ImagesClient.CreateOrUpdate(resourceGroupName, imageName, parameters);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ImageName, VerbsCommon.New))
                {
                    string resourceGroupName = this.ResourceGroupName;
                    string imageName         = this.ImageName;
                    Image parameters         = new Image();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSImage, Image>(this.Image, parameters);
                    parameters.HyperVGeneration = HyperVGenerationTypes.V1; // temporarily unblock create image until this parameter is added.

                    var result   = ImagesClient.CreateOrUpdate(resourceGroupName, imageName, parameters);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Esempio n. 12
0
        public override void ExecuteCmdlet()
        {
            ExecuteClientAction(() =>
            {
                WriteWarning("Update-AzureRmImage: A property of the output of this cmdlet will change in an upcoming breaking change release. " +
                             "The StorageAccountType property for a DataDisk will return Standard_LRS and Premium_LRS");

                if (ShouldProcess(this.ImageName, VerbsData.Update))
                {
                    string resourceGroupName = this.ResourceGroupName;
                    string imageName         = this.ImageName;
                    Image parameters         = new Image();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSImage, Image>(this.Image, parameters);

                    var result   = ImagesClient.CreateOrUpdate(resourceGroupName, imageName, parameters);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.ImageName, VerbsData.Update))
                {
                    string resourceGroupName;
                    string imageName;
                    switch (this.ParameterSetName)
                    {
                    case "ResourceIdParameter":
                        resourceGroupName = GetResourceGroupName(this.ResourceId);
                        imageName         = GetResourceName(this.ResourceId, "Microsoft.Compute/Images");
                        break;

                    case "ObjectParameter":
                        resourceGroupName = GetResourceGroupName(this.Image.Id);
                        imageName         = GetResourceName(this.Image.Id, "Microsoft.Compute/Images");
                        break;

                    default:
                        resourceGroupName = this.ResourceGroupName;
                        imageName         = this.ImageName;
                        break;
                    }

                    var parameters  = ImagesClient.Get(resourceGroupName, imageName);
                    parameters.Tags = this.MyInvocation.BoundParameters.ContainsKey("Tag") ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null;

                    var result   = ImagesClient.CreateOrUpdate(resourceGroupName, imageName, parameters);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecuteClientAction(() =>
            {
                WriteWarning("Get-AzureRmImage: A property of the output of this cmdlet will change in an upcoming breaking change release. " +
                             "The StorageAccountType property for a DataDisk will return Standard_LRS and Premium_LRS");

                string resourceGroupName = this.ResourceGroupName;
                string imageName         = this.ImageName;
                string expand            = this.Expand;

                if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(imageName))
                {
                    var result   = ImagesClient.Get(resourceGroupName, imageName, expand);
                    var psObject = new PSImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImage>(result, psObject);
                    WriteObject(psObject);
                }
                else if (!string.IsNullOrEmpty(resourceGroupName))
                {
                    var result       = ImagesClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = ImagesClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSImageList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImageList>(r));
                    }
                    WriteObject(psObject, true);
                }
                else
                {
                    var result       = ImagesClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = ImagesClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSImageList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Image, PSImageList>(r));
                    }
                    WriteObject(psObject, true);
                }
            });
        }