Esempio n. 1
0
        internal static ProfileSession Get(this MilSp_Profile profileData)
        {
            ProfileSession session = null;

            XmlSerializer serializer = new XmlSerializer(typeof(ProfileSession));

            using (var memoryStream = new MemoryStream())
            {
                using (var writer = new StreamWriter(memoryStream))
                {
                    // Various for loops etc as necessary that will ultimately do this:
                    writer.Write(profileData.ProfileData);
                    writer.Flush();

                    try
                    {
                        if (serializer.Deserialize(memoryStream) is ProfileSession result)
                        {
                            session = result;
                        }
                    }
                    catch (Exception ex)
                    {
                        //TODO: log the error
                        throw new MilSpaceDataException("MilSp_Profile", DataOperationsEnum.Convert, ex);
                    }
                }
            }

            return(session);
        }
Esempio n. 2
0
        private static string Serialize(ProfileSession session)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProfileSession));

            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, session);
                try
                {
                    var resu = Encoding.UTF8.GetString((stream as MemoryStream).ToArray());
                    //
                    ProfileSession sessionOut = null;

                    XmlSerializer serializerOut = new XmlSerializer(typeof(ProfileSession));

                    using (var memoryStream = new MemoryStream())
                    {
                        using (var writer = new StreamWriter(memoryStream))
                        {
                            // Various for loops etc as necessary that will ultimately do this:
                            writer.Write(resu);
                            writer.Flush();

                            try
                            {
                                memoryStream.Seek(0, SeekOrigin.Begin);
                                if (serializer.Deserialize(memoryStream) is ProfileSession result)
                                {
                                    sessionOut = result;
                                }
                            }
                            catch (Exception ex)
                            {
                                //TODO: log the error
                                //throw new MilSpaceDataException("MilSp_Profile", DataOperationsEnum.Convert, ex);
                            }
                        }
                    }
                    //

                    return(Encoding.UTF8.GetString((stream as MemoryStream).ToArray()));
                }
                catch (Exception ex)
                {
                    //TODO: log the error
                }

                return(null);
            }
        }
Esempio n. 3
0
        internal static MilSp_Profile Get(this ProfileSession session)
        {
            try
            {
                MilSp_Profile res = new MilSp_Profile
                {
                    idRow       = session.SessionId,
                    ProfileName = session.SessionName,
                    ProfileData = session.Serialized
                };

                return(res);
            }
            catch (Exception ex)
            {
                throw new MilSpaceDataException("ProfileSession", DataOperationsEnum.Convert, ex);
            }
        }
Esempio n. 4
0
        private static string Serialize(ProfileSession session)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProfileSession));


            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, session);
                try
                {
                    return(Encoding.UTF8.GetString((stream as MemoryStream).ToArray()));
                }
                catch (Exception ex)
                {
                    //TODO: log the error
                }

                return(null);
            }
        }
Esempio n. 5
0
        private static string Serialize(ProfileSession session)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProfileSession));

            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, session);
                try
                {
                    var            resu       = Encoding.UTF8.GetString((stream as MemoryStream).ToArray());
                    ProfileSession sessionOut = null;

                    XmlSerializer serializerOut = new XmlSerializer(typeof(ProfileSession));

                    using (var memoryStream = new MemoryStream())
                    {
                        using (var writer = new StreamWriter(memoryStream))
                        {
                            // Various for loops etc as necessary that will ultimately do this:
                            writer.Write(resu);
                            writer.Flush();


                            memoryStream.Seek(0, SeekOrigin.Begin);
                            if (serializer.Deserialize(memoryStream) is ProfileSession result)
                            {
                                sessionOut = result;
                            }
                        }
                    }

                    return(Encoding.UTF8.GetString((stream as MemoryStream).ToArray()));
                }
                catch (Exception ex)
                {
                    logger.ErrorEx(ex.Message);
                }

                return(null);
            }
        }