Exemplo n.º 1
0
 private static void InitializeOrleans()
 {
     if (!AzureClient.IsInitialized)
     {
         FileInfo clientConfigFile = AzureConfigUtils.ClientConfigFileLocation;
         if (!clientConfigFile.Exists)
         {
             throw new FileNotFoundException(string.Format("Cannot find Orleans client config file for initialization at {0}", clientConfigFile.FullName), clientConfigFile.FullName);
         }
         AzureClient.Initialize(clientConfigFile);
     }
 }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            loginButton.Click    += loginButton_Click;
            registerButton.Click += loginButton_Click;

            OAuthClient = new AzureClient(PortalId, Mode);

            loginItem.Visible    = (Mode == AuthMode.Login);
            registerItem.Visible = (Mode == AuthMode.Register);
        }
        public TopNewsViewModel(AzureClient client)
        {
            _client = client;
            Title = "Top News";

            GoToNewsCommand = new Command<NewsModel>(ExecuteGoToNewsCommand);
            LoadNewsCommand = new Command(ExecuteLoadNewsCommand);
            FavoriteCommand = new Command(ExecuteFavoriteCommand);
            PreferencesCommand = new Command(ExecutePreferencesCommand);

            Task.Run(() => LoadAsync());
        }
Exemplo n.º 4
0
        public async Task <JsonResult> GetAggregatorGrainResult(int id)
        {
            if (!AzureClient.IsInitialized)
            {
                AzureClient.Initialize(this.Server.MapPath("~/AzureClientConfiguration.xml"));
            }

            var aggregatorGrain = GrainClient.GrainFactory.GetGrain <IAggregatorGrain>("aggregator");
            var state           = await aggregatorGrain.GetGrainInformation(id);

            return(this.Json(state, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        private async static Task <bool> AddMemberToAzureADRole(string tenantId, string roleId, string memberId)
        {
            var azureClient = new AzureClient();
            var users       = await azureClient.GetAzureADDirectoryRoleMembersAsync(tenantId, roleId).ConfigureAwait(false);

            if (!users.Value.Any(u => u.ObjectId == memberId))
            {
                return(await azureClient.AddAzureADDirectoryRoleMembersAsync(tenantId, roleId, memberId).ConfigureAwait(false));
            }

            return(true);
        }
Exemplo n.º 6
0
        private static void StartStopVm()
        {
            AzureClient client        = new AzureClient();
            var         subscription  = client.Subscriptions[subscriptionId];
            var         resourceGroup = subscription.ResourceGroups[rgName];
            var         vm            = resourceGroup.Vms()[vmName];

            Console.WriteLine("Found VM {0}", vmName);
            Console.WriteLine("--------Stopping VM--------");
            vm.Stop();
            Console.WriteLine("--------Starting VM--------");
            vm.Start();
        }
Exemplo n.º 7
0
 public SocialLoginView(AzureClient client)
 {
     try
     {
         InitializeComponent();
         _client = client;
         SetInitialObjects();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
Exemplo n.º 8
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            loginButton.Click += loginButton_Click;
            registerButton.Click += loginButton_Click;

            OAuthClient = new AzureClient(PortalId, Mode);

            loginItem.Visible = (Mode == AuthMode.Login);
            registerItem.Visible = (Mode == AuthMode.Register);

        }
 public App()
 {
     try
     {
         InitializeComponent();
         AzureClient = new AzureClient();
         SetMainPage();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
Exemplo n.º 10
0
        public async Task <List <Responses> > GetResponsesForCurrentQuestion()
        {
            if (CurrentQuestion != null)
            {
                IsBusy = true;
                var table     = AzureClient.GetTable <Responses>();
                var responses = await table.Where(x => x.QuestionId == CurrentQuestion.Id).ToListAsync();

                IsBusy = false;
                return(responses);
            }
            return(new List <Responses>());
        }
Exemplo n.º 11
0
        public IActionResult GetImage(string filename)
        {
            FileStreamResult image = null;

            using (AzureClient client = new AzureClient()) {
                if (!string.Equals(filename, string.Empty))
                {
                    image = File(client.getBlobData(filename), "image/jpeg");
                }
            };

            return(image);
        }
Exemplo n.º 12
0
        public async Task <int> DeleteOptionByQuestionId(int questionId)
        {
            var table = AzureClient.GetTable <Option>();
            var opts  = await table.Where(x => x.QuestionId == questionId).ToListAsync();

            foreach (var opt in opts)
            {
                await DeleteReponsesByOptionId(opt.Id);

                await table.DeleteAsync(opt);
            }
            return(0);
        }
Exemplo n.º 13
0
        public void GetDataLakeClientTest3()
        {
            //Code is made unreachable so unit test can run on a remote machine. If you wish to test the login prompt, simple remove the inconclusive assert and the return statement and run the test.
            Assert.Inconclusive();
            return;

            AzureClient clientService = new AzureClient(new Utilities.PipelineContext());  //will use settings from app config
            AdlsClient  client        = null;

            client = clientService.GetDataLakeClient("csreadingadlmackey.azuredatalakestore.net", true);

            Assert.IsNotNull(client);
        }
        /// <summary>Get the list of the availability sets by resource group.
        /// And get the virtual machine by resource group and the availability sets.
        /// And get the batch operation for the availability sets</summary>
        /// <param name="resourceGroupList"></param>
        /// <param name="virtualMachinesConcurrent"></param>
        /// <param name="batchTasks"></param>
        /// <param name="azureClient"></param>
        /// <param name="log"></param>
        private static void SetTheVirtualMachinesAndAvailabilitySetBatchTask(IEnumerable <IResourceGroup> resourceGroupList,
                                                                             ConcurrentBag <IEnumerable <IGrouping <string, IVirtualMachine> > > virtualMachinesConcurrent,
                                                                             ConcurrentBag <Task> batchTasks,
                                                                             AzureClient azureClient,
                                                                             TraceWriter log)
        {
            var availabilitySetCloudTable = StorageAccountProvider.CreateOrGetTable(StorageTableNames.AvailabilitySetCrawlerTableName);

            if (availabilitySetCloudTable == null)
            {
                return;
            }

            Parallel.ForEach(resourceGroupList, eachResourceGroup =>
            {
                try
                {
                    var availabilitySetIds = new List <string>();
                    var availabilitySetsByResourceGroup = azureClient.AzureInstance.AvailabilitySets.ListByResourceGroup(eachResourceGroup.Name);
                    // table batch operation currently allows only 100 per batch, So ensuring the one batch operation will have only 100 items
                    var setsByResourceGroup = availabilitySetsByResourceGroup.ToList();
                    for (var i = 0; i < setsByResourceGroup.Count; i += TableConstants.TableServiceBatchMaximumOperations)
                    {
                        var batchItems = setsByResourceGroup.Skip(i)
                                         .Take(TableConstants.TableServiceBatchMaximumOperations).ToList();
                        // get the availability sets by resource group
                        // get the availability sets batch operation and get the list of availability set ids
                        var availabilitySetbatchOperation =
                            GetAvailabilitySetBatchOperation(batchItems, availabilitySetIds);

                        // add the batch operation into task list
                        if (availabilitySetbatchOperation.Count > 0 && availabilitySetCloudTable != null)
                        {
                            batchTasks.Add(availabilitySetCloudTable.ExecuteBatchAsync(availabilitySetbatchOperation));
                        }
                    }

                    // Get the virtual machines by resource group and by availability set ids
                    var virtualMachinesByAvailabilitySetId = GetVirtualMachineListByResourceGroup(eachResourceGroup.Name, availabilitySetIds, azureClient);
                    if (virtualMachinesByAvailabilitySetId != null && virtualMachinesByAvailabilitySetId.Count > 0)
                    {
                        virtualMachinesConcurrent.Add(virtualMachinesByAvailabilitySetId);
                    }
                }
                catch (Exception e)
                {
                    log.Error($"timercrawlerforavailableset threw the exception ", e,
                              "for resource group: " + eachResourceGroup.Name);
                }
            });
        }
Exemplo n.º 15
0
        public async Task <int> LoadSurveyById(int surveyId)
        {
            var result = await AzureClient.GetTable <Survey>().Where(x => x.Id == surveyId).ToListAsync();

            if (result != null && result.Any())
            {
                CurrentSurvey = result.First();
                return(1);
            }
            else
            {
                return(0);
            }
        }
        private object RemoveApplicationRegistrationAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            AzureApplication application = client.GetApplicationAsync(DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName).Result;

            if (application == null)
            {
                return(true);
            }

            return(client.DeleteApplicationAsync(application.Id).Result);
        }
Exemplo n.º 17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Page.IsPostBack)
     {
         if (!AzureClient.IsInitialized)
         {
             FileInfo clientConfigFile = AzureConfigUtils.ClientConfigFileLocation;
             if (!clientConfigFile.Exists)
             {
                 throw new FileNotFoundException(string.Format("Cannot find Orleans client config file for initialization at {0}", clientConfigFile.FullName), clientConfigFile.FullName);
             }
             AzureClient.Initialize(clientConfigFile);
         }
     }
 }
Exemplo n.º 18
0
        public async Task <int> DeleteQuestionBySurvey(int surveyId)
        {
            IsBusy = true;
            var table     = AzureClient.GetTable <Question>();
            var questions = await table.Where(x => x.SurveyId == surveyId).ToListAsync();

            foreach (var q in questions)
            {
                await DeleteOptionByQuestionId(q.Id);

                await table.DeleteAsync(q).ConfigureAwait(true);
            }
            IsBusy = false;
            return(0);
        }
Exemplo n.º 19
0
        public async Task <List <Responses> > GetResponsesAndLoadDataByQuestionId(int questionId)
        {
            IsBusy = true;
            var table     = AzureClient.GetTable <Responses>();
            var responses = await table.Where(x => x.QuestionId == questionId).ToListAsync();

            if (responses != null && responses.Any())
            {
                var temp = responses.First();
                await LoadSurveyById(temp.SurveyId);
                await LoadQuestionsByQuestionId(temp.QuestionId);
            }
            IsBusy = false;
            return(responses);
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Init()
        {
            MongoDbClient       dbClient = new MongoDbClient();
            ElasticSearchClient esClient = new ElasticSearchClient();
            AzureClient         aClient  = new AzureClient();

            dbClient.Init();
            esClient.Index();
            await aClient.Init();

            return(new ContentResult()
            {
                Content = "Ok"
            });
        }
Exemplo n.º 21
0
        public async Task <int> UpdateSurvey()
        {
            var table = AzureClient.GetTable <Survey>();

            if (CurrentSurvey.Id == 0)
            {
                await table.InsertAsync(CurrentSurvey);
            }
            else
            {
                await table.UpdateAsync(CurrentSurvey);
            }

            return(0);
        }
Exemplo n.º 22
0
        protected void Application_Start()
        {
            if (RoleEnvironment.IsAvailable)
            {
                // running in Azure
                AzureClient.Initialize(Server.MapPath(@"~/AzureConfiguration.xml"));
            }
            else
            {
                // not running in Azure
                GrainClient.Initialize(Server.MapPath(@"~/LocalConfiguration.xml"));
            }

            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
Exemplo n.º 23
0
        protected void Application_Start()
        {
            if (RoleEnvironment.IsAvailable)
            {
                // running in Azure
                AzureClient.Initialize(AzureClient.DefaultConfiguration());
            }
            else
            {
                // not running in Azure
                GrainClient.Initialize(ClientConfiguration.LocalhostSilo());
            }

            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
Exemplo n.º 24
0
        private object DeployAzureADFunctionAppRegistrationAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            AzureApplication application = client.GetApplicationAsync(DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName).Result;

            if (application != null)
            {
                return(application);
            }

            return(client.CreateApplicationAsync(new AzureApplicationRequestBase()
            {
                DisplayName = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName,
                IdentifierUris = new string[]
                {
                    $"https://{DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName}",
                },
                PasswordCredentials = new AzureApplicationPasswordCredential[]
                {
                    new AzureApplicationPasswordCredential()
                    {
                        StartDateTime = DateTime.Now.ToString("o"),
                        EndDateTime = DateTime.Now.AddYears(1).ToString("o"),
                        SecretText = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationSecret.Password,
                    },
                },
                RequiredResourceAccess = new AzureApplicationRequiredResourceAccess[]
                {
                    new AzureApplicationRequiredResourceAccess()
                    {
                        ResourceAppId = "00000003-0000-0000-c000-000000000000",
                        ResourceAccess = new ResourceAccess[]
                        {
                            new ResourceAccess()
                            {
                                Id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
                                Type = "Scope",
                            },
                        },
                    },
                },
                SignInAudience = "AzureADMyOrg",
            }).Result);
        }
Exemplo n.º 25
0
        /// <summary>1. Iterate the resource groups to get the scale sets for individual resource group.
        /// 2. Convert the List of scale sets into scale set entity and add them into the table batch operation.
        /// 3. Get the list of virtual machine instances, convert into entity and them into the table batach operation
        /// 3. Execute all the task parallely</summary>
        /// <param name="resourceGroups">List of resource groups for the particular subscription.</param>
        /// <param name="log">Trace writer instance</param>
        private static async Task GetLoadBalancersForResourceGroupsAsync(IEnumerable <IResourceGroup> resourceGroups,
                                                                         TraceWriter log)
        {
            try
            {
                var virtualMachineCloudTable = StorageAccountProvider.CreateOrGetTable(StorageTableNames.VirtualMachineCrawlerTableName);
                var loadBalancerTable        = StorageAccountProvider.CreateOrGetTable(StorageTableNames.LoadBalancerCrawlerTableName);
                if (virtualMachineCloudTable == null || loadBalancerTable == null)
                {
                    return;
                }

                var batchTasks  = new ConcurrentBag <Task>();
                var azureClient = new AzureClient();
                // using parallel here to run all the resource groups parallelly, parallel is 10times faster than normal foreach.
                foreach (var eachResourceGroup in resourceGroups)
                //Parallel.ForEach(resourceGroups, eachResourceGroup =>
                {
                    try
                    {
                        var loadBalancersList = azureClient.AzureInstance.LoadBalancers
                                                .ListByResourceGroup(eachResourceGroup.Name);
                        //var count = loadBalancersList.Count();
                        if (loadBalancersList.Count() > 0)
                        {
                            GetVirtualMachineAndLoadBalancerBatch(loadBalancersList.ToList(), batchTasks,
                                                                  virtualMachineCloudTable,
                                                                  loadBalancerTable, azureClient, log);
                        }
                    }
                    catch (Exception e)
                    {
                        //  catch the error, to continue adding other entities to table
                        log.Error($"timercrawlerforloadbalancer threw the exception ", e,
                                  "GetLoadBalancerForResourceGroups: for the resource group " + eachResourceGroup.Name);
                    }
                }
                //);

                // execute all batch operation as parallel
                await Task.WhenAll(batchTasks);
            }
            catch (Exception ex)
            {
                log.Error($"timercrawlerforloadbalancer threw the exception ", ex, "GetLoadBalancerForResourceGroups");
            }
        }
Exemplo n.º 26
0
        public SocialLoginViewModel(AzureClient client)
        {
            _client  = client;
            Title    = "Centralizador de notícias";
            UserInfo = new UserInfoModel {
                Id = "0", Image = "", Name = "Fazer Login"
            };
            var loginsTypeList = new List <SocialLoginModel>
            {
                new SocialLoginModel
                {
                    BackgroundColor = Color.FromHex("#ba3a2a"),
                    TextColor       = Color.White,
                    Name            = "Google +",
                    Logo            = "google.png",
                    Provider        = MobileServiceAuthenticationProvider.Google
                },
                new SocialLoginModel
                {
                    BackgroundColor = Color.FromHex("#daf5fd"),
                    TextColor       = Color.FromHex("#0078ff"),
                    Name            = "Microsoft Account",
                    Logo            = "windows.png",
                    Provider        = MobileServiceAuthenticationProvider.MicrosoftAccount
                },
                new SocialLoginModel
                {
                    BackgroundColor = Color.FromHex("#677ca7"),
                    TextColor       = Color.White,
                    Name            = "Facebook",
                    Logo            = "facebook.png",
                    Provider        = MobileServiceAuthenticationProvider.Facebook
                },
                new SocialLoginModel
                {
                    BackgroundColor = Color.FromHex("#268ed7"),
                    TextColor       = Color.White,
                    Name            = "Twitter",
                    Logo            = "twitter.png",
                    Provider        = MobileServiceAuthenticationProvider.Twitter
                }
            };

            SocialLogins       = new ObservableCollection <SocialLoginModel>(loginsTypeList);
            SocialLoginCommand = new Command <SocialLoginModel>(ExecuteSocialLoginCommand);
        }
Exemplo n.º 27
0
        public async Task <int> LoadSurveysForCurrentUser()
        {
            if (User != null)
            {
                IsBusy = true;
                SurveyCollection.Clear();
                var results = await AzureClient.GetTable <Survey>().Where(x => x.AccountUserId == User.Id).ToListAsync();

                foreach (var item in results)
                {
                    SurveyCollection.Add(item);
                }
                IsBusy = false;
                return(SurveyCollection.Count);
            }
            return(0);
        }
Exemplo n.º 28
0
        static CsmManager()
        {
            csmClient = new AzureClient(retryCount: 3);
            csmClient.ConfigureSpnLogin(SimpleSettings.TryTenantId, SimpleSettings.TryUserName, SimpleSettings.TryPassword);

            graphClient = new AzureClient(retryCount: 3);
            graphClient.ConfigureUpnLogin(SimpleSettings.GraphUserName, SimpleSettings.GraphPassword);

            linuxClient = new AzureClient(retryCount: 3);
            linuxClient.ConfigureSpnLogin(SimpleSettings.LinuxTenantId, SimpleSettings.LinuxServicePrincipal, SimpleSettings.LinuxServicePrincipalKey);

            monitoringToolsClient = new AzureClient(retryCount: 3);
            monitoringToolsClient.ConfigureSpnLogin(SimpleSettings.MonitoringToolsTenantId, SimpleSettings.MonitoringToolsServicePrincipal, SimpleSettings.MonitoringToolsServicePrincipalKey);

            monitoringToolsGraphClient = new AzureClient(retryCount: 3);
            monitoringToolsGraphClient.ConfigureUpnLogin(SimpleSettings.MonitoringToolsGraphUserName, SimpleSettings.MonitoringToolsGraphPassword);
        }
Exemplo n.º 29
0
        private static void CreateNetworkOnly()
        {
            AzureClient client       = new AzureClient();
            var         subscription = client.Subscriptions[subscriptionId];

            // Set Location
            var location = subscription.Locations[loc];

            // Create Resource Group
            Console.WriteLine("--------Start create group--------");
            var resourceGroup = location.ResourceGroups.CreateOrUpdate(rgName);

            // Create IP Address
            Console.WriteLine("--------Start create IP Address--------");
            var ipAddress = resourceGroup.ConstructIPAddress();

            ipAddress = resourceGroup.IpAddresses().CreateOrUpdatePublicIpAddress(vmName + "_ip", ipAddress);

            // Create VNet
            Console.WriteLine("--------Start create VNet--------");
            string vnetName = vmName + "_vnet";
            var    vnet     = resourceGroup.VNets()[vnetName];

            if (vnet == null)
            {
                vnet = resourceGroup.ConstructVnet("10.0.0.0/16");
                vnet = resourceGroup.VNets().CreateOrUpdateVNet(vmName + "_vnet", vnet);
            }

            //create subnet
            Console.WriteLine("--------Start create Subnet--------");
            var subnet = vnet.Subnets[subnetName];

            if (subnet == null)
            {
                subnet = vnet.ConstructSubnet(subnetName, "10.0.0.0/24");
                subnet = vnet.Subnets.CreateOrUpdateSubnets(subnet);
            }

            // Create Network Interface
            Console.WriteLine("--------Start create Network Interface--------");
            var nic = resourceGroup.ConstructNic(ipAddress, subnet.Model.Id);

            nic = resourceGroup.Nics().CreateOrUpdateNic(vmName + "_nic", nic);
        }
Exemplo n.º 30
0
        public async Task <int> FindSurveyCurrentChannel()
        {
            IsBusy = true;
            if (!string.IsNullOrEmpty(ChannelName))
            {
                var results = await AzureClient.GetTable <Survey>().Where(x => x.ChannelName == ChannelName).ToListAsync();

                if (results != null && results.Count > 0)
                {
                    var survey = results.First();
                    if (!survey.IsLiveSurvey)
                    {
                        if (survey.RequiresUserName)
                        {
                            if (string.IsNullOrEmpty(User.FirstName) || string.IsNullOrEmpty(User.LastName))
                            {
                                ErrorMessage = "This Survey Requires Your First And Last Name";
                                return(0);
                            }
                        }

                        ErrorMessage  = string.Empty;
                        CurrentSurvey = survey;
                        await LoadQuestionsForCurrentSurvey();

                        IsBusy = false;
                        return(1);
                    }
                    else
                    {
                        ErrorMessage = "Please Enter A Survey Code Associated To A Static Survey";
                    }
                }
                else
                {
                    ErrorMessage = "Could Not Find Survey. Is The Code Correct?";
                }
            }
            else
            {
                ErrorMessage = "A Survey Code Must Be Entered!";
            }
            IsBusy = false;
            return(0);
        }
Exemplo n.º 31
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     if (RoleEnvironment.IsAvailable || RoleEnvironment.IsEmulated)
     {
         // azure
         AzureClient.Initialize(this.Server.MapPath("AzureClientConfiguration.xml"));
     }
     else
     {
         //premise
         Orleans.GrainClient.Initialize(this.Server.MapPath("DevTestClientConfiguration.xml"));
     }
 }
 public RoomAvailabilitySlot IsFreeNow()
 {
     var client = new AzureClient();
     var result = client.IsRoomFreeNow();
     return result;
 }
Exemplo n.º 33
0
 public UserResource(AzureClient client)
 {
     this.azureClient = client;
 }
 public RoomAvailabilityHistory RoomHistory()
 {
     var client = new AzureClient();
     var result = client.GetRoomHistory();
     return result;
 }