本文整理汇总了C#中SortedList.AddSafe方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.AddSafe方法的具体用法?C# SortedList.AddSafe怎么用?C# SortedList.AddSafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.AddSafe方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParsePostBody
//.........这里部分代码省略.........
fileStream.Close();
fileStream.Dispose();
inMemoryFileUploadsTotal -= biggestUpload.Data.LongLength;
biggestUpload.Data = null;
if (inMemoryFileUploads[lastKey].Count == 0)
inMemoryFileUploads.Remove(lastKey);
}
else
{
// ... switch this one to a temporary file
currentFileUploadTempFilename = HttpInternalObjects.RandomTempFilepath(tempPath, out currentWritingStream);
memory.WriteTo(currentWritingStream);
memory.Close();
memory.Dispose();
}
}
currentWritingStream.Write(buffer, bufferIndex, howMuchToWrite);
}
// If we encountered the boundary, add this field to _postFields or this upload to _fileUploads or inMemoryFileUploads
if (boundaryFound)
{
if (currentWritingStream != null)
{
currentWritingStream.Close();
if (!currentIsFileUpload)
// It's a normal field
_postFields[currentFieldName].Add(Encoding.UTF8.GetString(((MemoryStream) currentWritingStream).ToArray()));
else
{
// It's a file upload
var fileUpload = new FileUpload(currentFileUploadContentType, currentFileUploadFilename);
if (currentFileUploadTempFilename != null)
// The file upload has already been written to disk
fileUpload.LocalFilename = currentFileUploadTempFilename;
else
{
// The file upload is still in memory. Keep track of it in inMemoryFileUploads so that we can still write it to disk later if necessary
var memory = (MemoryStream) currentWritingStream;
fileUpload.Data = memory.ToArray();
inMemoryFileUploads.AddSafe(fileUpload.Data.LongLength, fileUpload);
inMemoryFileUploadsTotal += fileUpload.Data.LongLength;
}
_fileUploads[currentFieldName] = fileUpload;
}
currentWritingStream.Dispose();
currentWritingStream = null;
}
// If that was the final boundary, we are done
if (end)
break;
// Consume the boundary and go back to processing headers
bytesRead -= boundaryIndex - bufferIndex + middleBoundary.Length;
bufferIndex = boundaryIndex + middleBoundary.Length;
processingHeaders = true;
currentHeaders = "";
utf8Decoder.Reset();
continue;
}
else
{
// No boundary there. Received data has been written to the currentWritingStream above.
// Now copy the remaining little bit (which may contain part of the bounary) into a new buffer
switchBuffer(bufferIndex + howMuchToWrite, bytesRead - howMuchToWrite);
bytesRead -= howMuchToWrite;
writeIndex = bytesRead;
}
}
else if (bufferIndex > 0)
{
// We are processing content, but there is not enough data in the buffer to ensure that it doesn't contain part of the boundary.
// Therefore, just copy the data to a new buffer and continue receiving more
switchBuffer(bufferIndex, bytesRead);
writeIndex = bytesRead;
}
}
bufferIndex = 0;
// We need to read enough data to contain the boundary
do
{
bytesRead = body.Read(buffer, writeIndex, bufferSize - writeIndex);
if (bytesRead == 0) // premature end of content
{
if (currentWritingStream != null)
{
currentWritingStream.Close();
currentWritingStream.Dispose();
}
return;
}
writeIndex += bytesRead;
}
while (writeIndex < lastBoundary.Length);
bytesRead = writeIndex;
}
}