本文整理汇总了C#中System.Text.UTF8Encoding.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.Substring方法的具体用法?C# UTF8Encoding.Substring怎么用?C# UTF8Encoding.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.Substring方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: txtProcessDemo_Click
private void txtProcessDemo_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
StringBuilder sbResultsForStorage = new StringBuilder();
AzureQueueStorage aqs = new AzureQueueStorage(txtAccount.Text, string.Format("http://{0}.queue.core.windows.net", txtAccount.Text), txtSharedKey.Text, "SharedKey");
azureResults ar = aqs.Messages(cmdType.get, bulkTag, "", "visibilitytimeout=7200", "");
string MessageID = "";
string PopReceipt = "";
string Message = "";
if (ar.Body != null)
{
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
if (ar.Succeeded)
{
xdoc.LoadXml(ar.Body);
System.Xml.XmlNodeList nodes = xdoc.SelectNodes("//QueueMessage");
StringBuilder sbMultipart = new StringBuilder();
if (nodes.Count == 0)
txtMessage.Text = "No message to process";
else
foreach (System.Xml.XmlNode node in nodes)
{
MessageID = node.SelectSingleNode("MessageId").InnerText;
PopReceipt = node.SelectSingleNode("PopReceipt").InnerText;
Message = node.SelectSingleNode("MessageText").InnerText;
System.Xml.XmlDocument msgDoc = new XmlDocument();
msgDoc.LoadXml(Message);
string newAccount = msgDoc.SelectSingleNode("//account[1]").InnerXml;
string newKey = msgDoc.SelectSingleNode("//key[1]").InnerXml;
string newSource = msgDoc.SelectSingleNode("//source[1]").InnerXml;
string updateID = msgDoc.SelectSingleNode("//updateID[1]").InnerXml;
string newTable = msgDoc.SelectSingleNode("//table[1]").InnerXml;
AzureTableStorage ats = new AzureTableStorage(txtAccount.Text, "", txtSharedKey.Text, "SharedKey");
AzureTableStorage ats1 = new AzureTableStorage(txtAccount.Text, "", txtSharedKey.Text, "SharedKey");
azureHelper ah = new azureHelper(txtAccount.Text, txtEndpoint.Text, txtSharedKey.Text, "SharedKey");
string mrgMessage = string.Format(queueUpdateCreationEntity, updateID, 0, 0);
ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, "");
ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", string.Format("<m:properties>\n\t<d:PartitionKey>{0}</d:PartitionKey>\n\t<d:RowKey>000000000000000</d:RowKey><d:StartedProcessing>{1}</d:StartedProcessing></m:properties>", updateID, DateTime.UtcNow.ToLongTimeString()), "");
AzureBlobStorage abs = new AzureBlobStorage(newAccount, string.Format("http://{0}.blob.core.windows.net", newAccount), newKey, "SharedKey");
AzureTableStorage atsNew = new AzureTableStorage(newAccount, string.Format("http://{0}.blob.core.windows.net", newAccount), newKey, "SharedKey");
ar = atsNew.Tables(cmdType.post, newTable);
if (ar.Succeeded || ar.StatusCode == System.Net.HttpStatusCode.Conflict)
{
ar = new azureResults();
string newContainer = newSource.Replace(string.Format("http://{0}.blob.core.windows.net/", newAccount), "");
newContainer = newContainer.Substring(0, newContainer.IndexOf("/"));
string newBlob = newSource.Replace(string.Format("http://{0}.blob.core.windows.net/", newAccount), "").Replace(newContainer, "");
byte[] blob = abs.GetBlob(newContainer, newBlob, "", ref ar);
string x = new System.Text.UTF8Encoding().GetString(blob);
x = x.Substring(x.IndexOf("<"));
msgDoc.LoadXml(x);
int errorCt = 0;
int processedCt = 0;
//Instantiate an XmlNamespaceManager object.
System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(xdoc.NameTable);
//Add the namespaces used in books.xml to the XmlNamespaceManager.
xmlnsManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
xmlnsManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
XmlNodeList pnodes = msgDoc.SelectNodes("//m:properties", xmlnsManager);
int iCounter = 101;
int iResponse = 1;
foreach (XmlNode pnode in pnodes)
{
if (iCounter > 100)
{
if (sbMultipart.Length > 0)
{
sbMultipart.Append("</entry>");
ProcessMultiPartForStatus(ats.auth, ah.entityGroupTransaction(cmdType.post, newTable, sbMultipart.ToString()), bulkTag, updateID, iResponse.ToString("D15"), ref processedCt, ref errorCt, "201 Created");
ar = ats1.Entities(cmdType.post, bulkTag, updateID, iResponse.ToString("D15"), sbResultsForStorage.ToString(), "");
mrgMessage = string.Format(queueUpdateCreationEntity, updateID, processedCt, errorCt);
ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, "", "*");
iResponse++;
}
sbMultipart = new StringBuilder();
sbMultipart.AppendFormat(@"<?xml version=""1.0"" encoding=""utf-8"" ?><entry xml:base=""http://finseldemos.table.core.windows.net/"" xmlns:d=""http://schemas.microsoft.com/ado/2007/08/dataservices"" xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" xmlns=""http://www.w3.org/2005/Atom"">");
iCounter = 0;
}
sbMultipart.Append(pnode.OuterXml);
iCounter++;
}
sbMultipart.Append("</entry>");
ProcessMultiPartForStatus(ats.auth, ah.entityGroupTransaction(cmdType.post, newTable, sbMultipart.ToString()), bulkTag, updateID, iResponse.ToString("D15"), ref processedCt, ref errorCt, "201 Created");
mrgMessage = string.Format(queueUpdateCreationEntity, updateID, processedCt, errorCt).Replace("Processing", "Completed");
ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, "", "*");
}
else
{
mrgMessage = string.Format(queueUpdateCreationEntity, updateID, 0, 0).Replace("Processing", "Failed to create table!");
ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, "");
//.........这里部分代码省略.........
示例2: FromEncryptionAtRest
/// <summary>
/// Decrypt string data with a supported cipher, authenticate the cipher using a supported digest type, deviate the cipher password with a supported divination type, and, finally pad a cipher using a supported padding type.
/// </summary>
/// <param name="data">String data.</param>
/// <param name="password">Cipher password. Will be deviated using the supplied divination type.</param>
/// <param name="salt">Cipher salt to be used, should be proper format for the cipher type. (Note: Normally 8, or, 14 bytes)</param>
/// <param name="secondaryVerifier">Secondary data you wish to use to validate the cipher. This is a secondary validation check. The cipher binary is already validated. (Note: This will increase the size of the cipher)</param>
/// <returns>Byte data</returns>
public static string FromEncryptionAtRest(this string data, string password, byte[] salt, string secondaryVerifier = null)
{
var iv = new UTF8Encoding().GetBytes(data.Substring(0, 16));
var key = password.ToHash(salt);
var suspectedInputVerifier = data.Substring(data.Length - 32, data.Length);
var input = new UTF8Encoding().GetBytes(data.Substring(16, data.Length - 32));
var expectedInputVerifier = input.ToHmac(key.Data, salt);
if (!suspectedInputVerifier.Equals(expectedInputVerifier.Data))
{
return string.Empty;
}
var cipher = CipherUtilities.GetCipher("AES/CBC/PKCS7");
cipher.Init(false, new ParametersWithIV(new KeyParameter(key.Data), iv));
var outputData = cipher.DoFinal(input);
cipher.Reset();
var output = new UTF8Encoding().GetString(outputData);
if (!string.IsNullOrEmpty(secondaryVerifier))
{
var expectedVerifier = secondaryVerifier.ToHmac(key.Data, salt).Data.ToHex();
var suspectedVerifier = output.Substring(output.Length - 64, 64);
if (!expectedVerifier.SequenceEqual(suspectedVerifier))
{
return string.Empty;
}
output = output.Substring(0, output.Length - 64);
}
return output;
}
示例3: SerializeToXmlElement
protected override bool SerializeToXmlElement(XmlWriter writer, String elementName)
{
bool writeMe = base.SerializeToXmlElement(writer, elementName);
bool writeComment = this.OptionalIssuedTokenParameters.Count > 0;
if (writeComment && writer != null)
{
MemoryStream memoryStream = new MemoryStream();
using (XmlTextWriter commentWriter = new XmlTextWriter(memoryStream, Encoding.UTF8))
{
commentWriter.Formatting = Formatting.Indented;
commentWriter.WriteStartElement(ConfigurationStrings.AlternativeIssuedTokenParameters);
foreach (IssuedTokenParametersElement element in this.OptionalIssuedTokenParameters)
{
element.SerializeToXmlElement(commentWriter, ConfigurationStrings.IssuedTokenParameters);
}
commentWriter.WriteEndElement();
commentWriter.Flush();
string commentString = new UTF8Encoding().GetString(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
writer.WriteComment(commentString.Substring(1, commentString.Length - 1));
commentWriter.Close();
}
}
return writeMe || writeComment;
}
示例4: SerializeToXmlElement
protected override bool SerializeToXmlElement(XmlWriter writer, string elementName)
{
bool flag = base.SerializeToXmlElement(writer, elementName);
bool flag2 = this.OptionalIssuedTokenParameters.Count > 0;
if (flag2 && (writer != null))
{
MemoryStream w = new MemoryStream();
using (XmlTextWriter writer2 = new XmlTextWriter(w, Encoding.UTF8))
{
writer2.Formatting = Formatting.Indented;
writer2.WriteStartElement("alternativeIssuedTokenParameters");
foreach (IssuedTokenParametersElement element in this.OptionalIssuedTokenParameters)
{
element.SerializeToXmlElement(writer2, "issuedTokenParameters");
}
writer2.WriteEndElement();
writer2.Flush();
string str = new UTF8Encoding().GetString(w.GetBuffer(), 0, (int) w.Length);
writer.WriteComment(str.Substring(1, str.Length - 1));
writer2.Close();
}
}
if (!flag)
{
return flag2;
}
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:IssuedTokenParametersElement.cs