/*using Aws.Rules.Config;
using Aws.Rules.Models;
using Aws.Rules.ProjectFile;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Aws.Rules.ProjectStructure
{
///
/// Runs changes on the project files and structure
///
public class ProjectFilesRewriter
{
private List _actions;
private string _projectFile;
private BlockingCollection _packageAction;
private List _targetVersions;
private BlockingCollection _projectReferences;
private bool _isAnalysisRun;
///
/// Initializes an instance of ProjectFilesRewriter
///
/// The csproj file to run this on
/// The target versions to be added to the project file
/// The package references to be added to the project file
public ProjectFilesRewriter(string projectFile, List targetVersions, BlockingCollection packageAction, BlockingCollection projectReferences)
{
_projectFile = projectFile;
_packageAction = packageAction;
_targetVersions = targetVersions;
_projectReferences = projectReferences;
_actions = new List();
}
///
/// Runs the ProjectFileRewriter
///
public List Run(bool isAnalysisRun = false)
{
_isAnalysisRun = isAnalysisRun;
//Update csproj
string projectDir = Directory.GetParent(_projectFile).FullName;
ProjectType projectType = GetProjectType(_projectFile, projectDir);
LogChange(string.Format("Detected project type {0}", projectType.ToString()));
ConfigMigrate configMigrate = new ConfigMigrate(projectDir, projectType);
_actions.AddRange(configMigrate.Run(_isAnalysisRun));
ArchiveFiles(projectDir);
FolderUpdate folderUpdate = new FolderUpdate(projectDir, projectType);
_actions.AddRange(folderUpdate.Run(_isAnalysisRun));
ProjectFileCreator projectFileCreator = new ProjectFileCreator(_projectFile, _targetVersions,
_packageAction.ToList(), _projectReferences.ToList(), _isAnalysisRun, projectType);
_actions.AddRange(projectFileCreator.Create());
return _actions;
}
//TODO Use project guids, or add to codelyzer and send here
///
/// Gets the type of the project based on folder structure
///
///
///
///
private ProjectType GetProjectType(string projectFile, string projectDir)
{
if (Directory.Exists(string.Concat(projectDir, @"\Content"))
|| Directory.Exists(string.Concat(projectDir, @"\Views"))
|| Directory.Exists(string.Concat(projectDir, @"\wwwroot")))
{
return ProjectType.Mvc;
}
else if ((Directory.Exists(string.Concat(projectDir, @"\Controllers"))))
{
return ProjectType.WebApi;
}
else
{
return ProjectType.ClassLibrary;
}
}
//TODO Is there a better way to do this?
///
/// Archives known .NET Framework files
///
/// Directory of the project
private void ArchiveFiles(string projectDir)
{
List result = new List();
foreach(var fileToArchive in Constants.filesToArchive)
{
IEnumerable files = Directory.EnumerateFiles(projectDir, fileToArchive, SearchOption.AllDirectories);
if(files != null && files.Count() > 0)
{
result.AddRange(files);
}
}
foreach (string s in result)
{
if (!s.EndsWith(".bak"))
{
try
{
if (!_isAnalysisRun)
{
string backupFile = string.Concat(s, ".bak");
if (File.Exists(backupFile))
{
File.Delete(backupFile);
LogChange(string.Format("Deleted file {0}", backupFile));
}
File.Move(s, string.Concat(s, ".bak"));
}
LogChange(string.Format("Archived file {0}", s));
}
catch (Exception ex)
{
LogHelper.LogError("Error archiving files: ");
LogHelper.LogError(ex.Message);
}
}
}
}
private void LogChange(string message)
{
_actions.Add(message);
LogHelper.LogInformation(message);
}
}
}
*/