private static void ClearAllValues() { using (var ctx = new SamplesContext(GetOptions())) { ctx.Database.ExecuteSqlCommand("DELETE FROM [dbo].[SampleEntry]"); } }
private static void InsertSampleValues() { using (var ctx = new SamplesContext(GetOptions())) { ctx.SampleEntries.Add(new SampleEntry { Value = $"Value at {DateTime.Now}" }); ctx.SaveChanges(); } }
private static void OutputSampleValues() { using (var ctx = new SamplesContext(GetOptions())) { var values = ctx.SampleEntries.AsNoTracking().ToArray(); foreach (var entity in values) { Console.WriteLine($"{entity.Id} - {entity.Value}"); } } }
public ProductCreationValidator(SamplesContext context) { _context = context; }
public TransactionalBehavior(SamplesContext context) { _context = context; }
public SqlServerPersonRepository(EventStoreContext dbContext, SamplesContext samplesContext, IDocumentSerializer serializer, IAggregateFactory aggregateFactory) : base(dbContext, serializer, aggregateFactory) { _samplesContext = samplesContext; }
public Handler(SamplesContext context) { _context = context; }
private void ProcessQueueMessageFromApi(CloudQueueMessage msg, int id) { //Get connection to the DB via the Samples Context. var dbConnString = CloudConfigurationManager.GetSetting("ShortenerDbConnectionString"); SamplesContext db = new SamplesContext(dbConnString); //Find the record with the ID that was taken from the Message. var sample = db.Samples.Find(id); Log("ID from queue is " + id); Log("CloudQueueMessage is " + msg.AsString); Log("File name from DB for ID " + id + " is: " + sample.Title); //Store the Blob path as a local variable string path = sample.MP3Blob; //get input blob CloudBlockBlob inputBlob = soundBlobContainer.GetBlockBlobReference(path); //make folder for blob to be downloaded into string folder = path.Split('\\')[0]; System.IO.Directory.CreateDirectory(GetLocalStoragePath() + @"\" + folder); //download file to local storage Log("Downloading blob to local storage..."); soundBlobContainer.GetBlockBlobReference(path).DownloadToFile(GetLocalStoragePath() + path, FileMode.Create); Log("Done downloading"); //get file's current location fullInPath = GetLocalStoragePath() + path; //new file name string soundName = Path.GetFileNameWithoutExtension(inputBlob.Name) + "cropped.mp3"; Log("New file name: " + soundName); //get and make directory for file output fullOutPath = GetLocalStoragePath() + @"out\" + soundName; CloudBlockBlob outputBlob = this.soundBlobContainer.GetBlockBlobReference(@"out\" + soundName); System.IO.Directory.CreateDirectory(GetLocalStoragePath() + @"out\"); //shorten the sound to 10s Log("Shortening MP3 to 10s."); stopWatch.Start(); CropSound(10); stopWatch.Stop(); Log("Took " + stopWatch.ElapsedMilliseconds + " ms to shorten mp3."); stopWatch.Reset(); //set content type to mp3 outputBlob.Properties.ContentType = "audio/mpeg3"; //set id3 tags Log("Setting ID3 tags."); TagLib.File tagFile = TagLib.File.Create(fullOutPath); tagFile.Tag.Comment = "Shortened on WorkerRole Instance " + GetInstanceIndex(); tagFile.Tag.Conductor = "Craig"; //Check that title tag isn't null fileTitle = tagFile.Tag.Title ?? "File has no original Title Tag"; tagFile.Save(); LogMP3Metadata(tagFile); //upload blob from local storage to container Log("Returning mp3 to the blob container."); using (var fileStream = File.OpenRead(fullOutPath)) { outputBlob.UploadFromStream(fileStream); } //Add metadata to blob Log("Adding metadata to the blob."); outputBlob.FetchAttributes(); outputBlob.Metadata["Title"] = fileTitle; outputBlob.Metadata["InstanceNo"] = GetInstanceIndex(); outputBlob.SetMetadata(); //Add the SampleMP3Date to the DB record. sample.SampleMP3Blob = @"out\" + soundName; sample.DateOfSampleCreation = DateTime.Now; //Save changes made to the record. db.SaveChanges(); //Print blob metadata to console Log("Blob's metadata: "); foreach (var item in outputBlob.Metadata) { Log(" " + item.Key + ": " + item.Value); } //remove message from queue Log("Removing message from the queue."); soundQueue.DeleteMessage(msg); //remove initial blob Log("Deleting the input blob."); inputBlob.Delete(); //remove files from local storage Log("Deleting files from local storage."); File.Delete(fullInPath); File.Delete(fullOutPath); }