From 148bf2656b04f2080b3b3c0bfc716cc4de0a327c Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 3 May 2015 11:26:43 -0500 Subject: [PATCH] (GH-121) Add files service Add ability to read and save package file information. --- src/chocolatey/chocolatey.csproj | 2 + .../registration/ContainerBinding.cs | 1 + .../services/FilesService.cs | 48 +++++++++++++++++++ .../services/IFilesService.cs | 25 ++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/chocolatey/infrastructure.app/services/FilesService.cs create mode 100644 src/chocolatey/infrastructure.app/services/IFilesService.cs diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index 2cb7f6605e..18b9ede0fa 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -104,6 +104,8 @@ + + diff --git a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs index 995a09b297..28fde79390 100644 --- a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs +++ b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs @@ -53,6 +53,7 @@ public void RegisterComponents(Container container) container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); + container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); diff --git a/src/chocolatey/infrastructure.app/services/FilesService.cs b/src/chocolatey/infrastructure.app/services/FilesService.cs new file mode 100644 index 0000000000..c8e0adee6d --- /dev/null +++ b/src/chocolatey/infrastructure.app/services/FilesService.cs @@ -0,0 +1,48 @@ +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.infrastructure.app.services +{ + using domain; + using filesystem; + using infrastructure.services; + + public sealed class FilesService : IFilesService + { + private readonly IXmlService _xmlService; + private readonly IFileSystem _fileSystem; + + public FilesService(IXmlService xmlService, IFileSystem fileSystem) + { + _xmlService = xmlService; + _fileSystem = fileSystem; + } + + public PackageFiles read_from_file(string filePath) + { + if (!_fileSystem.file_exists(filePath)) + { + return null; + } + + return _xmlService.deserialize(filePath); + } + + public void save_to_file(PackageFiles snapshot, string filePath) + { + _xmlService.serialize(snapshot, filePath); + } + } +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/services/IFilesService.cs b/src/chocolatey/infrastructure.app/services/IFilesService.cs new file mode 100644 index 0000000000..daf42c7fcf --- /dev/null +++ b/src/chocolatey/infrastructure.app/services/IFilesService.cs @@ -0,0 +1,25 @@ +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.infrastructure.app.services +{ + using domain; + + public interface IFilesService + { + PackageFiles read_from_file(string filepath); + void save_to_file(PackageFiles snapshot, string filePath); + } +} \ No newline at end of file