public void ReleaseFiles(bool _save_changes)
        {
            if (_save_changes)
            {
                // modifies this.loaded_file_records
                this.SaveFiles();
            }

            // release locks on files
            StringBuilder sb_new = new StringBuilder();

            foreach (PartialFileRecord fr in this.loaded_file_records)
            {
                if (DXFDistributedDecoder.HasEditingRights(this.manager, fr.Manager))
                {
                    fr.NrLocks--;
                }
                fr.AddToExport(ref sb_new);
            }

            // ... release the watcher
            this.ReleaseWatcher();

            // ... modify the summary file accordingly
            this.WriteSummaryFile(this.SummaryFileName, ref sb_new);

            // reset internal state
            this.SetFileManagementContent(null, ComponentManagerType.GUEST);
            this.COMP_Factory.ClearRecord();
        }
        public void LoadFiles(bool _use_a_watcher = true)
        {
            if (!File.Exists(this.SummaryFileName))
            {
                return;
            }

            try
            {
                // read and parse file
                this.FStream = new StreamReader(this.SummaryFileName);
                bool reached_eof = false;
                while (this.HasNext())
                {
                    this.Next();
                    if (this.FValue == ParamStructTypes.EOF)
                    {
                        reached_eof = true;
                        if (this.current_file_record != null)
                        {
                            this.loaded_file_records.Add(this.current_file_record);
                        }
                        this.ReleaseRessources();
                        break;
                    }
                    this.ParseSummaryFile();
                }
                if (!reached_eof)
                {
                    this.ReleaseRessources();
                }

                // load components from the files according to user role and ...
                StringBuilder sb_new      = new StringBuilder();
                DXFDecoder    dxf_decoder = new DXFDecoder(this.MV_Factory, this.P_Factory, this.COMP_Factory);

                foreach (PartialFileRecord fr in this.loaded_file_records)
                {
                    if (File.Exists(fr.FileName))
                    {
                        // adjust the locks on the file (06.02.2017)
                        bool lock_edit = true;
                        this.nr_locks_record[(int)fr.Manager] = fr.NrLocks;
                        if (DXFDistributedDecoder.HasEditingRights(this.manager, fr.Manager))
                        {
                            lock_edit = (fr.NrLocks > 0);
                            this.nr_locks_record[(int)fr.Manager] = fr.NrLocks + 1;
                            fr.NrLocks++;
                        }

                        dxf_decoder.LoadFromFile(fr.FileName, lock_edit);
                    }
                    fr.AddToExport(ref sb_new);
                }
                dxf_decoder.DoDeferredOperations(); // connects components and networks saved in different partial files
                this.COMP_Factory.RestoreReferencesWithinRecord();
                this.COMP_Factory.MakeParameterOutsideBoundsVisible();

                // ... modify the summary file accordingly
                this.WriteSummaryFile(this.SummaryFileName, ref sb_new);
                this.FileRecordsOpen = true;

                // ... set a watcher on the file
                if (_use_a_watcher)
                {
                    this.SetWatcher();
                }
            }
            catch (Exception ex)
            {
                this.ReleaseRessources();
                MessageBox.Show(ex.Message, "Error reading simultan file: " + this.SummaryFileName,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        // writing the summary file (smn: SIMULTAN)
        // ----------------------------------------------------------------------
        // code 0  : ENTITY_START
        // value   : file name (e.g. architecture: 'ComponentRecord_01ARC.dxf')
        // code 904: ENTITY_KEY
        // value   : role that can open the file with writing access (e.g. administrator: '@')
        // code 902: TIME_STAMP
        // value   : last modified
        // code 910: X_VALUE
        // value   : 1 if locked, 0 if unlocked (this is set during file open, according to role)

        // only the files corsponding to the manager role can be replaced
        // NO !!! (added 01.09.2016)
        // all files can be replaced: user w/o writing access can still have supervizing or release access
        public void SaveFiles(bool _unlock_the_summary_file = false)
        {
            if (this.loaded_file_records.Count == 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(this.SummaryFileName))
            {
                return;
            }
            if (this.SummaryFileName.Length < 5)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();
            string        filename_wo_ext = this.SummaryFileName.Substring(0, this.SummaryFileName.Length - ParamStructFileExtensions.FILE_EXT_PROJECT.Length - 1);

            // create the export stringS
            Dictionary <ComponentManagerType, StringBuilder> exports = this.COMP_Factory.ExportRecordDistributed();
            // prepare for checking the state of the single files (init w ZERO)
            List <int> single_file_state = new List <int>(ComponentUtils.MANAGER_TYPE_OPENING_SIGNATURE_NONE);

            // save the file records
            foreach (var entry in exports)
            {
                // changed 01.09.2016 to allow for release and supervize actions to be recorded
                //if (DXFDistributedDecoder.HasEditingRights(this.manager, entry.Key))
                //{
                // check if the locks are set correctly, if a new single file is to be created (added 07.02.2017)
                if (DXFDistributedDecoder.HasEditingRights(this.manager, entry.Key) && this.nr_locks_record[(int)entry.Key] == 0)
                {
                    this.nr_locks_record[(int)entry.Key] = 1;
                }
                // save file
                PartialFileRecord record = this.WriteSingleFile(filename_wo_ext, this.nr_locks_record[(int)entry.Key], entry.Key, entry.Value);
                single_file_state[(int)entry.Key] = 1;
                // replace record, if it exists; otherwise just add
                PartialFileRecord pfr = this.loaded_file_records.Find(x => x.Manager == entry.Key);
                if (pfr != null)
                {
                    this.loaded_file_records.Remove(pfr);
                }
                this.loaded_file_records.Add(record);
                //}
            }

            // clean up old file records (e.g. when the writing rights of components change a record may become obsolete)
            for (int c = 0; c < single_file_state.Count; c++)
            {
                if (single_file_state[c] > 0)
                {
                    continue;
                }

                // get rid of the record and of the file
                PartialFileRecord pfr = this.loaded_file_records.Find(x => x.Manager == (ComponentManagerType)c);
                if (pfr != null)
                {
                    this.loaded_file_records.Remove(pfr);
                    this.DeleteSingleFile(filename_wo_ext, (ComponentManagerType)c);
                }
            }

            // ... modify the summary file accordingly
            this.SingleFileNames = new List <string>();
            foreach (PartialFileRecord fr in this.loaded_file_records)
            {
                if (_unlock_the_summary_file)
                {
                    fr.NrLocks = 0;
                }
                fr.AddToExport(ref sb);
                this.SingleFileNames.Add(fr.FileName);
            }
            this.WriteSummaryFile(this.SummaryFileName, ref sb);
        }