本文整理汇总了C#中System.Text.UTF8Encoding.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.Replace方法的具体用法?C# UTF8Encoding.Replace怎么用?C# UTF8Encoding.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.Replace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadMessage
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
var msgContents = new byte[buffer.Count];
Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
var message = new UTF8Encoding().GetString(msgContents);
var reader = XmlReader.Create(new MemoryStream(msgContents));
var xmlDocument = new XmlDocument();
xmlDocument.Load(reader);
var elementsByTagName = xmlDocument.GetElementsByTagName("Envelope", Soap11Namespace);
if (elementsByTagName.Count == 0)
throw new XmlException("Не найден узел Envelope");
var prefixOfNamespace = elementsByTagName[0].GetPrefixOfNamespace(Soap11Namespace);
if (string.IsNullOrEmpty(prefixOfNamespace))
throw new XmlException(string.Format("Не найден префикс пространста имен {0}", Soap11Namespace));
LogMessage(xmlDocument, true);
// Убираем actors из входящего сообщения
message = message.Replace(prefixOfNamespace + ":mustUnderstand=\"1\"", "");
message = message.Replace(prefixOfNamespace + ":actor=\"" + SmevActor + "\"", "");
var bytes = new UTF8Encoding().GetBytes(message.Replace(prefixOfNamespace + ":actor=\"" + RecipientActor + "\"", ""));
var length = bytes.Length;
var array = bufferManager.TakeBuffer(length);
Array.Copy(bytes, 0, array, 0, length);
buffer = new ArraySegment<byte>(array, 0, length);
return _innerEncoder.ReadMessage(buffer, bufferManager, contentType);
}
示例2: BuildServiceDescriptions
private void BuildServiceDescriptions(CodeProcessor cs, UPnPDevice device, Hashtable serviceNames)
{
UTF8Encoding U = new UTF8Encoding();
Log(" Service description blocks.");
string http_200_header;
UPnPDevice root = device;
while (root.ParentDevice != null)
{
root = root.ParentDevice;
}
if (!Configuration.HTTP_1dot1)
{
http_200_header = "HTTP/1.0 200 OK\r\nCONTENT-TYPE: text/xml; charset=\"utf-8\"\r\nServer: " + UseSystem + ", UPnP/" + root.ArchitectureVersion + ", MicroStack/" + UseVersion + "\r\n";
}
else
{
http_200_header = "HTTP/1.1 200 OK\r\nCONTENT-TYPE: text/xml; charset=\"utf-8\"\r\nServer: " + UseSystem + ", UPnP/" + root.ArchitectureVersion + ", MicroStack/" + UseVersion + "\r\n";
}
foreach (UPnPService service in device.Services)
{
string servicexml = new UTF8Encoding().GetString(service.GetSCPDXml());
for (int i = 0; i < 40; i++) servicexml = servicexml.Replace("\r\n ", "\r\n");
servicexml = servicexml.Replace("\r\n", "");
string servicehttpresponse = http_200_header + "Content-Length: " + U.GetByteCount(servicexml).ToString() + "\r\n\r\n" + servicexml;
cs.Comment(serviceNames[service].ToString());
byte[] _sr = OpenSource.Utilities.StringCompressor.CompressString(servicehttpresponse);
cs.Append("const int " + pc_methodPrefix + serviceNames[service] + "DescriptionLengthUX = " + U.GetByteCount(servicehttpresponse).ToString() + ";" + cl);
cs.Append("const int " + pc_methodPrefix + serviceNames[service] + "DescriptionLength = " + (_sr.Length).ToString() + ";" + cl);
cs.Append("const char " + pc_methodPrefix + serviceNames[service] + "Description[" + (_sr.Length).ToString() + "] = {" + cl);
bool _first = true;
int _ctr = 0;
foreach (byte b in _sr)
{
if (_first == false)
{
cs.Append(",");
}
else
{
_first = false;
}
string hx = b.ToString("X");
cs.Append("0x");
if (hx.Length == 1) { cs.Append("0"); }
cs.Append(hx);
++_ctr;
if (_ctr % 20 == 0)
{
cs.Append("\r\n");
}
}
cs.Append("};" + cl);
}
foreach (UPnPDevice d in device.EmbeddedDevices)
{
BuildServiceDescriptions(cs, d, serviceNames);
}
}
示例3: OnSucceed
private void OnSucceed(string url, byte[] raw, object userData)
{
switch (mPreStep)
{
case Step.HashmapHash:
{
// 和本地的HashmapHash进行对比
mServerHash = new UTF8Encoding(false).GetString(raw);
string local_hashmaphash = GetLocalHashmapHash();
if (string.Equals(local_hashmaphash, mServerHash))
{
SendLocalMapToAssetManager();
Finish();
}
else
mStep = Step.Hashmap;
}
break;
case Step.Hashmap:
{
mServerFiles = new UTF8Encoding(false).GetString(raw);
string[] array = mServerFiles.Replace("\r\n", "\n").Split('\n');
mUpdateQueue = new Queue<string>(array.Length);// 筛选出待更新的项
mTotalUpdateSize = 0u;
for (int i = 0; i < array.Length; i++)
{
string line = array[i];
if (string.IsNullOrEmpty(line))
continue;
string[] cells = line.Split('|');
if (cells == null || cells.Length == 0)
continue;
string key = cells[0];
AssetCfg item = new AssetCfg(cells, GetLocalItemHash(key));
AssetManager.AddCfg(item);
if (item.needUpdate)
{
mUpdateQueue.Enqueue(key);
mTotalUpdateSize += item.size;
}
}
mUpdateQueue.TrimExcess();
// 选择Patch或更新
if (mUpdateQueue.Count == 0)
{
SendLocalMapToAssetManager();
mStep = Step.Patch;
onProgress(null, 1f);
}
else
{
mStep = Step.Update;
mUpdatedSize = 0u;
onProgress(null, 0f);
}
}
break;
case Step.Update:
{
// 写入到Raw中
string key = userData.ToString();
string rawPath = GetRawPath(key, true);
File.WriteAllBytes(rawPath, raw);
// 检查队列
if (mUpdateQueue.Count > 0)
mStep = Step.Update;
else
mStep = Step.Patch;
// 更新进度
AssetCfg item = AssetManager.GetCfg(key);
mUpdatedSize += item.size;
float percent = (mUpdatedSize * 1.0f / mTotalUpdateSize);
onProgress(key, percent);
}
break;
}
}