public async Task <ActionResult> Upload(IFormFile file) { if (file?.Length > 0) { // Make sure the user selected an image file if (!file.ContentType.StartsWith("image")) { TempData["Message"] = "Only image files may be uploaded"; } else { try { // Save the original image in the "photos" container CloudStorageAccount account = CloudStorageAccount.Parse(_configuration.GetConnectionString("Storage")); CloudBlobClient client = account.CreateCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference("photos"); CloudBlockBlob photo = container.GetBlockBlobReference(Path.GetFileName(file.FileName)); await photo.UploadFromStreamAsync(file.OpenReadStream()); // Generate a thumbnail and save it in the "thumbnails" container using (var formFileStream = file.OpenReadStream()) using (var sourceImage = Image.FromStream(formFileStream)) { var newWidth = 192; var newHeight = (Int32)(1.0 * sourceImage.Height / sourceImage.Width * newWidth); using (var destinationImage = new Bitmap(sourceImage, new Size(newWidth, newHeight))) using (var stream = new MemoryStream()) { destinationImage.Save(stream, sourceImage.RawFormat); stream.Seek(0L, SeekOrigin.Begin); container = client.GetContainerReference("thumbnails"); CloudBlockBlob thumbnail = container.GetBlockBlobReference(Path.GetFileName(file.FileName)); await thumbnail.UploadFromStreamAsync(stream); } } // Submit the image to Azure's Computer Vision API ComputerVisionClient vision = new ComputerVisionClient( new ApiKeyServiceClientCredentials(_configuration.GetSection("Vision").GetValue <String>("Key")), new System.Net.Http.DelegatingHandler[] { } ); vision.Endpoint = _configuration.GetSection("Vision").GetValue <String>("Endpoint"); VisualFeatureTypes[] features = new VisualFeatureTypes[] { VisualFeatureTypes.Description }; ImageAnalysis result = await vision.AnalyzeImageAsync(photo.Uri.ToString(), features); // Record the image description and tags in blob metadata photo.Metadata.Add("Caption", result.Description.Captions[0].Text); for (int i = 0; i < result.Description.Tags.Count; i++) { string key = String.Format("Tag{0}", i); photo.Metadata.Add(key, result.Description.Tags[i]); } await photo.SetMetadataAsync(); } catch (Exception ex) { // In case something goes wrong TempData["Message"] = ex.Message; } } } return(RedirectToAction("Index")); }
public AzureBlobStorage(IConfiguration configuration) { var blobCs = configuration.GetConnectionString("ReplayBlobStorage"); _cloudStorageAccount = CloudStorageAccount.Parse(blobCs); }
static void RawFileMovetoEncrypt() { PGPLib pgp = new PGPLib(); bool asciiArmor = false; bool withIntegrityCheck = false; string sourcePath = @"C:\DATA FILES\Raw Data Files\"; string targetPath = @"C:\DATA FILES\Encrypted Data Files\"; string fileName = ""; int fileSize; string sourceFile = System.IO.Path.Combine(sourcePath, fileName); string destFile = System.IO.Path.Combine(targetPath, fileName); if (System.IO.Directory.Exists(sourcePath)) { string[] files = System.IO.Directory.GetFiles(sourcePath); // Copy the files and overwrite destination files if they already exist. foreach (string s in files) { // Use static Path methods to extract only the file name from the path. fileName = System.IO.Path.GetFileName(s); pgp.EncryptFile(sourcePath + fileName, @"C:\DATA FILES\publickey.asc", targetPath + fileName, asciiArmor, withIntegrityCheck); // destFile = System.IO.Path.Combine(targetPath, fileName); // System.IO.File.Copy(s, destFile, true); } } CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); //encryptedtgblfiles CloudBlobContainer container = blobClient.GetContainerReference("encryptedtgblfiles"); if (System.IO.Directory.Exists(sourcePath)) { string[] files = System.IO.Directory.GetFiles(sourcePath); // Copy the files and overwrite destination files if they already exist. foreach (string s in files) { fileName = System.IO.Path.GetFileName(s); CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); fileSize = fileName.Length; // Create or overwrite the "myblob" blob with contents from a local file. using (var fileStream = System.IO.File.OpenRead(targetPath + fileName)) { blockBlob.UploadFromStream(fileStream); } // To move a file or folder to a new location: // logger(fileName, "Uploaded",fileSize); // To move an entire directory. To programmatically modify or combine // path strings, use the System.IO.Path class. //System.IO.Directory.Move(@"C:\Users\Public\public\test\", @"C:\Users\Public\private"); } } }
internal static CloudStorageAccount CreateStorageAccount() { var connectionString = CloudConfigurationManager.GetSetting(SharedConstants.StorageConnectionStringName); return(CloudStorageAccount.Parse(connectionString)); }
public Fixture() { TestSiteName = "TestSiteName"; BlobConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage); BlobContainer = CloudStorageAccount.Parse(BlobConnectionString).CreateCloudBlobClient().GetContainerReference("azure-webjobs-secrets"); }
public QueueStorageService(IOptions <AzureStorageSettings> options) { var storageAccount = CloudStorageAccount.Parse(options.Value.AzureStorage); _client = storageAccount.CreateCloudQueueClient(); }
private static CloudStorageAccount GetCloudStorageAccount(string connectionString) { return(CloudStorageAccount.Parse(connectionString)); }
public AzureFileService(AppSettings appSettings) { this._appSettings = appSettings; this.Credentials = this._appSettings.AzureFileStoreConnectionString; this.storageAccount = CloudStorageAccount.Parse(this.Credentials); }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); Configuration = builder.Build(); CloudStorageAccount account = CloudStorageAccount.Parse(Configuration["AppSettings:storageConnection"]); CloudQueueClient queueClient = account.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference("blobcreateevents"); queue.CreateIfNotExistsAsync(); CloudBlobClient blobClient = account.CreateCloudBlobClient(); bool done = false; ListBlockItem lastBlockDownloaded = null; int currentBackOff = 0; int maxBackOff = 5; byte[] bytesFromBlob = new byte[4 * 1024 * 1024]; do { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Getting messages from the queue."); queue.FetchAttributesAsync().Wait(); int countOfMessages = Convert.ToInt32(queue.ApproximateMessageCount); if (countOfMessages > 0) { currentBackOff = 1; var msgs = queue.GetMessagesAsync(countOfMessages > 32 ? 32 : countOfMessages).Result; var numberOfMessagesLeftInBatch = msgs.Count(); foreach (var msg in msgs) { if (numberOfMessagesLeftInBatch == 1) // process only the last message // all messages are equivalent in meaning // sender usually gets ahead of receiver { JToken token = JObject.Parse(msg.AsString); string resourceId = (string)token.SelectToken("topic"); string subject = (string)token.SelectToken("subject"); string eventType = (string)token.SelectToken("eventType"); if (eventType == "Microsoft.Storage.BlobCreated") { var storageAccountName = resourceId.Split('/')[8]; var storageContainerName = subject.Split('/')[4]; var blobName = subject.Split('/')[6]; Uri uri = new Uri($"https://{storageAccountName}.blob.core.windows.net/{storageContainerName}/{blobName}"); CloudBlockBlob blob = new CloudBlockBlob(uri, blobClient); var blockList = blob.DownloadBlockListAsync().Result; long blobOffset = 0; var blocksToCopy = blockList; if (lastBlockDownloaded != null) { // count the blocks already written var countOfblocksAlreadyWritten = blockList.TakeWhile(item => (item.Name != lastBlockDownloaded.Name)).Count() + 1; // get an enumerable of those block list items var blocksAlreadyWritten = blockList.Take(countOfblocksAlreadyWritten); // add up the bytes already written foreach (var block in blocksAlreadyWritten) { blobOffset += block.Length; } // skip over blocks already written blocksToCopy = blockList.SkipWhile(item => (item.Name != lastBlockDownloaded.Name)).Skip(1); } if (blocksToCopy.Count() > 0) { var fs = File.OpenWrite(@"c:\temp\abigfile.dat"); using (BinaryWriter writer = new BinaryWriter(fs)) { foreach (var block in blocksToCopy) { blob.DownloadRangeToByteArrayAsync(bytesFromBlob, 0, blobOffset, block.Length).Wait(); writer.Seek(0, SeekOrigin.End); writer.Write(bytesFromBlob, 0, (int)block.Length); blobOffset += block.Length; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"{block.Name}"); } }; fs.Close(); } lastBlockDownloaded = blockList.Last(); } } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Deleting a message from the queue"); queue.DeleteMessageAsync(msg); numberOfMessagesLeftInBatch--; } } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Waiting for {currentBackOff} seconds for next message"); Thread.Sleep(currentBackOff * 1000); currentBackOff += (currentBackOff < maxBackOff ? 1 : 0); } // set done flag in some way, or loop forever. } while (!done); Console.ReadKey(); }
public async Task <FileInfo> GetExcelFile() { Dictionary <string, Int32> sharedStringDic = new Dictionary <string, int>(); const string excelTemplate = "Tools_CalDue_Template.xlsx"; const string sheetname = "Sheet1"; const int styleString = 0; // for this template const int styleDate = 3; // for this template string providername = Startup.AppSettings["StorageProvider"]; string folder = Startup.AppSettings["PdfFoldername"]; FileInfo fileinfo; Int32 sharedStringId = 0; UInt32 lineIndex; SysIO.MemoryStream ms = new SysIO.MemoryStream();; if (providername == "localfile") { string filepath = SysIO.Path.Combine(folder, excelTemplate); //fileinfo.FileByteStream = SysIO.File.Open(filepath, SysIO.FileMode.Open); SysIO.FileStream fs; fs = SysIO.File.Open(filepath, System.IO.FileMode.Open); fs.CopyTo(ms); long bytesInStream = ms.Length; fs.Close(); } else if (providername == "AzureBlob") { string connectionstring = Startup.AppSettings["AzureBlob"]; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionstring); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("templates"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(excelTemplate); SysIO.Stream frs = await blockBlob.OpenReadAsync(); frs.CopyTo(ms); long bytesInStream = ms.Length; bool canread = ms.CanRead; bool canwrite = ms.CanWrite; frs.Close(); } SpreadsheetDocument document = SpreadsheetDocument.Open(ms, true); WorkbookPart wbPart = document.WorkbookPart; Sheet theSheet = wbPart.Workbook.Descendants <Sheet>().Where(s => s.Name == sheetname).FirstOrDefault(); if (theSheet == null) { throw new ArgumentException("sheetName"); } WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id)); Worksheet ws = wsPart.Worksheet; Columns columns = ws.Descendants <Columns>().FirstOrDefault(); SheetData sheetData = ws.Descendants <SheetData>().FirstOrDefault(); Row firstRow = sheetData.Descendants <Row>().ElementAt(0); // get first row , line 1 firstRow.DyDescent = 0.3D; Row secondRow = sheetData.Descendants <Row>().ElementAt(1); // get second row , line 2 secondRow.Remove(); SharedStringTablePart sharedStringPart = wbPart.GetPartsOfType <SharedStringTablePart>().First(); SharedStringTable sharedStringTable = sharedStringPart.SharedStringTable; foreach (SharedStringItem item in sharedStringTable.Elements <SharedStringItem>()) // read shared string and add to Dictionary { if (item.InnerText != null) { sharedStringDic.Add(item.InnerText, sharedStringId); ++sharedStringId; } } lineIndex = 2; string id; // StoreLocation が column "B" と "M" の 2箇所にある foreach (var tool in filteredData) { Row newRow = new Row() { RowIndex = lineIndex, Spans = new ListValue <StringValue>() { InnerText = "1:20" }, Height = 16.5D, CustomHeight = true, DyDescent = 0.3D }; Cell cell1 = new Cell() { CellReference = "A" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.Plant).ToString(); cell1.CellValue = new CellValue(id); Cell cell2 = new Cell() { CellReference = "B" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.StoreLocation).ToString(); cell2.CellValue = new CellValue(id); Cell cell3 = new Cell() { CellReference = "C" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.ToolkitSloc).ToString(); cell3.CellValue = new CellValue(id); Cell cell4 = new Cell() { CellReference = "D" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.SerialNumber).ToString(); cell4.CellValue = new CellValue(id); Cell cell5 = new Cell() { CellReference = "E" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.Material).ToString(); cell5.CellValue = new CellValue(id); Cell cell6 = new Cell() { CellReference = "F" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.Description).ToString(); cell6.CellValue = new CellValue(id); Cell cell7 = new Cell() { CellReference = "G" + lineIndex.ToString(), StyleIndex = styleDate }; if (tool.LatestCalDate != null) { cell7.CellValue = new CellValue(((DateTime)tool.LatestCalDate).ToOADate().ToString()); } else { cell7.CellValue = new CellValue(); } Cell cell8 = new Cell() { CellReference = "H" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.CalStatus).ToString(); cell8.CellValue = new CellValue(id); Cell cell9 = new Cell() { CellReference = "I" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.Comment).ToString(); cell9.CellValue = new CellValue(id); Cell cell10 = new Cell() { CellReference = "J" + lineIndex.ToString(), StyleIndex = styleDate }; if (tool.CalDue != null) { cell10.CellValue = new CellValue(((DateTime)tool.CalDue).ToOADate().ToString()); } else { cell10.CellValue = new CellValue(); } Cell cell11 = new Cell() { CellReference = "K" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.CalPlace).ToString(); cell11.CellValue = new CellValue(id); Cell cell12 = new Cell() { CellReference = "L" + lineIndex.ToString(), DataType = CellValues.Number, StyleIndex = styleString }; cell12.CellValue = new CellValue(tool.CalInterval.ToString()); Cell cell13 = new Cell() { CellReference = "M" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.StoreLocation).ToString(); cell13.CellValue = new CellValue(id); Cell cell14 = new Cell() { CellReference = "N" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.SystemStatus).ToString(); cell14.CellValue = new CellValue(id); // todo tool.System_status is null, replace field to represent value Cell cell15 = new Cell() { CellReference = "O" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.UserStatus).ToString(); cell15.CellValue = new CellValue(id); Cell cell16 = new Cell() { CellReference = "P" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.Room).ToString(); cell16.CellValue = new CellValue(id); Cell cell17 = new Cell() { CellReference = "Q" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.SuperordEquip).ToString(); cell17.CellValue = new CellValue(id); Cell cell18 = new Cell() { CellReference = "R" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.SortField).ToString(); cell18.CellValue = new CellValue(id); Cell cell19 = new Cell() { CellReference = "S" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.Machine).ToString(); cell19.CellValue = new CellValue(id); Cell cell20 = new Cell() { CellReference = "T" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(tool.ToolkitMachine).ToString(); cell20.CellValue = new CellValue(id); newRow.Append(cell1); newRow.Append(cell2); newRow.Append(cell3); newRow.Append(cell4); newRow.Append(cell5); newRow.Append(cell6); newRow.Append(cell7); newRow.Append(cell8); newRow.Append(cell9); newRow.Append(cell10); newRow.Append(cell11); newRow.Append(cell12); newRow.Append(cell13); newRow.Append(cell14); newRow.Append(cell15); newRow.Append(cell16); newRow.Append(cell17); newRow.Append(cell18); newRow.Append(cell19); newRow.Append(cell20); sheetData.AppendChild <Row>(newRow); ++lineIndex; } Int32 count = 0; foreach (string key in sharedStringDic.Keys) { if (count >= sharedStringId) { sharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(key))); } ++count; } sharedStringTable.Save(); ws.Save(); wbPart.Workbook.Save(); document.Close(); fileinfo = new FileInfo(); fileinfo.FileName = ""; // file name is added at client (Silverlight) fileinfo.Length = ms.Length; fileinfo.byteArray = new byte[fileinfo.Length + 10]; Array.Copy(ms.GetBuffer(), fileinfo.byteArray, fileinfo.Length); //Array.Resize(ref fileinfo.FileByteStream, (int)ms.Length) ; //fileinfo.Length = ms.Length; return(fileinfo); }
public async Task <FileInfo> GetExcelFile() { Dictionary <string, Int32> sharedStringDic = new Dictionary <string, int>(); const string excelTemplate = "CalInProcessTemplateVer4.xlsx"; const string sheetname = "Sheet1"; uint styleString = 0; uint styleDate = 0; string providername = Startup.AppSettings["StorageProvider"]; FileInfo fileinfo; Int32 sharedStringId = 0; UInt32 lineIndex; SysIO.MemoryStream ms = new SysIO.MemoryStream();; if (providername == "localfile") { // Response.WriteFile(AppResources.GetCalCertPath(pdffilename)); TemplateFolder string folder = Startup.AppSettings["PdfFoldername"]; string filepath = SysIO.Path.Combine(folder, excelTemplate); //fileinfo.FileByteStream = SysIO.File.Open(filepath, SysIO.FileMode.Open); SysIO.FileStream fs; fs = SysIO.File.Open(filepath, System.IO.FileMode.Open); fs.CopyTo(ms); long bytesInStream = ms.Length; fs.Close(); } else if (providername == "AzureBlob") { string connectionstring = Startup.AppSettings["AzureBlob"]; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionstring); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("templates"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(excelTemplate); //SysIO.Stream templateStream = blockBlob.OpenRead(); //fileinfo.FileByteStream = blockBlob.OpenRead(); SysIO.Stream frs = await blockBlob.OpenReadAsync(); frs.CopyTo(ms); long bytesInStream = ms.Length; bool canread = ms.CanRead; bool canwrite = ms.CanWrite; frs.Close(); } SpreadsheetDocument document = SpreadsheetDocument.Open(ms, true); WorkbookPart wbPart = document.WorkbookPart; Sheet theSheet = wbPart.Workbook.Descendants <Sheet>().Where(s => s.Name == sheetname).FirstOrDefault(); if (theSheet == null) { throw new ArgumentException(string.Format("sheetName{0} not found", sheetname)); } WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id)); Worksheet ws = wsPart.Worksheet; Columns columns = ws.Descendants <Columns>().FirstOrDefault(); SheetData sheetData = ws.Descendants <SheetData>().FirstOrDefault(); Row firstRow = sheetData.Descendants <Row>().ElementAt(0); // get first row , line 1 firstRow.DyDescent = 0.3D; Row secondRow = sheetData.Descendants <Row>().ElementAt(1); // get second row , line 2 foreach (Cell cel2nd in secondRow) { if (cel2nd != null) { var cellAdd = cel2nd.CellReference; if (cellAdd == "A2") { styleString = cel2nd.StyleIndex.Value; } if (cellAdd == "H2") { styleDate = cel2nd.StyleIndex.Value; } } } secondRow.Remove(); SharedStringTablePart sharedStringPart = wbPart.GetPartsOfType <SharedStringTablePart>().First(); SharedStringTable sharedStringTable = sharedStringPart.SharedStringTable; foreach (SharedStringItem item in sharedStringTable.Elements <SharedStringItem>()) // read shared string and add to Dictionary { if (item.InnerText != null) { sharedStringDic.Add(item.InnerText, sharedStringId); ++sharedStringId; } } lineIndex = 2; string id; foreach (var entry in filteredData) { Row newRow = new Row() { RowIndex = lineIndex, Spans = new ListValue <StringValue>() { InnerText = "1:22" }, Height = 16.5D, CustomHeight = true, DyDescent = 0.3D }; Cell cell1 = new Cell() { CellReference = "A" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.Plant).ToString(); cell1.CellValue = new CellValue(id); Cell cell2 = new Cell() { CellReference = "B" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.Location).ToString(); cell2.CellValue = new CellValue(id); Cell cell3 = new Cell() { CellReference = "C" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.SerialNumber).ToString(); cell3.CellValue = new CellValue(id); Cell cell4 = new Cell() { CellReference = "D" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.Material).ToString(); cell4.CellValue = new CellValue(id); Cell cell5 = new Cell() { CellReference = "E" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.Description).ToString(); cell5.CellValue = new CellValue(id); Cell cell6 = new Cell() { CellReference = "F" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.CalPlace).ToString(); cell6.CellValue = new CellValue(id); Cell cell7 = new Cell() { CellReference = "G" + lineIndex.ToString(), DataType = CellValues.Number, StyleIndex = styleString }; cell7.CellValue = new CellValue(entry.CalInterval.ToString()); Cell cell8 = new Cell() { CellReference = "H" + lineIndex.ToString(), StyleIndex = styleDate }; cell8.CellValue = ConvertDateToCellValue(entry.RegisteredDate); Cell cell9 = new Cell() { CellReference = "I" + lineIndex.ToString(), StyleIndex = styleDate }; cell9.CellValue = ConvertDateToCellValue(entry.UserShipDate); Cell cell10 = new Cell() { CellReference = "J" + lineIndex.ToString(), StyleIndex = styleDate }; cell10.CellValue = ConvertDateToCellValue(entry.VenReceiveDate); Cell cell11 = new Cell() { CellReference = "K" + lineIndex.ToString(), StyleIndex = styleDate }; cell11.CellValue = ConvertDateToCellValue(entry.CalDate); Cell cell12 = new Cell() { CellReference = "L" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; string result = ""; if (entry.CalResult == true) { result = "GD"; } if (entry.CalResult == false) { result = "NG"; } id = sharedStringDic.AddToSharedString(result).ToString(); cell12.CellValue = new CellValue(id); Cell cell13 = new Cell() { CellReference = "M" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.VenComment).ToString(); cell13.CellValue = new CellValue(id); Cell cell14 = new Cell() { CellReference = "N" + lineIndex.ToString(), StyleIndex = styleDate }; cell14.CellValue = ConvertDateToCellValue(entry.PlanedShipDate); Cell cell15 = new Cell() { CellReference = "O" + lineIndex.ToString(), StyleIndex = styleDate }; cell15.CellValue = ConvertDateToCellValue(entry.VenShipDate); // todo tool.System_status is null, replace field to represent value Cell cell16 = new Cell() { CellReference = "P" + lineIndex.ToString(), StyleIndex = styleDate }; cell16.CellValue = ConvertDateToCellValue(entry.UserReceiveDate); Cell cell17 = new Cell() { CellReference = "Q" + lineIndex.ToString(), StyleIndex = styleDate }; cell17.CellValue = ConvertDateToCellValue(entry.CcReceiveDate); Cell cell18 = new Cell() { CellReference = "R" + lineIndex.ToString(), StyleIndex = styleDate }; cell18.CellValue = ConvertDateToCellValue(entry.CcUploadDate); Cell cell19 = new Cell() { CellReference = "S" + lineIndex.ToString(), DataType = CellValues.Number, StyleIndex = styleString }; cell19.CellValue = new CellValue(entry.StdTat.ToString()); Cell cell20 = new Cell() { CellReference = "T" + lineIndex.ToString(), DataType = CellValues.Number, StyleIndex = styleString }; cell20.CellValue = new CellValue(entry.Tat.ToString()); Cell cell21 = new Cell() { CellReference = "U" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.TatStatus).ToString(); cell21.CellValue = new CellValue(id); Cell cell22 = new Cell() { CellReference = "V" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; string finished = ""; if (entry.Finished == true) { finished = "Done"; } id = sharedStringDic.AddToSharedString(finished).ToString(); cell22.CellValue = new CellValue(id); Cell cell23 = new Cell() { CellReference = "W" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; String yearmonth; if (entry.UserShipDate == null) { yearmonth = ""; } else { yearmonth = String.Format("{0:yyyy-MM}", (DateTime)entry.UserShipDate); } id = sharedStringDic.AddToSharedString(yearmonth).ToString(); cell23.CellValue = new CellValue(id); Cell cell24 = new Cell() { CellReference = "X" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.PMaker).ToString(); cell24.CellValue = new CellValue(id); Cell cell25 = new Cell() { CellReference = "Y" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.PModel).ToString(); cell25.CellValue = new CellValue(id); Cell cell26 = new Cell() { CellReference = "Z" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.PName).ToString(); cell26.CellValue = new CellValue(id); Cell cell27 = new Cell() { CellReference = "AA" + lineIndex.ToString(), DataType = CellValues.SharedString, StyleIndex = styleString }; id = sharedStringDic.AddToSharedString(entry.PSN).ToString(); cell27.CellValue = new CellValue(id); newRow.Append(cell1); newRow.Append(cell2); newRow.Append(cell3); newRow.Append(cell4); newRow.Append(cell5); newRow.Append(cell6); newRow.Append(cell7); newRow.Append(cell8); newRow.Append(cell9); newRow.Append(cell10); newRow.Append(cell11); newRow.Append(cell12); newRow.Append(cell13); newRow.Append(cell14); newRow.Append(cell15); newRow.Append(cell16); newRow.Append(cell17); newRow.Append(cell18); newRow.Append(cell19); newRow.Append(cell20); newRow.Append(cell21); newRow.Append(cell22); newRow.Append(cell23); newRow.Append(cell24); newRow.Append(cell25); newRow.Append(cell26); newRow.Append(cell27); sheetData.AppendChild <Row>(newRow); ++lineIndex; } Int32 count = 0; foreach (string key in sharedStringDic.Keys) { if (count >= sharedStringId) { sharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(key))); } ++count; } sharedStringTable.Save(); ws.Save(); wbPart.Workbook.Save(); document.Close(); fileinfo = new FileInfo(); fileinfo.FileName = ""; // file name is added at client (Silverlight) fileinfo.Length = ms.Length; fileinfo.byteArray = new byte[fileinfo.Length + 10]; Array.Copy(ms.GetBuffer(), fileinfo.byteArray, fileinfo.Length); //Array.Resize(ref fileinfo.FileByteStream, (int)ms.Length) ; //fileinfo.Length = ms.Length; return(fileinfo); }
/// <inheritdoc /> public EmailService(CarWashConfiguration configuration) { // Parse the connection string and return a reference to the storage account. _storage = CloudStorageAccount.Parse(configuration.ConnectionStrings.StorageAccount); }
public StorageService(IConfiguration configuration) { this.storageAccount = CloudStorageAccount.Parse(configuration["App:StorageConnectionString"]); }
public string By(string firstQueryElement, string seccondQueryElement) { string queryResult = null; CloudStorageAccount storageAccount = CloudStorageAccount.Parse("" + "DefaultEndpointsProtocol=https;AccountName=egovtestbotae3a;AccountKey=HMZbdHjseB8xd8kc8bJgn1ch9R3h2glxFlVZRJCUrnDWtmcZyE11BHD5rkRM6WfjoqrTlS0TJ2GJ8fjKOXSNdA==;EndpointSuffix=core.windows.net"); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("botdata"); TableOperation retrieveOperation = TableOperation.Retrieve <GetInfoFromTable>("Servicii", seccondQueryElement); TableResult retrievedResult = table.Execute(retrieveOperation); if (retrievedResult.Result != null) { switch (firstQueryElement) { case "Cerereonline": queryResult = (((GetInfoFromTable)retrievedResult.Result).CerereOnline); break; case "Adresa si datele de contact": queryResult = (((GetInfoFromTable)retrievedResult.Result).Adresa + "" + ((GetInfoFromTable)retrievedResult.Result).Contact); break; case "Costul prestarii serviciului": queryResult = (((GetInfoFromTable)retrievedResult.Result).Costul); break; case "Informatie generala": queryResult = (((GetInfoFromTable)retrievedResult.Result).Descrierea); break; case "Documentele necesare": queryResult = (((GetInfoFromTable)retrievedResult.Result).Documente); break; case "Program de lucru": queryResult = (((GetInfoFromTable)retrievedResult.Result).Programul); break; case "TipPersoana": queryResult = (((GetInfoFromTable)retrievedResult.Result).TipPersoana); break; case "Acte normative": queryResult = (((GetInfoFromTable)retrievedResult.Result).TipPersoana); break; default: queryResult = "Și uaiiiiiiii!"; break; } return(queryResult); } else { return("Nu am gasit așa informație "); } }
public async Task <IActionResult> UploadFileNow(ICollection <IFormFile> files) { // get your storage accounts connection string var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=cst8359;AccountKey=ecMPpNU6vimZKMDTJG4seALrY7Kq7UJYjgl0/yLanXn857C8xtUJ2sF4ciB6wy9gg+e/YeYbRTaly2DVOxWhXQ=="); // create an instance of the blob client var blobClient = storageAccount.CreateCloudBlobClient(); // create a container to hold your blob (binary large object.. or something like that) // naming conventions for the curious https://msdn.microsoft.com/en-us/library/dd135715.aspx var container = blobClient.GetContainerReference("charlesstorage"); await container.CreateIfNotExistsAsync(); // set the permissions of the container to 'blob' to make them public var permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; await container.SetPermissionsAsync(permissions); // for each file that may have been sent to the server from the client foreach (var file in files) { try { // create the blob to hold the data var blockBlob = container.GetBlockBlobReference(file.FileName); if (await blockBlob.ExistsAsync()) { await blockBlob.DeleteAsync(); } using (var memoryStream = new MemoryStream()) { // copy the file data into memory await file.CopyToAsync(memoryStream); // navigate back to the beginning of the memory stream memoryStream.Position = 0; // send the file to the cloud await blockBlob.UploadFromStreamAsync(memoryStream); } // add the photo to the database if it uploaded successfully var photo = new Photo(); photo.Url = blockBlob.Uri.AbsoluteUri; photo.FileName = file.FileName; photo.BlogPostId = Convert.ToInt32(HttpContext.Request.Form["BlogPostId"]); _assignment1DataContext.Photos.Add(photo); _assignment1DataContext.SaveChanges(); } catch { } } return(RedirectToAction("Index")); }
private static async Task MainAsync() { const string poolId = "FileHandlingPool"; const string jobId = "FileHandlingJobDemo"; var settings = Config.LoadAccountSettings(); SetupStorage(settings.StorageAccountName, settings.StorageAccountKey); BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials(settings.BatchServiceUrl, settings.BatchAccountName, settings.BatchAccountKey); using (BatchClient batchClient = BatchClient.Open(cred)) { var pool = await BatchUtils.CreatePoolIfNotExistAsync(batchClient, poolId); var job = await BatchUtils.CreateJobIfNotExistAsync(batchClient, poolId, jobId); //set up auto storage file ResourceFile autoStorageFile = ResourceFile.FromAutoStorageContainer(AutoStorageContainerName, AutoStorageFileName); Console.WriteLine("\n[INFO] Autostorage resource File reference: "); Console.WriteLine("AutoStorageContainer: " + autoStorageFile.AutoStorageContainerName); Console.WriteLine("FilePath: " + autoStorageFile.FilePath); //upload file to external storage and add it as a resource file string storageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={settings.StorageAccountName};AccountKey={settings.StorageAccountKey}"; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer externalContainer = blobClient.GetContainerReference(ExternalStorageContainerName); await externalContainer.CreateIfNotExistsAsync(); var externalFile = await UploadFileToContainer(blobClient, ExternalStorageContainerName, "resource_files/resource_file.txt", "resource_file.txt"); Console.WriteLine("\n[INFO] External storage resource File reference:"); Console.WriteLine("SAS Url: " + externalFile.HttpUrl); Console.WriteLine("FilePath: " + externalFile.FilePath); // using staging files API var filesToStage = new List <IFileStagingProvider>(); StagingStorageAccount fileStagingStorageAccount = new StagingStorageAccount( storageAccount: settings.StorageAccountName, storageAccountKey: settings.StorageAccountKey, blobEndpoint: storageAccount.BlobEndpoint.ToString()); FileToStage stagedFile = new FileToStage("resource_files/staged_file.txt", fileStagingStorageAccount); Console.WriteLine("\n[INFO] Staged File added:"); Console.WriteLine("Local File: " + stagedFile.LocalFileToStage); Console.WriteLine("Node File: " + stagedFile.NodeFileName); filesToStage.Add(stagedFile); // setup output files // Generate SAS for outputcontainer CloudBlobContainer outputContainer = blobClient.GetContainerReference(OutputContainerName); await outputContainer.CreateIfNotExistsAsync(); string containerSas = outputContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Write, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddDays(1) }); string containerUrl = outputContainer.Uri.AbsoluteUri + containerSas; Console.WriteLine("\n[INFO] Output container: " + containerUrl); Console.WriteLine("\nPress return to continue..."); Console.ReadLine(); // Create tasks List <CloudTask> tasks = new List <CloudTask>(); for (var i = 1; i <= 10; i++) { var taskId = i.ToString().PadLeft(3, '0'); var commandLine = $@"/bin/bash -c ""echo 'Hello from {taskId}' && printf 'root dir:\n' > output.txt && ls -la >> output.txt && printf '\ninput dir:\n' >> output.txt && ls -la input >> output.txt"""; var task = new CloudTask(taskId, commandLine); // add resource files to task (one autostorage, one in external storage) task.ResourceFiles = new[] { autoStorageFile, externalFile }; // add staged files task.FilesToStage = filesToStage; // add output files var outputFiles = new List <OutputFile> { new OutputFile( filePattern: @"../std*.txt", destination: new OutputFileDestination(new OutputFileBlobContainerDestination( containerUrl: containerUrl, path: taskId)), uploadOptions: new OutputFileUploadOptions( uploadCondition: OutputFileUploadCondition.TaskCompletion)), new OutputFile( filePattern: @"output.txt", destination: new OutputFileDestination(new OutputFileBlobContainerDestination( containerUrl: containerUrl, path: taskId + @"\output.txt")), uploadOptions: new OutputFileUploadOptions( uploadCondition: OutputFileUploadCondition.TaskCompletion)), }; task.OutputFiles = outputFiles; tasks.Add(task); } Console.WriteLine("Submitting tasks and awaiting completion..."); // Add all tasks to the job. batchClient.JobOperations.AddTask(job.Id, tasks); await BatchUtils.WaitForTasksAndPrintOutputAsync(batchClient, job.ListTasks(), TimeSpan.FromMinutes(30)); // Clean up Batch resources (if the user so chooses) Console.WriteLine(); Console.Write("Delete job? [yes] no: "); string response = Console.ReadLine().ToLower(); if (response != "n" && response != "no") { batchClient.JobOperations.DeleteJob(jobId); } Console.Write("Delete pool? [yes] no: "); response = Console.ReadLine().ToLower(); if (response != "n" && response != "no") { batchClient.PoolOperations.DeletePool(poolId); } } }
public TableStorageContext(string connectionString) { _cloudClient = CloudStorageAccount.Parse(connectionString).CreateCloudTableClient(); _tables = new ConcurrentDictionary <string, CloudTable>(); }
public AzureStorageService(IOptions <AzureStorageSettings> options) { this.settings = options.Value; storageAccount = CloudStorageAccount.Parse(settings.StorageConnectionString); }
public async static void Run([BlobTrigger("mp3s/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, ILogger log) { trace = log; trace.LogInformation($"Mp3ToWav function processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); var mp3Temp = string.Format("{0}.mp3", Path.GetTempFileName()); var wavTemp = string.Format("{0}.wav", Path.GetTempFileName()); using (var ms = new MemoryStream()) { myBlob.CopyTo(ms); File.WriteAllBytes(mp3Temp, ms.ToArray()); } var mp3Bytes = File.ReadAllBytes(mp3Temp); trace.LogInformation($"mp3 size: {ConvertBytesToMegabytes(mp3Bytes.Length).ToString("0.00")} MB"); var process = new Process(); process.StartInfo.FileName = Environment.GetEnvironmentVariable("ffmpegPath"); process.StartInfo.Arguments = $"-i \"{mp3Temp}\" \"{wavTemp}\""; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.UseShellExecute = false; process.OutputDataReceived += new DataReceivedEventHandler((s, e) => { trace.LogInformation($"O: {e.Data}"); }); process.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { trace.LogInformation($"E: {e.Data}"); }); process.Start(); trace.LogInformation("***Converting from mp3 to wav***"); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); trace.LogInformation($"ffmpeg exit code: {process.ExitCode}"); trace.LogInformation($"wav temp out exists: {File.Exists(wavTemp)}"); var bytes = File.ReadAllBytes(wavTemp); trace.LogInformation($"wav size: {ConvertBytesToMegabytes(bytes.Length).ToString("0.00")} MB"); trace.LogInformation("***Uploading wav to Azure Storage***"); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")); var client = storageAccount.CreateCloudBlobClient(); var container = client.GetContainerReference("wavs"); await container.CreateIfNotExistsAsync(); var blob = container.GetBlockBlobReference(name.Replace("mp3", "wav")); blob.Properties.ContentType = "audio/wav"; var progressHandler = new Progress <StorageProgress>(); progressHandler.ProgressChanged += ProgressHandler_ProgressChanged; using (Stream stream = new MemoryStream(bytes)) { totalBytes = File.Open(wavTemp, FileMode.Open).Length; try { await blob.UploadFromStreamAsync(stream, null, new BlobRequestOptions(), new OperationContext(), progressHandler, CancellationToken.None); } catch (Exception ex) { trace.LogInformation($"Error: {ex.Message}"); } } //Delete temp files File.Delete(mp3Temp); File.Delete(wavTemp); trace.LogInformation("Done!"); }
/// <summary> /// 获取需要分配的资产、订单,排除资产 /// </summary> /// <returns></returns> private static async Task UserToAllocateAssetByNoIncludeAsync(string[] noIncludeAssetIds, long minAmount, long maxAmount, string assetAzureTableName, string yemUserProductAzureTableName, string writeAssetAzureTable, string writeYemUserProductAzureTable, string writeUserAssetRatioAzureTable, string writeAssetUserRatioAzureTable) { string yemUserPurchase = ConfigurationManager.AppSettings["PurchasePartitionKey"]; Console.WriteLine("创建CloudTable对象"); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["BlobConnectionString"]); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(2.Seconds(), 6); tableClient.DefaultRequestOptions.MaximumExecutionTime = 2.Minutes(); tableClient.DefaultRequestOptions.ServerTimeout = 2.Minutes(); CloudTable cloudOnSellAssetTable = tableClient.GetTableReference(assetAzureTableName); //查询所有资产信息 TableQuery <OnSellAssetDto> queryOnSellAsset = new TableQuery <OnSellAssetDto>() .Where("RemainderTotal gt 0 and IsLock eq false"); List <OnSellAssetDto> onSellAssetDtos = noIncludeAssetIds.Any() ? cloudOnSellAssetTable.ExecuteQuery(queryOnSellAsset).Where(p => !noIncludeAssetIds.Contains(p.OnSellAssetId)).ToList() : cloudOnSellAssetTable.ExecuteQuery(queryOnSellAsset).OrderBy(p => p.RemainderTotal).ToList(); //获取购买信息 CloudTable cloudPurchaseOrderTable = tableClient.GetTableReference(yemUserProductAzureTableName); TableQuery <YemUserProductDto> queryPurchaseOrder; // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (maxAmount > 0) { //queryPurchaseOrder = new TableQuery<YemUserProductDto>() // .Where($"PartitionKey eq '{yemUserPurchase}' and RemainingAmount ge {minAmount} and RemainingAmount lt {maxAmount} and IsLock eq false"); string startsWithCondition = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, yemUserPurchase), TableOperators.And, TableQuery.GenerateFilterConditionForLong("RemainingAmount", QueryComparisons.GreaterThanOrEqual, minAmount)); string filterCondition = TableQuery.CombineFilters( TableQuery.GenerateFilterConditionForLong("RemainingAmount", QueryComparisons.LessThan, maxAmount), TableOperators.And, startsWithCondition ); string endCondition = TableQuery.CombineFilters( TableQuery.GenerateFilterConditionForBool("IsLock", QueryComparisons.Equal, false), TableOperators.And, filterCondition ); queryPurchaseOrder = new TableQuery <YemUserProductDto>().Where(endCondition); } else { queryPurchaseOrder = new TableQuery <YemUserProductDto>() .Where($"PartitionKey eq '{yemUserPurchase}' and RemainingAmount gt 0 and IsLock eq false"); } var yemUserProductDtos = cloudPurchaseOrderTable.ExecuteQuery(queryPurchaseOrder).OrderByDescending(p => p.RemainingAmount).ToList(); Console.WriteLine("要处理的购买订单条数=" + yemUserProductDtos.Count()); Console.WriteLine("待分配的资产数=" + onSellAssetDtos.Count()); List <OnSellAssetDto> oldOnSellAssetDtos = onSellAssetDtos; if (!oldOnSellAssetDtos.Any()) { Console.WriteLine("没有处理的资产"); return; } int index = 0; foreach (var item in yemUserProductDtos) { index++; var addUserAssetRatios = new List <UserAssetRatio>(); //记录每笔购买产生的比例 用户资产关系 var addAssetUserRatios = new List <UserAssetRatio>(); //记录每笔购买产生的比例 资产用户关系 List <OnSellAssetDto> modifyOnSellAssets = new List <OnSellAssetDto>(); //记录每笔购买使用的资产 YemUserProductDto newYemUserProductDto = null; Console.WriteLine("总共处理的条数为:" + yemUserProductDtos.Count + ",当前处理的条数:" + index); Console.WriteLine("还需要处理的资产数=" + oldOnSellAssetDtos.Count()); long sumAssetCount = oldOnSellAssetDtos.Sum(p => p.RemainderTotal); long waitingDealAmount = item.RemainingAmount; //购买订单待处理的金额 for (int i = oldOnSellAssetDtos.Count - 1; i >= 0; i--) { var assetItem = oldOnSellAssetDtos[i]; long allocateAmount = AllocateAmountByAsset(waitingDealAmount, assetItem.RemainderTotal, sumAssetCount); if (item.RemainingAmount < allocateAmount) { allocateAmount = item.RemainingAmount; } if (assetItem.RemainderTotal < allocateAmount) { allocateAmount = assetItem.RemainderTotal; } if (allocateAmount <= 0) { continue; } var userAssetRatioTuple = CreateUserAssetRatio(item, assetItem, allocateAmount); //第一个是用户资产关系 第二个是资产用户关系 addUserAssetRatios.Add(userAssetRatioTuple.Item1); addAssetUserRatios.Add(userAssetRatioTuple.Item2); var updateOnSellAsset = BuildOnSellAsset(assetItem, allocateAmount); //修改资产的信息 modifyOnSellAssets.Add(updateOnSellAsset); newYemUserProductDto = BuildYemUserProduct(item, allocateAmount); //修改购买订单需要配置的参数 assetItem.RemainderTotal -= allocateAmount; if (assetItem.RemainderTotal == 0) { oldOnSellAssetDtos.Remove(assetItem); } } //保存数据库 await InsertOrReplaceAzureTable(tableClient, newYemUserProductDto, addUserAssetRatios, addAssetUserRatios, modifyOnSellAssets, writeAssetAzureTable, writeYemUserProductAzureTable, writeUserAssetRatioAzureTable, writeAssetUserRatioAzureTable); if (!oldOnSellAssetDtos.Any()) { Console.WriteLine("没有处理的资产"); break; } } }
public CloudStorageAccount CreateStorageAccountFromConnectionString() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(this.StorageConnectionString); return(storageAccount); }
public async static Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var model = JsonConvert.DeserializeObject <DataTableAjaxPostModel>(requestBody); var cache = ConnectionMultiplexer.Connect(Environment.GetEnvironmentVariable("RedisCache")).GetDatabase(); var totalRecords = await cache.SortedSetLengthAsync("AccountData"); // if the data has not been loaded into Redis if (totalRecords == 0) { log.LogInformation($"AccountData is not loaded in cache. Retrieving records from storage."); // retrieve from table storage var account = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("TableStorageConnectionString")); var tableClient = account.CreateCloudTableClient(); var table = tableClient.GetTableReference("AccountData"); var items = new List <AccountData>(); try { var query = new TableQuery <AccountData>(); TableContinuationToken token = null; do { var resultSegment = await table.ExecuteQuerySegmentedAsync(query, token); token = resultSegment.ContinuationToken; items.AddRange(resultSegment.Results); } while (token != null); log.LogInformation($"Saving {items.Count} AccountData records to cache."); await cache.SortedSetAddAsync("AccountData", items.Select(i => new SortedSetEntry(JsonConvert.SerializeObject(i), int.Parse(i.RowKey))).ToArray()); totalRecords = await cache.SortedSetLengthAsync("AccountData"); } catch (Exception ex) { log.LogError(ex.Message); } } log.LogInformation($"Retrieving {model.length} records from cache."); var accountData = await cache.SortedSetRangeByScoreAsync("AccountData", model.start, model.start + model.length); var response = new { draw = model.draw, recordsTotal = totalRecords, recordsFiltered = totalRecords, data = accountData.Select(d => { var data = JsonConvert.DeserializeObject <AccountData>(d); return(new string[] { data.FirstName, data.LastName, data.Office, data.Position, data.Salary, data.StartDate }); }).ToList() }; log.LogInformation($"Returning successful response for {accountData.Length} out of {totalRecords} records."); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json") }); }
public CloudStorageAccount Parse(string connectionString) { return(CloudStorageAccount.Parse(connectionString)); }
public static void Main(string[] args) { string ContainerName = ConfigurationManager.AppSettings["documentsContainer"].ToString(); string ContainerNamepb = ConfigurationManager.AppSettings["pbdocumentsContainer"].ToString(); string continerDraftisda = ConfigurationManager.AppSettings["isdareportstorageContainer"].ToString(); string continerdraftpb = ConfigurationManager.AppSettings["pbreportsstorageContainer"].ToString(); string AgreementCode = string.Empty; //int clientid = 0; try{ string a; CloudStorageAccount account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"].ToString()); CloudBlobClient blobClient = account.CreateCloudBlobClient(); Console.WriteLine("Enter '1' to move Executed Isda Documets"); Console.WriteLine("\n"); Console.WriteLine("Enter '2' to move Executed PB Documets"); Console.WriteLine("\n"); Console.WriteLine("Enter '3' to move Draft Isda Documets"); Console.WriteLine("\n"); Console.WriteLine("Enter '4' to move Draft PB Documets"); Console.WriteLine("\n"); Console.WriteLine("Enter Number"); a = Console.ReadLine(); switch (a) { case "1": DataTable dt = DataAccess.ISDAAgreement.usp_GetDocumentForCloudStroages(); Isdamovestroage(blobClient, ContainerName, dt, new string[] { "executed/", "isda/" }); break; case "2": DataTable dt1 = DataAccess.PBAgreements.Get_PBAllcloudstroagemovedagreements(); Isdamovestroage(blobClient, ContainerNamepb, dt1, new string[] { "executed/", "pb/" }); break; case "3": DataTable draftisda = DataAccess.Draft_AgreementsISDA.Draft_ISDAGetAgreementscloudstroage(); draftIsdamovestroage(blobClient, continerDraftisda, draftisda, new string[] { "draft/", "isda/" }); break; case "4": DataTable dratpb = DataAccess.Draft_AgreementsPB.Draft_PBGetAgreementscloudstroage(); draftIsdamovestroage(blobClient, continerdraftpb, dratpb, new string[] { "draft/", "pb/" }); break; default: Console.WriteLine("Invalid Selection"); break; } } catch (Exception ex) { Console.WriteLine("Error While Running Code"); Console.WriteLine(ex.StackTrace.ToString()); } }
/// <summary> /// Ingest all Mezzamine files to Asset /// </summary> private void IngestAssets() { IAccessPolicy writePolicy = MediaContext.AccessPolicies.Create("writePolicy_" + currentAsset.Name, TimeSpan.FromMinutes(120), AccessPermissions.Write); ILocator destinationLocator = MediaContext.Locators.CreateLocator(LocatorType.Sas, currentAsset, writePolicy); //Asset Storage CloudStorageAccount assetStorageCount = CloudStorageAccount.Parse(myRequest.MediaStorageConn); CloudBlobClient assetClient = assetStorageCount.CreateCloudBlobClient(); CloudBlobContainer assetContainer = assetClient.GetContainerReference(currentAsset.Uri.Segments[1]); //Mezzamine Storage CloudStorageAccount MezzamineStorageCount = CloudStorageAccount.Parse(myRequest.ButlerRequest.StorageConnectionString); CloudBlobClient MezzamineClient = MezzamineStorageCount.CreateCloudBlobClient(); CloudBlobContainer MezzamineContainer = MezzamineClient.GetContainerReference(myRequest.ButlerRequest.WorkflowName); //Filter Ingest only MP4 foreach (string urlMezzamineFile in myRequest.ButlerRequest.MezzanineFiles.Where(mf => mf.ToLower().EndsWith(".mp4"))) { Uri xFile = new Uri(urlMezzamineFile); int segmentIndex = xFile.Segments.Count() - 1; //Asset BLOB Xfile string AssetBlobName = Uri.UnescapeDataString(xFile.Segments[segmentIndex]); CloudBlockBlob assetBlob = assetContainer.GetBlockBlobReference(AssetBlobName); assetContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob } ); //Mezzamine BLOB Xfile string MezzamineBlobName = ""; for (int i = 2; i <= segmentIndex; i++) { MezzamineBlobName += xFile.Segments[i]; } MezzamineBlobName = Uri.UnescapeDataString(MezzamineBlobName); CloudBlockBlob MezzamineBlob = MezzamineContainer.GetBlockBlobReference(MezzamineBlobName); var sas = MezzamineContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15), SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7), Permissions = SharedAccessBlobPermissions.Read, }); //USE decode URL for spetial characters var srcBlockBlobSasUri = string.Format("{0}{1}", Uri.UnescapeDataString(MezzamineBlob.Uri.AbsoluteUri), sas); assetBlob.StartCopy(new Uri(srcBlockBlobSasUri)); Trace.TraceInformation("{0} in process {1} processId {2} Start copy MezzamineFile {3}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId, MezzamineBlobName); CloudBlockBlob blobStatusCheck; blobStatusCheck = (CloudBlockBlob)assetContainer.GetBlobReferenceFromServer(AssetBlobName); while (blobStatusCheck.CopyState.Status == CopyStatus.Pending) { Task.Delay(TimeSpan.FromSeconds(10d)).Wait(); Trace.TraceInformation("{0} in process {1} processId {2} copying MezzamineFile {3} status {4}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId, MezzamineBlobName, blobStatusCheck.CopyState.Status); blobStatusCheck = (CloudBlockBlob)assetContainer.GetBlobReferenceFromServer(AssetBlobName); } assetBlob.FetchAttributes(); //Add the xFile to Asset var assetFile = currentAsset.AssetFiles.Create(AssetBlobName); MezzamineBlob.FetchAttributes(); assetFile.ContentFileSize = MezzamineBlob.Properties.Length; assetFile.Update(); Trace.TraceInformation("{0} in process {1} processId {2} finish MezzamineFile {3}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId, MezzamineBlobName); } destinationLocator.Delete(); writePolicy.Delete(); currentAsset.Update(); }
public static async Task Main(string[] args) { // read the configuration var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true) .AddJsonFile($"appsettings.{environmentName}.json", true) .AddUserSecrets <Program>() .AddCommandLine(args); var configuration = builder.Build(); // get queue name var queueName = configuration["Queue"] ?? throw new ArgumentException("Specify queue name"); var poisonQueueName = $"{queueName}-poison"; // get storage references var connectionString = configuration["ConnectionString"] ?? throw new ArgumentException("Specify connection string"); var storageAccount = CloudStorageAccount.Parse(connectionString); var queueClient = storageAccount.CreateCloudQueueClient(); var queue = queueClient.GetQueueReference(queueName); var poisonQueue = queueClient.GetQueueReference(poisonQueueName); // get max property var maxString = configuration["Max"]; if (!int.TryParse(maxString, out var max)) { max = int.MaxValue; } // get max age property var maxAgeString = configuration["MaxAge"]; if (!int.TryParse(maxAgeString, out var maxAge)) { maxAge = 1; } // get interval property var intervalString = configuration["Interval"]; if (!int.TryParse(intervalString, out var intervalInt)) { intervalInt = 0; } var interval = TimeSpan.FromMilliseconds(intervalInt); var requeued = 0; var deleted = 0; var ageLimit = DateTime.UtcNow.AddDays(-maxAge); var delay = TimeSpan.Zero; while (true) { var message = await poisonQueue.GetMessageAsync(); if (message == null) { break; } var isOld = message.InsertionTime < ageLimit; if (isOld) { ++deleted; } else { await queue.AddMessageAsync(new CloudQueueMessage(message.AsString), null, delay, null, null); ++requeued; delay += interval; } await poisonQueue.DeleteMessageAsync(message); if (requeued == max) { break; } } Console.WriteLine($"Requeued {requeued} messages to {queueName}, deleted {deleted}"); if (delay < TimeSpan.FromMinutes(3)) { Console.WriteLine($"Total delay: {delay.TotalSeconds} seconds"); } else if (delay < TimeSpan.FromHours(3)) { Console.WriteLine($"Total delay: {(delay.TotalSeconds / 60):F1} minutes"); } else { Console.WriteLine($"Total delay: {(delay.TotalSeconds / 3600):F1} hours"); } Console.WriteLine("Enter ENTER to continue"); Console.ReadLine(); }
public AzureTableDataSource(string name, string connectionString) { Name = name; _storageAccount = CloudStorageAccount.Parse(connectionString); _tableClient = _storageAccount.CreateCloudTableClient(); }
public CloudStorageImageUriComposer(string connectionString) { storageAccount = CloudStorageAccount.Parse(connectionString); }
public static async Task Run([QueueTrigger("traces", Connection = "TracesStorageConnectionString")] string traceMessage, ILogger log, Microsoft.Azure.WebJobs.ExecutionContext context) { log.LogInformation($"ExchangeMessageTrackingToSplunk function was triggered with the following message: {traceMessage}"); var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var traceStorageConnectionString = config["TracesStorageConnectionString"]; if (traceStorageConnectionString == null) { string m = $"{context.InvocationId} - Variable TracesStorageConnectionString is not set in configuration. This function cannot run."; log.LogCritical(m); throw new Exception(m); } log.LogDebug($"{context.InvocationId} - TracesStorageConnectionString: {traceStorageConnectionString.Substring(0, 40)}"); var archiveContainerName = config["TraceArchiveContainerName"]; if (archiveContainerName == null) { log.LogWarning($"{context.InvocationId} - Variable TraceArchiveContainerName is not set in configuration. Using default value: 'trace-archive' "); archiveContainerName = "trace-archive"; } try { log.LogDebug($"{context.InvocationId} - Get hold of archive storage container"); CloudStorageAccount archiveStorageAccount = CloudStorageAccount.Parse(traceStorageConnectionString); CloudBlobClient archiveStorageClient = archiveStorageAccount.CreateCloudBlobClient(); CloudBlobContainer archiveStorageContainer = archiveStorageClient.GetContainerReference(archiveContainerName); if (await archiveStorageContainer.CreateIfNotExistsAsync()) { log.LogInformation(($"{context.InvocationId} - Archive container {archiveContainerName} did not exist and was created sucessfully.")); archiveStorageContainer.Metadata.Add("origin", "Created automatically by ExchangeMessageTrackingToSplunk Function"); await archiveStorageContainer.SetMetadataAsync(); } log.LogInformation($"{context.InvocationId} - Archive container name: {archiveContainerName}"); var blobName = Guid.NewGuid().ToString(); CloudBlockBlob archiveBlob = archiveStorageContainer.GetBlockBlobReference(blobName); log.LogInformation($"{context.InvocationId} -archiveBlob.Uri: {archiveBlob.Uri}"); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(traceMessage))) { await archiveBlob.UploadFromStreamAsync(stream); } log.LogInformation($"{context.InvocationId} -archiveBlob.Uri: {archiveBlob.Uri} was created for message"); } catch (Exception e) { log.LogError($"{context.InvocationId} - Exception {e.Message}"); log.LogError($"{context.InvocationId} - Stacktrace {e.StackTrace}"); if (e.InnerException != null) { log.LogError($"{context.InvocationId} - Inner Exception was {e.InnerException.Message}"); } throw e; } }
/// <summary> /// Initializes a new instance of the <see cref="DisconnectedPerformanceMonitor"/> class. /// </summary> /// <param name="storageConnectionString">The connection string for the Azure Storage account to monitor.</param> /// <param name="taskHub">The name of the task hub within the specified storage account.</param> public DisconnectedPerformanceMonitor(string storageConnectionString, string taskHub) : this(CloudStorageAccount.Parse(storageConnectionString), taskHub) { }