Skip to content

Commit

Permalink
(chocolateyGH-121) Add files service
Browse files Browse the repository at this point in the history
Add ability to read and save package file information.
  • Loading branch information
ferventcoder committed May 3, 2015
1 parent cd483be commit 148bf26
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<Compile Include="infrastructure.app\runners\GenericRunner.cs" />
<Compile Include="infrastructure.app\services\AutomaticUninstallerService.cs" />
<Compile Include="infrastructure.app\services\ChocolateyConfigSettingsService.cs" />
<Compile Include="infrastructure.app\services\FilesService.cs" />
<Compile Include="infrastructure.app\services\IFilesService.cs" />
<Compile Include="infrastructure\adapters\CustomString.cs" />
<Compile Include="infrastructure.app\services\IChocolateyConfigSettingsService.cs" />
<Compile Include="infrastructure.app\configuration\ConfigFileApiKeySetting.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void RegisterComponents(Container container)
container.Register<IChocolateyPackageInformationService, ChocolateyPackageInformationService>(Lifestyle.Singleton);
container.Register<IShimGenerationService, ShimGenerationService>(Lifestyle.Singleton);
container.Register<IRegistryService, RegistryService>(Lifestyle.Singleton);
container.Register<IFilesService, FilesService>(Lifestyle.Singleton);
container.Register<ITemplateService, TemplateService>(Lifestyle.Singleton);
container.Register<IChocolateyConfigSettingsService, ChocolateyConfigSettingsService>(Lifestyle.Singleton);
container.Register<IChocolateyPackageService, ChocolateyPackageService>(Lifestyle.Singleton);
Expand Down
48 changes: 48 additions & 0 deletions src/chocolatey/infrastructure.app/services/FilesService.cs
Original file line number Diff line number Diff line change
@@ -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<PackageFiles>(filePath);
}

public void save_to_file(PackageFiles snapshot, string filePath)
{
_xmlService.serialize(snapshot, filePath);
}
}
}
25 changes: 25 additions & 0 deletions src/chocolatey/infrastructure.app/services/IFilesService.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 148bf26

Please sign in to comment.