protected object LoadPageStateFromCompressedViewState() { string viewState = Request.Form["__VSTATE"]; byte[] bytes = Convert.FromBase64String(viewState); bytes = IntegrationWebSiteMvc.Classes.Compressor.Decompress(bytes); LosFormatter formatter = new LosFormatter(); return formatter.Deserialize(Convert.ToBase64String(bytes)); }
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)"); }
public override void Load() { IPersistViewState state = Ra.Brix.Data.Internal.Adapter.Instance as IPersistViewState; LosFormatter formatter = new LosFormatter(); Pair pair = formatter.Deserialize(state.Load(_session.ToString(), Page.Request.Url.ToString())) as Pair; ViewState = pair.First; ControlState = pair.Second; }
public override void Load() { string viewStateString = Page.Request["__AJAXVIEWSTATE"]; viewStateString = viewStateString.Replace(",", "").Replace(" ", ""); LosFormatter los = new LosFormatter(); Pair pair = (Pair)los.Deserialize(viewStateString); base.ViewState = pair.First; base.ControlState = pair.Second; }
[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); }
protected override object LoadPageStateFromPersistenceMedium() { _formatter = new LosFormatter(); object o; string vsString = Request.Form["__COMPRESSEDVIEWSTATE"]; string outStr = new ComDePress().DeCompress(vsString); o = _formatter.Deserialize(outStr); return o; }
protected override object LoadPageStateFromPersistenceMedium() { string vState = this.Request.Form["__VSTATE"]; byte[] bytes = System.Convert.FromBase64String( vState ); bytes = this.Decompress( bytes ); LosFormatter format = new LosFormatter(); return format.Deserialize( System.Convert.ToBase64String( bytes ) ); }
protected override object LoadPageStateFromPersistenceMedium() { string viewState = Request.Form["__VSTATE"]; byte[] bytes = Convert.FromBase64String(viewState); LosFormatter formatter = new LosFormatter(); bytes = bytes.Decompress(); return formatter.Deserialize(Convert.ToBase64String(bytes)); }
[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"); }
public override void Load() { string id = _session.ToString() + "|" + Page.Request.Url.ToString(); LosFormatter formatter = new LosFormatter(); if (Page.Session[id] == null) throw new ArgumentException("session timeout ..."); string obj = Page.Session[id] as string; Pair pair = formatter.Deserialize(obj) as Pair; ViewState = pair.First; ControlState = pair.Second; }
protected override object LoadPageStateFromPersistenceMedium() { object retVal; string id = Request.Form["__VIEWSTATE_UniqueID"]; byte[] bytes = null; _config = (ViewStateConfiguration) ConfigurationManager.GetSection("ViewStateConfiguration"); this._viewstateStorage = ViewstateStorageFactory.GetStorageMedium(); bytes = Convert.FromBase64String(this._viewstateStorage.Get(id).Value); if (_config.Compression) bytes = bytes.Decompress(); LosFormatter formatter = new LosFormatter(); retVal = formatter.Deserialize(Convert.ToBase64String(bytes)); return retVal; }
protected override object LoadPageStateFromPersistenceMedium() { object state = null; StreamReader reader = new StreamReader(GenerateFileName()); LosFormatter formator = new LosFormatter(); state = formator.Deserialize(reader); reader.Close(); return state; }
// De-serialize view state protected override object LoadPageStateFromPersistenceMedium() { var isCompressed = true; var compressedViewState = Request.Form[_compressedViewState]; isCompressed = Convert.ToBoolean(Convert.ToInt32(compressedViewState.Substring(0, 1))); compressedViewState = compressedViewState.Remove(0, 1); var bytes = Convert.FromBase64String(compressedViewState); if(isCompressed) bytes = Compressor.Decompress<byte[]>(bytes); var losformatter = new LosFormatter(); return losformatter.Deserialize(Convert.ToBase64String(bytes)); }
/// <summary> /// Loads any saved view-state information to the <see cref="T:System.Web.UI.Page"></see> object. /// </summary> /// <returns>The saved view state.</returns> protected override object LoadPageStateFromPersistenceMedium() { String viewState = Request.Params[ViewStateKey]; if (viewState == null) { return null; } else { LosFormatter formatter = new LosFormatter(); return formatter.Deserialize(viewState); } }
// Create a logger for use in this class /* * private static readonly log4net.ILog log * = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); */ protected virtual void Deserialize(Stream s) { // Deserialize the storageConfig System.Web.UI.LosFormatter scFormatter = new System.Web.UI.LosFormatter(); Hashtable ht = (Hashtable)scFormatter.Deserialize(s); // Convert to a NameValueCollection. We only use Hashtable for serialization because // LosFormatter can serialize it efficiently. if (ht != null) { foreach (string key in ht.Keys) { this[key] = (string)ht[key]; } } }
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"); }
// Create a logger for use in this class /* private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); */ protected virtual void Deserialize(Stream s) { // Deserialize the storageConfig System.Web.UI.LosFormatter scFormatter = new System.Web.UI.LosFormatter(); Hashtable ht = (Hashtable)scFormatter.Deserialize(s); // Convert to a NameValueCollection. We only use Hashtable for serialization because // LosFormatter can serialize it efficiently. if (ht != null) { foreach (string key in ht.Keys) { this[key] = (string)ht[key]; } } }
// 序列化ViewState protected override object LoadPageStateFromPersistenceMedium() { object viewStateBag; string m_viewState = (string)Session["ViewState"]; byte[] ViewStateBytes = Convert.FromBase64String(m_viewState); ViewStateBytes = ViewStateCompression.Decompress(ViewStateBytes); LosFormatter m_formatter = new LosFormatter(); try { viewStateBag = m_formatter.Deserialize(Convert.ToBase64String(ViewStateBytes)); } catch (Exception ex) { //Log.Insert( "页面Viewtate是空。" ); viewStateBag = string.Empty; } return viewStateBag; }
public override void Load() { if (!File.Exists(ViewStateFilePath)) { base.ViewState = null; base.ControlState = null; } else { StreamReader sr = File.OpenText(ViewStateFilePath); string viewStateString = sr.ReadToEnd(); sr.Close(); LosFormatter los = new LosFormatter(); Pair pair = (Pair)los.Deserialize(viewStateString); base.ViewState = pair.First; base.ControlState = pair.Second; } }
/// <summary> /// ViewState objektum kiolvasása /// </summary> /// <param name="key">A mentés kulcsa</param> /// <returns>ViewState objektum</returns> public static object Load(string key) { // Kiolvasás a gyorsítótárból object data = HttpContext.Current.Cache.Get(key); if (data != null) { // Objektummá alakítás LosFormatter formatter = new LosFormatter(); object viewState = formatter.Deserialize((string) data); // Visszatérés a ViewState objektummal return viewState; } else { return null; } }
protected override object LoadPageStateFromPersistenceMedium() { var viewState = Request.Form["__COMPRESSEDVIEWSTATE"]; if (string.IsNullOrEmpty(viewState)) { return null; } try { byte[] bytes = Convert.FromBase64String(viewState); bytes = ViewStateCompressor.Decompress(bytes); var formatter = new LosFormatter(); return formatter.Deserialize(Convert.ToBase64String(bytes)); } catch (Exception) { return null; } }
protected override String getViewStateXMLFromBase64(String viewStateBase64) { LosFormatter formatter = new LosFormatter(); XmlDocument dom = new XmlDocument(); XmlElement element = null; dom.AppendChild(dom.CreateElement("ViewState")); element = dom.CreateElement("Version"); element.InnerText = m_version.ToString(); dom.DocumentElement.AppendChild(element); element = dom.CreateElement("VersionString"); element.InnerText = m_versionString; dom.DocumentElement.AppendChild(element); element = dom.CreateElement("MAC"); element.InnerText = m_MAC; dom.DocumentElement.AppendChild(element); element = dom.CreateElement("ViewStateDeserialized"); dom.DocumentElement.AppendChild(element); buildXMLElement(dom, (XmlElement) element, formatter.Deserialize(this.viewStateBase64)); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); dom.Save(writer); return sb.ToString(); }
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"); }
/// <summary> /// Returns a specific set of resources for a given culture and 'resource set' which /// in this case is just the virtual directory and culture. /// </summary> /// <param name="cultureName"></param> /// <param name="resourceSet"></param> /// <returns></returns> public IDictionary GetResourceSet(string cultureName, string resourceSet) { if (cultureName == null) cultureName = string.Empty; string resourceFilter; resourceFilter = " ResourceSet=@ResourceSet"; var resources = new Dictionary<string, object>(); using (var data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString)) { DbDataReader reader; if (string.IsNullOrEmpty(cultureName)) reader = data.ExecuteReader("select ResourceId,Value,Type,BinFile,TextFile,FileName from " + DbResourceConfiguration.Current.ResourceTableName + " where " + resourceFilter + " and (LocaleId is null OR LocaleId = '') order by ResourceId", data.CreateParameter("@ResourceSet", resourceSet)); else reader = data.ExecuteReader("select ResourceId,Value,Type,BinFile,TextFile,FileName from " + DbResourceConfiguration.Current.ResourceTableName + " where " + resourceFilter + " and LocaleId=@LocaleId order by ResourceId", data.CreateParameter("@ResourceSet", resourceSet), data.CreateParameter("@LocaleId", cultureName)); if (reader == null) { SetError(data.ErrorMessage); return resources; } try { while (reader.Read()) { object resourceValue = reader["Value"] as string; string resourceType = reader["Type"] as string; if (!string.IsNullOrWhiteSpace(resourceType)) { try { // FileResource is a special type that is raw file data stored // in the BinFile or TextFile data. Value contains // filename and type data which is used to create: String, Bitmap or Byte[] if (resourceType == "FileResource") resourceValue = LoadFileResource(reader); else { LosFormatter formatter = new LosFormatter(); resourceValue = formatter.Deserialize(resourceValue as string); } } catch { // ignore this error resourceValue = null; } } else { if (resourceValue == null) resourceValue = string.Empty; } resources.Add(reader["ResourceId"].ToString(), resourceValue); } } catch (Exception ex) { SetError(ex.GetBaseException().Message); return resources; } finally { // close reader and connection reader.Close(); } } return resources; }
/// <summary> /// Returns an object from the Resources. Use this for any non-string /// types. While this method can be used with strings GetREsourceString /// is much more efficient. /// </summary> /// <param name="resourceId"></param> /// <param name="resourceSet"></param> /// <param name="cultureName"></param> /// <returns></returns> public object GetResourceObject(string resourceId, string resourceSet, string cultureName) { object result = null; SetError(); if (cultureName == null) cultureName = string.Empty; var data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString); DbDataReader reader = data.ExecuteReader("select Value,Type from " + DbResourceConfiguration.Current.ResourceTableName + " where ResourceId=@ResourceId and ResourceSet=@ResourceSet and LocaleId=@LocaleId", data.CreateParameter("@ResourceId", resourceId), data.CreateParameter("@ResourceSet", resourceSet), data.CreateParameter("@LocaleId", cultureName)); if (reader == null) return null; if (reader.HasRows) { reader.Read(); string Type = reader["Type"] as string; if (string.IsNullOrEmpty(Type)) result = reader["Value"] as string; else { LosFormatter Formatter = new LosFormatter(); result = Formatter.Deserialize(reader["Value"] as string); } } reader.Dispose(); return result; }
/// <summary> /// Returns a fully normalized list of resources that contains the most specific /// locale version for the culture provided. /// /// This means that this routine walks the resource hierarchy and returns /// the most specific value in this order: de-ch, de, invariant. /// </summary> /// <param name="cultureName"></param> /// <param name="resourceSet"></param> /// <returns></returns> public Dictionary<string, object> GetResourceSetNormalizedForLocaleId(string cultureName, string resourceSet) { if (cultureName == null) cultureName = string.Empty; Dictionary<string, object> resDictionary = new Dictionary<string, object>(); SqlDataAccess data = new SqlDataAccess(DbResourceConfiguration.Current.ConnectionString); DbDataReader reader = null; string sql = @"select resourceId, LocaleId, Value, Type, BinFile, TextFile, FileName from " + DbResourceConfiguration.Current.ResourceTableName + @" where ResourceSet=@ResourceSet and (LocaleId = '' {0} ) order by ResourceId, LocaleId DESC"; // use like parameter or '' if culture is empty/invariant string localeFilter = string.Empty; List<DbParameter> parameters = new List<DbParameter>(); parameters.Add(data.CreateParameter("@ResourceSet", resourceSet)); if (!string.IsNullOrEmpty(cultureName)) { localeFilter += " OR LocaleId = @LocaleId"; parameters.Add(data.CreateParameter("@LocaleId", cultureName)); // *** grab shorter version if (cultureName.Contains("-")) { localeFilter += " OR LocaleId = @LocaleId1"; parameters.Add(data.CreateParameter("@LocaleId1", cultureName.Split('-')[0])); } } sql = string.Format(sql, localeFilter); reader = data.ExecuteReader(sql, parameters.ToArray()); if (reader == null) { SetError(data.ErrorMessage); return resDictionary; } try { string lastResourceId = "xxxyyy"; while (reader.Read()) { // only pick up the first ID returned - the most specific locale string resourceId = reader["ResourceId"].ToString(); if (resourceId == lastResourceId) continue; lastResourceId = resourceId; // Read the value into this object resourceValue = null; resourceValue = reader["Value"] as string; string resourceType = reader["Type"] as string; if (!string.IsNullOrWhiteSpace(resourceType)) { // FileResource is a special type that is raw file data stored // in the BinFile or TextFile data. Value contains // filename and type data which is used to create: String, Bitmap or Byte[] if (resourceType == "FileResource") resourceValue = LoadFileResource(reader); else { LosFormatter Formatter = new LosFormatter(); resourceValue = Formatter.Deserialize(resourceValue as string); } } else { if (resourceValue == null) resourceValue = string.Empty; } resDictionary.Add(resourceId, resourceValue); } } catch { } finally { // close reader and connection reader.Close(); data.CloseConnection(); } return resDictionary; }
/// <summary> /// 加载Gzipped的ViewState /// </summary> /// <param name="gzippedState"></param> /// <returns></returns> public static object LoadGzippedViewState(string gzippedState) { string ungzippedState = StringUtil.Ungzip(gzippedState); LosFormatter formatter = new LosFormatter(); return formatter.Deserialize(ungzippedState); }
/// <summary> /// Loads the compressed viewstate /// </summary> /// <returns></returns> /// <remarks></remarks> protected override object LoadPageStateFromPersistenceMedium() { string viewState = Request.Form["__VSTATE"]; if (viewState.StartsWith("C$")) { byte[] bytes = Convert.FromBase64String(viewState.Substring(2)); MemoryStream ms = new MemoryStream(); ms.Write(bytes, 0, bytes.Length); ms.Position = 0; GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress, true); MemoryStream ms2 = new MemoryStream(); byte[] buff = new byte[65]; int read = -1; read = gzip.Read(buff, 0, buff.Length); while (read > 0) { ms2.Write(buff, 0, read); read = gzip.Read(buff, 0, buff.Length); } gzip.Close(); bytes = ms2.ToArray(); LosFormatter format = new LosFormatter(); return format.Deserialize(Convert.ToBase64String(bytes)); } else { LosFormatter format = new LosFormatter(); return format.Deserialize(viewState); } }
private object LosDeserializeObject(string inputString) { LosFormatter input = new LosFormatter(); return input.Deserialize(inputString); }
private void textBox1_TextChanged(object sender, EventArgs e) { LosFormatter formatter = new LosFormatter(); object deserializedObject = formatter.Deserialize(textBox1.Text); }
public void Deserialize(Stream s) { System.Web.UI.LosFormatter scFormatter = new System.Web.UI.LosFormatter(); Obj = scFormatter.Deserialize(s); }
private WorkspaceWizardSetting GetWizardState() { var input = CurrentUserControl.FindControl("_settings") as HtmlInputHidden; if (input == null) return null; var value = input.Value; if (string.IsNullOrEmpty(input.Value)) return null; var formatter = new LosFormatter(); var result = formatter.Deserialize(value); return result as WorkspaceWizardSetting; }