private static async Task BasicDataOperationsAsync(CloudTable table) { // Create an instance of a customer entity. See the Model\CustomerEntity.cs for a description of the entity. BitcoinEntity bitcoin = new BitcoinEntity("10982384", "2323", "2022") { SomeData = "2444", SomeMoreData = "1997" }; // Demonstrate how to insert the entity Console.WriteLine("Insert an Entity."); bitcoin = await SamplesUtils.InsertOrMergeEntityAsync(table, bitcoin); // Demonstrate how to Update the entity by changing the phone number Console.WriteLine("Update an existing Entity using the InsertOrMerge Upsert Operation."); bitcoin.SomeMoreData = "425-555-0105"; await SamplesUtils.InsertOrMergeEntityAsync(table, bitcoin); Console.WriteLine(); // Demonstrate how to Read the updated entity using a point query Console.WriteLine("Reading the updated Entity."); bitcoin = await SamplesUtils.RetrieveEntityUsingPointQueryAsync(table, "Harp", "Walter"); Console.WriteLine(); // Demonstrate how to Delete an entity //Console.WriteLine("Delete the entity. "); //await SamplesUtils.DeleteEntityAsync(table, customer); //Console.WriteLine(); }
public static async Task <BitcoinEntity> RetrieveEntityUsingPointQueryAsync(CloudTable table, string partitionKey, string rowKey) { try { TableOperation retrieveOperation = TableOperation.Retrieve <BitcoinEntity>(partitionKey, rowKey); TableResult result = await table.ExecuteAsync(retrieveOperation); BitcoinEntity customer = result.Result as BitcoinEntity; if (customer != null) { Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", customer.PartitionKey, customer.RowKey, customer.SomeData, customer.SomeMoreData); } // Get the request units consumed by the current operation. RequestCharge of a TableResult is only applied to Azure CosmoS DB if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of Retrieve Operation: " + result.RequestCharge); } return(customer); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public static async Task DeleteEntityAsync(CloudTable table, BitcoinEntity deleteEntity) { try { if (deleteEntity == null) { throw new ArgumentNullException("deleteEntity"); } TableOperation deleteOperation = TableOperation.Delete(deleteEntity); TableResult result = await table.ExecuteAsync(deleteOperation); // Get the request units consumed by the current operation. RequestCharge of a TableResult is only applied to Azure CosmoS DB if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of Delete Operation: " + result.RequestCharge); } } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public static async Task <BitcoinEntity> InsertOrMergeEntityAsync(CloudTable table, BitcoinEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { // Create the InsertOrReplace table operation TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity); // Execute the operation. TableResult result = await table.ExecuteAsync(insertOrMergeOperation); BitcoinEntity insertedBitcoin = result.Result as BitcoinEntity; // Get the request units consumed by the current operation. RequestCharge of a TableResult is only applied to Azure Cosmos DB if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge); } return(insertedBitcoin); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
/// <summary> /// 处理平台html数据 /// </summary> /// <param name="htmlDetail"></param> /// <param name="sourceId"></param> public static bool HandlePlatFornHtml(string platForm, string htmlDetail, ref List <BitcoinEntity> resultList, ref string msg) { htmlDetail = CommonTools.Compress(htmlDetail); //HtmlDocument doc = new HtmlDocument(); //doc.LoadHtml(htmlDetail); // LogHelper.LogInfo(htmlDetail); Regex tableRegex = new Regex("<table class=\"table noBg\">[\\s\\S]+?</table>", RegexOptions.IgnoreCase); Regex trRegex = new Regex(@"<tr[\s\S]+?添加自选</div>", RegexOptions.IgnoreCase); Regex tdRegex = new Regex(@"<tr><td>[\d\*]+<td>([\s\S]+?)<td>([^<]+?)<td[^>]+?data-btc=([\d\.]+)[^>]+?>([^<]+?)<td>([^<]+?)<td[^>]+?>([^<]+?)<td>([^<]+?)<td>([\d\u4e00-\u9fa5]+?)<td>", RegexOptions.IgnoreCase); Regex platRegex = new Regex(@"<img[^>]+?>([^>]+?)</a>", RegexOptions.IgnoreCase); Match tablematchs = tableRegex.Match(htmlDetail); if (!tablematchs.Success) { msg = "获取不到数据"; return(false); } //HtmlNode tableNode = doc.DocumentNode.SelectSingleNode("//table[@class='table noBg']//tbody"); // LogHelper.LogInfo(tablematchs.Value); //tableNode.InnerHtml = ""; MatchCollection matchs = trRegex.Matches(tablematchs.Value); int i = 0; foreach (Match item in matchs) { string trDetail = item.Value; Match tdmatchs = tdRegex.Match(trDetail); if (tdmatchs.Success) { i++; BitcoinEntity coinEnt = new BitcoinEntity(); coinEnt.Id = i + 1; coinEnt.PlatForm = platForm; coinEnt.NameHtml = tdmatchs.Groups[1].Value.Replace("/exchange", "https://www.feixiaohao.com/exchange"); Match platMatch = platRegex.Match(coinEnt.NameHtml); if (platMatch.Success) { coinEnt.Name = platMatch.Groups[1].Value; } coinEnt.ExchangeType = tdmatchs.Groups[2].Value; string aPrice = tdmatchs.Groups[4].Value; decimal price = 0; decimal btcPrice = 0; if ((aPrice.Contains("¥"))) { price = Convert.ToDecimal(aPrice.Replace("¥", "").Replace(",", "")); btcPrice = CommonTools.ChangeDataToD(tdmatchs.Groups[3].Value); } if (price == 0) { msg = "价格为0"; continue; } coinEnt.Amout = tdmatchs.Groups[5].Value; coinEnt.TotalPrice = tdmatchs.Groups[6].Value; coinEnt.Percent = Convert.ToDecimal(tdmatchs.Groups[7].Value.Replace("%", "")); coinEnt.Time = tdmatchs.Groups[8].Value; coinEnt.Price = price; coinEnt.BtcPrice = btcPrice; string nameEnglish = ""; string[] arr = coinEnt.ExchangeType.Split('/'); if (arr.Length == 2) { nameEnglish = arr[0].ToUpper(); } coinEnt.NameEnglish = nameEnglish; if (resultList.Exists(x => x.NameEnglish.ToLower() == coinEnt.NameEnglish.ToLower())) { continue; } resultList.Add(coinEnt); } } //for (int i = 0; i < trNodeList.Count; i++) //{ // BitcoinEntity coinEnt = new BitcoinEntity(); // HtmlNodeCollection tdNodeList = trNodeList[i].ChildNodes; // if (tdNodeList == null || tdNodeList.Count < 9) // { // msg = "html结构有变化"; // return false; // } // decimal price = 0; // decimal btcPrice = 0; // if ((tdNodeList[3].InnerText.Contains("¥"))) // { // price = Convert.ToDecimal(tdNodeList[3].InnerText.Replace("¥", "").Replace(",", "")); // HtmlAttributeCollection attrColl = tdNodeList[3].Attributes; // btcPrice = CommonTools.ChangeDataToD(attrColl["data-btc"].Value); // } // string name = tdNodeList[1].InnerText.ToLower().Trim(); // coinEnt.Id = i + 1; // coinEnt.PlatForm = platForm; // coinEnt.Name = name; // coinEnt.NameHtml = tdNodeList[1].InnerHtml.Replace("/currencies", "https://www.feixiaohao.com/currencies"); // coinEnt.ExchangeType = tdNodeList[2].InnerText.Trim(); // coinEnt.Price = price; // coinEnt.BtcPrice = btcPrice; // coinEnt.Amout = tdNodeList[4].InnerText; // coinEnt.TotalPrice = tdNodeList[5].InnerText; // coinEnt.Percent = Convert.ToDecimal(tdNodeList[6].InnerText.Replace("%", "")); // coinEnt.Time = tdNodeList[7].InnerText; // string nameEnglish = ""; // string[] arr = coinEnt.ExchangeType.Split('/'); // if (arr.Length == 2) // { // nameEnglish = arr[0].ToUpper(); // } // coinEnt.NameEnglish = nameEnglish; // //if (!coinEnt.ExchangeType.ToUpper().Contains("BTC")) // //{ // // continue; // //} // if (resultList.Exists(x => x.NameEnglish.ToLower() == coinEnt.NameEnglish.ToLower())) // { // continue; // } // resultList.Add(coinEnt); //} return(true); }