예제 #1
0
            public void RemoveObject(string ObjName)
            {
                //get the main mmf table and remove the key
                MemoryMappedFile map = new MemoryMappedFile();

                if (map.OpenEx(ObjectNamesMMF + ".nat", MapProtection.PageReadWrite, ObjectNamesMMF, MapAccess.FileMapAllAccess))
                {
                    BinaryFormatter bf        = new BinaryFormatter();
                    MapViewStream   mmfStream = map.MapView(MapAccess.FileMapRead, 0, 0, "");
                    mmfStream.Position = 0;
                    Hashtable oFilesMap = bf.Deserialize(mmfStream) as Hashtable;
                    oFilesMap.Remove(ObjName);
                    mmfStream.Close();
                    //update the main file
                    bf = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    bf.Serialize(ms, oFilesMap);
                    MapViewStream stream = map.MapView(MapAccess.FileMapAllAccess, 0, (int)0, "");
                    stream.Position = 0;
                    stream.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    stream.Flush();
                    stream.Close();
                    //delete the map of the object
                    MemoryMappedFile oMMf = new MemoryMappedFile();
                    if (oMMf.Open(MapAccess.FileMapAllAccess, ObjName))
                    {
                        oMMf.Close();
                        oMMf.Dispose();
                    }
                    if (System.IO.File.Exists(map.GetMMFDir() + ObjName + ".nat"))
                    {
                        System.IO.File.Delete(map.GetMMFDir() + ObjName + ".nat");
                    }
                }
            }