/// <summary> /// this funtion is calles from parent process to /// transfer the new data to the plugin class /// </summary> /// <param name="data">list with all new log data items</param> public void add_log_data(List <LogDataSet> data) { AquaComputer.Logdata.LogDataExport export = new Logdata.LogDataExport(); export.logdata = data; export.name = export_name; export.exportTime = DateTime.Now; System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(export_path); if (!dir.Exists) { return; //dir is not valid } if (export_name == null || export_name == string.Empty) { return; //file name not valid } if (_in_progress) { return; //the current function is running in an other thread } //export data to xml file _in_progress = true; string file = dir.FullName + "//" + export_name + ".xml"; export.SaveToFile(file); _in_progress = false; }
/// <summary> /// this funtion is calles from parent process to /// transfer the new data to the plugin class /// </summary> /// <param name="data">list with all new log data items</param> public void add_log_data(List<LogDataSet> data) { AquaComputer.Logdata.LogDataExport export = new Logdata.LogDataExport(); export.logdata = data; export.name = export_name; export.exportTime = DateTime.Now; System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(export_path); if (!dir.Exists) return; //dir is not valid if (export_name == null || export_name == string.Empty) return; //file name not valid if (_in_progress) return; //the current function is running in an other thread //export data to xml file _in_progress = true; string file = dir.FullName + "//" + export_name + ".xml"; export.SaveToFile(file); _in_progress = false; }
/// <summary> /// this funtion is calles from parent process to /// transfer the new data to the plugin class /// </summary> /// <param name="data">list with all new log data items</param> public void add_log_data(List<LogDataSet> data) { if (_in_progress) //the current process is locked return; //export current data to a buffer for file writing _in_progress = true; AquaComputer.Logdata.LogDataExport export = new Logdata.LogDataExport(); export.logdata = data; export.name = export_name; export.exportTime = DateTime.Now; byte[] buffer = export.ToBuffer(); if (buffer == null || export_name == null || export_name == string.Empty) { _in_progress = false; return; } //try to create a new shared memory file if (memory_file == null || memory_file.SafeMemoryMappedFileHandle.IsClosed || memory_file.SafeMemoryMappedFileHandle.IsInvalid) { try { memory_file = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(export_name, buffer.LongLength * 2); memory_file_size = buffer.Length * 2; } catch { memory_file = null; memory_file_size = 0; } } //not able to craeate to use a shared memory file with the current settings if (memory_file == null) { _in_progress = false; return; } //check if the file used from external ressources //wait until all locks are released or timeout elapsed bool initial_owned; System.Threading.Mutex shm_mutex = new System.Threading.Mutex(true, "Global\\" + export_name + "_mutex", out initial_owned); if (!initial_owned) { bool mutex_is_free = shm_mutex.WaitOne(50); if (mutex_is_free == false) { _in_progress = false; return; } } if (memory_file_size < buffer.Length) { //file buffer is too small, create file buffer memory_file.Dispose(); memory_file = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(export_name, buffer.LongLength * 2); memory_file_size = buffer.Length * 2; } //acces file to write data to ram segement using(var accessor = memory_file.CreateViewAccessor(0, memory_file_size)) { if (accessor != null) { accessor.WriteArray<byte>(0, buffer, 0, buffer.Length); //reset rest of data array to 0 byte[] reset_buffer = new byte[memory_file_size - buffer.Length]; for (int i = 0; i < reset_buffer.Length; i++) reset_buffer[i] = 0; accessor.WriteArray<byte>(buffer.Length, reset_buffer, 0, reset_buffer.Length); } } //release ressources shm_mutex.ReleaseMutex(); //release mutex _in_progress = false; }
/// <summary> /// this funtion is calles from parent process to /// transfer the new data to the plugin class /// </summary> /// <param name="data">list with all new log data items</param> public void add_log_data(List <LogDataSet> data) { if (_in_progress) //the current process is locked { return; } //export current data to a buffer for file writing _in_progress = true; AquaComputer.Logdata.LogDataExport export = new Logdata.LogDataExport(); export.logdata = data; export.name = export_name; export.exportTime = DateTime.Now; byte[] buffer = export.ToBuffer(); if (buffer == null || export_name == null || export_name == string.Empty) { _in_progress = false; return; } //try to create a new shared memory file if (memory_file == null || memory_file.SafeMemoryMappedFileHandle.IsClosed || memory_file.SafeMemoryMappedFileHandle.IsInvalid) { try { memory_file = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(export_name, buffer.LongLength * 2); memory_file_size = buffer.Length * 2; } catch { memory_file = null; memory_file_size = 0; } } //not able to craeate to use a shared memory file with the current settings if (memory_file == null) { _in_progress = false; return; } //check if the file used from external ressources //wait until all locks are released or timeout elapsed bool initial_owned; System.Threading.Mutex shm_mutex = new System.Threading.Mutex(true, "Global\\" + export_name + "_mutex", out initial_owned); if (!initial_owned) { bool mutex_is_free = shm_mutex.WaitOne(50); if (mutex_is_free == false) { _in_progress = false; return; } } if (memory_file_size < buffer.Length) { //file buffer is too small, create file buffer memory_file.Dispose(); memory_file = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateNew(export_name, buffer.LongLength * 2); memory_file_size = buffer.Length * 2; } //acces file to write data to ram segement using (var accessor = memory_file.CreateViewAccessor(0, memory_file_size)) { if (accessor != null) { accessor.WriteArray <byte>(0, buffer, 0, buffer.Length); //reset rest of data array to 0 byte[] reset_buffer = new byte[memory_file_size - buffer.Length]; for (int i = 0; i < reset_buffer.Length; i++) { reset_buffer[i] = 0; } accessor.WriteArray <byte>(buffer.Length, reset_buffer, 0, reset_buffer.Length); } } //release ressources shm_mutex.ReleaseMutex(); //release mutex _in_progress = false; }