private void CleanAccounts(string azureaccountname, string azureaccountkey, string amazons3accountname, string amazons3accountkey) { AzureHelper helper = new AzureHelper(azureaccountname, azureaccountkey, "foo", CompressionType.None, EncryptionType.None, null, null, new Logger(), 0, 0); helper.CleanAccount(); AmazonS3Helper s3helper = new AmazonS3Helper(new RemoteInfo(amazons3accountname, amazons3accountkey),"foo723r2y3r723rh27r8i", CompressionType.None, EncryptionType.None, null, null, new Logger(), 0, 0); s3helper.DeleteAllBuckets(); }
//protected SyncOrchestrator orchestrator; public AzureChunkSynchronizer(RemoteInfo ri, string container, SynchronizeDirection syncDirection, CompressionType compressionType, EncryptionType encryptionType, byte[] encryptionKey, byte[] initializationVector, Logger log, int ChunkSize, int ThreadPoolSize=1) { logger = log; disposed = false; // Setup Store and Provider // this.accountName = ri.accountName; this.accountKey = ri.accountKey; this.container = container; this.syncDirection = syncDirection; this.azureHelper = new AzureHelper(this.accountName, this.accountKey, this.container, compressionType, encryptionType, encryptionKey, initializationVector, log, ChunkSize, ThreadPoolSize); this.chunkListHash = null; this.ThreadPoolSize = ThreadPoolSize; }
private async Task EnsureNoKuduLiteBuildSettings(Site functionApp) { var anySettingsRemoved = functionApp.AzureAppSettings.RemoveIfKeyValPresent(Constants.KuduLiteDeploymentConstants.LinuxDedicatedBuildSettings); if (anySettingsRemoved) { var result = await AzureHelper.UpdateFunctionAppAppSettings(functionApp, AccessToken, ManagementURL); if (!result.IsSuccessful) { throw new CliException(Constants.Errors.UnableToUpdateAppSettings); } await WaitForAppSettingUpdateSCM(functionApp, functionApp.AzureAppSettings, strictEqual : true, timeOutSeconds : 300); } }
private async Task <bool> PublishAppSettings(Site functionApp, IDictionary <string, string> local, IDictionary <string, string> additional) { functionApp.AzureAppSettings = MergeAppSettings(functionApp.AzureAppSettings, local, additional); var result = await AzureHelper.UpdateFunctionAppAppSettings(functionApp, AccessToken, ManagementURL); if (!result.IsSuccessful) { ColoredConsole .Error .WriteLine(ErrorColor("Error updating app settings:")) .WriteLine(ErrorColor(result.ErrorResult)); return(false); } return(true); }
public void SubscriptionIdShouldBeReadFromEnvironmentVariable() { try { const string fakeSubscriptionId = "68373267-6C36-4B66-B92F-F124A23E313E"; Environment.SetEnvironmentVariable("subscriptionId", fakeSubscriptionId); var az = new AzureHelper(); az.GetSubscriptionId().Should().Be(fakeSubscriptionId); } finally { Environment.SetEnvironmentVariable("subscriptionId", null); } }
public ActionResult UploadImages(IEnumerable <HttpPostedFileBase> fileToUpload) { List <Models.ImageModel> objUploadedImg = new List <Models.ImageModel>(); foreach (HttpPostedFileBase img in fileToUpload) { Models.ImageModel objImg = new Models.ImageModel(); AzureHelper azureHelper = new AzureHelper(); //Here 111 and 222 is the static value for azure path you will be change according to your requirement. objImg.ImageUrl = azureHelper.UploadImage(img, 111, 222); objUploadedImg.Add(objImg); } TempData["image"] = objUploadedImg.ToList(); return(RedirectToAction("Index", new { fileName = "" })); }
public Response Create(CreateExerciseViewModel model) { var file = Request.Files["PictureUrl"]; var url = AzureHelper.Upload(file, "PictureUrl", Guid.NewGuid()); model.PictureUrl = url; var creationResponse = ExerciseCore.CreateExercises(model); if (creationResponse == null) { return(ResponseFactory.ErrorReponse); } return(ResponseFactory.SuccessResponse); }
public override async Task RunAsync() { var functionApp = await AzureHelper.GetFunctionApp(FunctionAppName, AccessToken, ManagementURL, Slot, Subscription); if (functionApp != null) { await AzureHelper.PrintFunctionsInfo(functionApp, AccessToken, ManagementURL, ShowKeys); if (!ShowKeys) { ColoredConsole.WriteLine("Use --show-keys to retrieve the Http-triggered URLs with appropriate keys in them (if enabled)"); } } else { ColoredConsole.Error.WriteLine(ErrorColor($"Can't find function app by name {FunctionAppName}")); } }
protected void Run_Click(object sender, EventArgs e) { FreezeUI(); ClearIndicators(); Guid jobID = Guid.NewGuid(); Status.Text = string.Format("Running job {0}.", jobID); DownloadLog.NavigateUrl = string.Format("Log.aspx?JobID={0}", jobID); DownloadLog.Enabled = true; Session["jobID"] = jobID; Session["lastLogRefreshTime"] = DateTime.MinValue; Session["allLogs"] = new List <PerformanceLog>(); Uri pointsBlobUri = null; if (PointsFile.HasFile) { CloudBlob pointsBlob = AzureHelper.CreateBlob(jobID.ToString(), AzureHelper.PointsBlob); using (BlobStream stream = pointsBlob.OpenWrite()) { PointsFile.FileContent.CopyTo(stream); } pointsBlobUri = pointsBlob.Uri; } else if (!string.IsNullOrEmpty(PointsBlob.Text)) { CloudBlob pointsBlob = AzureHelper.CreateBlob(jobID.ToString(), AzureHelper.PointsBlob); pointsBlob.CopyFromBlob(AzureHelper.GetBlob(new Uri(PointsBlob.Text))); pointsBlobUri = pointsBlob.Uri; } int nInt = 0, kInt = 0, maxIterationCountInt = 0; int.TryParse(N.Text, out nInt); int.TryParse(K.Text, out kInt); int.TryParse(MaxIterationCount.Text, out maxIterationCountInt); KMeansJobData jobData = new KMeansJobData(jobID, nInt, pointsBlobUri, kInt, maxIterationCountInt, DateTime.Now) { ProgressEmail = ProgressEmail.Text }; AzureHelper.EnqueueMessage(AzureHelper.ServerRequestQueue, jobData); WaitForResults(); }
private async Task PublishFunctionApp(Site functionApp, GitIgnoreParser ignoreParser, IDictionary <string, string> additionalAppSettings) { ColoredConsole.WriteLine("Getting site publishing info..."); var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); if (functionApp.IsLinux && !functionApp.IsDynamic && RunFromZipDeploy) { throw new CliException("Run from package is not supported with dedicated linux apps. Please use --nozip"); } var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; var workerRuntimeEnum = string.IsNullOrEmpty(workerRuntime) ? WorkerRuntime.None : WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); if (workerRuntimeEnum == WorkerRuntime.python && !functionApp.IsLinux) { throw new CliException("Publishing Python functions is only supported for Linux FunctionApps"); } Func <Task <Stream> > zipStreamFactory = () => ZipHelper.GetAppZipFile(workerRuntimeEnum, functionAppRoot, BuildNativeDeps, ignoreParser, AdditionalPackages, ignoreDotNetCheck: true); // if consumption Linux, or run from zip if ((functionApp.IsLinux && functionApp.IsDynamic) || RunFromZipDeploy) { await PublishRunFromZip(functionApp, await zipStreamFactory()); } else { await PublishZipDeploy(functionApp, zipStreamFactory); } if (PublishLocalSettings) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else if (additionalAppSettings.Any()) { await PublishAppSettings(functionApp, new Dictionary <string, string>(), additionalAppSettings); } // Syncing triggers is not required when using zipdeploy api if ((functionApp.IsLinux && functionApp.IsDynamic) || RunFromZipDeploy) { await Task.Delay(TimeSpan.FromSeconds(5)); await SyncTriggers(functionApp); } await AzureHelper.PrintFunctionsInfo(functionApp, AccessToken, showKeys : true); }
protected override async Task OnExecuteAsync(CommandLineApplication app) { var keyvaultAddress = $"https://{KeyVaultName}.vault.azure.net/"; var azureHelper = new AzureHelper(TenantId); var storageAccount = CloudStorageAccount.Parse( azureHelper.GetSecretValue( keyvaultAddress, "StorageAccountConnectionString").GetAwaiter().GetResult()); var tableClient = storageAccount.CreateCloudTableClient(); var nameTable = new NameTable(tableClient); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var entities = await nameTable.GetPeroidAsync(DaysBeforeNow, DaysAfterNow, cts.Token); DumpTypedEntities(entities, ResourceType.SignalR); DumpTypedEntities(entities, ResourceType.Deployment); }
public void UploadSignatureForBlob(string blobName, string containerName, SizeBasedCompleteSignature sig) { var client = AzureHelper.GetCloudBlobClient(); var container = client.GetContainerReference(containerName); // upload sig. var sigBlobName = AzureHelper.SetSignatureName(containerName, blobName); var sigBlob = container.GetBlockBlobReference(sigBlobName); using (Stream s = new MemoryStream()) { SerializationHelper.WriteBinarySizedBasedSignature(sig, s); s.Seek(0, SeekOrigin.Begin); sigBlob.UploadFromStream(s); } }
/// <summary> /// /// </summary> /// <param name="tenantName"></param> private static void CopyDbTemplate(string tenantName) { AzureHelper.CopyNewTenantDb ( TenantConfigHelper.GetTemplateDatabase(), tenantName, new Models.ApplicationConfigModel { ClientId = ApplicationConfigHelper.GetClientId(), ClientSecret = ApplicationConfigHelper.GetClientSecret(), TenantId = ApplicationConfigHelper.GetTenantId(), Subscription = ApplicationConfigHelper.GetSubscription(), ResourceGroupName = ApplicationConfigHelper.GetResourceGroupName(), ServerName = DatabaseConfigHelper.GetServerName() } ); }
public bool CleanupAsync() { var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); logger.Info("Success in getting token for cleanup-async!"); logger.Info("Deleting deployment..."); Task t = AzureHelper.DeleteResourceGroupAsync( credential, groupName, subscriptionId); logger.Info("Deletion of resource group triggered!!"); return(true); }
public async Task <JsonResult> UploadSingleImage() { if (Request.Form != null && Request.Form.Files != null) { string imageUrl = String.Empty; IFormFile file = Request.Form.Files.FirstOrDefault(); if (file != null & file.Length > 0) { AzureHelper azureImage = new AzureHelper(); imageUrl = await azureImage.UploadImage(file); } return(Json(new { success = true, url = imageUrl })); } return(Json(new { success = false })); }
public async Task <IReadOnlyList <Instance> > GetSearchEndpointsAsync( RegionInformation regionInformation, CancellationToken token) { var result = await _azureManagementApiWrapper.GetCloudServicePropertiesAsync( _configuration.Value.Subscription, regionInformation.ResourceGroup, regionInformation.ServiceName, ProductionSlot, token); var cloudService = AzureHelper.ParseCloudServiceProperties(result); var instances = GetInstances(cloudService.Uri, cloudService.InstanceCount, regionInformation); return(instances); }
private bool SelectNamespace(ref CloudWebDeployInputs inputs) { Console.WriteLine("Retrieving a list of created namespaces..."); ServiceBusNamespace[] namespaces = AzureHelper.GetNamespaces(inputs.Credentials); int namespaceCount = namespaces.Length; Console.WriteLine("Created namespaces: "); for (int currentNamespace = 1; currentNamespace <= namespaceCount; ++currentNamespace) { Console.WriteLine(currentNamespace + ": " + namespaces[currentNamespace - 1].Name + " (" + namespaces[currentNamespace - 1].Region + ")"); } Console.WriteLine("0: Exit without processing"); for ( ;;) { Console.WriteLine("Please select namespace you want to use: "); string answer = Console.ReadLine( ); int selection = 0; if (!int.TryParse(answer, out selection) || selection > namespaceCount || selection < 0) { Console.WriteLine("Incorrect namespace number."); continue; } if (selection == 0) { return(false); } if (ConsoleHelper.Confirm("Are you sure you want to select " + namespaces[selection - 1].Name + " namespace?")) { if (namespaces[selection - 1].Name.EndsWith("-ns")) { namespaces[selection - 1].Name = namespaces[selection - 1].Name.Substring(0, namespaces[selection - 1].Name.Length - 3); } inputs.NamePrefix = namespaces[selection - 1].Name; inputs.Location = namespaces[selection - 1].Region; return(true); } } }
public void GetBlobTest() { string containerName = "foo"; string blobName = "bar"; CloudBlobContainer container = AzureHelper.StorageAccount.CreateCloudBlobClient().GetContainerReference(containerName); container.CreateIfNotExist(); CloudBlob blob = container.GetBlobReference(blobName); using (BlobStream stream = blob.OpenWrite()) { byte[] bytes = new System.Text.UTF8Encoding().GetBytes("hello world"); stream.Write(bytes, 0, bytes.Length); } Assert.AreEqual(blob.Properties.Length, AzureHelper.GetBlob(blob.Uri).Properties.Length); }
public override bool Validate() { // TODO add these under a timeout try { // TODO Include test name in the logs logger.Info("Validations for Linux in progress..."); var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); bool ifCustomDataValid = true; PublicIPAddress ipAddress = AzureHelper.GetPublicAddressAsync(credential, groupName, subscriptionId, "myPublicIP").Result; using (var client = new SshClient(ipAddress.IpAddress, username, password)) { client.Connect(); SshCommand command = client.RunCommand("echo 'hello'"); logger.Info("Result of command 'x': " + command.Result); if (!string.IsNullOrWhiteSpace(customData)) { command = client.RunCommand("echo '<PASSWORD>' | sudo -S cat /var/lib/waagent/CustomData"); ifCustomDataValid = command.Result.Contains(customData); } client.Disconnect(); } if (!ifCustomDataValid) { throw new ArgumentException("Incorrect custom data!!"); } logger.Info("Validations for Linux...success!!"); } catch (Exception e) { logger.Error(e); return(false); } return(true); }
public override void Run() { InitializeToServer(); while (true) { System.Diagnostics.Trace.TraceInformation("[WorkerRole] Waiting for messages..."); AzureHelper.PollForMessage <KMeansTaskData>(AzureHelper.GetWorkerRequestQueue(machineID), ProcessNewTask, visibilityTimeoutSeconds); // Note that if the previous call to PollForMessage finds a task to do, it will block until the task is complete. // So we will only start checking the buddies *after* we're done with our own task. This gives time for the buddies to complete their work normally. // But this shouldn't matter because of the way CheckBuddies works: it only declares a buddy as failed once the task has reappeared on its queue after the visibility timeout, // which should be longer than the time it takes to process a task. CheckBuddies(); Thread.Sleep(500); } }
private DateTime GetNextExecutionTime() { DateTime toReturn = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, AzureHelper.BackupExecutionHour, 0, 0); string containerName = this.Name.Contains('/') ? this.Name.Substring(0, this.Name.IndexOf('/')) : string.Empty; string blobName = this.Name.Contains('/') ? this.Name.Substring(this.Name.IndexOf('/') + 1) : this.Name; string dateString = AzureHelper.GetTextBlob(AzureHelper.StorageConnectionString, containerName, blobName); if (string.IsNullOrEmpty(dateString)) { this.SaveNextExecutionTime(toReturn); } else { toReturn = DateTime.Parse(dateString, CultureInfo.CreateSpecificCulture("en-US")); } return(toReturn); }
protected override async Task OnExecuteAsync(CommandLineApplication app) { var keyvaultAddress = $"https://{KeyVaultName}.vault.azure.net/"; var azureHelper = new AzureHelper(TenantId); var storageAccount = CloudStorageAccount.Parse( azureHelper.GetSecretValue( keyvaultAddress, "StorageAccountConnectionString").GetAwaiter().GetResult()); var tableClient = storageAccount.CreateCloudTableClient(); var monitorTable = Helper.GenMonitorTable(TableName, tableClient); var stopWatch = new Stopwatch(); stopWatch.Start(); var entries = await monitorTable.GetBasedTimestamp(DaysBeforeNow); stopWatch.Stop(); Console.WriteLine($"Get {entries.Count} entries takes {stopWatch.ElapsedMilliseconds} milli-seconds"); }
public Response Update(CreateMealViewModel model) { if (model == null) { return(ResponseFactory.ErrorReponse); } var deleteOldPictureResponse = AzureHelper.DeleteFromBlob(model.Id); if (ResponseFactory.IsSuccessful(deleteOldPictureResponse)) { var file = Request.Files["PictureUrl"]; var url = AzureHelper.Upload(file, "PictureUrl", model.Id); model.PictureUrl = url; } return(MealCore.UpdateMeal(model)); }
public async Task <string> DownloadBlobAsString(string blobPath) { string url = $"{FeedContainerUrl}/{blobPath}"; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Clear(); var request = AzureHelper.RequestMessage("GET", url, AccountName, AccountKey)(); using (HttpResponseMessage response = await client.SendAsync(request)) { if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsStringAsync()); } return(null); } } }
public override async Task RunAsync() { // Get function app var functionApp = await AzureHelper.GetFunctionApp(FunctionAppName, AccessToken); // Get the GitIgnoreParser from the functionApp root var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); var ignoreParser = PublishHelper.GetIgnoreParser(functionAppRoot); // Get the WorkerRuntime var workerRuntime = WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(_secretsManager); // Check for any additional conditions or app settings that need to change // before starting any of the publish activity. var additionalAppSettings = ValidateFunctionAppPublish(functionApp, workerRuntime); if (workerRuntime == WorkerRuntime.dotnet && !Csx && !NoBuild) { const string outputPath = "bin/publish"; await DotnetHelpers.BuildDotnetProject(outputPath, DotnetCliParameters); Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, outputPath); } if (ListIncludedFiles) { InternalListIncludedFiles(ignoreParser); } else if (ListIgnoredFiles) { InternalListIgnoredFiles(ignoreParser); } else { if (PublishLocalSettingsOnly) { await PublishLocalAppSettings(functionApp, additionalAppSettings); } else { await PublishFunctionApp(functionApp, ignoreParser, additionalAppSettings); } } }
public void AzureChunkWriteRead() { string accountName = "testdrive"; string accountKey = "zRTT++dVryOWXJyAM7NM0TuQcu0Y23BgCQfkt7xh2f/Mm+r6c8/XtPTY0xxaF6tPSACJiuACsjotDeNIVyXM8Q=="; RemoteInfo ri = new RemoteInfo(accountName, accountKey); AzureHelper helper = new AzureHelper(accountName, accountKey, "testuploadchunksfile", CompressionType.None, EncryptionType.None, null, null, new Logger(), 4*1024*1024 , 1); helper.UploadFileAsChunks("D:\\testfiles\\testhuge.txt"); int OFFSET_TO_READ = 4492321; int BYTES_TO_READ = 11000; List<ChunkInfo> metadata = helper.GetBlobMetadata("testhuge.txt").Item1; Dictionary<int, long> chunkindexandoffsets = helper.GetChunkIndexAndOffsetInChunk(metadata, OFFSET_TO_READ, BYTES_TO_READ); byte[] temp = null; foreach(int chunkIndex in chunkindexandoffsets.Keys) { if(temp!=null) temp = temp.Concat(helper.DownloadChunk("testhuge.txt", metadata,chunkIndex)).ToArray(); else temp = helper.DownloadChunk("testhuge.txt", metadata, chunkIndex); } byte[] test = temp.Skip((int)chunkindexandoffsets.ElementAt(0).Value).Take(BYTES_TO_READ).ToArray(); byte[] truth = new byte[BYTES_TO_READ]; using (BinaryReader reader = new BinaryReader(new FileStream("D:\\testfiles\\testhuge.txt", FileMode.Open))) { reader.BaseStream.Seek(OFFSET_TO_READ, SeekOrigin.Begin); reader.Read(truth, 0, BYTES_TO_READ); } bool arraysAreEqual = Enumerable.SequenceEqual(test, truth); Console.WriteLine(arraysAreEqual); if (!arraysAreEqual) throw new Exception("local and downloaded bits dont match"); }
public bool Cleanup() { var token = AzureHelper.GetAccessTokenAsync(); var credential = new TokenCredentials(token.Result.AccessToken); logger.Info("Success in getting token for cleanup!"); logger.Info("Deleting deployment..."); Task t = AzureHelper.DeleteResourceGroupAsync( credential, groupName, subscriptionId); t.Wait(TimeSpan.FromMinutes(15)); logger.Info("Success in deleting deployment!!"); return(true); }
private bool ProcessNewTask(KMeansTaskData task) { System.Diagnostics.Trace.TraceInformation("[WorkerRole] ProcessNewTask(jobID={1}, taskID={0})", task.TaskID, task.JobID); UpdateBuddyGroup(task); AzureHelper.LogPerformance(() => { // Process the taskData KMeansTaskProcessor taskProcessor = new KMeansTaskProcessor(task); taskProcessor.Run(); // Send the result back taskProcessor.TaskResult.SavePointsProcessedDataByCentroid(); AzureHelper.EnqueueMessage(AzureHelper.WorkerResponseQueue, taskProcessor.TaskResult); }, jobID: task.JobID.ToString(), methodName: "ProcessNewTask", iterationCount: task.Iteration, points: task.Points.ToString(), centroids: task.Centroids.ToString(), machineID: machineID); return(true); }
private async Task <SearchServiceProperties> GetSearchServiceFromAzureAsync(AzureCloudServiceDetails serviceDetails, ITestOutputHelper logger) { logger.WriteLine($"Extracting search service properties from Azure. " + $"Subscription: {serviceDetails.Subscription}, " + $"Resource group: {serviceDetails.ResourceGroup}, " + $"Service name: {serviceDetails.Name}"); string result = await _azureManagementAPIWrapper.GetCloudServicePropertiesAsync( serviceDetails.Subscription, serviceDetails.ResourceGroup, serviceDetails.Name, serviceDetails.Slot, logger, CancellationToken.None); var cloudService = AzureHelper.ParseCloudServiceProperties(result); return(new SearchServiceProperties(ClientHelper.ConvertToHttpsAndClean(cloudService.Uri), cloudService.InstanceCount)); }
public Record Create(Record record, string zoneName) { try { AuthenticationResult = AzureHelper.GetAuthToken(AzureHelper.GetSubscriptionTenantId(Settings.SubscriptionId), Settings.ClientId, Settings.ClientSecret); RestClient.Authenticator = new JwtAuthenticator(AuthenticationResult.AccessToken); var request = new RestRequest(Settings.Azure.RecordUri, Method.PUT) { RequestFormat = DataFormat.Json }; request.AddUrlSegment("subscriptionId", Settings.SubscriptionId); request.AddUrlSegment("resourceGroupName", Settings.ResourceGroup); request.AddUrlSegment("zoneName", zoneName); request.AddUrlSegment("recordType", Settings.RecordType); request.AddUrlSegment("recordSetName", record.name); var jsonRecord = JsonConvert.SerializeObject(record, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }); request.AddParameter("application/json", jsonRecord, ParameterType.RequestBody); var response = RestClient.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { return(JsonConvert.DeserializeObject <Record>(response.Content)); } var eventType = EventLogEntryType.Error; if (response.StatusCode == HttpStatusCode.Forbidden || response.StatusCode == HttpStatusCode.Unauthorized) { eventType = EventLogEntryType.FailureAudit; } EventLogger.LogMessage(JObject.Parse(response.Content).ToString(), eventType); } catch (Exception ex) { EventLogger.LogMessage(JsonConvert.SerializeObject(ex), EventLogEntryType.Error); } return(null); }
private void UpdateUI() { Guid jobID = default(Guid); if (Session["jobID"] != null) { jobID = (Guid)Session["jobID"]; UpdateStatus(jobID, false); } UpdateWorkers(); if (Session["jobID"] != null) { AzureHelper.PollForMessage <KMeansJobResult>(AzureHelper.ServerResponseQueue, ShowResults, condition: message => message.JobID == jobID); } }
private void UpdateUIFromLogs(bool final, IEnumerable <PerformanceLog> logs) { // Show all logs Stats.Text = string.Empty; foreach (PerformanceLog log in logs) { Stats.Text += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", log.IterationCount, log.MethodName, (log.EndTime - log.StartTime).TotalSeconds); } // Show the group stats var logsByMethod = logs.GroupBy(log => log.MethodName); StatsSummary.Text = string.Empty; foreach (IGrouping <string, PerformanceLog> logGroup in logsByMethod) { StatsSummary.Text += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>", logGroup.Key, logGroup.Min(log => (log.EndTime - log.StartTime).TotalSeconds), logGroup.Average(log => (log.EndTime - log.StartTime).TotalSeconds), logGroup.Max(log => (log.EndTime - log.StartTime).TotalSeconds), logGroup.Count()); } // Update the points and centroids displays try { UpdatePointsCentroids( AzureHelper.GetBlob(logs.First().PartitionKey, AzureHelper.PointsBlob), AzureHelper.GetBlob(logs.First().PartitionKey, AzureHelper.CentroidsBlob), final); } catch (StorageClientException e) { Trace.Write("Information", "Updating points and centroids failed. Will try again later.", e); } catch (IOException e) { Trace.Write("Information", "Updating points and centroids failed. Will try again later.", e); } }
public Response Update(CreateFoodViewModel model) { if (string.IsNullOrWhiteSpace(model.Name)) { return(null); } var foodItem = FoodCore.Get(model.Id); if (foodItem == null) { return(ResponseFactory.ErrorReponse); } if (!string.IsNullOrWhiteSpace(model.Photo) && model.Photo != "undefined") { var file = Request.Files["Photo"]; var url = AzureHelper.Upload(file, "Photo", Guid.NewGuid()); foodItem.PictureUrl = url; } foodItem.Name = model.Name; foodItem.Carbohidrates = model.Carbohydrates; foodItem.Description = model.Description; foodItem.Fats = model.Fats; foodItem.Fiber = model.Fibre; foodItem.Proteins = model.Proteins; foodItem.Sugar = model.Sugar; foodItem.Grams = model.Grams; foodItem.Calories = model.Calories; foodItem.Status = (int)EntityStatus.ACTIVE; var foodCreationResponse = FoodCore.Update(foodItem); if (foodCreationResponse == null) { return(ResponseFactory.ErrorReponse); } return(ResponseFactory.SuccessResponse); }
public void AzureChunkWriteRead() { string accountName = "msrlot"; string accountKey = "wC3ou+VLBTu8ryKbsiSMtsIIHIpxGSIAWA0NtK58da2wELQ+USgYQwmVMtyq/p8ILsuZc8TiLeHBjaPI+a3A2Q=="; RemoteInfo ri = new RemoteInfo(accountName, accountKey); AzureHelper helper = new AzureHelper(accountName, accountKey, "testuploadchunksfile", CompressionType.None, EncryptionType.None, null, null, new Logger(), 4*1024*1024 , 1); helper.UploadFileAsChunks("D:\\testfiles\\testhuge.txt"); int OFFSET_TO_READ = 4492321; int BYTES_TO_READ = 11000; List<ChunkInfo> metadata = helper.GetBlobMetadata("testhuge.txt").Item1; Dictionary<int, long> chunkindexandoffsets = helper.GetChunkIndexAndOffsetInChunk(metadata, OFFSET_TO_READ, BYTES_TO_READ); byte[] temp = null; foreach(int chunkIndex in chunkindexandoffsets.Keys) { if(temp!=null) temp = temp.Concat(helper.DownloadChunk("testhuge.txt", metadata,chunkIndex)).ToArray(); else temp = helper.DownloadChunk("testhuge.txt", metadata, chunkIndex); } byte[] test = temp.Skip((int)chunkindexandoffsets.ElementAt(0).Value).Take(BYTES_TO_READ).ToArray(); byte[] truth = new byte[BYTES_TO_READ]; using (BinaryReader reader = new BinaryReader(new FileStream("D:\\testfiles\\testhuge.txt", FileMode.Open))) { reader.BaseStream.Seek(OFFSET_TO_READ, SeekOrigin.Begin); reader.Read(truth, 0, BYTES_TO_READ); } bool arraysAreEqual = Enumerable.SequenceEqual(test, truth); Console.WriteLine(arraysAreEqual); if (!arraysAreEqual) throw new Exception("local and downloaded bits dont match"); }
public Table(string tableName, IfTableDoesNotExist doesNotExistAction, AzureHelper azureHelper) { _tableName = tableName; _azureHelper = azureHelper; _autoCreate = doesNotExistAction == IfTableDoesNotExist.CreateIt; }
static void Main(string[] args) { string AzureaccountName = ConfigurationManager.AppSettings.Get("AccountName"); string AzureaccountKey = ConfigurationManager.AppSettings.Get("AccountSharedKey"); LocationInfo li = new LocationInfo(AzureaccountName, AzureaccountKey, SynchronizerType.Azure); string dataFile = "D:\\b"; int KB = 1024; int[] chunk_sizes = { 4*1024*KB , 8*1024*KB }; for (int i = 1; i <= 1; i++) { for (int threads = 1; threads <= 1; threads++) { foreach (int csize in chunk_sizes) { Console.Write(">"); File.Copy(dataFile, dataFile + threads + "," + csize); AzureHelper helper = new AzureHelper(AzureaccountName, AzureaccountKey, "foo123123", CompressionType.None, EncryptionType.None, null, null, new Logger(), csize, threads); long start = DateTime.Now.Ticks; helper.UploadFileAsChunks(dataFile + threads + "," + csize); long end = DateTime.Now.Ticks; Console.WriteLine(threads + "," + csize + "," + (((double)(end - start) / (double)10000000)) ); } } } FqStreamID fq_sid = new FqStreamID("1299-2716", "A", "TestBS"); CallerInfo ci = new CallerInfo(null, "A", "A", 1); StreamFactory sf = StreamFactory.Instance; sf.deleteStream(fq_sid, ci); IStream dfs_byte_val = sf.openFileStream<StrKey, ByteValue>(fq_sid, ci, li, StreamFactory.StreamSecurityType.Plain, CompressionType.None, StreamFactory.StreamOp.Write); StrKey k1 = new StrKey("k1"); dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-cmu"))); dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-msr"))); dfs_byte_val.Seal(false); dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-uw"))); dfs_byte_val.Close(); Console.ReadKey(); dfs_byte_val = sf.openFileStream<StrKey, ByteValue>(fq_sid, ci, li, StreamFactory.StreamSecurityType.Plain, CompressionType.None, StreamFactory.StreamOp.Read); Console.WriteLine("Get in read : " + dfs_byte_val.Get(k1)); IEnumerable<IDataItem> data = dfs_byte_val.GetAll(k1, 0, StreamFactory.NowUtc()); foreach (IDataItem dataItem in data) Console.WriteLine(dataItem.GetVal().ToString()); dfs_byte_val.Close(); Console.ReadKey(); /* ValueSerializerBase<StrKey> vsb = new ValueSerializerBase<StrKey>(); Byte[] buffer1 = vsb.SerializeToByteStream().ToArray(); Byte[] buffer2 = SerializerHelper<StrKey>.SerializeToProtoStream(k1).ToArray(); FileStream fout = new FileStream("tmp.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); BinaryWriter fs_bw = new BinaryWriter(fout); fs_bw.Write(buffer1); fs_bw.Write("-----W00t!-----"); fs_bw.Write(buffer2); fs_bw.Write("-----W00t!-----"); fs_bw.Close(); fout.Close(); */ }
public TableService(AzureHelper azureHelper) { _azureHelper = azureHelper; }
public Table(string tableName, AzureHelper azureHelper) : this(tableName, IfTableDoesNotExist.ThrowAnException, azureHelper) { }