Example #1
0
        // класс для вычисления маршрута.
        public static List<Point> FindPath(AreaType[,] field, Point start, Point goal)
        {
            // Шаг 1.
            var closedSet = new Collection<PathNode>();
            var openSet = new Collection<PathNode>();
            // Шаг 2.
            PathNode startNode = new PathNode()
            {
                Position = start,
                CameFrom = null,
                PathLengthFromStart = 0,
                HeuristicEstimatePathLength = GetHeuristicPathLength(start, goal)
            };
            openSet.Add(startNode);
            while (openSet.Count > 0)
            {
                // Шаг 3.

                var currentNode = openSet.OrderBy(node =>
                  node.EstimateFullPathLength).First();
                // Шаг 4.
                if (currentNode.Position == goal /*|| GetHeuristicPathLength(currentNode.Position, start) > 50*/)
                {
                    
                    return GetPathForNode(currentNode);
                  
                }
                // Шаг 5.
                openSet.Remove(currentNode);
                closedSet.Add(currentNode);
                // Шаг 6.
                foreach (var neighbourNode in GetNeighbours(currentNode, goal, field))
                {
                    // Шаг 7.
                    if (closedSet.Count(node => node.Position == neighbourNode.Position) > 0)
                    {
                        continue;
                    }
                        
                    var openNode = openSet.FirstOrDefault(node =>
                      node.Position == neighbourNode.Position);
                    // Шаг 8.
                    if (openNode == null)
                        openSet.Add(neighbourNode);
                    else
                        if (openNode.PathLengthFromStart > neighbourNode.PathLengthFromStart)
                        {
                            // Шаг 9.
                            openNode.CameFrom = currentNode;
                            openNode.PathLengthFromStart = neighbourNode.PathLengthFromStart;
                        }
                }
            }
            // Шаг 10.
            return null;
        }
 public static void Initialize()
 {
     Tasks = new Collection<Task>();
     Done = new Collection<Task>();
     string videoFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
     Tasks.Add(new Task(1, "Première tache"));
     Tasks.Add(new Task(2, "Première tadche"));
     Tasks.Add(new Task(2, "Première tacezrhe"));
     Tasks.Add(new Task(4, "Première tfache"));
 }
        protected Collection<InputEndpointContext> GetInputEndpoints()
        {
            var role = VM.GetInstance();

            var networkConfiguration = role.ConfigurationSets
                                           .OfType<NetworkConfigurationSet>()
                                           .SingleOrDefault();

            if (networkConfiguration == null)
            {
                networkConfiguration = new NetworkConfigurationSet();
                role.ConfigurationSets.Add(networkConfiguration);
            }

            if (networkConfiguration.InputEndpoints == null)
            {
                networkConfiguration.InputEndpoints = new Collection<InputEndpoint>();
            }

            var inputEndpoints = networkConfiguration.InputEndpoints;

            Collection<InputEndpointContext> endpoints = new Collection<InputEndpointContext>();
            foreach (InputEndpoint ep in inputEndpoints)
            {
                InputEndpointContext endpointCtx = new InputEndpointContext
                {
                    LBSetName = ep.LoadBalancedEndpointSetName,
                    LocalPort = ep.LocalPort,
                    Name = ep.Name,
                    Port = ep.Port,
                    Protocol = ep.Protocol,
                    Vip = ep.Vip,
                    Acl = ep.EndpointAccessControlList,
                    EnableDirectServerReturn = ep.EnableDirectServerReturn,
                    InternalLoadBalancerName = ep.LoadBalancerName,
                    IdleTimeoutInMinutes = ep.IdleTimeoutInMinutes,
                };

                if (ep.LoadBalancerProbe != null && string.IsNullOrEmpty(endpointCtx.LBSetName) == false)
                {
                    endpointCtx.ProbePath = ep.LoadBalancerProbe.Path;
                    endpointCtx.ProbePort = ep.LoadBalancerProbe.Port;
                    endpointCtx.ProbeProtocol = ep.LoadBalancerProbe.Protocol;
                    endpointCtx.ProbeIntervalInSeconds = ep.LoadBalancerProbe.IntervalInSeconds;
                    endpointCtx.ProbeTimeoutInSeconds = ep.LoadBalancerProbe.TimeoutInSeconds;
                }

                endpoints.Add(endpointCtx);
            }

            return endpoints;
        }
