本文整理汇总了C#中System.Web.SessionState.SessionStateItemCollection.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# SessionStateItemCollection.Serialize方法的具体用法?C# SessionStateItemCollection.Serialize怎么用?C# SessionStateItemCollection.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.SessionState.SessionStateItemCollection
的用法示例。
在下文中一共展示了SessionStateItemCollection.Serialize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
private byte[] Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
if (items != null)
{
items.Serialize(writer);
}
writer.Close();
return ms.ToArray();
}
示例2: SerializeSessionState
/// <summary>
/// Session 정보를 직렬화합니다. (일반적인 직렬화 방식은 안되고, SessionStateItemCollection 자체의 Serialize를 사용해서 직렬화합니다.)
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
public static byte[] SerializeSessionState(SessionStateItemCollection items) {
if(IsDebugEnabled)
log.Debug("세션 정보를 직렬화를 수행합니다...");
if(items == null)
return new byte[0];
using(var ms = new MemoryStream())
using(var writer = new BinaryWriter(ms)) {
items.Serialize(writer);
writer.Close();
return ms.ToArray();
}
}
示例3: save
public void save()
{
Data.sName = "aa";
Data.dBaseRadius = 2;
Data.dNoseRadius = .5;
String x = "";
foreach (string key in HttpContext.Current.Session.Keys)
{
x += key + " - " + HttpContext.Current.Session[key] + ";";
}
//SessionStateItemCollection items = HttpContext.Current.Session.
SessionStateItemCollection items = new SessionStateItemCollection();
items["Name"] = "NN";
items["Desc"] = "DD";
try
{
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(
System.IO.File.Open(HttpContext.Current.Server.MapPath("./session_collection.bin"), System.IO.FileMode.Create));
items.Serialize(writer);
writer.Close();
items["Name"] = "";
items["Desc"] = "";
System.IO.BinaryReader reader = new System.IO.BinaryReader(
System.IO.File.Open(HttpContext.Current.Server.MapPath("./session_collection.bin"), System.IO.FileMode.Open));
items = SessionStateItemCollection.Deserialize(reader);
String x2 = items["Name"].ToString();
String y2 = items["Desc"].ToString();
}
catch (Exception e)
{
String err = e.StackTrace;
}
}
示例4: serialize
private string serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
if (items != null)
items.Serialize(writer);
writer.Close();
return Convert.ToBase64String(ms.ToArray());
}
示例5: serialize
private string[] serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
if (items != null)
items.Serialize(writer);
writer.Close();
byte[] raw = ms.ToArray();
ms.Close();
List<string> parts = new List<string>();
byte[] segment;
int scount = (raw.Length / SHARD_SIZE);
int tcount = raw.Length - (scount * SHARD_SIZE);
for (int pos = 0; pos < scount; pos++)
{
segment = new byte[SHARD_SIZE];
int startIndex = pos * SHARD_SIZE;
Buffer.BlockCopy(raw, pos * SHARD_SIZE, segment, 0, SHARD_SIZE);
parts.Add(Convert.ToBase64String(segment));
}
segment = new byte[tcount];
Buffer.BlockCopy(raw, scount * SHARD_SIZE, segment, 0, tcount);
parts.Add(Convert.ToBase64String(segment));
return parts.ToArray();
}
示例6: Serialize
private string Serialize(SessionStateItemCollection items)
{
using (var stream = new MemoryStream())
{
using (var writer = new BinaryWriter(stream))
{
if (items != null)
items.Serialize(writer);
writer.Flush();
writer.Close();
return Convert.ToBase64String(stream.ToArray());
}
}
}
开发者ID:sumothecat,项目名称:RavenDbSessionStateStoreProvider,代码行数:16,代码来源:RavenSessionStateStoreProvider.cs
示例7: Serialize
/// <summary>
/// Serialize
/// (SessionStateItemCollection → Base64)
/// </summary>
/// <param name="items">アイテム</param>
/// <returns>Base64</returns>
private string Serialize(SessionStateItemCollection items)
{
using (MemoryStream ms = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
if (items != null)
items.Serialize(writer);
}
return Convert.ToBase64String(ms.ToArray());
}
}
示例8: Serialize
/// <summary>
/// Convert a SessionStateItemCollection into a Base64 string
/// </summary>
private static string Serialize(SessionStateItemCollection items)
{
if (items == null || items.Count < 1)
return string.Empty;
using (MemoryStream mStream = new MemoryStream())
{
using (BinaryWriter bWriter = new BinaryWriter(mStream))
{
items.Serialize(bWriter);
bWriter.Close();
}
return Convert.ToBase64String(mStream.ToArray());
}
}
示例9: Serialize
//
// Serialize is called by the SetAndReleaseItemExclusive method to
// convert the SessionStateItemCollection into a Binary.
//
private byte[] Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
try
{
if (items != null)
items.Serialize(writer);
}
catch (Exception e)
{
if (WriteExceptionsToEventLog)
{
WriteToEventLog(e, "GetSessionStoreItem");
throw new ProviderException(e.Message, e.InnerException);
}
else
throw e;
}
finally
{
writer.Close();
}
return ms.ToArray();
}
示例10: Serialize
private byte[] Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
try
{
if (items != null)
items.Serialize(writer);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
writer.Close();
}
return ms.ToArray();
}
示例11: Serialize
private static byte[] Serialize(SessionStateItemCollection items)
{
using (var ms = new MemoryStream())
{
using (var writer = new BinaryWriter(ms))
{
if (items != null)
items.Serialize(writer);
writer.Close();
return ms.ToArray();
}
}
}
示例12: Serialize
private string Serialize(SessionStateItemCollection items)
{
using (MemoryStream ms = new MemoryStream()) {
using (BinaryWriter writer = new BinaryWriter(ms)) {
if (items != null) {
items.Serialize(writer);
}
}
var encryptedData = MachineKey.Protect(ms.ToArray(), "Session Data");
return Convert.ToBase64String(encryptedData);
}
}
示例13: Serialize
public void Serialize(SessionStateItemCollection items)
{
var ms = new MemoryStream();
var writer = new BinaryWriter(ms);
if (items != null)
items.Serialize(writer);
writer.Close();
_serializedSessionData = ms.ToArray();
}
示例14: Serialize
private string Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
List<string> itemsABorrar = new List<string>();
foreach (string item in items.Keys)
{
if (!(items[item].GetType().IsSerializable))
itemsABorrar.Add(item);
}
foreach(string item in itemsABorrar)
items.Remove(item);
if (items != null)
{
items.Serialize(writer);
}
writer.Close();
return Convert.ToBase64String(ms.ToArray());
}