コード例 #1
0
        public BotModel(Bot bot)
        {
            this.Id             = bot.Id;
            this.Name           = bot.Name ?? bot.IPAddress;
            this.WorkHours      = Format.AsAge(bot.CreationDate);
            this.Profit         = Format.AsBitCoin(bot.Balance);
            this.Efficiency     = Format.AsPercent(bot.Share, bot.TotalShare);
            this.EfficiencyText = string.Format("工作:{0} (总数:{1})", bot.Share, bot.TotalShare);
            this.Shares         = Format.AsCurrentAndPercent(bot.Share, Server.Recent.TotalShare);
            this.Action         = bot.Account == null ? "Authorize" : "Manage";
            this.ActionText     = bot.Account == null ? "认领" : "管理";

            //try get mine information from bot
            var cm = ComputeManager.ByBot(bot);

            if (cm != null)
            {
                var mine = Mine.Find(cm.MineId);
                if (mine != null)
                {
                    this.MineIcon = mine.Icon;
                    this.MineText = mine.IconName;
                }
            }

            //try get bot speed
            var speed = Server.Recent.TestBotSpeed(bot.Id);

            this.StatusIcon = "/Content/status/" + Format.AsSpeedIcon(speed) + ".png";
            this.StatusText = Format.AsSpeed(speed);
        }
コード例 #2
0
        private Azure(RestClient restClient, string subscriptionId, string tenantId, IAuthenticated authenticated)
        {
            resourceManager          = ResourceManager.Fluent.ResourceManager.Authenticate(restClient).WithSubscription(subscriptionId);
            storageManager           = StorageManager.Authenticate(restClient, subscriptionId);
            computeManager           = ComputeManager.Authenticate(restClient, subscriptionId);
            networkManager           = NetworkManager.Authenticate(restClient, subscriptionId);
            batchManager             = BatchManager.Authenticate(restClient, subscriptionId);
            keyVaultManager          = KeyVaultManager.Authenticate(restClient, subscriptionId, tenantId);
            trafficManager           = TrafficManager.Fluent.TrafficManager.Authenticate(restClient, subscriptionId);
            dnsZoneManager           = DnsZoneManager.Authenticate(restClient, subscriptionId);
            sqlManager               = SqlManager.Authenticate(restClient, subscriptionId);
            redisManager             = RedisManager.Authenticate(restClient, subscriptionId);
            cdnManager               = CdnManager.Authenticate(restClient, subscriptionId);
            appServiceManager        = AppServiceManager.Authenticate(restClient, subscriptionId, tenantId);
            searchManager            = SearchManager.Authenticate(restClient, subscriptionId);
            serviceBusManager        = ServiceBusManager.Authenticate(restClient, subscriptionId);
            containerInstanceManager = ContainerInstanceManager.Authenticate(restClient, subscriptionId);
            registryManager          = RegistryManager.Authenticate(restClient, subscriptionId);
            containerServiceManager  = ContainerServiceManager.Authenticate(restClient, subscriptionId);
            cosmosDBManager          = CosmosDBManager.Authenticate(restClient, subscriptionId);
            authorizationManager     = AuthorizationManager.Authenticate(restClient, subscriptionId);
            msiManager               = MsiManager.Authenticate(restClient, subscriptionId);
            batchAIManager           = BatchAIManager.Authenticate(restClient, subscriptionId);
            monitorManager           = MonitorManager.Authenticate(restClient, subscriptionId);
            eventHubManager          = EventHubManager.Authenticate(restClient, subscriptionId);

            SubscriptionId     = subscriptionId;
            this.authenticated = authenticated;
        }
コード例 #3
0
        public static string[] GetVMList([ActivityTrigger] DurableActivityContext inputs, ILogger log)
        {
            List <string> vmListNames = new List <string>();

            (string subscriptionId, string resourceGroupName, string tag) = inputs.GetInput <(string, string, string)>();
            string           token       = Authenticate().Result;
            AzureCredentials credentials = new AzureCredentials(new TokenCredentials(token), new TokenCredentials(token), string.Empty, AzureEnvironment.AzureGlobalCloud);
            IComputeManager  azure;

            try
            {
                azure = ComputeManager.Configure().Authenticate(credentials, subscriptionId);
            }
            catch (Exception ex)
            {
                throw new Exception("There was an issue authenticating to Azure. Please check your subscriptionId and if MSI has been set up correctly", ex);
            }

            var vmList = !string.IsNullOrEmpty(resourceGroupName)
                        ? azure.VirtualMachines.ListByResourceGroup(resourceGroupName)
                        : azure.VirtualMachines.List();

            foreach (var vm in vmList)
            {
                if ((!string.IsNullOrEmpty(tag) && vm.Tags.ContainsKey(tag)) || string.IsNullOrEmpty(tag))
                {
                    vmListNames.Add(vm.Id);
                }
            }

            return(vmListNames.ToArray());
        }
コード例 #4
0
        public static async Task <string> StartStopVMList([ActivityTrigger] DurableActivityContext vmlist, ILogger log)
        {
            string[]      vmlistResourceIds = vmlist.GetInput <string[]>();
            StringBuilder resultText        = new StringBuilder();
            string        mode           = vmlistResourceIds[0];
            string        subscriptionId = vmlistResourceIds[1];

            string           token       = Authenticate().Result;
            AzureCredentials credentials = new AzureCredentials(new TokenCredentials(token), new TokenCredentials(token), string.Empty, AzureEnvironment.AzureGlobalCloud);
            var azure = ComputeManager.Configure().Authenticate(credentials, subscriptionId);
            var tasks = new List <Task>();

            for (int i = 2; i < vmlistResourceIds.Length; i++)
            {
                string vmName = vmlistResourceIds[i].Split('/')[8];
                resultText.Append(vmName);
                resultText.Append(",");
                InsertRow(vmlistResourceIds[i], mode);
                if (vmlistResourceIds[0] == "start")
                {
                    log.LogInformation("Starting vm with resource id {0}", vmlistResourceIds[i]);
                    tasks.Add(azure.VirtualMachines.GetById(vmlistResourceIds[i]).StartAsync());
                }
                else if (vmlistResourceIds[0] == "stop")
                {
                    log.LogInformation("Stopping vm with resource id {0}", vmlistResourceIds[i]);
                    tasks.Add(azure.VirtualMachines.GetById(vmlistResourceIds[i]).DeallocateAsync());
                }
            }

            await Task.WhenAll(tasks);

            return(resultText.ToString().TrimEnd(','));
        }
コード例 #5
0
 public static IComputeManager CreateComputeManager()
 {
     return(CreateMockedManager(c => ComputeManager
                                .Configure()
                                .WithDelegatingHandlers(GetHandlers())
                                .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                                .Authenticate(c, c.DefaultSubscriptionId)));
 }
コード例 #6
0
ファイル: MetalUnity.cs プロジェクト: tylerpayne/MetalUnity
 public static void Compute(ComputeManager cm, ResourceManager rm)
 {
     MUCompute(cm.iD, rm.iD);
 }
コード例 #7
0
 public KaUtil(AzureCredentials credential, string subscription, TimeSpan timeout)
 {
     this.resourceGroups = ResourceManager.Authenticate(credential).WithSubscription(subscription).ResourceGroups;
     this.computeUsages  = ComputeManager.Authenticate(credential, subscription).Usages;
     this.cleanupTimeout = timeout;
 }