Example #4
0
 public int AddCollection(CollectionModel collection)
 {
     try
     {
         Collection newCollection=new Collection();
         newCollection.Car_ID = collection.CarID;
         newCollection.UserInfo_ID = collection.UserInfo_ID;
         context.AddToCollection(newCollection);
         context.SaveChanges();
         return 1;
     }
     catch (Exception)
     {
         return 0;
     }
 }
        protected Collection<InputEndpointContext> GetInputEndpoints()
        {
            var role = VM.GetInstance();

            var networkConfiguration = role.ConfigurationSets
                                        .OfType<NetworkConfigurationSet>()
                                        .SingleOrDefault();

            if (networkConfiguration == null)
            {
                networkConfiguration = new NetworkConfigurationSet();
                role.ConfigurationSets.Add(networkConfiguration);
            }

            if (networkConfiguration.InputEndpoints == null)
            {
                networkConfiguration.InputEndpoints = new Collection<InputEndpoint>();
            }

            var inputEndpoints = networkConfiguration.InputEndpoints;

            Collection<InputEndpointContext> endpoints = new Collection<InputEndpointContext>();
            foreach (InputEndpoint ep in inputEndpoints)
            {
                InputEndpointContext endpointCtx = new InputEndpointContext
                {
                    LBSetName = ep.LoadBalancedEndpointSetName,
                    LocalPort = ep.LocalPort,
                    Name = ep.Name,
                    Port = ep.Port,
                    Protocol = ep.Protocol,
                    Vip = ep.Vip
                };

                if (ep.LoadBalancerProbe != null && string.IsNullOrEmpty(endpointCtx.LBSetName) == false)
                {
                    endpointCtx.ProbePath = ep.LoadBalancerProbe.Path;
                    endpointCtx.ProbePort = ep.LoadBalancerProbe.Port;
                    endpointCtx.ProbeProtocol = ep.LoadBalancerProbe.Protocol;
                }

                endpoints.Add(endpointCtx);
            }

            return endpoints;
        }
 public Collection<OSImageContext> GetAzureVMImage(string imageName = null)
 {
     GetAzureVMImageCmdletInfo getAzureVMImageCmdlet = new GetAzureVMImageCmdletInfo(imageName);
     WindowsAzurePowershellCmdletSequence azurePowershellCmdlet = new WindowsAzurePowershellCmdletSequence();
     azurePowershellCmdlet.Add(getAzureVMImageCmdlet);
     Collection<OSImageContext> osImageContext = new Collection<OSImageContext>();
     foreach (PSObject result in azurePowershellCmdlet.Run())
     {
         osImageContext.Add((OSImageContext)result.BaseObject);
     }
     return osImageContext;
 }
        public Collection<VirtualNetworkGatewayContext> GetAzureVNetGateway(string vnetName)
        {
            GetAzureVNetGatewayCmdletInfo getAzureVNetGatewayCmdletInfo = new GetAzureVNetGatewayCmdletInfo(vnetName);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureVNetGatewayCmdletInfo);
            Collection<PSObject> result = azurePowershellCmdlet.Run();

            Collection<VirtualNetworkGatewayContext> vnetGateways = new Collection<VirtualNetworkGatewayContext>();
            foreach (PSObject re in result)
            {
                vnetGateways.Add ((VirtualNetworkGatewayContext) re.BaseObject);
            }
            return vnetGateways;
        }
        internal Collection<ManagementOperationContext> NewAzureVM(string serviceName, PersistentVM[] vms, string vnetName, DnsServer[] dnsSettings, string affinityGroup,
            string serviceLabel, string serviceDescription, string deploymentLabel, string deploymentDescription, string location)
        {
            NewAzureVMCmdletInfo newAzureVMCmdletInfo =
                new NewAzureVMCmdletInfo(serviceName, vms, vnetName, dnsSettings, affinityGroup, serviceLabel, serviceDescription, deploymentLabel, deploymentDescription, location);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(newAzureVMCmdletInfo);

            Collection<ManagementOperationContext> newAzureVMs = new Collection<ManagementOperationContext>();
            foreach (PSObject result in azurePowershellCmdlet.Run())
            {
                newAzureVMs.Add((ManagementOperationContext)result.BaseObject);
            }
            return newAzureVMs;
        }
        public Collection<SubscriptionData> GetAzureSubscription()
        {
            GetAzureSubscriptionCmdletInfo getAzureSubscriptionCmdlet = new GetAzureSubscriptionCmdletInfo();
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureSubscriptionCmdlet);
            Collection<SubscriptionData> subscriptions = new Collection<SubscriptionData>();
            foreach (PSObject result in azurePowershellCmdlet.Run())
            {
                subscriptions.Add((SubscriptionData)result.BaseObject);
            }

            return subscriptions;
        }
