Beispiel #1
0
        public void Write(Mapping configuration)
        {
            var filePath = _configFilePathLocator.Locate();

            using (StreamWriter file = File.CreateText(filePath.FullName))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, configuration);
            }
        }
Beispiel #2
0
        // Methods

        public void Write(IEnumerable <FileNode> fileConfigurations)
        {
            var filePath = _configFilePathLocator.Locate();

            using (var fileStream = new FileStream(filePath.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                using (StreamWriter file = new StreamWriter(fileStream))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, fileConfigurations);
                }
        }
Beispiel #3
0
        public FileNode Manage(FileInfo fileInfo)
        {
            var node = _configuration.FirstOrDefault(x => Path.Combine(x.Directory, x.FileName) == fileInfo.FullName);

            if (node == null)
            {
                var newNode = new FileNode(fileInfo, _configFilePathLocator.Locate().Directory);
                _configuration.Add(newNode);
                _fileConfigurationWriter.Write(_configuration);
                CreateFileWatcher(newNode);
                node = newNode;
            }
            return(node);
        }
Beispiel #4
0
        // Methods

        public Mapping Read()
        {
            Mapping result = null;

            var filePath = _configFilePathLocator.Locate();

            using (StreamReader fileReader = File.OpenText(filePath.FullName))
            {
                JsonSerializer serializer = new JsonSerializer();
                result = (Mapping)serializer.Deserialize(fileReader, typeof(Mapping));
            }

            return(result);
        }
Beispiel #5
0
        // Methods

        public IList <FileNode> Read()
        {
            List <FileNode> result = null;

            var filePath = _configFilePathLocator.Locate();

            using (StreamReader fileReader = File.OpenText(filePath.FullName))
            {
                JsonSerializer serializer = new JsonSerializer();
                result = (List <FileNode>)serializer.Deserialize(fileReader, typeof(List <FileNode>));
            }

            return(result ?? new List <FileNode>());
        }