public void SaveToFile()
        {
            FileIOPermission fileIOPerm = new FileIOPermission(FileIOPermissionAccess.Write, r_CacheFilePath);

            if (File.Exists(r_CacheFilePath))
            {
                using (Stream stream = new FileStream(r_CacheFilePath, FileMode.Truncate))
                {
                    LoginResultAdapter objectToSave;
                    if (CurretnLoginResult == null)
                    {
                        objectToSave = new LoginResultAdapter();
                    }
                    else
                    {
                        objectToSave = CurretnLoginResult;
                    }

                    IFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, objectToSave);
                }
            }
            else
            {
                using (Stream stream = new FileStream(r_CacheFilePath, FileMode.CreateNew))
                {
                    IFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, CurretnLoginResult);
                }
            }
        }
        public CachedLoginResultAdapter(LoginResultAdapter i_LoginResult)
        {
            m_LoginResult = i_LoginResult;
            LogingResultAdapterCacher.s_Instance.CurretnLoginResult = m_LoginResult;
            LogingResultAdapterCacher.s_Instance.SaveToFile();
            var CacheThread = new Thread(LogingResultAdapterCacher.s_Instance.SaveToFile);

            CacheThread.SetApartmentState(ApartmentState.STA);
            CacheThread.Start();
        }
        public LoginResultAdapter LoadCachedLoginResultFromDisc()
        {
            LoginResultAdapter retVal = null;

            if (File.Exists(r_CacheFilePath))
            {
                using (Stream stream = new FileStream(r_CacheFilePath, FileMode.Open))
                {
                    IFormatter formatter = new BinaryFormatter();
                    retVal = (LoginResultAdapter)formatter.Deserialize(stream);
                }
            }

            return(retVal);
        }
 private void getLoginResultAdapterAndPopulateCache(LoginResultAdapter i_LoginResultAdapter)
 {
     LoginResult = new CachedLoginResultAdapter(i_LoginResultAdapter);
 }
 public CachedLoginResultAdapter()
 {
     m_LoginResult = LogingResultAdapterCacher.s_Instance.LoadCachedLoginResultFromDisc();
 }