Example #10
0
        public void GetRoleProcess()
        {
            Operation getDeploymentOperation;
            var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation);
            if (currentDeployment != null)
            {
                if (this.InstanceDetails.IsPresent == false)
                {
                    var roleContexts = new Collection<RoleContext>();
                    RoleList roles = null;
                    if (string.IsNullOrEmpty(this.RoleName))
                    {
                        roles = currentDeployment.RoleList;
                    }
                    else
                    {
                        roles = new RoleList(currentDeployment.RoleList.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                    }

                    foreach (var r in roles.Select(role => new RoleContext
                        {
                            InstanceCount = currentDeployment.RoleInstanceList.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)),
                            RoleName = role.RoleName,
                            OperationDescription = this.CommandRuntime.ToString(),
                            OperationStatus = getDeploymentOperation.Status,
                            OperationId = getDeploymentOperation.OperationTrackingId,
                            ServiceName = this.ServiceName,
                            DeploymentID = currentDeployment.PrivateID
                        }))
                    {
                        roleContexts.Add(r);
                    }

                    WriteObject(roleContexts, true);
                }
                else
                {
                    Collection<RoleInstanceContext> instanceContexts = new Collection<RoleInstanceContext>();
                    RoleInstanceList roleInstances = null;

                    if (string.IsNullOrEmpty(this.RoleName))
                    {
                        roleInstances = currentDeployment.RoleInstanceList;
                    }
                    else
                    {
                        roleInstances = new RoleInstanceList(currentDeployment.RoleInstanceList.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                    }

                    foreach (RoleInstance role in roleInstances)
                    {
                        var context = new RoleInstanceContext()
                        {
                            ServiceName = this.ServiceName,
                            OperationId = getDeploymentOperation.OperationTrackingId,
                            OperationDescription = this.CommandRuntime.ToString(),
                            OperationStatus = getDeploymentOperation.Status,
                            InstanceErrorCode = role.InstanceErrorCode,
                            InstanceFaultDomain = role.InstanceFaultDomain,
                            InstanceName = role.InstanceName,
                            InstanceSize = role.InstanceSize,
                            InstanceStateDetails = role.InstanceStateDetails,
                            InstanceStatus = role.InstanceStatus,
                            InstanceUpgradeDomain = role.InstanceUpgradeDomain,
                            RoleName = role.RoleName,
                            DeploymentID = currentDeployment.PrivateID,
                            InstanceEndpoints = role.InstanceEndpoints
                        };

                        instanceContexts.Add(context);
                    }

                    WriteObject(instanceContexts, true);
                }
            }
        }
        public static  IList<Management.Compute.Models.ConfigurationSet> MapConfigurationSets(Collection<ConfigurationSet> configurationSets)
        {
            var result = new Collection<Management.Compute.Models.ConfigurationSet>();
            foreach (var networkConfig in configurationSets.OfType<NetworkConfigurationSet>())
            {
                result.Add(Mapper.Map<Management.Compute.Models.ConfigurationSet>(networkConfig));
            }
            foreach (var windowsConfig in configurationSets.OfType<WindowsProvisioningConfigurationSet>())
            {
                var newWinCfg = Mapper.Map<Management.Compute.Models.ConfigurationSet>(windowsConfig);
                if (windowsConfig.WinRM != null)
                {
                    newWinCfg.WindowsRemoteManagement = new WindowsRemoteManagementSettings();

                    // AutoMapper doesn't work for WinRM.Listeners -> WindowsRemoteManagement.Listeners
                    if (windowsConfig.WinRM.Listeners != null)
                    {
                        foreach (var s in windowsConfig.WinRM.Listeners)
                        {
                            newWinCfg.WindowsRemoteManagement.Listeners.Add(new WindowsRemoteManagementListener
                            {
                                ListenerType = (VirtualMachineWindowsRemoteManagementListenerType)Enum.Parse(typeof(VirtualMachineWindowsRemoteManagementListenerType), s.Protocol, true),
                                CertificateThumbprint = s.CertificateThumbprint
                            });
                        }
                    }
                }
                result.Add(newWinCfg);
            }
            foreach (var linuxConfig in configurationSets.OfType<LinuxProvisioningConfigurationSet>())
            {
                result.Add(Mapper.Map<Management.Compute.Models.ConfigurationSet>(linuxConfig));
            }
            return result;
        }
        public Collection<InputEndpointContext> GetAzureEndPoint(PersistentVMRoleContext vmRoleCtxt)
        {
            GetAzureEndpointCmdletInfo getAzureEndpointCmdletInfo = new GetAzureEndpointCmdletInfo(vmRoleCtxt);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureEndpointCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<InputEndpointContext> epCtxts = new Collection<InputEndpointContext>();

            foreach(PSObject re in result)
            {
                epCtxts.Add((InputEndpointContext)re.BaseObject);
            }
            return epCtxts;
        }
        private Management.Compute.Models.Role CreatePersistenVMRole(CloudStorageAccount currentStorage)
        {
            var vm = new Management.Compute.Models.Role
            {
                AvailabilitySetName         = AvailabilitySetName,
                RoleName                    = String.IsNullOrEmpty(Name) ? ServiceName : Name, // default like the portal
                RoleSize                    = InstanceSize,
                RoleType                    = "PersistentVMRole",
                Label                       = ServiceName,
                OSVirtualHardDisk           = _isVMImage ? null : Mapper.Map<Management.Compute.Models.OSVirtualHardDisk>(
                                              new OSVirtualHardDisk
                                              {
                                                  DiskName        = null,
                                                  SourceImageName = ImageName,
                                                  MediaLink       = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation),
                                                  HostCaching     = HostCaching
                                              }),
                VMImageName                 = _isVMImage ? this.ImageName : null,
                MediaLocation               = _isVMImage && !string.IsNullOrEmpty(this.MediaLocation) ? new Uri(this.MediaLocation) : null,
                ProvisionGuestAgent         = !this.DisableGuestAgent,
                ResourceExtensionReferences = this.DisableGuestAgent ? null : Mapper.Map<List<ResourceExtensionReference>>(
                    new VirtualMachineExtensionImageFactory(this.ComputeClient).MakeList(
                        VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultPublisher,
                        VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultName,
                        VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultVersion))
            };

            if (!_isVMImage && vm.OSVirtualHardDisk.MediaLink == null && String.IsNullOrEmpty(vm.OSVirtualHardDisk.Name))
            {
                var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, vm.RoleName);
                vm.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create();
            }

            var configurationSets = new Collection<ConfigurationSet>();
            var netConfig = CreateNetworkConfigurationSet();

            if (ParameterSetName.Equals(WindowsParamSet, StringComparison.OrdinalIgnoreCase))
            {
                if (this.AdminUsername != null && this.Password != null)
                {
                    var windowsConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.WindowsProvisioningConfigurationSet
                    {
                        AdminUsername = this.AdminUsername,
                        AdminPassword = SecureStringHelper.GetSecureString(Password),
                        ComputerName = string.IsNullOrEmpty(Name) ? ServiceName : Name,
                        EnableAutomaticUpdates = true,
                        ResetPasswordOnFirstLogon = false,
                        StoredCertificateSettings = CertUtilsNewSM.GetCertificateSettings(this.Certificates, this.X509Certificates),
                        WinRM = GetWinRmConfiguration()
                    };

                    if (windowsConfig.StoredCertificateSettings == null)
                    {
                        windowsConfig.StoredCertificateSettings = new Model.PersistentVMModel.CertificateSettingList();
                    }

                    configurationSets.Add(windowsConfig);
                }

                netConfig.InputEndpoints.Add(new InputEndpoint {LocalPort = 3389, Protocol = "tcp", Name = "RemoteDesktop"});
                if (!this.NoWinRMEndpoint.IsPresent && !this.DisableWinRMHttps.IsPresent)
                {
                    netConfig.InputEndpoints.Add(new InputEndpoint {LocalPort = WinRMConstants.HttpsListenerPort, Protocol = "tcp", Name = WinRMConstants.EndpointName});
                }

                configurationSets.Add(netConfig);
            }
            else if (ParameterSetName.Equals(LinuxParamSet, StringComparison.OrdinalIgnoreCase))
            {
                if (this.LinuxUser != null && this.Password != null)
                {
                    var linuxConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.LinuxProvisioningConfigurationSet
                    {
                        HostName = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name,
                        UserName = this.LinuxUser,
                        UserPassword = SecureStringHelper.GetSecureString(this.Password),
                        DisableSshPasswordAuthentication = false
                    };

                    if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 ||
                        this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0)
                    {
                        linuxConfig.SSH = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.LinuxProvisioningConfigurationSet.SSHSettings
                        {
                            PublicKeys = this.SSHPublicKeys,
                            KeyPairs = this.SSHKeyPairs
                        };
                    }

                    configurationSets.Add(linuxConfig);
                }

                var rdpEndpoint = new InputEndpoint {LocalPort = 22, Protocol = "tcp", Name = "SSH"};
                netConfig.InputEndpoints.Add(rdpEndpoint);
                configurationSets.Add(netConfig);
            }

            PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c));

            return vm;
        }
        public Collection<DataVirtualHardDisk> GetAzureDataDisk(string vmName, string serviceName)
        {
            PersistentVMRoleContext vmRolectx = GetAzureVM(vmName, serviceName);

            GetAzureDataDiskCmdletInfo getAzureDataDiskCmdlet = new GetAzureDataDiskCmdletInfo(vmRolectx.VM);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureDataDiskCmdlet);

            Collection<DataVirtualHardDisk> hardDisks = new Collection<DataVirtualHardDisk>();
            foreach (PSObject disk in azurePowershellCmdlet.Run())
            {
                hardDisks.Add((DataVirtualHardDisk)disk.BaseObject);
            }
            return hardDisks;
        }
 public Collection<DiskContext> GetAzureDiskAttachedToRoleName(string[] roleName, bool exactMatch = true)
 {
     Collection<DiskContext> retDisks = new Collection<DiskContext>();
     Collection<DiskContext> disks = GetAzureDisk();
     foreach (DiskContext disk in disks)
     {
         if (disk.AttachedTo != null && disk.AttachedTo.RoleName != null)
         {
             if (Utilities.MatchKeywords(disk.AttachedTo.RoleName, roleName, exactMatch) >= 0)
                 retDisks.Add(disk);
         }
     }
     return retDisks;
 }
        public Collection<CertificateContext> GetAzureCertificate(string serviceName, string thumbprint, string algorithm)
        {
            GetAzureCertificateCmdletInfo getAzureCertificateCmdletInfo = new GetAzureCertificateCmdletInfo(serviceName, thumbprint, algorithm);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureCertificateCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<CertificateContext> certCtxts = new Collection<CertificateContext>();
            foreach (PSObject re in result)
            {
                certCtxts.Add((CertificateContext)re.BaseObject);
            }
            return certCtxts;
        }
        public Collection<AffinityGroupContext> GetAzureAffinityGroup(string name)
        {
            GetAzureAffinityGroupCmdletInfo getAzureAffinityGroupCmdletInfo = new GetAzureAffinityGroupCmdletInfo(name);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureAffinityGroupCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<AffinityGroupContext> certCtxts = new Collection<AffinityGroupContext>();
            foreach (PSObject re in result)
            {
                certCtxts.Add((AffinityGroupContext)re.BaseObject);
            }
            return certCtxts;
        }
        private Collection<DiskContext> GetAzureDisk(GetAzureDiskCmdletInfo getAzureDiskCmdletInfo)
        {
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureDiskCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<DiskContext> disks = new Collection<DiskContext>();
            foreach (PSObject re in result)
            {
                disks.Add((DiskContext)re.BaseObject);
            }
            return disks;
        }
        public Collection<VirtualNetworkSiteContext> GetAzureVNetSite(string vnetName)
        {
            GetAzureVNetSiteCmdletInfo getAzureVNetSiteCmdletInfo = new GetAzureVNetSiteCmdletInfo(vnetName);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureVNetSiteCmdletInfo);
            Collection<PSObject> result = azurePowershellCmdlet.Run();

            Collection<VirtualNetworkSiteContext> connections = new Collection<VirtualNetworkSiteContext>();
            foreach (PSObject re in result)
            {
                connections.Add((VirtualNetworkSiteContext)re.BaseObject);
            }
            return connections;
        }
        public Collection<LocationsContext> GetAzureLocation()
        {
            GetAzureLocationCmdletInfo getAzureLocationCmdlet = new GetAzureLocationCmdletInfo();
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureLocationCmdlet);

            Collection<LocationsContext> locationsContext = new Collection<LocationsContext>();
            foreach (PSObject result in azurePowershellCmdlet.Run())
            {
                locationsContext.Add((LocationsContext)result.BaseObject);
            }
            return locationsContext;
        }
        public Collection<PersistentVM> ImportAzureVM(string path)
        {
            Collection<PersistentVM> result = new Collection<PersistentVM>();
            ImportAzureVMCmdletInfo importAzureVMCmdletInfo = new ImportAzureVMCmdletInfo(path);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(importAzureVMCmdletInfo);

            foreach (var vm in azurePowershellCmdlet.Run())
            {
                result.Add((PersistentVM)vm.BaseObject);
            }
            return result;
        }
