public Serialize ( Stream stream, object value ) : void | ||
stream | Stream | |
value | object | |
리턴 | void |
public void Ctor0_Deny_Unrestricted () { LosFormatter lf = new LosFormatter (); MemoryStream ms = new MemoryStream (); lf.Serialize (ms, "mono"); ms.Position = 0; Assert.IsNotNull (lf.Deserialize (ms), "Deserialize(Stream)"); StringWriter sw = new StringWriter (); lf.Serialize (sw, "mono"); string s = sw.ToString (); StringReader sr = new StringReader (s); Assert.IsNotNull (lf.Deserialize (sr), "Deserialize(TextReader)"); Assert.IsNotNull (lf.Deserialize (s), "Deserialize(string)"); }
/// <summary> /// Creates a unique key which describes the current object. This key is used /// by <see cref="SoundInTheory.DynamicImage.Caching.DynamicImageCacheManager" /> /// to cache dynamically generated images. /// </summary> /// <returns>A unique key which describes the current object.</returns> public string GetCacheKey() { object allViewState = SaveViewState(true); LosFormatter formatter = new LosFormatter(); StringWriter output = new StringWriter(); formatter.Serialize(output, allViewState); return output.ToString(); }
protected void SavePageStateToCompressedViewState(object viewState) { LosFormatter formatter = new LosFormatter(); System.IO.StringWriter writer = new System.IO.StringWriter(); formatter.Serialize(writer, viewState); string viewStateString = writer.ToString(); byte[] bytes = Convert.FromBase64String(viewStateString); bytes = IntegrationWebSiteMvc.Classes.Compressor.Compress(bytes); ClientScript.RegisterHiddenField("__VSTATE", Convert.ToBase64String(bytes)); }
private LosFormatter _formatter;// = new LosFormatter(); protected override void SavePageStateToPersistenceMedium(object viewState) { _formatter = new LosFormatter(); StringWriter sw = new StringWriter(); _formatter.Serialize(sw, viewState); ComDePress cmp = new ComDePress(); string outStr = cmp.Compress(sw.ToString()); Page.RegisterHiddenField("__COMPRESSEDVIEWSTATE",outStr); }
[Test] // bug #411115 public void Deserialize_Stream_NonSeekable () { string s1 = "Hello world"; NonSeekableStream ns = new NonSeekableStream (); LosFormatter lf = new LosFormatter (); lf.Serialize (ns, s1); ns.Reset (); string s2 = lf.Deserialize (ns) as string; Assert.AreEqual (s1, s2); }
public override void Save() { IPersistViewState state = Ra.Brix.Data.Internal.Adapter.Instance as IPersistViewState; LosFormatter formatter = new LosFormatter(); StringBuilder builder = new StringBuilder(); using (StringWriter writer = new StringWriter(builder)) { formatter.Serialize(writer, new Pair(ViewState, ControlState)); } state.Save(_session.ToString(), Page.Request.Url.ToString(), builder.ToString()); }
[Test] // bug #324526 public void Serialize () { string s = "Hello world"; LosFormatter lf = new LosFormatter (); StringWriter sw = new StringWriter (); lf.Serialize (sw, s); string s1 = sw.ToString (); Assert.IsNotNull (s1, "#1"); string s2 = lf.Deserialize (s1) as string; Assert.IsNotNull (s2, "#2"); Assert.AreEqual (s, s2, "#3"); }
static internal int EstimateSize(object obj) { if (obj == null) { return(0); } StringWriter sw = new StringWriter(); LosFormatter formatter = new LosFormatter(); formatter.Serialize(sw, obj); return(sw.ToString().Length); }
public override void Save() { LosFormatter formatter = new LosFormatter(); StringBuilder builder = new StringBuilder(); using (StringWriter writer = new StringWriter(builder)) { formatter.Serialize(writer, new Pair(ViewState, ControlState)); } string id = _session.ToString() + "|" + Page.Request.Url.ToString().Replace(" ", "+"); Page.Session[id] = builder.ToString(); }
protected override void SavePageStateToPersistenceMedium(object pageViewState) { MemoryStream ms = new MemoryStream(); LosFormatter m_formatter = new LosFormatter(); m_formatter.Serialize(ms, pageViewState); ms.Position = 0; StreamReader sr = new StreamReader(ms); string viewStateString = sr.ReadToEnd(); byte[] ViewStateBytes = Convert.FromBase64String(viewStateString); ViewStateBytes = ViewStateCompression.Compress(ViewStateBytes); Session["ViewState"] = Convert.ToBase64String(ViewStateBytes); ms.Close(); return; }
protected override void SavePageStateToPersistenceMedium( object viewState ) { LosFormatter format = new LosFormatter(); StringWriter writer = new StringWriter(); format.Serialize( writer, viewState ); string viewStateStr = writer.ToString(); byte[] bytes = System.Convert.FromBase64String( viewStateStr ); bytes = this.Compress( bytes ); string vStateStr = System.Convert.ToBase64String( bytes ); ClientScript.RegisterHiddenField( "__VSTATE", vStateStr ); }
public override void Save() { Pair pair = new Pair(); if (base.ViewState != null) pair.First = base.ViewState; if (base.ControlState != null) pair.Second = base.ControlState; // LosFormatter los = new LosFormatter(); StringWriter writer = new StringWriter(); los.Serialize(writer, pair); StreamWriter sw = File.CreateText(ViewStateFilePath); sw.Write(writer.ToString()); sw.Close(); }
protected override void SavePageStateToPersistenceMedium(object viewState) { this._viewstateStorage = ViewstateStorageFactory.GetStorageMedium(); _config = (ViewStateConfiguration) ConfigurationManager.GetSection("ViewStateConfiguration"); LosFormatter formatter = new LosFormatter(); StringWriter writer = new StringWriter(); formatter.Serialize(writer, viewState); string viewStateString = writer.ToString(); byte[] bytes = Convert.FromBase64String(viewStateString); if (_config.Compression) bytes = bytes.Compress(); string viewstateBase64 = Convert.ToBase64String(bytes); string id = ViewstateStorageFactory.GetUserUniqueID().GetUniqueID(); this._viewstateStorage.Add(new KeyValuePair<object, string>(id, viewstateBase64)); ScriptManager.RegisterHiddenField(this, "__VIEWSTATE_UniqueID", id); }
public void Serialize_Output () { string s = "Hello world"; LosFormatter lf = new LosFormatter (); StringWriter sw = new StringWriter (); lf.Serialize (sw, s); string s1 = sw.ToString (); #if NET_2_0 Assert.AreEqual ("/wEFC0hlbGxvIHdvcmxk", s1, "#1"); #else Assert.AreEqual ("SGVsbG8gd29ybGQ=", s1, "#1"); #endif string s2 = lf.Deserialize (s1) as string; Assert.IsNotNull (s2, "#2"); Assert.AreEqual (s, s2, "#3"); }
protected override void SavePageStateToPersistenceMedium(object state) { string file = GenerateFileName(true); FileStream filestream = new FileStream(file, FileMode.Create); LosFormatter formator = new LosFormatter(); formator.Serialize(filestream, state); filestream.Flush(); filestream.Close(); filestream = null; }
protected override void SavePageStateToPersistenceMedium(object state) { LosFormatter formatter = new LosFormatter(); StringWriter writer = new StringWriter(); formatter.Serialize(writer, state); string viewStateString = writer.ToString(); byte[] bytes = Convert.FromBase64String(viewStateString); this.normalViewState.Text = viewStateString; bytes = bytes.Compress(); this.encryptedViewState.Text = Convert.ToBase64String(bytes); ClientScript.RegisterHiddenField("__VSTATE", Convert.ToBase64String(bytes)); }
public override void Save() { Pair pair = new Pair(); if (base.ViewState != null) { pair.First = base.ViewState; } if (base.ControlState != null) { pair.Second = base.ControlState; } // LosFormatter los = new LosFormatter(); StringWriter writer = new StringWriter(); los.Serialize(writer, pair); // string viewStateString = writer.ToString(); Page.ClientScript.RegisterHiddenField("__AJAXVIEWSTATE", viewStateString); if (((IAjaxPage)Page).PageEngine.IsAjaxPostBack) { ((IAjaxPage)Page).PageEngine.OutMessages.Add(new Message(MessageType.Script, "__AJAXVIEWSTATE", string.Format("document.getElementById('__AJAXVIEWSTATE').value='{0}'", viewStateString))); } }
/// <summary> /// ViewState objektum elmentése /// </summary> /// <param name="viewState">ViewState objektum</param> /// <returns>A mentés kulcsa, amivel majd hivatkozni kell az elmentett ViewState objektumra</returns> public static string Save(object viewState) { // Szöveges formátummá alakítás LosFormatter formatter = new LosFormatter(); StringBuilder stringBuilder = new StringBuilder(); StringWriter stringWriter = new StringWriter(stringBuilder); formatter.Serialize(stringWriter, viewState); string data = stringBuilder.ToString(); // Gyorsítótárba mentés string key = Guid.NewGuid().ToString(); int minutes = (HttpContext.Current.Session != null) ? HttpContext.Current.Session.Timeout : 60*20; DateTime expiration = DateTime.Now.AddMinutes(minutes); HttpContext.Current.Cache.Add(key, data, null, expiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null); // Visszatérés a kulccsal return key; }
protected override void SavePageStateToPersistenceMedium(object pageViewState) { var compressed = true; var viewState = string.Empty; var losformatter = new LosFormatter(); var stringWriter = new StringWriter(); losformatter.Serialize(stringWriter, pageViewState); var viewStateString = stringWriter.ToString(); var bytes = Convert.FromBase64String(viewStateString); var compressedBytes = Compressor.Compress<byte[]>(bytes); if (compressedBytes.Length > bytes.Length) { compressed = false; viewState = Convert.ToInt32(compressed) + Convert.ToBase64String(bytes); } else { viewState = Convert.ToInt32(compressed) + Convert.ToBase64String(compressedBytes); } ClientScript.RegisterHiddenField(_compressedViewState, viewState); }
/// <summary> /// Saves the view state to the Web server file system. /// </summary> protected override void SavePageStateToPersistenceMedium(object state) { // save the view state to disk based on the user's ID and the URL // serialize the view state into a base-64 encoded string StringWriter stringWriter = new StringWriter(); System.Web.UI.LosFormatter los = new System.Web.UI.LosFormatter(); StringWriter sw = new StringWriter(); los.Serialize(sw, state); string vs = sw.ToString(); byte[] bytes = Convert.FromBase64String(vs); // bytes = Compressor.Compress(bytes); System.Web.UI.ScriptManager sm = System.Web.UI.ScriptManager.GetCurrent(this); if (sm != null && sm.IsInAsyncPostBack) { System.Web.UI.ScriptManager.RegisterHiddenField(this, "__VSTATE", vs); } String folderPath = Path.Combine(Request.PhysicalApplicationPath, "PersistedViewState"); // check folder exists if (Directory.Exists(folderPath) == false) { Directory.CreateDirectory(folderPath); } // save the string to disk StreamWriter streamWriter = File.CreateText(ViewStateFilePath); streamWriter.Write(Convert.ToBase64String(bytes)); streamWriter.Close(); sw.Close(); }
/// <summary> /// Updates an existing resource in the Localization table /// </summary> /// <param name="ResourceId"></param> /// <param name="Value"></param> /// <param name="CultureName"></param> /// <param name="ResourceSet"></param> /// <param name="Type"></param> public int UpdateResource(string ResourceId, object Value, string CultureName, string ResourceSet, string Comment, bool ValueIsFileName) { string Type = string.Empty; if (CultureName == null) CultureName = string.Empty; SqlDataAccess Data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString); if (Transaction != null) Data.Transaction = Transaction; if (Value != null && !(Value is string)) { Type = Value.GetType().AssemblyQualifiedName; try { LosFormatter output = new LosFormatter(); StringWriter writer = new StringWriter(); output.Serialize(writer, Value); Value = writer.ToString(); } catch (Exception ex) { ErrorMessage = ex.Message; return -1; } } else { Type = string.Empty; if (Value == null) Value = string.Empty; } byte[] BinFile = null; string TextFile = null; string FileName = string.Empty; if (ValueIsFileName) { FileInfoFormat FileData = null; try { FileData = GetFileInfo(Value as string); } catch (Exception ex) { ErrorMessage = ex.Message; return -1; } Type = "FileResource"; Value = FileData.ValueString; FileName = FileData.FileName; if (FileData.FileFormatType == FileFormatTypes.Text) TextFile = FileData.TextContent; else BinFile = FileData.BinContent; } if (Value == null) Value = string.Empty; // Set up Binfile and TextFile parameters which are set only for // file values - otherwise they'll pass as Null values. DbParameter BinFileParm = Data.CreateParameter("@BinFile", BinFile, DbType.Binary); DbParameter TextFileParm = Data.CreateParameter("@TextFile", TextFile); int Result = 0; string Sql = "update " + DbResourceConfiguration.Current.ResourceTableName + " set Value=@Value, Type=@Type, BinFile=@BinFile,TextFile=@TextFile,FileName=@FileName, Comment=@Comment " + "where LocaleId=@LocaleId AND ResourceSet=@ResourceSet and ResourceId=@ResourceId"; Result = Data.ExecuteNonQuery(Sql, Data.CreateParameter("@ResourceId", ResourceId), Data.CreateParameter("@Value", Value), Data.CreateParameter("@Type", Type), Data.CreateParameter("@LocaleId", CultureName), Data.CreateParameter("@ResourceSet", ResourceSet), BinFileParm, TextFileParm, Data.CreateParameter("@FileName", FileName), Data.CreateParameter("@Comment", Comment) ); if (Result == -1) { ErrorMessage = Data.ErrorMessage; return -1; } return Result; }
/// <summary> /// Adds a resource to the Localization Table /// </summary> /// <param name="resourceId"></param> /// <param name="value"></param> /// <param name="cultureName"></param> /// <param name="resourceSet"></param> /// <param name="Type"></param> /// <param name="Filename"></param> /// <param name="valueIsFileName">if true the Value property is a filename to import</param> public int AddResource(string resourceId, object value, string cultureName, string resourceSet, string comment, bool valueIsFileName) { string Type = string.Empty; if (cultureName == null) cultureName = string.Empty; if (string.IsNullOrEmpty(resourceId)) { ErrorMessage = "No ResourceId specified. Can't add resource"; return -1; } SqlDataAccess Data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString); if (Transaction != null) Data.Transaction = Transaction; if (value != null && !(value is string)) { Type = value.GetType().AssemblyQualifiedName; try { LosFormatter output = new LosFormatter(); StringWriter writer = new StringWriter(); output.Serialize(writer, value); value = writer.ToString(); } catch (Exception ex) { ErrorMessage = ex.Message; return -1; } } else Type = string.Empty; byte[] BinFile = null; string TextFile = null; string FileName = string.Empty; if (valueIsFileName) { FileInfoFormat FileData = null; try { FileData = GetFileInfo(value as string); } catch (Exception ex) { ErrorMessage = ex.Message; return -1; } Type = "FileResource"; value = FileData.ValueString; FileName = FileData.FileName; if (FileData.FileFormatType == FileFormatTypes.Text) TextFile = FileData.TextContent; else BinFile = FileData.BinContent; } if (value == null) value = string.Empty; DbParameter BinFileParm = Data.CreateParameter("@BinFile", BinFile, DbType.Binary); DbParameter TextFileParm = Data.CreateParameter("@TextFile", TextFile); string Sql = "insert into " + DbResourceConfiguration.Current.ResourceTableName + " (ResourceId,Value,LocaleId,Type,Resourceset,BinFile,TextFile,Filename,Comment) Values (@ResourceID,@Value,@LocaleId,@Type,@ResourceSet,@BinFile,@TextFile,@FileName,@Comment)"; if (Data.ExecuteNonQuery(Sql, Data.CreateParameter("@ResourceId", resourceId), Data.CreateParameter("@Value", value), Data.CreateParameter("@LocaleId", cultureName), Data.CreateParameter("@Type", Type), Data.CreateParameter("@ResourceSet", resourceSet), BinFileParm, TextFileParm, Data.CreateParameter("@FileName", FileName), Data.CreateParameter("@Comment", comment)) == -1) { ErrorMessage = Data.ErrorMessage; return -1; } return 1; }
/// <summary> /// 生成Gzipped的ViewState /// </summary> /// <param name="viewState"></param> /// <returns></returns> public static string GenerateGzippedViewState(object viewState) { LosFormatter formatter = new LosFormatter(); using (StringWriter writer = new StringWriter()) { formatter.Serialize(writer, viewState); return StringUtil.Gzip(writer.ToString()); } }
/// <summary> /// saves the compressed viewstate /// </summary> /// <param name="viewState">The viewstate object to compress</param> protected override void SavePageStateToPersistenceMedium(object viewState) { LosFormatter format = new LosFormatter(); StringWriter sw = new StringWriter(); format.Serialize(sw, viewState); string vss = sw.ToString(); if (vss.Length > 512) { byte[] bytes = Convert.FromBase64String(vss); MemoryStream ms = new MemoryStream(); GZipStream gzip = new GZipStream(ms, CompressionMode.Compress, true); gzip.Write(bytes, 0, bytes.Length); gzip.Close(); bytes = ms.ToArray(); string vsc = Convert.ToBase64String(bytes); if (vsc.Length < vss.Length) ScriptManager.RegisterHiddenField(Page, "__VSTATE", "C$" + vsc); else ScriptManager.RegisterHiddenField(Page, "__VSTATE", vss); } else ScriptManager.RegisterHiddenField(Page, "__VSTATE", vss); }
public void Serialize_Stream () { string s = "Hello world"; LosFormatter lf = new LosFormatter (); MemoryStream ms = new MemoryStream (); lf.Serialize (ms, s); string s1 = Encoding.UTF8.GetString (ms.GetBuffer (), 0, (int) ms.Length); #if NET_2_0 Assert.AreEqual ("/wEFC0hlbGxvIHdvcmxk", s1, "#1"); #else Assert.AreEqual ("SGVsbG8gd29ybGQ=", s1, "#1"); #endif string s2 = lf.Deserialize (s1) as string; Assert.IsNotNull (s2, "#2"); Assert.AreEqual (s, s2, "#3"); }
private void SetWizardState(WorkspaceWizardSetting value) { if (value == null) throw new ArgumentNullException("value"); var formatter = new LosFormatter(); var writer = new StringWriter(); formatter.Serialize(writer, value); var input = CurrentUserControl.FindControl("_settings") as HtmlInputHidden; if (input == null) return; input.Value = writer.ToString(); }
protected override String getViewStateBase64FromXMLTree(String viewStateXML) { LosFormatter formatter = new LosFormatter(); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); XmlDocument dom = new XmlDocument(); StringReader reader = new StringReader(viewStateXML); dom.Load(reader); XmlElement xmlElement = (XmlElement) dom.DocumentElement.GetElementsByTagName("ViewStateDeserialized").Item(0); object viewStateObjectTree = null; if (xmlElement.Name == "ViewStateDeserialized") { viewStateObjectTree = buildObjectElement((XmlElement)xmlElement.ChildNodes.Item(0)); } formatter.Serialize(writer, viewStateObjectTree); return sb.ToString(); }
private string Serialize(object val) { LosFormatter lf = new LosFormatter(); TextWriter tw = new StringWriter(); lf.Serialize(tw, val); return tw.ToString(); }
/// <summary> /// /// </summary> /// <param name="state"></param> protected override void SavePageStateToPersistenceMedium(object state) { try { LosFormatter los = new LosFormatter(); System.IO.StringWriter sw = new System.IO.StringWriter(); this.Session[("\'" + (Session.SessionID + "\'"))] = String.Empty; los.Serialize(sw, state); this.Session[("\'" + (Session.SessionID + "\'"))] = sw.ToString(); sw.Close(); } catch (Exception ex) { throw ex; } }
private string LosSerializeObject(object obj) { LosFormatter output = new LosFormatter(); StringWriter writer = new StringWriter(); output.Serialize(writer, obj); return writer.ToString(); }
[Category ("NotDotNet")] // MS throws NullReferenceException public void Serialize_Output_Null () { LosFormatter lf = new LosFormatter (); try { lf.Serialize ((TextWriter) null, "test"); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsNotNull (ex.ParamName, "#5"); Assert.AreEqual ("output", ex.ParamName, "#6"); } }
public void Serialize_Value_Null () { LosFormatter lf = new LosFormatter (); MemoryStream ms = new MemoryStream (); lf.Serialize (ms, null); string s1 = Encoding.UTF8.GetString (ms.GetBuffer (), 0, (int) ms.Length); #if NET_2_0 Assert.AreEqual ("/wFk", s1, "#1"); #else Assert.AreEqual (string.Empty, s1, "#1"); #endif StringWriter sw = new StringWriter (); lf.Serialize (sw, null); string s2 = sw.ToString (); #if NET_2_0 Assert.AreEqual ("/wFk", s1, "#2"); #else Assert.AreEqual (string.Empty, s1, "#2"); #endif }