public void Close()
 {
     if (m_mapFile != null)
     {
         m_mapFile.Close();
     }
     if (m_mapPort != null)
     {
         m_mapPort.Close();
     }
     if (listener != null)
     {
         listener.Abort();
     }
 }
Esempio n. 2
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");
                    }
                }
            }
Esempio n. 3
0
        public void CustomOnDestroy()
        {
            if (fileKeyFloat != null)
            {
                fileKeyFloat.Dispose();
                fileKeyFloat.Close();
            }

            if (streamFloatValue != null)
            {
                streamFloatValue.Dispose();
                streamFloatValue.Close();
            }

            if (fileHeader != null)
            {
                fileHeader.Dispose();
                fileHeader.Close();
            }

            if (fileValueFloat != null)
            {
                fileValueFloat.Dispose();
                fileValueFloat.Close();
            }
        }
Esempio n. 4
0
        public void TestMMFViewSeeking()
        {
            string           filename = Path.GetTempFileName();
            MemoryMappedFile map      = MemoryMappedFile.Create(filename, MapProtection.PageReadWrite, MAX_BYTES);

            using (Stream view = map.MapView(MapAccess.FileMapWrite, 0, MAX_BYTES))
            {
                view.WriteByte(0x12);
                // seek from start of view
                view.Seek(12, SeekOrigin.Begin);
                Assert.AreEqual(12, (int)view.Position);
                // Seek from current pos
                view.Seek(1, SeekOrigin.Current);
                Assert.AreEqual(13, (int)view.Position);
                // seek from end
                view.Seek(-1, SeekOrigin.End);
                Assert.AreEqual(MAX_BYTES - 1, (int)view.Position);

                try
                {
                    // no seeking past end of stream
                    view.Seek(1, SeekOrigin.End);
                    Assert.Fail("Seeked past end of stream");
                }
                catch (FileMapIOException)
                {
                }
            }
            map.Close();
        }
Esempio n. 5
0
    //public void SetBaseHeight(float globalY)
    //{
    //    if (limbIK.gait)
    //    {
    //        var tempPos = baseTarget.position;
    //        tempPos.y = globalY;
    //        baseTarget.position = tempPos;
    //    }
    //}

    void OnDestroy()
    {
        if (limbFile != null)
        {
            limbFile.Close();
        }
    }
Esempio n. 6
0
        public static void createMemFile(string input)
        {
            // grab the mutex
            m_mmf = MemoryMappedFile.CreateInMemoryMap(SharedMapName, MaxMapSize);

            if (!m_mutex.WaitOne(5000, false))
            {
                m_mmf.Close();
                m_mmf = MemoryMappedFile.CreateInMemoryMap(SharedMapName, MaxMapSize);

                Debug.WriteLine("Unable to acquire mutex.  create Abandoned");
                //return;
            }

            // String to byte array
            byte[] x = Encoding.UTF8.GetBytes(input);
            byte[] y = { 0, 0, 0, 0, 0, 0, 0, 0 };

            var z = new byte[x.Length + y.Length];
            x.CopyTo(z, 0);
            y.CopyTo(z, x.Length);

            Buffer.BlockCopy(z, 0, dataBuffer, 0, z.Length);

            // write the packet at the start

            m_mmf.Seek(0, System.IO.SeekOrigin.Begin);
            m_mmf.Write(z, 0, z.Length);

            // release the mutex
            m_mutex.ReleaseMutex();
        }
 void OnDestroy()
 {
     if (camFeedFile != null)
     {
         camFeedFile.Close();
     }
 }
Esempio n. 8
0
 void OnDestroy()
 {
     if (vesselFile != null)
     {
         vesselFile.Close();
     }
 }
Esempio n. 9
0
 void OnDestroy()
 {
     if (IRFile != null)
     {
         IRFile.Close();
     }
 }
 void OnDestroy()
 {
     if (LimbFile != null)
     {
         LimbFile.Dispose();
         LimbFile.Close();
     }
 }
 /// <summary>
 /// Closes the TempFileDatabase. After calling this method, the data recorded is lost, because the temporary file is deleted.
 /// </summary>
 public void Close()
 {
     if (mmf != null)
     {
         mmf.Close();
     }
     file.Close();
 }
Esempio n. 12
0
 public void Close()
 {
     m_mapPort.Close();
     foreach (var db in m_dataFile.Values)
     {
         db.Close();
     }
 }
 /// <summary>
 ///
 /// </summary>
 public virtual void Close()
 {
     if (!m_IsOpen)
     {
         return;
     }
     //
     m_File.Close();
     m_Stream.Close();
     //
     m_File   = null;
     m_Stream = null;
     //
     m_IsOpen = false;
 }
Esempio n. 14
0
        public void TestNamedMMF()
        {
            try {
                const string     NAME = "MyMappedFile";
                MemoryMappedFile map  =
                    MemoryMappedFile.Create(MapProtection.PageReadWrite, MAX_BYTES, NAME);

                MemoryMappedFile map2 =
                    MemoryMappedFile.Open(MapAccess.FileMapRead, NAME);
                map2.Close();
                map.Close();
            } catch (FileMapIOException e) {
                Assert.Fail("Failed Named MMF: " + e);
            }
        }