Example #22
0
        public void GetRoleProcess()
        {
            OperationStatusResponse getDeploymentOperation;
            try
            {
                var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation);
                if (currentDeployment != null)
                {
                    if (this.InstanceDetails.IsPresent)
                    {
                        Collection<PVM.RoleInstanceContext> instanceContexts = new Collection<PVM.RoleInstanceContext>();
                        IList<RoleInstance> roleInstances = null;

                        if (string.IsNullOrEmpty(this.RoleName))
                        {
                            roleInstances = currentDeployment.RoleInstances;
                        }
                        else
                        {
                            roleInstances = new List<RoleInstance>(currentDeployment.RoleInstances.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                        }

                        foreach (var role in roleInstances)
                        {
                            var vmRole = currentDeployment.Roles == null || !currentDeployment.Roles.Any() ? null
                                       : currentDeployment.Roles.FirstOrDefault(r => string.Equals(r.RoleName, role.RoleName, StringComparison.OrdinalIgnoreCase));

                            instanceContexts.Add(new PVM.RoleInstanceContext
                            {
                                ServiceName           = this.ServiceName,
                                OperationId           = getDeploymentOperation.Id,
                                OperationDescription  = this.CommandRuntime.ToString(),
                                OperationStatus       = getDeploymentOperation.Status.ToString(),
                                InstanceErrorCode     = role.InstanceErrorCode,
                                InstanceFaultDomain   = role.InstanceFaultDomain,
                                InstanceName          = role.InstanceName,
                                InstanceSize          = role.InstanceSize,
                                InstanceStateDetails  = role.InstanceStateDetails,
                                InstanceStatus        = role.InstanceStatus,
                                InstanceUpgradeDomain = role.InstanceUpgradeDomain,
                                RoleName              = role.RoleName,
                                IPAddress             = role.IPAddress,
                                PublicIPAddress       = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Address,
                                PublicIPName          = role.PublicIPs == null || !role.PublicIPs.Any() ? null
                                                      : !string.IsNullOrEmpty(role.PublicIPs.First().Name) ? role.PublicIPs.First().Name
                                                      : PersistentVMHelper.GetPublicIPName(vmRole),
                                PublicIPIdleTimeoutInMinutes = role.PublicIPs == null || !role.PublicIPs.Any() ? null
                                                      : role.PublicIPs.First().IdleTimeoutInMinutes,
                                PublicIPDomainNameLabel = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().DomainNameLabel,
                                PublicIPFqdns = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Fqdns.ToList(),
                                DeploymentID          = currentDeployment.PrivateId,
                                InstanceEndpoints     = Mapper.Map<PVM.InstanceEndpointList>(role.InstanceEndpoints)
                            });
                        }

                        WriteObject(instanceContexts, true);
                    }
                    else
                    {
                        var roleContexts = new Collection<PVM.RoleContext>();
                        IList<Role> roles = null;
                        if (string.IsNullOrEmpty(this.RoleName))
                        {
                            roles = currentDeployment.Roles;
                        }
                        else
                        {
                            roles = new List<Role>(currentDeployment.Roles.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                        }

                        foreach (var r in roles.Select(role => new PVM.RoleContext
                        {
                            InstanceCount        = currentDeployment.RoleInstances.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)),
                            RoleName             = role.RoleName,
                            OSVersion            = role.OSVersion,
                            OperationDescription = this.CommandRuntime.ToString(),
                            OperationStatus      = getDeploymentOperation.Status.ToString(),
                            OperationId          = getDeploymentOperation.Id,
                            ServiceName          = this.ServiceName,
                            DeploymentID         = currentDeployment.PrivateId
                        }))
                        {
                            roleContexts.Add(r);
                        }

                        WriteObject(roleContexts, true);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteExceptionError(ex);
            }
        }
Example #23
0
        public void GetRoleProcess()
        {
            OperationStatusResponse getDeploymentOperation;
            var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation);
            if (currentDeployment != null)
            {
                if (this.InstanceDetails.IsPresent == false)
                {
                    var roleContexts = new Collection<RoleContext>();
                    IList<Role> roles = null;
                    if (string.IsNullOrEmpty(this.RoleName))
                    {
                        roles = currentDeployment.Roles;
                    }
                    else
                    {
                        roles = new List<Role>(currentDeployment.Roles.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                    }

                    foreach (var r in roles.Select(role => new RoleContext
                    {
                        InstanceCount = currentDeployment.RoleInstances.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)),
                        RoleName = role.RoleName,
                        OperationDescription = this.CommandRuntime.ToString(),
                        OperationStatus = getDeploymentOperation.Status.ToString(),
                        OperationId = getDeploymentOperation.Id,
                        ServiceName = this.ServiceName,
                        DeploymentID = currentDeployment.PrivateId
                    }))
                    {
                        roleContexts.Add(r);
                    }

                    WriteObject(roleContexts, true);
                }
                else
                {
                    Collection<RoleInstanceContext> instanceContexts = new Collection<RoleInstanceContext>();
                    IList<Management.Compute.Models.RoleInstance> roleInstances = null;

                    if (string.IsNullOrEmpty(this.RoleName))
                    {
                        roleInstances = currentDeployment.RoleInstances;
                    }
                    else
                    {
                        roleInstances = new List<Management.Compute.Models.RoleInstance>(currentDeployment.RoleInstances.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase)));
                    }

                    foreach (var role in roleInstances)
                    {
                        instanceContexts.Add(new RoleInstanceContext()
                        {
                            ServiceName = this.ServiceName,
                            OperationId = getDeploymentOperation.Id,
                            OperationDescription = this.CommandRuntime.ToString(),
                            OperationStatus = getDeploymentOperation.Status.ToString(),
                            InstanceErrorCode = role.InstanceErrorCode,
                            InstanceFaultDomain = role.InstanceFaultDomain,
                            InstanceName = role.InstanceName,
                            InstanceSize = role.InstanceSize.ToString(),
                            InstanceStateDetails = role.InstanceStateDetails,
                            InstanceStatus = role.InstanceStatus,
                            InstanceUpgradeDomain = role.InstanceUpgradeDomain,
                            RoleName = role.RoleName,
                            DeploymentID = currentDeployment.PrivateId,
                            InstanceEndpoints = role.InstanceEndpoints == null ? null : Mapper.Map<Model.PersistentVMModel.InstanceEndpointList>((from ep in role.InstanceEndpoints
                                                                                                                                                  select Mapper.Map<Model.PersistentVMModel.InstanceEndpoint>(ep)).ToList())
                        });
                    }

                    WriteObject(instanceContexts, true);
                }
            }
        }
