Beispiel #1
0
        private void LoadFromDisk(FileGenerationConfiguration diskData)
        {
            this.FileGenerationOptionsCollection.Clear();

            foreach (var item in diskData.FileGenerationOptionsCollection)
            {
                this.FileGenerationOptionsCollection.Add(item.Key, item.Value);
            }

            this.DefaultFileGenerationOptions = diskData.DefaultFileGenerationOptions;
        }
Beispiel #2
0
        private static FileGenerationConfiguration GetStatic()
        {
            lock (_syncObject)
            {
                if (_singleton == null)
                {
                    string filePath = FileOperations.GetFileGenerationConfigurationFilePath();

                    FileGenerationConfiguration localFile = GetFromPath(filePath);

                    _singleton      = localFile ?? new FileGenerationConfiguration();
                    _singleton.Path = filePath;
                }

                return(_singleton);
            }
        }
Beispiel #3
0
        private static FileGenerationConfiguration GetFromPath(string filePath)
        {
            FileGenerationConfiguration result = null;

            if (File.Exists(filePath))
            {
                DataContractSerializer ser = new DataContractSerializer(typeof(FileGenerationConfiguration));

                using (Mutex mutex = new Mutex(false, FileOperations.GetMutexName(filePath)))
                {
                    try
                    {
                        mutex.WaitOne();

                        using (var sr = File.OpenRead(filePath))
                        {
                            result = ser.ReadObject(sr) as FileGenerationConfiguration;
                        }
                    }
                    catch (Exception ex)
                    {
                        DTEHelper.WriteExceptionToOutput(null, ex);

                        FileOperations.CreateBackUpFile(filePath, ex);

                        result = null;
                    }
                    finally
                    {
                        mutex.ReleaseMutex();
                    }
                }
            }

            return(result);
        }