Example #1
0
        public void Update_General(string email, d_On_User_Action action, Object args, d_On_User_PostAction postAction, IMyLog log)
        {
            string filePath =
                FolderNames.GetFolder(NiceSystemInfo.DEFAULT, MyFolders.ASP_UserAccountFolder_) +
                Path.DirectorySeparatorChar +
                Data_AppUserFile.EmailSaveChars(email) + ".txt";

            using (Stream stream = OpenFile.ForRead(filePath, true, true, log))
            {
                Data_AppUserFile r = null;

                if (stream != null)
                {
                    r = Data_AppUserFile.CreateBlank();
                    //1) read it in
                    BinaryReader br = new BinaryReader(stream);
                    r.ReadFromStream(br);
                }

                //2) update values
                if (action != null)
                {
                    action(r, args);
                }

                //3) write it back
                if (r != null)
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    BinaryWriter bw = new BinaryWriter(stream);
                    r.WriteToStream(bw);
                    stream.SetLength(stream.Position);
                    stream.Close();
                }
            }
            if (postAction != null)
            {
                postAction(args);
            }
        }
Example #2
0
        public void StoreNew(Data_AppUserFile data, out bool fileArleadyUsed, IMyLog log)
        {
            fileArleadyUsed = false;
            string folder = FolderNames.GetFolder(NiceSystemInfo.DEFAULT, MyFolders.ASP_UserAccountFolder_);
            string file   = folder + Path.DirectorySeparatorChar + Data_AppUserFile.EmailSaveChars(data.Email) + ".txt";

            if (File.Exists(file))
            {
                fileArleadyUsed = true;
                return;
            }

            try
            {
                using (BinaryWriter bw = new BinaryWriter(OpenFile.ForWrite(file, log)))
                {
                    data.WriteToStream(bw);
                }
            }
            catch (IOException)
            { }
        }