Example #24
0
        //списка соседей для точки:
        private static Collection<PathNode> GetNeighbours(PathNode pathNode,
          Point goal, AreaType[,] field)
        {
            var result = new Collection<PathNode>();

            // Соседними точками являются соседние по стороне клетки.
            Point[] neighbourPoints = new Point[8];
            neighbourPoints[0] = new Point(pathNode.Position.X + 1, pathNode.Position.Y);
            neighbourPoints[1] = new Point(pathNode.Position.X - 1, pathNode.Position.Y);
            neighbourPoints[2] = new Point(pathNode.Position.X, pathNode.Position.Y + 1);
            neighbourPoints[3] = new Point(pathNode.Position.X, pathNode.Position.Y - 1);
            neighbourPoints[4] = new Point(pathNode.Position.X + 1, pathNode.Position.Y+1);
            neighbourPoints[5] = new Point(pathNode.Position.X - 1, pathNode.Position.Y-1);
            neighbourPoints[6] = new Point(pathNode.Position.X-1, pathNode.Position.Y + 1);
            neighbourPoints[7] = new Point(pathNode.Position.X+1, pathNode.Position.Y - 1);
            foreach (var point in neighbourPoints)
            {
                // Проверяем, что не вышли за границы карты.
                if (point.X < 0 || point.X >= field.GetLength(0)*10)
                    continue;
                if (point.Y < 0 || point.Y >= field.GetLength(1)*10)
                    continue;
                // Проверяем, что по клетке можно ходить.
                if ((field[(int)point.X/10, (int)point.Y/10]== AreaType.Water))
                    continue;
                // Заполняем данные для точки маршрута.
                var neighbourNode = new PathNode()
                {
                    Position = point,
                    CameFrom = pathNode,
                    PathLengthFromStart = pathNode.PathLengthFromStart +
                      GetDistanceBetweenNeighbours(),
                    HeuristicEstimatePathLength = GetHeuristicPathLength(point, goal)
                };
                result.Add(neighbourNode);
            }
            return result;
        }
 public static Collection<ConfigurationSet> MapConfigurationSets(IList<Management.Compute.Models.ConfigurationSet> configurationSets)
 {
     var result = new Collection<ConfigurationSet>();
     var n = configurationSets.Where(c => c.ConfigurationSetType == "NetworkConfiguration").Select(Mapper.Map<Model.PersistentVMModel.NetworkConfigurationSet>).ToList();
     var w = configurationSets.Where(c => c.ConfigurationSetType == ConfigurationSetTypes.WindowsProvisioningConfiguration).Select(Mapper.Map<WindowsProvisioningConfigurationSet>).ToList();
     var l = configurationSets.Where(c => c.ConfigurationSetType == ConfigurationSetTypes.LinuxProvisioningConfiguration).Select(Mapper.Map<LinuxProvisioningConfigurationSet>).ToList();
     n.ForEach(result.Add);
     w.ForEach(result.Add);
     l.ForEach(result.Add);
     return result;
 }
        public Collection<StorageServicePropertiesOperationContext> GetAzureStorageAccount(string accountName)
        {
            GetAzureStorageAccountCmdletInfo getAzureStorageAccountCmdlet = new GetAzureStorageAccountCmdletInfo(accountName);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureStorageAccountCmdlet);

            Collection<StorageServicePropertiesOperationContext> storageAccounts = new Collection<StorageServicePropertiesOperationContext>();
            foreach (PSObject result in azurePowershellCmdlet.Run())
            {
                storageAccounts.Add((StorageServicePropertiesOperationContext)result.BaseObject);
            }
            return storageAccounts;
        }
        public Collection<OSVersionsContext> GetAzureOSVersion()
        {
            GetAzureOSVersionCmdletInfo getAzureOSVersionCmdletInfo = new GetAzureOSVersionCmdletInfo();
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureOSVersionCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<OSVersionsContext> osVersions = new Collection<OSVersionsContext>();
            foreach (PSObject re in result)
            {
                osVersions.Add((OSVersionsContext)re.BaseObject);
            }
            return osVersions;
        }
 public bool TestAzureServiceName(string serviceName)
 {
     TestAzureNameCmdletInfo testAzureNameCmdlet = new TestAzureNameCmdletInfo("Service", serviceName);
     WindowsAzurePowershellCmdlet testAzureName = new WindowsAzurePowershellCmdlet(testAzureNameCmdlet);
     Collection<bool> response = new Collection<bool>();
     foreach (PSObject result in testAzureName.Run())
     {
         response.Add((bool)result.BaseObject);
     }
     return response[0];
 }
        public Collection<RoleContext> GetAzureRole(string serviceName, string slot, string roleName, bool details)
        {
            GetAzureRoleCmdletInfo getAzureRoleCmdletInfo = new GetAzureRoleCmdletInfo(serviceName, slot, roleName, details);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureRoleCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<RoleContext> roles = new Collection<RoleContext>();
            foreach (PSObject re in result)
            {
                roles.Add((RoleContext)re.BaseObject);
            }
            return roles;
        }
Example #30
0
 /// <summary>
 /// 创建新的 Collection 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 /// <param name="userInfo_ID">UserInfo_ID 属性的初始值。</param>
 /// <param name="car_ID">Car_ID 属性的初始值。</param>
 public static Collection CreateCollection(global::System.Int32 id, global::System.Int32 userInfo_ID, global::System.Int32 car_ID)
 {
     Collection collection = new Collection();
     collection.ID = id;
     collection.UserInfo_ID = userInfo_ID;
     collection.Car_ID = car_ID;
     return collection;
 }