Esempio n. 15
0
        public void TestMMFViewSize()
        {
            string           filename = Path.GetTempFileName();
            MemoryMappedFile map      = MemoryMappedFile.Create(filename, MapProtection.PageReadWrite, MAX_BYTES);

            using (Stream view = map.MapView(MapAccess.FileMapWrite, 0, MAX_BYTES))
            {
                view.Seek(MAX_BYTES, SeekOrigin.Begin);
                // no writing past end of view
                view.WriteByte(0x01);
                Assert.AreEqual(MAX_BYTES, (int)view.Position);
                // no reading past end of stream
                Assert.AreEqual(-1, view.ReadByte());
            }
            map.Close();
        }
Esempio n. 16
0
        public void TestNonBackedMMF()
        {
            try {
                MemoryMappedFile map =
                    MemoryMappedFile.Create(MapProtection.PageReadWrite, MAX_BYTES);

                using (Stream view = map.MapView(MapAccess.FileMapWrite, 0, MAX_BYTES))
                {
                    WriteBytesToStream(view, MAX_BYTES);
                }
                using (Stream view = map.MapView(MapAccess.FileMapRead, 0, MAX_BYTES / 2))
                {
                    VerifyBytesInStream(view, MAX_BYTES / 2);
                }
                map.Close();
            } catch (FileMapIOException e) {
                Assert.Fail("Write error: " + e);
            }
        }
Esempio n. 17
0
 public static void CloseMemoryMap()
 {
     try
     {
         if (_mapViewSteam != null)
         {
             _mapViewSteam.Close();
             _mapViewSteam = null;
         }
         if (_memoryMap != null)
         {
             _memoryMap.Close();
             _memoryMap = null;
         }
     }
     catch (Exception)
     {
         //ignore
     }
 }
 public void CustomOnDestroy()
 {
     UpdateHeaderFile();
     if (fileHeader != null)
     {
         fileHeader.Close();
     }
     if (streamFloatValue != null)
     {
         streamFloatValue.Close();
     }
     if (fileKeyFloat != null)
     {
         fileKeyFloat.Close();
     }
     if (fileValueFloat != null)
     {
         fileValueFloat.Close();
     }
 }
Esempio n. 19
0
        public void TestMMFFileWrite()
        {
            try {
                string           filename = Path.GetTempFileName();
                MemoryMappedFile map      =
                    MemoryMappedFile.Create(filename, MapProtection.PageReadWrite, MAX_BYTES);

                using (Stream view = map.MapView(MapAccess.FileMapWrite, 0, MAX_BYTES))
                {
                    WriteBytesToStream(view, MAX_BYTES);
                }
                using (Stream view = map.MapView(MapAccess.FileMapRead, 0, MAX_BYTES / 2))
                {
                    VerifyBytesInStream(view, MAX_BYTES / 2);
                }
                map.Close();
            } catch (FileMapIOException e) {
                Assert.Fail("Write error: " + e);
            }
        }
        public void TestSeekPositive()
        {
            MemoryMappedFile mmf = MemoryMappedFile.CreateInMemoryMap();

            Assert.IsNotNull(mmf);

            // begin - from begin
            mmf.Seek(0, SeekOrigin.Begin);
            Assert.AreEqual(mmf.Position, 0, "Failed Seek begin from begin");

            // the middle - from begin
            long offset = mmf.Length / 2;

            mmf.Seek(offset, SeekOrigin.Begin);
            Assert.AreEqual(mmf.Position, offset, "Failed Seek middle from begin");

            // end - from begin
            mmf.Seek(MemoryMappedFile.DefaultInMemoryMapSize, SeekOrigin.Begin);
            Assert.AreEqual(mmf.Position, MemoryMappedFile.DefaultInMemoryMapSize, "Failed Seek end from begin");

            // begin - from end
            mmf.Seek(-MemoryMappedFile.DefaultInMemoryMapSize, SeekOrigin.End);
            Assert.AreEqual(mmf.Position, 0, "Failed Seek begin from end");

            // middle - from end
            mmf.Seek(-offset, SeekOrigin.End);
            Assert.AreEqual(mmf.Position, offset, "Failed Seek middle from end");

            // end - from end
            mmf.Seek(0, SeekOrigin.End);
            Assert.AreEqual(mmf.Position, MemoryMappedFile.DefaultInMemoryMapSize, "Failed Seek end from end");

            mmf.Seek(offset, SeekOrigin.Begin);
            mmf.Seek(-offset, SeekOrigin.Current);
            Assert.AreEqual(mmf.Position, 0, "Failed Seek begin from current");

            mmf.Close();
        }
 public void close()
 {
     reader.Flush();
     mapFile.Close();
 }
 void OnDestroy()
 {
     if (LimbFile != null)
         LimbFile.Close();
 }