diff --git a/src/DiviK-standalone-client.sln b/src/DiviK-standalone-client.sln index ce54f13..b735858 100644 --- a/src/DiviK-standalone-client.sln +++ b/src/DiviK-standalone-client.sln @@ -6,46 +6,17 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Algorithms", "Spectre.Algorithms\Spectre.Algorithms.csproj", "{9A886AEC-58DB-410D-91B9-C62E157501FA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Algorithms.Tests", "Spectre.Algorithms.Tests\Spectre.Algorithms.Tests.csproj", "{BBF6329D-7BEC-494E-9FC9-B24B12D94EA0}" - ProjectSection(ProjectDependencies) = postProject - {287A1A8D-C029-4D47-96BC-755C91B7985D} = {287A1A8D-C029-4D47-96BC-755C91B7985D} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Data", "Spectre.Data\Spectre.Data.csproj", "{70C87AF7-3189-4F6C-AC85-93309CF7CFDC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Data.Tests", "Spectre.Data.Tests\Spectre.Data.Tests.csproj", "{01391E76-3D20-4B4B-B727-2A133B35A144}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", "{7EAC5FD7-C9CD-42E8-A24B-3665E854F4CD}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Mvvm", "Spectre.Mvvm\Spectre.Mvvm.csproj", "{2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Mvvm.Tests", "Spectre.Mvvm.Tests\Spectre.Mvvm.Tests.csproj", "{23A97D0F-B6D9-4B67-84FE-4B52EA7D82EC}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Clients", "Clients", "{D3C36686-9667-48B2-A14B-FF46E6350A51}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.DivikWpfClient", "Spectre.DivikWpfClient\Spectre.DivikWpfClient.csproj", "{F518ED4B-ADE0-4B5C-A01B-48D9FA216E0C}" - ProjectSection(ProjectDependencies) = postProject - {287A1A8D-C029-4D47-96BC-755C91B7985D} = {287A1A8D-C029-4D47-96BC-755C91B7985D} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Service", "Spectre.Service\Spectre.Service.csproj", "{287A1A8D-C029-4D47-96BC-755C91B7985D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Service.Tests", "Spectre.Service.Tests\Spectre.Service.Tests.csproj", "{1D79FD14-1DF4-4AED-94DF-62E595206DEF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9660DC51-B40B-454B-84B7-7FF830DA2D34}" ProjectSection(SolutionItems) = preProject CSharpCodingConvention.ruleset = CSharpCodingConvention.ruleset EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Database", "Spectre.Database\Spectre.Database.csproj", "{B5B60F79-653C-4E41-9721-06C478CE9E7C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Database.Tests", "Spectre.Database.Tests\Spectre.Database.Tests.csproj", "{2D5AD568-F2EE-4B8C-AF81-2C46EB45B0ED}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Dependencies", "Spectre.Dependencies\Spectre.Dependencies.csproj", "{2B9F4DFD-C222-477A-9107-1A3C356002A4}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.DataValidatorApp", "Spectre.DataValidatorApp\Spectre.DataValidatorApp.csproj", "{3D932849-312C-473C-B74C-ABD1F11A0739}" - ProjectSection(ProjectDependencies) = postProject - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC} = {70C87AF7-3189-4F6C-AC85-93309CF7CFDC} - EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.DivikResultConverter", "Spectre.DivikResultConverter\Spectre.DivikResultConverter.csproj", "{74E04873-BB6F-4115-841D-50C162928B19}" EndProject @@ -63,46 +34,10 @@ Global {BBF6329D-7BEC-494E-9FC9-B24B12D94EA0}.Debug|x64.Build.0 = Debug|x64 {BBF6329D-7BEC-494E-9FC9-B24B12D94EA0}.Release|x64.ActiveCfg = Release|x64 {BBF6329D-7BEC-494E-9FC9-B24B12D94EA0}.Release|x64.Build.0 = Release|x64 - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC}.Debug|x64.ActiveCfg = Debug|x64 - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC}.Debug|x64.Build.0 = Debug|x64 - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC}.Release|x64.ActiveCfg = Release|x64 - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC}.Release|x64.Build.0 = Release|x64 - {01391E76-3D20-4B4B-B727-2A133B35A144}.Debug|x64.ActiveCfg = Debug|x64 - {01391E76-3D20-4B4B-B727-2A133B35A144}.Debug|x64.Build.0 = Debug|x64 - {01391E76-3D20-4B4B-B727-2A133B35A144}.Release|x64.ActiveCfg = Release|x64 - {01391E76-3D20-4B4B-B727-2A133B35A144}.Release|x64.Build.0 = Release|x64 - {2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE}.Debug|x64.ActiveCfg = Debug|x64 - {2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE}.Debug|x64.Build.0 = Debug|x64 - {2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE}.Release|x64.ActiveCfg = Release|x64 - {2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE}.Release|x64.Build.0 = Release|x64 - {23A97D0F-B6D9-4B67-84FE-4B52EA7D82EC}.Debug|x64.ActiveCfg = Debug|x64 - {23A97D0F-B6D9-4B67-84FE-4B52EA7D82EC}.Debug|x64.Build.0 = Debug|x64 - {23A97D0F-B6D9-4B67-84FE-4B52EA7D82EC}.Release|x64.ActiveCfg = Release|x64 - {23A97D0F-B6D9-4B67-84FE-4B52EA7D82EC}.Release|x64.Build.0 = Release|x64 {F518ED4B-ADE0-4B5C-A01B-48D9FA216E0C}.Debug|x64.ActiveCfg = Debug|x64 {F518ED4B-ADE0-4B5C-A01B-48D9FA216E0C}.Debug|x64.Build.0 = Debug|x64 {F518ED4B-ADE0-4B5C-A01B-48D9FA216E0C}.Release|x64.ActiveCfg = Release|x64 {F518ED4B-ADE0-4B5C-A01B-48D9FA216E0C}.Release|x64.Build.0 = Release|x64 - {287A1A8D-C029-4D47-96BC-755C91B7985D}.Debug|x64.ActiveCfg = Debug|x64 - {287A1A8D-C029-4D47-96BC-755C91B7985D}.Debug|x64.Build.0 = Debug|x64 - {287A1A8D-C029-4D47-96BC-755C91B7985D}.Release|x64.ActiveCfg = Release|x64 - {287A1A8D-C029-4D47-96BC-755C91B7985D}.Release|x64.Build.0 = Release|x64 - {1D79FD14-1DF4-4AED-94DF-62E595206DEF}.Debug|x64.ActiveCfg = Debug|x64 - {1D79FD14-1DF4-4AED-94DF-62E595206DEF}.Debug|x64.Build.0 = Debug|x64 - {1D79FD14-1DF4-4AED-94DF-62E595206DEF}.Release|x64.ActiveCfg = Release|x64 - {1D79FD14-1DF4-4AED-94DF-62E595206DEF}.Release|x64.Build.0 = Release|x64 - {B5B60F79-653C-4E41-9721-06C478CE9E7C}.Debug|x64.ActiveCfg = Debug|x64 - {B5B60F79-653C-4E41-9721-06C478CE9E7C}.Debug|x64.Build.0 = Debug|x64 - {B5B60F79-653C-4E41-9721-06C478CE9E7C}.Release|x64.ActiveCfg = Release|x64 - {B5B60F79-653C-4E41-9721-06C478CE9E7C}.Release|x64.Build.0 = Release|x64 - {2D5AD568-F2EE-4B8C-AF81-2C46EB45B0ED}.Debug|x64.ActiveCfg = Debug|x64 - {2D5AD568-F2EE-4B8C-AF81-2C46EB45B0ED}.Debug|x64.Build.0 = Debug|x64 - {2D5AD568-F2EE-4B8C-AF81-2C46EB45B0ED}.Release|x64.ActiveCfg = Release|x64 - {2D5AD568-F2EE-4B8C-AF81-2C46EB45B0ED}.Release|x64.Build.0 = Release|x64 - {2B9F4DFD-C222-477A-9107-1A3C356002A4}.Debug|x64.ActiveCfg = Debug|x64 - {2B9F4DFD-C222-477A-9107-1A3C356002A4}.Debug|x64.Build.0 = Debug|x64 - {2B9F4DFD-C222-477A-9107-1A3C356002A4}.Release|x64.ActiveCfg = Debug|x64 - {2B9F4DFD-C222-477A-9107-1A3C356002A4}.Release|x64.Build.0 = Debug|x64 {3D932849-312C-473C-B74C-ABD1F11A0739}.Debug|x64.ActiveCfg = Debug|x64 {3D932849-312C-473C-B74C-ABD1F11A0739}.Debug|x64.Build.0 = Debug|x64 {3D932849-312C-473C-B74C-ABD1F11A0739}.Release|x64.ActiveCfg = Release|x64 @@ -116,8 +51,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE} = {7EAC5FD7-C9CD-42E8-A24B-3665E854F4CD} - {23A97D0F-B6D9-4B67-84FE-4B52EA7D82EC} = {7EAC5FD7-C9CD-42E8-A24B-3665E854F4CD} {F518ED4B-ADE0-4B5C-A01B-48D9FA216E0C} = {D3C36686-9667-48B2-A14B-FF46E6350A51} {3D932849-312C-473C-B74C-ABD1F11A0739} = {D3C36686-9667-48B2-A14B-FF46E6350A51} {74E04873-BB6F-4115-841D-50C162928B19} = {D3C36686-9667-48B2-A14B-FF46E6350A51} diff --git a/src/Spectre.Database/App.config b/src/Spectre.Algorithms.Tests/App.config similarity index 100% rename from src/Spectre.Database/App.config rename to src/Spectre.Algorithms.Tests/App.config diff --git a/src/Spectre.Algorithms.Tests/Spectre.Algorithms.Tests.csproj b/src/Spectre.Algorithms.Tests/Spectre.Algorithms.Tests.csproj index 1d0040c..b798b94 100644 --- a/src/Spectre.Algorithms.Tests/Spectre.Algorithms.Tests.csproj +++ b/src/Spectre.Algorithms.Tests/Spectre.Algorithms.Tests.csproj @@ -38,9 +38,21 @@ ..\CSharpCodingConvention.ruleset + + ..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + ..\packages\MatlabAlgorithmsNative.1.1.0\lib\MatlabAlgorithmsNative.dll + + ..\packages\Moq.4.7.99\lib\net45\Moq.dll + ..\packages\MatlabAlgorithmsNative.1.1.0\lib\MWArray.dll True @@ -49,11 +61,33 @@ False ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + + ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll True + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Data.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Database.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Dependencies.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Service.dll + + + + ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll + + + ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll + @@ -81,18 +115,14 @@ {9A886AEC-58DB-410D-91B9-C62E157501FA} Spectre.Algorithms - - {70c87af7-3189-4f6c-ac85-93309cf7cfdc} - Spectre.Data - - - {287a1a8d-c029-4d47-96bc-755c91b7985d} - Spectre.Service - + + + + diff --git a/src/Spectre.Algorithms.Tests/Spectre.ico b/src/Spectre.Algorithms.Tests/Spectre.ico new file mode 100644 index 0000000..ce22fc9 Binary files /dev/null and b/src/Spectre.Algorithms.Tests/Spectre.ico differ diff --git a/src/Spectre.Algorithms.Tests/packages.config b/src/Spectre.Algorithms.Tests/packages.config index a79a586..21cb06d 100644 --- a/src/Spectre.Algorithms.Tests/packages.config +++ b/src/Spectre.Algorithms.Tests/packages.config @@ -1,7 +1,14 @@  + + + + + + + \ No newline at end of file diff --git a/src/Spectre.Algorithms/App.config b/src/Spectre.Algorithms/App.config new file mode 100644 index 0000000..7e1d79c --- /dev/null +++ b/src/Spectre.Algorithms/App.config @@ -0,0 +1,17 @@ + + + + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Spectre.Algorithms/Spectre.Algorithms.csproj b/src/Spectre.Algorithms/Spectre.Algorithms.csproj index 83b5181..81db93e 100644 --- a/src/Spectre.Algorithms/Spectre.Algorithms.csproj +++ b/src/Spectre.Algorithms/Spectre.Algorithms.csproj @@ -35,9 +35,21 @@ bin\x64\Release\Spectre.Algorithms.xml + + ..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + ..\packages\MatlabAlgorithmsNative.1.1.0\lib\MatlabAlgorithmsNative.dll + + ..\packages\Moq.4.7.99\lib\net45\Moq.dll + ..\packages\MatlabAlgorithmsNative.1.1.0\lib\MWArray.dll True @@ -46,8 +58,30 @@ False ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + + ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Data.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Database.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Dependencies.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Service.dll + + + + ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll + + + ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll + @@ -72,18 +106,16 @@ - - {70c87af7-3189-4f6c-ac85-93309cf7cfdc} - Spectre.Data - - - + + + + - \ No newline at end of file diff --git a/src/Spectre.Data.Tests/packages.config b/src/Spectre.Data.Tests/packages.config deleted file mode 100644 index fe81e33..0000000 --- a/src/Spectre.Data.Tests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Spectre.Data/Datasets/BasicTextDataset.cs b/src/Spectre.Data/Datasets/BasicTextDataset.cs deleted file mode 100644 index ea9bd86..0000000 --- a/src/Spectre.Data/Datasets/BasicTextDataset.cs +++ /dev/null @@ -1,566 +0,0 @@ -/* - * BasicTextDataset.cs - * Class representing dataset created from streaming an ordinary text - * file containing formatted data. - * - Copyright 2017 Dariusz Kuchta, Michał Gallus - - 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. -*/ - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.IO.Abstractions; -using System.Linq; -using System.Text; -using System.Threading; -using Spectre.Data.Structures; -using Spectre.Dependencies; - -namespace Spectre.Data.Datasets -{ - /// - /// Class representing dataset created from streaming an ordinary text file containing formatted data. - /// - public class BasicTextDataset : IDataset - { - #region Fields - - /// - /// Container for storing spatial coordinates for every loaded spectrum. - /// - private List _spatialCoordinates; - - /// - /// Array of m/z values for all the spectras. - /// - private double[] _mz; - - /// - /// Container for storing intensity values for every loaded spectrum. - /// - private List _intensityArray; - - /// - /// Container for storing label values for every spectrum. - /// - private List _labels; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// Constructor with file initialization. - /// - /// Path to the text file. - public BasicTextDataset(string textFilePath) - { - FileSystem = DependencyResolver.GetService(); - CreateFromFile(textFilePath); - } - - /// - /// Initializes a new instance of the class. - /// Constructor with raw value initialization. - /// - /// Array of m/z values. - /// Array of intensity values. - /// Array of spatial coordinates. - public BasicTextDataset(double[] mz, double[,] data, int[,] coordinates) - { - FileSystem = DependencyResolver.GetService(); - CreateFromRawData(mz, data, coordinates); - } - - #endregion - - #region Properties - - /// - public Metadata Metadata { get; private set; } - - /// - /// See for description. - /// - public IEnumerable SpatialCoordinates - { - get { return _spatialCoordinates; } - private set { _spatialCoordinates = value.ToList(); } - } - - /// - /// See for description. - /// - public IEnumerable Labels - { - get { return _labels; } - set { _labels = value.ToList(); } - } - - /// - /// See for description. - /// - public int SpectrumLength - { - get { return _mz.Length; } - } - - /// - /// See for description. - /// - public int SpectrumCount - { - get { return _intensityArray.Count; } - } - - /// - /// Handle to file system. - /// - private IFileSystem FileSystem { get; } - - #endregion - - #region IDataset Methods - - /// - /// Method for creating new dataset from text file, overwriting current data. - /// - /// Path to a text file. - /// Thrown where there is a problem with file loading. - public void CreateFromFile(string filePath) - { - try - { - using (var sr = FileSystem.File.OpenText(filePath)) - { - var metadata = sr.ReadLine(); // global metadata -#pragma warning disable SA1305 // Field names must not use Hungarian notation - var mzValues = sr.ReadLine() -#pragma warning restore SA1305 // Field names must not use Hungarian notation - .Split(separator: null); - mzValues = mzValues.Where(predicate: str => !string.IsNullOrEmpty(str)) - .ToArray(); - if (mzValues.Length < 1) - { - throw new InvalidDataException(message: "No m/z values found."); - } - _mz = new double[mzValues.Length]; - for (var i = 0; i < _mz.Length; i++) - { - if (!double.TryParse( - s: mzValues[i], - style: NumberStyles.Any, - provider: CultureInfo.InvariantCulture, - result: out _mz[i])) - { - _mz[i] = double.NaN; - } - } - } - } - catch (NullReferenceException e) - { - throw new IOException( - message: "M/z data could not be parsed from file " + filePath + ".", - innerException: e); - } - catch (InvalidDataException e) - { - throw new IOException( - message: "M/z array parsed from file " + filePath + " is empty.", - innerException: e); - } - catch (Exception e) - { - // catch remaining Exceptions that are related to StreamReader - throw new IOException(message: "Streamer failed to read " + filePath + " file.", innerException: e); - } - - _intensityArray = new List(); - _spatialCoordinates = new List(); - _labels = new List(); - AppendFromFile(filePath); - } - - /// - public void CreateFromRawData(double[] mz, double[,] data, int[,] coordinates) - { - if ((mz == null) || (data == null)) - { - throw new InvalidDataException(message: "The input data is null."); - } - if ((coordinates != null) && (coordinates.GetLength(dimension: 0) != data.GetLength(dimension: 0))) - { - throw new InvalidDataException( - message: "Amount of input spectra does not match the amount of spatial coordinates."); - } - if (mz.Length != data.GetLength(dimension: 1)) - { - throw new InvalidDataException(message: "Length of the data must be equal to length of m/z values."); - } - - _intensityArray = new List(); - _spatialCoordinates = new List(); - _labels = new List(); - _mz = mz; - AppendFromRawData(data, coordinates); - } - - /// - /// Method parsing the whole text file and initializing the array - /// with found data. - /// - /// Path to the text file. - /// Thrown where there is a problem with file parsing. - public void AppendFromFile(string filePath) - { - try - { - using (var sr = FileSystem.File.OpenText(filePath)) - { - sr.ReadLine(); // omit global metadata - sr.ReadLine(); // omit m/z values - while (sr.Peek() > -1) - { - var metadata = sr.ReadLine() - ?.Split(separator: null); - var intensities = sr.ReadLine() - ?.Split(separator: null); - intensities = intensities.Where(predicate: str => !string.IsNullOrEmpty(str)) - .ToArray(); - if ((metadata.Length == 0) || (intensities.Length == 0)) - { - continue; - } - if (intensities.Length != _mz.Length) - { - throw new InvalidDataException( - message: "Length of the data must be equal to length of m/z values."); - } - - int x, - y, - z, - label; - - if (!int.TryParse( - s: metadata.Length > 0 ? metadata[0] : null, - style: NumberStyles.Any, - provider: CultureInfo.InvariantCulture, - result: out x)) - { - x = -1; - } - if (!int.TryParse( - s: metadata.Length > 1 ? metadata[1] : null, - style: NumberStyles.Any, - provider: CultureInfo.InvariantCulture, - result: out y)) - { - y = -1; - } - if (!int.TryParse( - s: metadata.Length > 2 ? metadata[2] : null, - style: NumberStyles.Any, - provider: CultureInfo.InvariantCulture, - result: out z)) - { - z = -1; - } - if (!int.TryParse( - s: metadata.Length > 3 ? metadata[3] : null, - style: NumberStyles.Any, - provider: CultureInfo.InvariantCulture, - result: out label)) - { - label = -1; - } - - _spatialCoordinates.Add(item: new SpatialCoordinates(x, y, z)); - _intensityArray.Add(item: new double[_mz.Length]); - _labels.Add(label); - - var backIdx = _intensityArray.Count - 1; - for (var i = 0; i < intensities.Length; i++) - { - if (!double.TryParse( - s: intensities[i], - style: NumberStyles.Any, - provider: CultureInfo.InvariantCulture, - result: out _intensityArray[backIdx][i])) - { - _intensityArray[backIdx][i] = double.NaN; - } - } - } - } - } - catch (InvalidDataException e) - { - throw new IOException(message: "Length mismatch in parsed data.", innerException: e); - } - catch (Exception e) - { - // catch remaining Exceptions that are related to StreamReader - throw new IOException(message: "Streamer failed to read " + filePath + " file.", innerException: e); - } - } - - /// - public void AppendFromRawData(double[,] data, int[,] coordinates) - { - if (data == null) - { - throw new InvalidDataException(message: "The input data is null."); - } - if ((coordinates != null) && (coordinates.GetLength(dimension: 0) != data.GetLength(dimension: 0))) - { - throw new InvalidDataException( - message: "Amount of input spectra does not match the amount of spatial coordinates."); - } - if (_mz.Length != data.GetLength(dimension: 1)) - { - throw new InvalidDataException( - message: "The length of input data does not match the length of present data."); - } - - var coordinateDimensions = coordinates?.GetLength(dimension: 1) ?? 0; - - for (var i = 0; i < data.GetLength(dimension: 0); i++) - { - int[] xyz = { -1, -1, -1 }; - for (var j = 0; j < coordinateDimensions; j++) - { - xyz[j] = coordinates[i, j]; - } - _spatialCoordinates.Add(item: new SpatialCoordinates(x: xyz[0], y: xyz[1], z: xyz[2])); - _intensityArray.Add(item: new double[data.GetLength(dimension: 1)]); - _labels.Add(item: -1); - - var backIdx = _intensityArray.Count - 1; - for (var j = 0; j < data.GetLength(dimension: 1); j++) - { - _intensityArray[backIdx][j] = data[i, j]; - } - } - } - - /// - public DataPoint GetDataPoint(int spectrumIdx, int valueIdx) - { - return new DataPoint( - mz: _mz[valueIdx], - intensity: _intensityArray[spectrumIdx][valueIdx]); - } - - /// - public DataPoint[] GetDataPoints(int spectrumIdx, int valueIdxFrom, int valueIdxTo) - { - if (valueIdxFrom >= valueIdxTo) - { - throw new IndexOutOfRangeException(); - } - var valueCnt = valueIdxTo - valueIdxFrom; - - var result = new DataPoint[valueCnt]; - for (var i = 0; i < valueCnt; i++) - { - result[i] = new DataPoint( - mz: _mz[valueIdxFrom + i], - intensity: _intensityArray[spectrumIdx][valueIdxFrom + i]); - } - return result; - } - - /// - public SpatialCoordinates GetSpatialCoordinates(int spectrumIdx) - { - return _spatialCoordinates[spectrumIdx]; - } - - /// - public double[] GetRawMzArray() - { - return _mz; - } - - /// - public double GetRawMzValue(int index) - { - return _mz[index]; - } - - /// - public double GetRawIntensityValue(int spectrumIdx, int valueIdx) - { - return _intensityArray[spectrumIdx][valueIdx]; - } - - /// - public double[] GetRawIntensityArray(int spectrumIdx) - { - return _intensityArray[spectrumIdx]; - } - - /// - public double[] GetRawIntensityRow(int valueIdx) - { - var result = new double[_intensityArray.Count]; - for (var i = 0; i < _intensityArray.Count; i++) - { - result[i] = _intensityArray[i][valueIdx]; - } - return result; - } - - /// - public double[,] GetRawIntensityRange(int spectrumIdxFrom, int spectrumIdxTo, int valueIdxFrom, int valueIdxTo) - { - if ((spectrumIdxFrom >= spectrumIdxTo) || (valueIdxFrom >= valueIdxTo)) - { - throw new IndexOutOfRangeException(); - } - var spectrumCnt = spectrumIdxTo - spectrumIdxFrom; - var valueCnt = valueIdxTo - valueIdxFrom; - - var result = new double[spectrumCnt, valueCnt]; - - for (var i = 0; i < spectrumCnt; i++) - { - for (var j = 0; j < valueCnt; j++) - { - result[i, j] = _intensityArray[index: spectrumIdxFrom + i][valueIdxFrom + j]; - } - } - - return result; - } - - /// - public double[,] GetRawIntensities() - { - return GetRawIntensityRange( - spectrumIdxFrom: 0, - spectrumIdxTo: SpectrumCount, - valueIdxFrom: 0, - valueIdxTo: SpectrumLength); - } - - /// - public int[,] GetRawSpacialCoordinates(bool is2D) - { - var dimensions = is2D ? 2 : 3; - - var result = new int[SpectrumCount, dimensions]; - for (var i = 0; i < SpectrumCount; i++) - { - var xyz = _spatialCoordinates[i] - .GetRaw(); - for (var j = 0; j < dimensions; j++) - { - result[i, j] = xyz[j]; - } - } - - return result; - } - - /// - public void SaveToFile(string path) - { - var fileBuilder = new StringBuilder(); - - // fixes comma-instead-of-dot related issues - BeginInvariantCulture(); - { - AppendMetadata(fileBuilder); - AppendMzValues(fileBuilder); - AppendIntensitiesAndLocalMetadata(fileBuilder); - - SaveDataToFile(path, fileBuilder); - } - EndInvariantCulture(); - } - - #endregion - - #region Private methods - - private void SaveDataToFile(string path, StringBuilder fileBuilder) - { - using (var sw = File.CreateText(path)) - { - sw.Write(value: fileBuilder.ToString()); - } - } - - private void AppendIntensitiesAndLocalMetadata(StringBuilder fileBuilder) - { - var spectrumBuilder = new StringBuilder(); - var coordinates = _spatialCoordinates.ToArray(); - var labels = _labels.ToArray(); - var intensities = _intensityArray.ToArray(); - - for (var i = 0; i < intensities.Length; i++) - { - fileBuilder.AppendLine(value: $"{coordinates[i].ToString()} {labels[i].ToString()}"); - - for (var j = 0; - j - < intensities[0] - .Length; - j++) - { - spectrumBuilder.Append(value: intensities[i][j]); - spectrumBuilder.Append(value: ' '); - } - fileBuilder.AppendLine(value: spectrumBuilder.ToString()); - spectrumBuilder.Clear(); - } - } - - private void AppendMzValues(StringBuilder fileBuilder) - { -#pragma warning disable SA1305 // Field names must not use Hungarian notation - var mzValuesString = new StringBuilder(); -#pragma warning restore SA1305 // Field names must not use Hungarian notation - foreach (var mz in _mz) - { - mzValuesString.Append(mz); - mzValuesString.Append(value: ' '); - } - fileBuilder.AppendLine(value: mzValuesString.ToString()); - } - - private void AppendMetadata(StringBuilder fileBuilder) - { - fileBuilder.AppendLine(Metadata.Description); - } - - private void EndInvariantCulture() - { - Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture; - } - - private void BeginInvariantCulture() - { - Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; - } - - #endregion - } -} diff --git a/src/Spectre.Data/Datasets/IDataset.cs b/src/Spectre.Data/Datasets/IDataset.cs deleted file mode 100644 index a797010..0000000 --- a/src/Spectre.Data/Datasets/IDataset.cs +++ /dev/null @@ -1,186 +0,0 @@ -/* - * IDataset.cs - * Contains interface class for basic functionalities of dataset - * representing measurements from single sample point - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System.Collections.Generic; -using Spectre.Data.Structures; - -namespace Spectre.Data.Datasets -{ - /// - /// Contains interface for basic functionalities of dataset representing measurements from single sample point. - /// - public interface IDataset - { - #region Metadata - - /// - /// Property containing metadata of the dataset. - /// - Metadata Metadata { get; } - - /// - /// Property for storing spacial coordinates for spectras in dataset. - /// - IEnumerable SpatialCoordinates { get; } - - /// - /// Property containing number of values in a single spectrum. - /// - int SpectrumLength { get; } - - /// - /// Property containing amount of spectra existing in dataset. - /// - int SpectrumCount { get; } - - #endregion - - #region Data creation - - /// - /// Method for creating new dataset from file, overwriting current data. - /// - /// Path to a file. - void CreateFromFile(string filePath); - - /// - /// Method for creating new dataset from raw data, overwriting current data. - /// - /// Array of m/z values. - /// Multidimensional array of intensity values. - /// Spatial coordinates of input spectra. - void CreateFromRawData(double[] mz, double[,] data, int[,] coordinates); - - /// - /// Method for appending new data from file. - /// - /// Path to a file. - void AppendFromFile(string filePath); - - /// - /// Method for appending new data from raw arrays. - /// - /// Multidimensional array of intensity values. - /// Spatial coordinates of input spectra. - void AppendFromRawData(double[,] data, int[,] coordinates); - - #endregion - - #region Data access - - /// - /// Method creating structure from dataset. - /// - /// Index of spectrum. - /// Index of value. - /// Created structure. - DataPoint GetDataPoint(int spectrumIdx, int valueIdx); - - /// - /// Method creating array of structures from dataset. - /// - /// Index of spectrum. - /// Beginning value index. - /// Ending value index. - /// Created array. - DataPoint[] GetDataPoints(int spectrumIdx, int valueIdxFrom, int valueIdxTo); - - /// - /// Method returning spatial coordinates of given spectrum. - /// - /// Index of spectrum. - /// Spatial coordinates of given spectrum. - SpatialCoordinates GetSpatialCoordinates(int spectrumIdx); - - #endregion - - #region Raw data access - - /// - /// Getter for whole array of raw m/z values used in dataset. - /// - /// Array of all m/z values. - double[] GetRawMzArray(); - - /// - /// Getter for single raw m/z value used in dataset. - /// - /// Index of value. - /// Value of m/z at specified index. - double GetRawMzValue(int index); - - /// - /// Getter for single raw intensity value present in dataset. - /// - /// Index of spectrum. - /// Index of value. - /// Value of intensity in specified spectrum at specified position. - double GetRawIntensityValue(int spectrumIdx, int valueIdx); - - /// - /// Getter for whole array of raw intensity values for given spectrum. - /// - /// Index of spectrum. - /// Array of intensities in specified spectrum. - double[] GetRawIntensityArray(int spectrumIdx); - - /// - /// Getter for row of intensities at given value position from all spectra present in dataset. - /// - /// Index of value. - /// Array of intensity values from all spectra at given value position. - double[] GetRawIntensityRow(int valueIdx); - - /// - /// Getter for arbitrary range of intensities picked from inside specified boundaries. - /// - /// Starting spectrum index. - /// Ending spectrum index. - /// Starting value index. - /// Ending value index. - /// Multidimensional array of intensities. - double[,] GetRawIntensityRange(int spectrumIdxFrom, int spectrumIdxTo, int valueIdxFrom, int valueIdxTo); - - /// - /// Getter for all the intensity values from all spectra from dataset. - /// - /// Multidimensional array of all the intensities present in dataset. - double[,] GetRawIntensities(); - - /// - /// Getter for spatial coordinates of all spectra present in dataset. - /// - /// true, if dataset is 2D - /// Multidimensional array of spatial coordinates. - int[,] GetRawSpacialCoordinates(bool is2D); - - #endregion - - #region File storage - - /// - /// Saves dataset to file using the default format. - /// - /// Path to the file. - void SaveToFile(string path); - - #endregion - } -} diff --git a/src/Spectre.Data/Properties/AssemblyInfo.cs b/src/Spectre.Data/Properties/AssemblyInfo.cs deleted file mode 100644 index 351c95c..0000000 --- a/src/Spectre.Data/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Spectre.Data")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Spectre.Data")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("70c87af7-3189-4f6c-ac85-93309cf7cfdc")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Data/Spectre.Data.csproj b/src/Spectre.Data/Spectre.Data.csproj deleted file mode 100644 index 0a9fb25..0000000 --- a/src/Spectre.Data/Spectre.Data.csproj +++ /dev/null @@ -1,78 +0,0 @@ - - - - - Debug - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC} - Library - Properties - Spectre.Data - Spectre.Data - v4.6.1 - 512 - - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - ..\CSharpCodingConvention.ruleset - true - bin\x64\Debug\Spectre.Data.xml - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - ..\CSharpCodingConvention.ruleset - bin\x64\Release\Spectre.Data.xml - - - - - - ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll - - - - - - - - - - - - - - - - - - - - - - - - - - {2b9f4dfd-c222-477a-9107-1a3c356002a4} - Spectre.Dependencies - - - - - \ No newline at end of file diff --git a/src/Spectre.Data/Structures/DataPoint.cs b/src/Spectre.Data/Structures/DataPoint.cs deleted file mode 100644 index e0ee9d3..0000000 --- a/src/Spectre.Data/Structures/DataPoint.cs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * DataPoint.cs - * Contains representation for single measurement from MALDI - * spectrometry for single XY coordinate. - * - Copyright 2017 Dariusz Kuchta - - 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 Spectre.Data.Structures -{ - /// - /// Contains representation for single measurement from MALDI spectrometry for single XY coordinate. - /// - public class DataPoint - { - #region Constructors - - /// - /// Initializes a new instance of the class - /// with user defined values of m/z and intensity. - /// - /// Value of m/z. - /// Value of intensity. - public DataPoint(double mz, double intensity) - { - Mz = mz; - Intensity = intensity; - } - - #endregion - - #region Fields - - /// - /// Value of m/z. - /// - public double Mz { get; } - - /// - /// Value of intensity. - /// - public double Intensity { get; } - - #endregion - } -} diff --git a/src/Spectre.Data/Structures/Metadata.cs b/src/Spectre.Data/Structures/Metadata.cs deleted file mode 100644 index bd16766..0000000 --- a/src/Spectre.Data/Structures/Metadata.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Metadata.cs - * Contains struct for storing metadata of associated dataset. - * - Copyright 2017 Dariusz Kuchta - - 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 Spectre.Data.Structures -{ - /// - /// Contains struct for storing metadata of associated dataset. - /// - public struct Metadata - { - /// - /// The description of the dataset. - /// Dummy property right now. - /// - public string Description; - - /// - /// Default template instance for class. - /// - /// Default metadata. - public static Metadata Default() - { - Metadata metadata; - metadata.Description = "default"; - return metadata; - } - } -} diff --git a/src/Spectre.Data/Structures/SpatialCoordinates.cs b/src/Spectre.Data/Structures/SpatialCoordinates.cs deleted file mode 100644 index b03869d..0000000 --- a/src/Spectre.Data/Structures/SpatialCoordinates.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SpatialCoordinates.cs - * Struct used for storing the spacial coordinates of a spectrum. - * - Copyright 2017 Dariusz Kuchta - - 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 Spectre.Data.Structures -{ - /// - /// Contains struct used for storing the spacial coordinates of a spectrum. - /// - public struct SpatialCoordinates - { - /// - /// Initializes a new instance of the struct. - /// Uses user defined values of spatial coordinates. - /// - /// X coordinate. - /// Y coordinate. - /// Z coordinate. - public SpatialCoordinates(int x, int y, int z) - { - X = x; - Y = y; - Z = z; - } - - /// - /// Gets the x. - /// - /// - /// The x. - /// - public int X { get; } - - /// - /// Gets the y. - /// - /// - /// The y. - /// - public int Y { get; } - - /// - /// Gets the z. - /// - /// - /// The z. - /// - public int Z { get; } - - /// - /// Returns raw form of spatial coordintates in order X, Y, Z. - /// - /// Array of values representing spatial coordinates. - public int[] GetRaw() - { - return new[] { X, Y, Z }; - } - - /// - /// Converts spatial coordinates into space-separated string of x, y and z values - /// - /// String of form "x y z" - public override string ToString() - { - return X.ToString() + ' ' + Y + ' ' + Z; - } - } -} diff --git a/src/Spectre.Data/packages.config b/src/Spectre.Data/packages.config deleted file mode 100644 index d9c48b7..0000000 --- a/src/Spectre.Data/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Spectre.DataValidatorApp/App.config b/src/Spectre.DataValidatorApp/App.config index bae5d6d..e78f703 100644 --- a/src/Spectre.DataValidatorApp/App.config +++ b/src/Spectre.DataValidatorApp/App.config @@ -1,6 +1,20 @@ - + - - - - + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Spectre.DataValidatorApp/Spectre.DataValidatorApp.csproj b/src/Spectre.DataValidatorApp/Spectre.DataValidatorApp.csproj index 8ee941d..81ccdde 100644 --- a/src/Spectre.DataValidatorApp/Spectre.DataValidatorApp.csproj +++ b/src/Spectre.DataValidatorApp/Spectre.DataValidatorApp.csproj @@ -54,8 +54,42 @@ bin\x64\Release\Spectre.DataValidatorApp.xml + + ..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + + + ..\packages\Moq.4.7.99\lib\net45\Moq.dll + + + ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Data.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Database.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Dependencies.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Service.dll + + + + ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll + + + ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll + @@ -75,12 +109,6 @@ - - - {70c87af7-3189-4f6c-ac85-93309cf7cfdc} - Spectre.Data - - False @@ -93,5 +121,8 @@ false + + + \ No newline at end of file diff --git a/src/Spectre.DataValidatorApp/Spectre.ico b/src/Spectre.DataValidatorApp/Spectre.ico new file mode 100644 index 0000000..ce22fc9 Binary files /dev/null and b/src/Spectre.DataValidatorApp/Spectre.ico differ diff --git a/src/Spectre.DataValidatorApp/packages.config b/src/Spectre.DataValidatorApp/packages.config index 2718f70..6761910 100644 --- a/src/Spectre.DataValidatorApp/packages.config +++ b/src/Spectre.DataValidatorApp/packages.config @@ -1,4 +1,11 @@  + + + + + + + \ No newline at end of file diff --git a/src/Spectre.Database.Tests/Properties/AssemblyInfo.cs b/src/Spectre.Database.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 0891f9e..0000000 --- a/src/Spectre.Database.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Spectre.Database.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Spectre.Database.Tests")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("2d5ad568-f2ee-4b8c-af81-2c46eb45b0ed")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Database.Tests/QueryTests.cs b/src/Spectre.Database.Tests/QueryTests.cs deleted file mode 100644 index 8652cb5..0000000 --- a/src/Spectre.Database.Tests/QueryTests.cs +++ /dev/null @@ -1,156 +0,0 @@ -/* - * QueryTests.cs - * Testing queries for translation - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Database.Entities; -using Spectre.Database.Utils; -using Spectre.Database.Contexts; -using System.Data.Entity; -using NUnit.Framework; -using Moq; - -namespace Spectre.Database.Tests -{ - [TestFixture] - public class QueryTests - { - private Mock _mockContext = new Mock(); - - [SetUp] - public void SetUp() - { - var data = new List - { - new Dataset { FriendlyName = "FriendlyName1", Hash = "Hash1", UploadNumber = "UploadNumber1"}, - new Dataset { FriendlyName = "FriendlyName2", Hash = "Hash2", UploadNumber = "UploadNumber2"}, - new Dataset { FriendlyName = "FriendlyName3", Hash = "Hash3", UploadNumber = "UploadNumber3"}, - }.AsQueryable(); - - var mockSet = new Mock>(); - mockSet.As>().Setup(m => m.Provider).Returns(data.Provider); - mockSet.As>().Setup(m => m.Expression).Returns(data.Expression); - mockSet.As>().Setup(m => m.ElementType).Returns(data.ElementType); - mockSet.As>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); - - _mockContext.Setup(c => c.Datasets).Returns(mockSet.Object); - } - - [Test] - public void HashToUploadNumber_finds_proper_uploadnumber_for_given_hash() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.HashToUploadNumberOrDefault("Hash1"); - - Assert.AreEqual("UploadNumber1", dataset); - } - - [Test] - public void FriendlyNameToUploadNumber_finds_proper_uploadnumber_for_given_friendlyname() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.FriendlyNameToUploadNumberOrDefault("FriendlyName2"); - - Assert.AreEqual("UploadNumber2", dataset); - } - - [Test] - public void HashToUploadNumer_returns_null_for_not_existing_hash() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.HashToUploadNumberOrDefault("NotExistingHash"); - - Assert.IsNull(dataset); - } - - [Test] - public void FriendlyNameToUploadNumer_returns_null_for_not_existing_friendly_name() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.FriendlyNameToUploadNumberOrDefault("NotExistingFriendlyName"); - - Assert.IsNull(dataset); - } - - [Test] - public void UploadNumberToHash_finds_proper_hash_for_given_uploadnumber() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.UploadNumberToHashOrDefault("UploadNumber3"); - - Assert.AreEqual(dataset, "Hash3"); - } - - [Test] - public void UploadNumberToHash_returns_null_for_not_existing_Upload_Name() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.UploadNumberToHashOrDefault("NotExistingUploadNumber"); - - Assert.IsNull(dataset); - } - - [Test] - public void HashToFriendlyName_finds_proper_friendlyname_for_given_hash() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.HashToFriendlyNameOrDefault("Hash1"); - - Assert.AreEqual(dataset, "FriendlyName1"); - } - - [Test] - public void HashToFriendlyName_returns_null_for_not_existing_Hash() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.HashToFriendlyNameOrDefault("NotExistingHash"); - - Assert.IsNull(dataset); - } - - [Test] - public void UploadNumberToFriendlyName_finds_proper_friendlyname_for_given_uploadnumber() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.UploadNumberToFriendlyNameOrDefault("UploadNumber2"); - - Assert.AreEqual(dataset, "FriendlyName2"); - } - - [Test] - public void UploadNumberToFriendlyName_returns_null_for_not_existing_uploadnumber() - { - var service = new DatasetDetailsFinder(_mockContext.Object); - - var dataset = service.HashToFriendlyNameOrDefault("NotExistingUploadNumber"); - - Assert.IsNull(dataset); - } - } -} \ No newline at end of file diff --git a/src/Spectre.Database.Tests/Spectre.Database.Tests.csproj b/src/Spectre.Database.Tests/Spectre.Database.Tests.csproj deleted file mode 100644 index 14af401..0000000 --- a/src/Spectre.Database.Tests/Spectre.Database.Tests.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Debug - AnyCPU - {2D5AD568-F2EE-4B8C-AF81-2C46EB45B0ED} - Library - Properties - Spectre.Database.Tests - Spectre.Database.Tests - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - ..\CSharpCodingConvention.ruleset - true - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - ..\CSharpCodingConvention.ruleset - - - - ..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll - - - ..\packages\Moq.4.7.99\lib\net45\Moq.dll - - - ..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll - - - - - - - - - - - - - - - {b5b60f79-653c-4e41-9721-06c478ce9e7c} - Spectre.Database - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/src/Spectre.Database.Tests/packages.config b/src/Spectre.Database.Tests/packages.config deleted file mode 100644 index f85aa5e..0000000 --- a/src/Spectre.Database.Tests/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/Spectre.Database/Configurations/Migrations.cs b/src/Spectre.Database/Configurations/Migrations.cs deleted file mode 100644 index b851bab..0000000 --- a/src/Spectre.Database/Configurations/Migrations.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Migrations.cs - * Configuration which creates automatic migrations - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System.Data.Entity.Migrations; - -namespace Spectre.Database.Configurations -{ - /// - /// Configuration of dataset migrations. - /// - /// - internal sealed class Migrations : DbMigrationsConfiguration - { - /// - /// Initializes a new instance of the class. - /// - public Migrations() - { - AutomaticMigrationsEnabled = true; - } - } -} diff --git a/src/Spectre.Database/Contexts/DatasetsContext.cs b/src/Spectre.Database/Contexts/DatasetsContext.cs deleted file mode 100644 index 0724187..0000000 --- a/src/Spectre.Database/Contexts/DatasetsContext.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* - * DatasetsContext.cs - * Database context for connections with database. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System.Data.Entity; -using Spectre.Database.Entities; - -namespace Spectre.Database.Contexts -{ - /// - /// Context for database access. - /// - /// - public class DatasetsContext : DbContext - { - /// - /// Gets or sets the datasets. - /// - /// - /// The datasets. - /// - public virtual DbSet Datasets { get; set; } - - /// - /// Gets or sets the operation datasets. - /// - /// - /// The operation datasets. - /// - public virtual DbSet Operations { get; set; } - } -} diff --git a/src/Spectre.Database/Entities/Dataset.cs b/src/Spectre.Database/Entities/Dataset.cs deleted file mode 100644 index a21365c..0000000 --- a/src/Spectre.Database/Entities/Dataset.cs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Dataset.cs - * Database model of dataset metadata. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using Spectre.Database.Entities.Enums; - -namespace Spectre.Database.Entities -{ - /// - /// Abstraction of dataset metadata needed to load a dataset. - /// - public class Dataset - { - /// - /// Gets or sets the item identifier. - /// - /// - /// The item identifier. - /// - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int DatasetId { get; set; } - - /// - /// The upload number - /// - /// - /// The upload number. - /// - public string UploadNumber { get; set; } - - /// - /// Gets or sets the hash. - /// - /// - /// The hash. - /// - public string Hash { get; set; } - - /// - /// Gets or sets the friendly name. - /// - /// - /// The friendly name - /// - public string FriendlyName { get; set; } - - ///// - ///// Gets or sets the owner. - ///// - ///// - ///// The owner. - ///// - // public string Owner { get; set; } will be implemented with proper User entity when OAuth support lands - - /// - /// Gets or sets the upload time. - /// - /// - /// The upload time. - /// - public DateTime UploadTime { get; set; } - - /// - /// Gets or sets the description of the dataset. - /// - /// - /// The description. - /// - public string Description { get; set; } - - /// - /// Gets or sets the type dataset. Either public, private or shared. - /// - /// - /// The type. - /// - public AccessType Type { get; set; } - } -} diff --git a/src/Spectre.Database/Entities/Enums/AccessType.cs b/src/Spectre.Database/Entities/Enums/AccessType.cs deleted file mode 100644 index 0f0eb41..0000000 --- a/src/Spectre.Database/Entities/Enums/AccessType.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * AccessType.cs - * File providing enumeration for entity class. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Spectre.Database.Entities.Enums -{ - /// - /// Enumeration for types of the AccessType. - /// - public enum AccessType - { - /// - /// Dataset available to the public. - /// - Public, - - /// - /// Dataset available only to the owner. - /// - Private, - - /// - /// Dataset available to users with link. - /// - Shared - } -} \ No newline at end of file diff --git a/src/Spectre.Database/Entities/Enums/OperationType.cs b/src/Spectre.Database/Entities/Enums/OperationType.cs deleted file mode 100644 index 230c619..0000000 --- a/src/Spectre.Database/Entities/Enums/OperationType.cs +++ /dev/null @@ -1,31 +0,0 @@ -/* - * OperationType.cs - * File providing enumeration for entity class. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Spectre.Database.Entities.Enums -{ - /// - /// Enumeration for types of the operation type. - /// - public enum OperationType - { } -} \ No newline at end of file diff --git a/src/Spectre.Database/Entities/Enums/Status.cs b/src/Spectre.Database/Entities/Enums/Status.cs deleted file mode 100644 index a7ebbec..0000000 --- a/src/Spectre.Database/Entities/Enums/Status.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Status.cs - * File providing enumeration for entity class. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Spectre.Database.Entities.Enums -{ - /// - /// Enumeration for types of the operation status. - /// - public enum Status - { - /// - /// Operation is idling. - /// - Idle, - - /// - /// Operation is working. - /// - Working, - - /// - /// Operation is finished. - /// - Finished, - - /// - /// The operation is invalid. - /// - Invalid - } -} \ No newline at end of file diff --git a/src/Spectre.Database/Entities/Operation.cs b/src/Spectre.Database/Entities/Operation.cs deleted file mode 100644 index 7f73644..0000000 --- a/src/Spectre.Database/Entities/Operation.cs +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Operation.cs - * Entity providing informations about operation. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using Spectre.Database.Entities.Enums; - -namespace Spectre.Database.Entities -{ - /// - /// Class for specifying information about the operation performed on the dataset. - /// - public class Operation - { - /// - /// Gets or sets the identifier. - /// - /// - /// The identifier. - /// - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int OperationId { get; set; } - - /// - /// Gets or sets the inputs. - /// - /// - /// The inputs. - /// - public List Inputs { get; set; } - - /// - /// Gets or sets the outputs. - /// - /// - /// The outputs. - /// - public List Outputs { get; set; } - - /// - /// Gets or sets the parameters. - /// - /// - /// The parameters. (JSON string) - /// - public string Parameters { get; set; } - - /// - /// Gets or sets the type of the operation. - /// - /// - /// The type of the operation. - /// - public OperationType Type { get; set; } - - /// - /// Gets or sets the operation status. - /// - /// - /// The operation status. - /// - public Status OperationStatus { get; set; } - - /// - /// Gets or sets the information about the validation error. - /// - /// - /// The log. - /// - public string Log { get; set; } - } -} diff --git a/src/Spectre.Database/Properties/AssemblyInfo.cs b/src/Spectre.Database/Properties/AssemblyInfo.cs deleted file mode 100644 index c0d03d4..0000000 --- a/src/Spectre.Database/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Spectre.Database")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Spectre.Database")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b5b60f79-653c-4e41-9721-06c478ce9e7c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Database/Spectre.Database.csproj b/src/Spectre.Database/Spectre.Database.csproj deleted file mode 100644 index d11fa5d..0000000 --- a/src/Spectre.Database/Spectre.Database.csproj +++ /dev/null @@ -1,72 +0,0 @@ - - - - - Debug - {B5B60F79-653C-4E41-9721-06C478CE9E7C} - Library - Properties - Spectre.Database - Spectre.Database - v4.5.2 - 512 - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - ..\CSharpCodingConvention.ruleset - bin\x64\Debug\Spectre.Database.xml - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - ..\CSharpCodingConvention.ruleset - bin\x64\Release\Spectre.Database.xml - - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Spectre.Database/Utils/DatasetDetailsFinder.cs b/src/Spectre.Database/Utils/DatasetDetailsFinder.cs deleted file mode 100644 index 7254f2f..0000000 --- a/src/Spectre.Database/Utils/DatasetDetailsFinder.cs +++ /dev/null @@ -1,170 +0,0 @@ -/* - * DatasetDetailsFinder.cs - * Class for translating hash and friendly name to name of the file. - * - Copyright 2017 Roman Lisak - - 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 Spectre.Database.Utils -{ - using System; - using System.Collections.Generic; - using System.Data.Entity; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Spectre.Database.Contexts; - using Spectre.Database.Entities; - - /// - /// Class for finding the path of chosen property. - /// - public class DatasetDetailsFinder : IDatasetDetailsFinder - { - /// - /// The context used for queries. - /// - private DatasetsContext _context; - - /// - /// Initializes a new instance of the class. - /// - /// The context. - public DatasetDetailsFinder(DatasetsContext context) - { - _context = context; - } - - /// - /// Query for translating hash to upload number. - /// - /// The hash. - /// - /// Returns UploadNumber for Hash. - /// Null for not existing Hash. - /// - public virtual string HashToUploadNumberOrDefault(string hash) - { - if (_context.Datasets.Any(o => o.Hash == hash)) - { - var dataset = _context.Datasets - .Where(b => b.Hash == hash) - .FirstOrDefault(); - - return dataset.UploadNumber.ToString(); - } - else - { - return null; - } - } - - /// - /// Query for translating friendly name to upload number. - /// - /// The friendlyname. - /// - /// Returns UploadNumber for friendly name. - /// Null for not existing friendly name. - /// - public virtual string FriendlyNameToUploadNumberOrDefault(string friendlyname) - { - if (_context.Datasets.Any(o => o.FriendlyName == friendlyname)) - { - var dataset = _context.Datasets - .Where(b => b.FriendlyName == friendlyname) - .FirstOrDefault(); - - return dataset.UploadNumber; - } - else - { - return null; - } - } - - /// - /// Query for translating upload number to hash. - /// - /// The uploadnumber. - /// - /// Returns hash for upload name. - /// Null for not existing upload name. - /// - public virtual string UploadNumberToHashOrDefault(string uploadnumber) - { - if (_context.Datasets.Any(o => o.UploadNumber == uploadnumber)) - { - var dataset = _context.Datasets - .Where(b => b.UploadNumber == uploadnumber) - .FirstOrDefault(); - - return dataset.Hash; - } - else - { - return null; - } - } - - /// - /// Query for translating hash to friendly name. - /// - /// The hash. - /// - /// Returns FriendlyName for Hash. - /// Null for not existing Hash. - /// - public virtual string HashToFriendlyNameOrDefault(string hash) - { - if (_context.Datasets.Any(o => o.Hash == hash)) - { - var dataset = _context.Datasets - .Where(b => b.Hash == hash) - .FirstOrDefault(); - - return dataset.FriendlyName; - } - else - { - return null; - } - } - - /// - /// Query for translating upload number to friendly name. - /// - /// The uploadnumber. - /// - /// Returns friendly name for given upload number. - /// Null for not existing upload number. - /// - public virtual string UploadNumberToFriendlyNameOrDefault(string uploadnumber) - { - if (_context.Datasets.Any(o => o.UploadNumber == uploadnumber)) - { - var dataset = _context.Datasets - .Where(b => b.UploadNumber == uploadnumber) - .FirstOrDefault(); - - return dataset.FriendlyName; - } - else - { - return null; - } - } - } -} diff --git a/src/Spectre.Database/Utils/IDatasetDetailsFinder.cs b/src/Spectre.Database/Utils/IDatasetDetailsFinder.cs deleted file mode 100644 index ea659f9..0000000 --- a/src/Spectre.Database/Utils/IDatasetDetailsFinder.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * IDatasetDetailsFinder.cs - * Interface for DatasetDetailsFinder. - * - Copyright 2017 Roman Lisak - - 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. -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Spectre.Database.Utils -{ - /// - /// Interface for the PathFinder class - /// - public interface IDatasetDetailsFinder - { - /// - /// Query for translating hash to upload number. - /// - /// The hash. - /// - /// Returns UploadNumber for Hash. - /// Null for not existing Hash. - /// - string HashToUploadNumberOrDefault(string hash); - - /// - /// Query for translating friendly name to upload number. - /// - /// The friendlyname. - /// - /// Returns UploadNumber for friendly name. - /// Null for not existing friendly name. - /// - string FriendlyNameToUploadNumberOrDefault(string friendlyname); - - /// - /// Query for translating upload number to hash. - /// - /// The uploadnumber. - /// - /// Returns hash for upload name. - /// Null for not existing upload name. - /// - string UploadNumberToHashOrDefault(string uploadnumber); - - /// - /// Query for translating Hash to friendly name. - /// - /// The hash. - /// - /// Returns FriendlyName for Hash. - /// Null for not existing Hash. - /// - string HashToFriendlyNameOrDefault(string hash); - - /// - /// Query for translating upload number to friendly name. - /// - /// The uploadnumber. - /// - /// Returns friendly name for given upload number. - /// Null for not existing upload number. - /// - string UploadNumberToFriendlyNameOrDefault(string uploadnumber); - } -} diff --git a/src/Spectre.Database/packages.config b/src/Spectre.Database/packages.config deleted file mode 100644 index d5ce45d..0000000 --- a/src/Spectre.Database/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Spectre.Dependencies/DependencyResolver.cs b/src/Spectre.Dependencies/DependencyResolver.cs deleted file mode 100644 index 0095306..0000000 --- a/src/Spectre.Dependencies/DependencyResolver.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* - * DependencyResolver.cs - * Singleton class for applying chosen dependencies to different parts of - * the application. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System; -using Ninject; -using Ninject.Modules; -using Spectre.Dependencies.Modules; - -namespace Spectre.Dependencies -{ - /// - /// Singleton class for applying chosen dependencies to different parts of the application. - /// - public sealed class DependencyResolver - { - private static readonly IKernel Kernel = new StandardKernel(new DefaultModule()); - - /// - /// Method for loading new modules containing bindings to types for dependency resolving. - /// - /// Module to load. - public static void AddModule(INinjectModule newModule) => Kernel.Load(newModule); - - /// - /// Method for getting a certain service according to its type. - /// - /// Found service. - public static T GetService() where T : class => Kernel.TryGet(typeof(T)) as T; - } -} diff --git a/src/Spectre.Dependencies/Modules/DefaultModule.cs b/src/Spectre.Dependencies/Modules/DefaultModule.cs deleted file mode 100644 index 1af9466..0000000 --- a/src/Spectre.Dependencies/Modules/DefaultModule.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * DefaultModule.cs - * Module containing default bindings for the core part of the application. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System.IO.Abstractions; -using Ninject.Modules; - -namespace Spectre.Dependencies.Modules -{ - /// - /// Module containing default bindings for the core part of the application. - /// - public class DefaultModule : NinjectModule - { - #region Overrides of NinjectModule - - /// - public override void Load() - { - Rebind() - .To() - .InSingletonScope(); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Spectre.Dependencies/Modules/MockModule.cs b/src/Spectre.Dependencies/Modules/MockModule.cs deleted file mode 100644 index 671307b..0000000 --- a/src/Spectre.Dependencies/Modules/MockModule.cs +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MockModule.cs - * Module containing bindings for mocks of certain parts of the application - * for testing purposes. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System.IO.Abstractions; -using System.IO.Abstractions.TestingHelpers; -using Ninject.Modules; - -namespace Spectre.Dependencies.Modules -{ - /// - /// Module containing bindings for mocks of certain parts of the application - /// for testing purposes. - /// - public class MockModule : NinjectModule - { - #region Overrides of NinjectModule - - /// - public override void Load() - { - Rebind() - .To() - .InSingletonScope(); - } - - #endregion - } -} diff --git a/src/Spectre.Dependencies/Properties/AssemblyInfo.cs b/src/Spectre.Dependencies/Properties/AssemblyInfo.cs deleted file mode 100644 index 4441c22..0000000 --- a/src/Spectre.Dependencies/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Spectre.Dependencies")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Spectre.Dependencies")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2b9f4dfd-c222-477a-9107-1a3c356002a4")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Dependencies/Spectre.Dependencies.csproj b/src/Spectre.Dependencies/Spectre.Dependencies.csproj deleted file mode 100644 index 521f641..0000000 --- a/src/Spectre.Dependencies/Spectre.Dependencies.csproj +++ /dev/null @@ -1,62 +0,0 @@ - - - - - Debug - x64 - {2B9F4DFD-C222-477A-9107-1A3C356002A4} - Library - Properties - Spectre.Dependencies - Spectre.Dependencies - v4.6.1 - 512 - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - - ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - - - - - ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll - - - ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Spectre.Dependencies/packages.config b/src/Spectre.Dependencies/packages.config deleted file mode 100644 index dd3393e..0000000 --- a/src/Spectre.Dependencies/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Spectre.DivikWpfClient/App.config b/src/Spectre.DivikWpfClient/App.config index 3a1753d..4241d51 100644 --- a/src/Spectre.DivikWpfClient/App.config +++ b/src/Spectre.DivikWpfClient/App.config @@ -1,4 +1,4 @@ - + + + +
+ - + - + + + + + + + + + + + \ No newline at end of file diff --git a/src/Spectre.DivikWpfClient/Properties/AssemblyInfo.cs b/src/Spectre.DivikWpfClient/Properties/AssemblyInfo.cs index 5a382a8..c926b4b 100644 --- a/src/Spectre.DivikWpfClient/Properties/AssemblyInfo.cs +++ b/src/Spectre.DivikWpfClient/Properties/AssemblyInfo.cs @@ -9,11 +9,11 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Spectre.DivikWpfClient")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Standalone client for DiviK algorithm")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("The Spectre Team")] [assembly: AssemblyProduct("Spectre.DivikWpfClient")] -[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyCopyright("Copyright © 2017 Spectre")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/Spectre.DivikWpfClient/Spectre.DivikWpfClient.csproj b/src/Spectre.DivikWpfClient/Spectre.DivikWpfClient.csproj index 2780ccb..33c1f47 100644 --- a/src/Spectre.DivikWpfClient/Spectre.DivikWpfClient.csproj +++ b/src/Spectre.DivikWpfClient/Spectre.DivikWpfClient.csproj @@ -39,15 +39,53 @@ true bin\x64\Release\Spectre.DivikWpfClient.xml + + + + + + ..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + ..\packages\Expression.Blend.Sdk.WPF.1.0.1\lib\net45\Microsoft.Expression.Interactions.dll + + ..\packages\Moq.4.7.99\lib\net45\Moq.dll + ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Data.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Database.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Dependencies.dll + + + ..\packages\Spectre.Mvvm.3.0.0.72\lib\net461\Spectre.Mvvm.dll + + + ..\packages\Spectre.Service.3.0.0.72\lib\net461\Spectre.Service.dll + + + + ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll + + + ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll + ..\packages\Expression.Blend.Sdk.WPF.1.0.1\lib\net45\System.Windows.Interactivity.dll @@ -119,18 +157,6 @@ {9A886AEC-58DB-410D-91B9-C62E157501FA} Spectre.Algorithms - - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC} - Spectre.Data - - - {2d24f1e7-18d4-4fc0-9e4f-2f32ff27fcce} - Spectre.Mvvm - - - {287A1A8D-C029-4D47-96BC-755C91B7985D} - Spectre.Service - @@ -139,6 +165,9 @@ + + + - \ No newline at end of file diff --git a/src/Spectre.Mvvm.Tests/packages.config b/src/Spectre.Mvvm.Tests/packages.config deleted file mode 100644 index fe81e33..0000000 --- a/src/Spectre.Mvvm.Tests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Spectre.Mvvm/Base/PropertyChangedNotification.cs b/src/Spectre.Mvvm/Base/PropertyChangedNotification.cs deleted file mode 100644 index 82cd2e5..0000000 --- a/src/Spectre.Mvvm/Base/PropertyChangedNotification.cs +++ /dev/null @@ -1,310 +0,0 @@ -/* - * PropertyChangedNotification.cs - * Base class for ViewModels. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace Spectre.Mvvm.Base -{ - /// - /// Provides handling necessary events when properties are set by user. - /// Moreover, provides an error info easy to bind to - validation of input - /// may be done by means of attributes. - /// Provides INotifyPropertyChanged implementation along with some - /// validation, which can be performed by using simple annotations. - /// Code is present at: http://social.technet.microsoft.com/wiki/contents/articles/22660.data-validation-in-mvvm.aspx - /// - /// - /// - public class PropertyChangedNotification : INotifyPropertyChanged, IDataErrorInfo - { - /// - /// The values which are returned by properties. - /// - private readonly Dictionary _values = new Dictionary(); - - /// - /// Raised when a property on this object has a new value. - /// - public event PropertyChangedEventHandler PropertyChanged; - - /// - /// Gets an error message indicating what is wrong with this object. - /// - string IDataErrorInfo.Error - { - get - { - var errors = new StringBuilder(); - foreach (var property in _values) - { - var error = ((IDataErrorInfo)this)[property.Key]; - if (!string.IsNullOrWhiteSpace(error)) - { - errors.AppendLine(error); - } - } - return errors.ToString(); - } - } - - /// - /// Gets a value indicating whether this instance has error. - /// Works through checking whether error message is empty. - /// - /// - /// true if this instance has error; otherwise, false. - /// - protected bool HasError - { - get { return !string.IsNullOrWhiteSpace(((IDataErrorInfo)this).Error); } - } - - /// - /// Returns whether an exception is thrown, or if a Debug.Fail() is used - /// when an invalid property name is passed to the VerifyPropertyName method. - /// The default value is false, but subclasses used by unit tests might - /// override this property's getter to return true. - /// - protected virtual bool ThrowOnInvalidPropertyName { get; private set; } - - /// - /// Gets the error of the property with specified name. - /// - /// - /// The . - /// - /// Name of the property. - /// Error info. - string IDataErrorInfo.this[string propertyName] - { - get { return OnValidate(propertyName); } - } - - /// - /// Warns the developer if this object does not have - /// a public property with the specified name. This - /// method does not exist in a Release build. - /// - /// String to be validated as property name - [Conditional(conditionString: "DEBUG")] - [DebuggerStepThrough] - public void VerifyPropertyName(string propertyName) - { - // Verify that the property name matches a real, - // public, instance property on this object. - if (TypeDescriptor.GetProperties(component: this)[propertyName] == null) - { - var msg = "Invalid property name: " + propertyName; - - if (ThrowOnInvalidPropertyName) - { - throw new Exception(msg); - } - Debug.Fail(msg); - } - } - - /// - /// Sets the value of a property. - /// - /// The type of the property value. - /// Expression tree contains the property definition. - /// The property value. - protected void SetValue(Expression> propertySelector, T value) - { - var propertyName = GetPropertyName(propertySelector); - - SetValue(propertyName, value); - } - - /// - /// Sets the value of a property. - /// - /// The type of the property value. - /// The name of the property. - /// The property value. - protected void SetValue(string propertyName, T value) - { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentException(message: "Invalid property name", paramName: propertyName); - } - - if (_values.ContainsKey(propertyName) && (value != null) && value.Equals(obj: _values[propertyName])) - { - return; - } - if (_values.ContainsKey(propertyName) && (_values[propertyName] == null) && (value == null)) - { - return; - } - - _values[propertyName] = value; - NotifyPropertyChanged(propertyName); - } - - /// - /// Gets the value of a property. - /// - /// The type of the property value. - /// Expression tree contains the property definition. - /// The value of the property or default value if not exist. - protected T GetValue(Expression> propertySelector) - { - var propertyName = GetPropertyName(propertySelector); - - return GetValue(propertyName); - } - - /// - /// Gets the value of a property. - /// - /// The type of the property value. - /// The name of the property. - /// The value of the property or default value if not exist. - protected T GetValue(string propertyName) - { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentException(message: "Invalid property name", paramName: propertyName); - } - - object value; - if (!_values.TryGetValue(propertyName, out value)) - { - value = default(T); - _values.Add(propertyName, value); - } - - return (T)value; - } - - /// - /// Validates current instance properties using Data Annotations. - /// - /// This instance property to validate. - /// Relevant error string on validation failure or on validation success. - protected virtual string OnValidate(string propertyName) - { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentException(message: "Invalid property name", paramName: propertyName); - } - - var error = string.Empty; - var value = GetValue(propertyName); - - // looks for first property which fails its validation - var results = new List(capacity: 1); - var validationContext = new ValidationContext(instance: this, serviceProvider: null, items: null) - { - MemberName = propertyName - }; - var result = Validator.TryValidateProperty(value, validationContext, results); - - if (!result) - { - var validationResult = results.First(); - error = validationResult.ErrorMessage; - } - - return error; - } - - /// - /// Raises this object's PropertyChanged event. - /// - /// The property that has a new value. - protected void NotifyPropertyChanged(string propertyName) - { - VerifyPropertyName(propertyName); - - var handler = PropertyChanged; - if (handler != null) - { - var e = new PropertyChangedEventArgs(propertyName); - handler(sender: this, e: e); - } - } - - /// - /// Notifies the property changed. - /// - /// Type of property which has changed. - /// The property selector. - protected void NotifyPropertyChanged(Expression> propertySelector) - { - var propertyChanged = PropertyChanged; - if (propertyChanged != null) - { - var propertyName = GetPropertyName(propertySelector); - propertyChanged(sender: this, e: new PropertyChangedEventArgs(propertyName)); - } - } - - /// - /// Gets the name of the property from lambda expression. - /// - /// The expression. - /// Name of the property. - /// When expression leads to not a member. - private string GetPropertyName(LambdaExpression expression) - { - var memberExpression = expression.Body as MemberExpression; - if (memberExpression == null) - { - throw new InvalidOperationException(); - } - - return memberExpression.Member.Name; - } - - /// - /// Gets the value of a property with specific name. - /// - /// Name of the property. - /// Value of the property - /// Invalid property name - private object GetValue(string propertyName) - { - object value; - if (!_values.TryGetValue(propertyName, out value)) - { - var propertyDescriptor = TypeDescriptor.GetProperties(componentType: GetType()) - .Find(propertyName, ignoreCase: false); - if (propertyDescriptor == null) - { - throw new ArgumentException(message: "Invalid property name", paramName: propertyName); - } - - value = propertyDescriptor.GetValue(component: this); - _values.Add(propertyName, value); - } - - return value; - } - } -} diff --git a/src/Spectre.Mvvm/Base/RelayCommand.cs b/src/Spectre.Mvvm/Base/RelayCommand.cs deleted file mode 100644 index 311c847..0000000 --- a/src/Spectre.Mvvm/Base/RelayCommand.cs +++ /dev/null @@ -1,244 +0,0 @@ -/* - * RelayCommand.cs - * Bindable ICommand implementation. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Windows.Input; -using Spectre.Mvvm.Helpers; - -namespace Spectre.Mvvm.Base -{ - /// - /// Provides a base class simplifying creation of commands to bind to from - /// GUI. - /// - /// - public class RelayCommand : ICommand - { - #region Fields - - /// - /// Service handling UI effects. - /// - private static UiService _uiService = new UiService(); - - /// - /// Action to be executed. - /// - private Action _execute; - - /// - /// Function stating, whether _execute action can be ran. - /// - private Predicate _canExecute; - - #endregion - - #region Constructors - - #region action - - /// - /// Initializes a new instance of the class - /// with default CanExecute function returning true. - /// - /// An action to be executed. - public RelayCommand(Action execute) : this(execute, RelayCommand.DefaultCanExecute) { } - - #endregion - - #region action-func - - /// - /// Initializes a new instance of the class - /// with a condition function which states whether an action can be - /// executed. - /// - /// An action to be executed. - /// Condition if the action can be performed. - public RelayCommand(Action execute, Func canExecute) : this(execute, canExecute: o => canExecute()) { } - - #endregion - - #region action-predicate - - /// - /// Initializes a new instance of the class - /// with an action and condition of execution. - /// - /// An action to be executed. - /// Condition if the action can be performed. - public RelayCommand(Action execute, Predicate canExecute) - : this(execute: o => execute(), canExecute: canExecute) { } - - #endregion - - #region action-generic - - /// - /// Initializes a new instance of the class - /// with a parameterized action to be executed, which always can be fired. - /// - /// An action to be executed. - public RelayCommand(Action execute) : this(execute, RelayCommand.DefaultCanExecute) { } - - #endregion - - #region action generic with predicate - - /// - /// Initializes a new instance of the class. - /// - /// An action to be executed. - /// A condition of execution. - /// - /// When execute is null - /// or - /// canExecute is null - /// - public RelayCommand(Action execute, Predicate canExecute) - { - if (execute == null) - { - throw new ArgumentNullException(paramName: nameof(execute)); - } - - if (canExecute == null) - { - throw new ArgumentNullException(paramName: nameof(canExecute)); - } - - _execute = execute; - _canExecute = canExecute; - } - - #endregion - - #endregion - - #region CanExecuteChanged - - /// - /// Occurs when changes occur that affect whether or not the command should execute. - /// - public event EventHandler CanExecuteChanged - { - add - { - CommandManager.RequerySuggested += value; - CanExecuteChangedInternal += value; - } - - remove - { - CommandManager.RequerySuggested -= value; - CanExecuteChangedInternal -= value; - } - } - - /// - /// Occurs when _canExecute changess. - /// - private event EventHandler CanExecuteChangedInternal; - - #endregion - - #region IntroduceUiMock - - /// - /// Allows to inject mock as a service. - /// - /// UI services mock. - public static void IntroduceUiMock(UiService mock) - { - RelayCommand._uiService = mock; - } - - #endregion - - #region CanExecute - - /// - /// Defines the method that determines whether the command can execute in its current state. - /// - /// Data used by the command. If the command does not require data to be passed, this object can be set to null. - /// - /// true if this command can be executed; otherwise, false. - /// - public bool CanExecute(object parameter) - { - return (_canExecute != null) && _canExecute(parameter); - } - - #endregion - - #region Execute - - /// - /// Defines the method to be called when the command is invoked. - /// - /// Data used by the command. If the command does not require data to be passed, this object can be set to null. - public void Execute(object parameter) - { - RelayCommand._uiService.SetBusyState(); - _execute(parameter); - } - - #endregion - - #region OnCanExecuteChanged - - /// - /// Called when CanExecute changed. - /// - public void OnCanExecuteChanged() - { - var handler = CanExecuteChangedInternal; - handler?.Invoke(sender: this, e: EventArgs.Empty); - } - - #endregion - - #region Destroy - - /// - /// Destroys this instance. - /// - public void Destroy() - { - _canExecute = _ => false; - _execute = _ => { return; }; - } - - #endregion - - #region DefaultCanExecute - - /// - /// Default state of condition of execution. - /// - /// The necessary parameter. - /// True. - private static bool DefaultCanExecute(object parameter) - { - return true; - } - - #endregion - } -} diff --git a/src/Spectre.Mvvm/Converters/BoolToVisibilityConverter.cs b/src/Spectre.Mvvm/Converters/BoolToVisibilityConverter.cs deleted file mode 100644 index 869b582..0000000 --- a/src/Spectre.Mvvm/Converters/BoolToVisibilityConverter.cs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * BoolToVisibilityConverter.cs - * Converter which allows to steer visibility with bools. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Globalization; -using System.Windows; -using System.Windows.Data; - -namespace Spectre.Mvvm.Converters -{ - /// - /// This allows to convert to and back. - /// - /// - public class BoolToVisibilityConverter : IValueConverter - { - /// - /// Modifies the source data before passing it to the target for display in the UI. - /// - /// The source data being passed to the target. - /// The of data expected by the target dependency property. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the target dependency property. - /// - /// if value is null - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if ((bool)value) - { - return Visibility.Visible; - } - return Visibility.Collapsed; - } - - /// - /// Modifies the target data before passing it to the source object. This method is called only in bindings. - /// - /// The target data being passed to the source. - /// The of data expected by the source object. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the source object. - /// - /// if value is null - public object ConvertBack( - object value, - Type targetType, - object parameter, - CultureInfo culture) - { - return (Visibility)value == Visibility.Visible; - } - } -} diff --git a/src/Spectre.Mvvm/Converters/CombinedConverter.cs b/src/Spectre.Mvvm/Converters/CombinedConverter.cs deleted file mode 100644 index c9052fb..0000000 --- a/src/Spectre.Mvvm/Converters/CombinedConverter.cs +++ /dev/null @@ -1,90 +0,0 @@ -/* - * CombinedConverter.cs - * Converter which allows chaining of other converters. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Windows.Data; - -namespace Spectre.Mvvm.Converters -{ - /// - /// Converter allowing nesting of the converters. - /// - public class CombinedConverter : IValueConverter - { - /// - /// Gets or sets the first converter used. - /// - /// - /// The first converter. - /// - public IValueConverter First { get; set; } - - /// - /// Gets or sets the second converter used. - /// - /// - /// The second converter. - /// - public IValueConverter Second { get; set; } - - /// - /// Modifies the source data before passing it to the target for display in the UI. - /// - /// The source data being passed to the target. - /// The of data expected by the target dependency property. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the target dependency property. - /// - /// if value is null - public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) - { - return Second.Convert( - value: First.Convert(value, targetType, parameter, culture), - targetType: targetType, - parameter: parameter, - culture: culture); - } - - /// - /// Modifies the target data before passing it to the source object. This method is called only in bindings. - /// - /// The target data being passed to the source. - /// The of data expected by the source object. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the source object. - /// - /// if value is null - public object ConvertBack( - object value, - Type targetType, - object parameter, - System.Globalization.CultureInfo culture) - { - return First.ConvertBack( - value: Second.ConvertBack(value, targetType, parameter, culture), - targetType: targetType, - parameter: parameter, - culture: culture); - } - } -} diff --git a/src/Spectre.Mvvm/Converters/IntPositivenessToBoolConverter.cs b/src/Spectre.Mvvm/Converters/IntPositivenessToBoolConverter.cs deleted file mode 100644 index 22ea511..0000000 --- a/src/Spectre.Mvvm/Converters/IntPositivenessToBoolConverter.cs +++ /dev/null @@ -1,72 +0,0 @@ -/* - * IntPositivenessToBoolConverter.cs - * Converter which gives true for positive ints, false otherwise. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Windows.Data; - -namespace Spectre.Mvvm.Converters -{ - /// - /// This converter allows to determine if integer value is positive. - /// - /// - public class IntPositivenessToBoolConverter : IValueConverter - { - /// - /// Modifies the source data before passing it to the target for display in the UI. - /// - /// The source data being passed to the target. - /// The of data expected by the target dependency property. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the target dependency property. - /// - /// if value is null - public object Convert( - object value, - Type targetType, - object parameter, - System.Globalization.CultureInfo culture) - { - return (int)value > 0; - } - - /// - /// Modifies the target data before passing it to the source object. This method is called only in bindings. - /// - /// The target data being passed to the source. - /// The of data expected by the source object. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the source object. - /// - /// Always as it cannot be used to bindings. - public object ConvertBack( - object value, - Type targetType, - object parameter, - System.Globalization.CultureInfo culture) - { - throw new InvalidOperationException( - message: "Cannot restore int value from bool."); - } - } -} diff --git a/src/Spectre.Mvvm/Converters/InverseBoolConverter.cs b/src/Spectre.Mvvm/Converters/InverseBoolConverter.cs deleted file mode 100644 index f5210a5..0000000 --- a/src/Spectre.Mvvm/Converters/InverseBoolConverter.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * InverseBoolConverter.cs - * Converter negating boolean values. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Windows.Data; - -namespace Spectre.Mvvm.Converters -{ - /// - /// Inverts boolean value. - /// - public class InverseBoolConverter : IValueConverter - { - /// - /// Modifies the source data before passing it to the target for display in the UI. - /// - /// The source data being passed to the target. - /// The of data expected by the target dependency property. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the target dependency property. - /// - /// if value is null - public object Convert( - object value, - Type targetType, - object parameter, - System.Globalization.CultureInfo culture) - { - return !(bool)value; - } - - /// - /// Modifies the target data before passing it to the source object. This method is called only in bindings. - /// - /// The target data being passed to the source. - /// The of data expected by the source object. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the source object. - /// - /// if value is null - public object ConvertBack( - object value, - Type targetType, - object parameter, - System.Globalization.CultureInfo culture) - { - return !(bool)value; - } - } -} diff --git a/src/Spectre.Mvvm/Converters/PercentageConverter.cs b/src/Spectre.Mvvm/Converters/PercentageConverter.cs deleted file mode 100644 index 1ee5cf4..0000000 --- a/src/Spectre.Mvvm/Converters/PercentageConverter.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - * PercentageConverter.cs - * Converter which allows to convert percentages to double values. - * - Copyright 2017 Michał Wolny - - 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. -*/ - -using System; -using System.Globalization; -using System.Windows.Data; - -namespace Spectre.Mvvm.Converters -{ - /// - /// This allows to convert percentage to and back. - /// - /// - public class PercentageConverter : IValueConverter - { - /// - /// Modifies the source data before passing it to the target for display in the UI. - /// - /// The source data being passed to the target. - /// The of data expected by the target dependency property. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the target dependency property. - /// - /// if value is null - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return ((double)value * 100).ToString(culture) + " %"; - } - - /// - /// Modifies the target data before passing it to the source object. This method is called only in bindings. - /// - /// The target data being passed to the source. - /// The of data expected by the source object. - /// An optional parameter to be used in the converter logic. - /// The culture of the conversion. - /// - /// The value to be passed to the source object. - /// - /// if value is null - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is double) - { - return (double)value / 100; - } - return double.Parse(s: ((string)value).Replace(oldChar: '%', newChar: ' ').Trim(), provider: culture) / 100; - } - } -} diff --git a/src/Spectre.Mvvm/Helpers/UiService.cs b/src/Spectre.Mvvm/Helpers/UiService.cs deleted file mode 100644 index b3a41cb..0000000 --- a/src/Spectre.Mvvm/Helpers/UiService.cs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * UiServices.cs - * Helps to maintain UI states. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.Windows.Input; -using System.Windows.Threading; - -namespace Spectre.Mvvm.Helpers -{ - /// - /// Abstraction for UI related services. - /// - public class UiService - { - /// - /// A value indicating whether the UI is currently busy - /// - private static bool _isBusy; - - /// - /// Sets the busystate as busy. - /// - public virtual void SetBusyState() - { - UiService.SetBusyState(busy: true); - } - - /// - /// Sets the busystate to busy or not busy. - /// - /// if set to true the application is now busy. - private static void SetBusyState(bool busy) - { - if (busy != UiService._isBusy) - { - UiService._isBusy = busy; - - var dispatcher = System.Windows.Application.Current?.Dispatcher - ?? Dispatcher.CurrentDispatcher; - - if (UiService._isBusy) - { - dispatcher.Invoke(callback: () => Mouse.OverrideCursor = Cursors.Wait); - new DispatcherTimer( - interval: TimeSpan.FromSeconds(value: 0), - priority: DispatcherPriority.ApplicationIdle, - callback: UiService.DispatcherTimer_Tick, - dispatcher: dispatcher); - } - else - { - dispatcher.Invoke(callback: () => Mouse.OverrideCursor = Cursors.Arrow); - } - } - } - - /// - /// Handles the Tick event of the dispatcherTimer control. - /// - /// The source of the event. - /// The instance containing the event data. - private static void DispatcherTimer_Tick(object sender, EventArgs e) - { - var dispatcherTimer = sender as DispatcherTimer; - if (dispatcherTimer != null) - { - UiService.SetBusyState(busy: false); - dispatcherTimer.Stop(); - } - } - } -} diff --git a/src/Spectre.Mvvm/Properties/AssemblyInfo.cs b/src/Spectre.Mvvm/Properties/AssemblyInfo.cs deleted file mode 100644 index 083b264..0000000 --- a/src/Spectre.Mvvm/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Mvvm")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Mvvm")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2d24f1e7-18d4-4fc0-9e4f-2f32ff27fcce")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Mvvm/Spectre.Mvvm.csproj b/src/Spectre.Mvvm/Spectre.Mvvm.csproj deleted file mode 100644 index 8109ff8..0000000 --- a/src/Spectre.Mvvm/Spectre.Mvvm.csproj +++ /dev/null @@ -1,78 +0,0 @@ - - - - - Debug - x64 - {2D24F1E7-18D4-4FC0-9E4F-2F32FF27FCCE} - Library - Properties - Spectre.Mvvm - Spectre.Mvvm - v4.6.1 - 512 - - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - ..\CSharpCodingConvention.ruleset - true - bin\x64\Debug\Spectre.Mvvm.xml - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - ..\CSharpCodingConvention.ruleset - bin\x64\Release\Spectre.Mvvm.xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Spectre.Mvvm/packages.config b/src/Spectre.Mvvm/packages.config deleted file mode 100644 index 2718f70..0000000 --- a/src/Spectre.Mvvm/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Spectre.Service.Tests/ConsoleCaptureServiceTest.cs b/src/Spectre.Service.Tests/ConsoleCaptureServiceTest.cs deleted file mode 100644 index fc2ab87..0000000 --- a/src/Spectre.Service.Tests/ConsoleCaptureServiceTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Threading; -using NUnit.Framework; -using Spectre.Service.Abstract; - -namespace Spectre.Service.Tests -{ - [TestFixture] - public class ConsoleCaptureServiceTest - { - private IServiceFactory _factory; - - [SetUp] - public void SetUp() - { - _factory = new ServiceFactory(); - } - - [Test] - public void ThrowsOnTooSmallUpdateInterval() - { - Assert.Throws(code: () => _factory.GetConsoleCaptureService(updateInterval: 1)); - } - - [Test] - public void CreatesSeamlesslyWithGreaterInterval() - { - Assert.DoesNotThrow(code: () => _factory.GetConsoleCaptureService(updateInterval: 100)); - } - - [Test] - public void WriteTest() - { - const string text = "blah bleh blash"; - using (var captureService = _factory.GetConsoleCaptureService(updateInterval: 100.0)) - { - Console.Write(text); - Thread.Sleep(millisecondsTimeout: 500); - Assert.AreEqual(text, captureService.Content, message: "Text has not been captured."); - } - } - - [Test] - public void WriteLineTest() - { - const string text = "blah bleh blash"; - using (var captureService = _factory.GetConsoleCaptureService(updateInterval: 100.0)) - { - Console.WriteLine(text); - Thread.Sleep(millisecondsTimeout: 500); - Assert.AreEqual(expected: text + "\r\n", - actual: captureService.Content, - message: "Text has not been captured."); - } - } - } -} diff --git a/src/Spectre.Service.Tests/DataRootConfigTest.cs b/src/Spectre.Service.Tests/DataRootConfigTest.cs deleted file mode 100644 index b984fc9..0000000 --- a/src/Spectre.Service.Tests/DataRootConfigTest.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * DataRootConfigTest.cs - * Tests for data directory root configuration. - * - Copyright 2017 Maciej Gamrat - - 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. -*/ - -using NUnit.Framework; -using Spectre.Service.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Spectre.Service.Tests -{ - [TestFixture] - class DataRootConfigTest - { - private string goodLocalPath = @"\Path\To\Data"; - private string wrongLocalPath = @"\Path\To\*"; - - private string goodRemotePath = @"\\Path\To\Data"; - private string wrongRemotePath = @"\\Path\To\*"; - - [Test] - public void DataRootThrowsOnMissingLocalPath() - { - Assert.Throws(code: () => new DataRootConfig(null, goodRemotePath)); - } - - [Test] - public void DataRootThrowsOnInvalidLocalPath() - { - Assert.Throws(code: () => new DataRootConfig(wrongLocalPath, goodRemotePath)); - } - - [Test] - public void DataRootThrowsOnMissingRemotePath() - { - Assert.Throws(code: () => new DataRootConfig(goodLocalPath, null)); - } - - [Test] - public void DataRootThrowsOnInvalidRemotePath() - { - Assert.Throws(code: () => new DataRootConfig(goodLocalPath, wrongRemotePath)); - } - - [Test] - public void DataRootDoesNotThrowForCorrectPaths() - { - Assert.DoesNotThrow(code: () => new DataRootConfig(goodLocalPath, goodRemotePath)); - } - - [Test] - public void DataRootReturnsInputValues() - { - var dataRootConfig = new DataRootConfig(goodLocalPath, goodRemotePath); - Assert.AreEqual(expected: goodLocalPath, actual: dataRootConfig.LocalPath); - Assert.AreEqual(expected: goodRemotePath, actual: dataRootConfig.RemotePath); - } - } -} diff --git a/src/Spectre.Service.Tests/Loaders/DatasetLoaderTest.cs b/src/Spectre.Service.Tests/Loaders/DatasetLoaderTest.cs deleted file mode 100644 index ea437f3..0000000 --- a/src/Spectre.Service.Tests/Loaders/DatasetLoaderTest.cs +++ /dev/null @@ -1,109 +0,0 @@ -/* - * DatasetLoaderTest.cs - * Tests for dataset loader class. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System; -using System.IO; -using System.IO.Abstractions; -using System.IO.Abstractions.TestingHelpers; -using System.Linq; -using NUnit.Framework; -using Spectre.Dependencies; -using Spectre.Dependencies.Modules; -using Spectre.Service.Configuration; -using Spectre.Service.Loaders; - -namespace Spectre.Service.Tests.Loaders -{ - [TestFixture] - public class DatasetLoaderTest - { - private DataRootConfig _rootConfig; - private DatasetLoader _datasetLoader; - private MockFileSystem _mockFileSystem; - - private readonly string _rootDir = @"C:\spectre_data"; - private readonly string _localDir = "local"; - private readonly string _remoteDir = "remote"; - - private readonly string _fileDir = $"{TestContext.CurrentContext.TestDirectory} + " - + @"\..\..\..\..\..\test_files"; - [OneTimeSetUp] - public void SetUp() - { - DependencyResolver.AddModule(new MockModule()); - - var localDirFull = Path.Combine(_rootDir, _localDir); - var remoteDirFull = Path.Combine(_rootDir, _remoteDir); - var correctDataset = File.ReadAllText(Path.Combine(_fileDir, "small-test.txt")); - - _mockFileSystem = DependencyResolver.GetService() as MockFileSystem; - - _mockFileSystem.AddFile(Path.Combine(localDirFull, "local_correct.txt"), new MockFileData(correctDataset)); - _mockFileSystem.AddFile(Path.Combine(remoteDirFull, "remote_correct.txt"), new MockFileData(correctDataset)); - _mockFileSystem.AddFile(Path.Combine(localDirFull, "local_incorrect.txt"), new MockFileData(textContents: "incorrect_data")); - _mockFileSystem.AddFile(Path.Combine(remoteDirFull, "remote_incorrect.txt"), new MockFileData(textContents: "incorrect_data")); - - _rootConfig = new DataRootConfig(localDirFull, remoteDirFull); - _datasetLoader = new DatasetLoader(_rootConfig); - } - - [Test] - public void ReturnsFromCorrectNameLocal() - { - Assert.IsNotNull(anObject: _datasetLoader.GetFromName(name: "local_correct"), - message: "Loader did not manage to load local file."); - } - - [Test] - public void ReturnsFromCorrectNameRemote() - { - Assert.IsNotNull(anObject: _datasetLoader.GetFromName(name: "remote_correct"), - message: "Loader did not manage to load remote file."); - } - - [Test] - public void ThrowsOnIncorrectName() - { - Assert.Throws(code: () => _datasetLoader.GetFromName(name: "invalid_name"), - message: "Loader accepted invalid file name."); - } - - [Test] - public void ThrowsOnIncorrectFileContents() - { - Assert.Throws(code: () => _datasetLoader.GetFromName(name: "local_incorrect"), - message: "Loader did not manage to load remote file."); - } - - [Test] - public void DeletesIncorrectFilesFromLocal() - { - try - { - _datasetLoader.GetFromName(name: "remote_incorrect"); - } - catch (DatasetFormatException) - { - // ignored - } - var result = _mockFileSystem.AllFiles.FirstOrDefault(predicate: file => file.Contains(value: Path.Combine(_localDir, "remote_incorrect"))); - Assert.IsNull(result, message: "Loader leaves copies of incorrect files in local directory."); - } - } -} diff --git a/src/Spectre.Service.Tests/Properties/AssemblyInfo.cs b/src/Spectre.Service.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index a37da45..0000000 --- a/src/Spectre.Service.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Spectre.Service.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Spectre.Service.Tests")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("1d79fd14-1df4-4aed-94df-62e595206def")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Service.Tests/ServiceTest.cs b/src/Spectre.Service.Tests/ServiceTest.cs deleted file mode 100644 index 1a04f3e..0000000 --- a/src/Spectre.Service.Tests/ServiceTest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using NUnit.Framework; - -namespace Spectre.Service.Tests -{ - [TestFixture] - [Category(name: "Service")] - public class ServiceTest - { - [Test] - public void TestMethod() { } - } -} diff --git a/src/Spectre.Service.Tests/Spectre.Service.Tests.csproj b/src/Spectre.Service.Tests/Spectre.Service.Tests.csproj deleted file mode 100644 index 4010459..0000000 --- a/src/Spectre.Service.Tests/Spectre.Service.Tests.csproj +++ /dev/null @@ -1,84 +0,0 @@ - - - - Debug - x64 - {1D79FD14-1DF4-4AED-94DF-62E595206DEF} - Library - Properties - Spectre.Service.Tests - Spectre.Service.Tests - v4.6.1 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - ..\CSharpCodingConvention.ruleset - true - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - ..\CSharpCodingConvention.ruleset - - - - ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - - - ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll - - - - - ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll - - - ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll - - - - - - - - - - - - - - - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC} - Spectre.Data - - - {2b9f4dfd-c222-477a-9107-1a3c356002a4} - Spectre.Dependencies - - - {287a1a8d-c029-4d47-96bc-755c91b7985d} - Spectre.Service - - - - - \ No newline at end of file diff --git a/src/Spectre.Service.Tests/packages.config b/src/Spectre.Service.Tests/packages.config deleted file mode 100644 index 10d0bd1..0000000 --- a/src/Spectre.Service.Tests/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/Spectre.Service/Abstract/IConsoleCaptureService.cs b/src/Spectre.Service/Abstract/IConsoleCaptureService.cs deleted file mode 100644 index 6dcebf8..0000000 --- a/src/Spectre.Service/Abstract/IConsoleCaptureService.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * IConsoleCaptureService.cs - * Interface of service for capturing stdout. - * - Copyright 2017 Michal Wolny, Grzegorz Mrukwa - - 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. -*/ - -using System; - -namespace Spectre.Service.Abstract -{ - /// - /// Captures stdout. - /// - /// - public interface IConsoleCaptureService : IDisposable - { - /// - /// Occurs when anything was written. - /// - event EventHandler Written; - - /// - /// Gets the captured content. - /// - /// - /// The content. - /// - string Content { get; } - } -} diff --git a/src/Spectre.Service/Abstract/IDatasetDetailsFinderService.cs b/src/Spectre.Service/Abstract/IDatasetDetailsFinderService.cs deleted file mode 100644 index a7e1c3b..0000000 --- a/src/Spectre.Service/Abstract/IDatasetDetailsFinderService.cs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * IDatasetDetailsFinderService.cs - * Interface for DatasetDetailsFinderService - * - Copyright 2017 Roman Lisak - - 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 Spectre.Service.Abstract -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Spectre.Database.Contexts; - using Spectre.Database.Utils; - - /// - /// Interface for DatasetDetailsFinderService - /// - public interface IDatasetDetailsFinderService - { - /// - /// Finds the hash using friendly name. - /// - /// The hash. - /// - /// Returns UploadNumber basing on hash. - /// Null for not existing hash. - /// - string HashToUploadNumberOrDefault(string hash); - - /// - /// Finds the friendky name using hash. - /// - /// The friendlyname. - /// - /// Returns UploadNumber basing on friendly name. - /// Null for not existing friendly name. - /// - string FriendlyNameToUploadNumberOrDefault(string friendlyname); - - /// - /// Service translating uploadnumber to hash. - /// - /// The uploadnumber. - /// - /// Returns Hash having upload number. - /// Null for not existing upload number. - /// - string UploadNumberToHashOrDefault(string uploadnumber); - - /// - /// Query for translating hash to friendly name. - /// - /// The hash. - /// - /// Returns FriendlyName for Hash. - /// Null for not existing Hash. - /// - string HashToFriendlyNameOrDefault(string hash); - - /// - /// Query for translating upload number to friendly name. - /// - /// The uploadnumber. - /// - /// Returns friendly name for given upload number. - /// Null for not existing upload number. - /// - string UploadNumberToFriendlyNameOrDefault(string uploadnumber); - } -} \ No newline at end of file diff --git a/src/Spectre.Service/Abstract/IDivikService.cs b/src/Spectre.Service/Abstract/IDivikService.cs deleted file mode 100644 index 1ebbe0b..0000000 --- a/src/Spectre.Service/Abstract/IDivikService.cs +++ /dev/null @@ -1,39 +0,0 @@ -/* - * IDivikService.cs - * Contains definition of interface for service for calculating Divik. - * - Copyright 2017 Michał Wolny - - 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. -*/ - -using Spectre.Algorithms.Parameterization; -using Spectre.Algorithms.Results; -using Spectre.Data.Datasets; - -namespace Spectre.Service.Abstract -{ - /// - /// Interface for class for calculating divik. - /// - public interface IDivikService - { - /// - /// Service method for calculating divik. - /// - /// The source dataset being passed to the target. - /// The options passed to the divik algorithm. - /// of a given divik calculation. - DivikResult CalculateDivik(IDataset dataset, DivikOptions options); - } -} diff --git a/src/Spectre.Service/Abstract/IServiceFactory.cs b/src/Spectre.Service/Abstract/IServiceFactory.cs deleted file mode 100644 index 847b817..0000000 --- a/src/Spectre.Service/Abstract/IServiceFactory.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * IServiceFactory.cs - * Contains definition of interface for Factory for creating services. - * - Copyright 2017 Michał Wolny, Grzegorz Mrukwa, Roman Lisak - - 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 Spectre.Service.Abstract -{ - /// - /// Interface for class for creating new services. - /// - public interface IServiceFactory - { - /// - /// Factory method for getting . - /// - /// IDivikService instance - IDivikService GetDivikService(); - - /// - /// Factory method for getting . - /// - /// The update interval. - /// IConsoleCaptureService instance - IConsoleCaptureService GetConsoleCaptureService(double updateInterval = 1000.0); - - /// - /// Gets the path finder service. - /// - /// IPathFinderInstance - IDatasetDetailsFinderService GetDatasetDetailsFinderService(); - } -} diff --git a/src/Spectre.Service/Configuration/ConfigValidationException.cs b/src/Spectre.Service/Configuration/ConfigValidationException.cs deleted file mode 100644 index 7a2caa7..0000000 --- a/src/Spectre.Service/Configuration/ConfigValidationException.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ConfigValidationException.cs - * Exception thrown by config validation logic when settings are incorrect. - * - Copyright 2017 Maciej Gamrat - - 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. -*/ -using System; - -namespace Spectre.Service.Configuration -{ - /// - /// Thrown by config validation logic when settings are incorrect. - /// - /// - public class ConfigValidationException : ArgumentException - { - /// - /// Initializes a new instance of the class. - /// - /// The exception message. - /// The original exception thrown during validation. - public ConfigValidationException(string message, Exception innerException) : base(message, innerException) - { - } - } -} diff --git a/src/Spectre.Service/Configuration/DataRootConfig.cs b/src/Spectre.Service/Configuration/DataRootConfig.cs deleted file mode 100644 index bf3461e..0000000 --- a/src/Spectre.Service/Configuration/DataRootConfig.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * DataRootConfig.cs - * Data directory configuration & validation class. - * - Copyright 2017 Maciej Gamrat - - 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. -*/ -using System.IO; - -namespace Spectre.Service.Configuration -{ - /// - /// Data directory root configuration class. - /// - public class DataRootConfig - { - /// - /// Initializes a new instance of the class, - /// accepting local and remote directory paths. - /// - /// Local data directory path. - /// Remote data directory path. - public DataRootConfig(string localPath, string remotePath) - { - ValidatePath(localPath); - ValidatePath(remotePath); - - LocalPath = localPath; - RemotePath = remotePath; - } - - /// - /// Local data directory root. - /// - public string LocalPath { get; private set; } - - /// - /// Remote data directory root. - /// - public string RemotePath { get; private set; } - - /// - /// Validates if argument is a valid path. - /// - /// File path to validate. - /// Thrown when data directory path fails validation. - private void ValidatePath(string path) - { - try - { - var fi = new FileInfo(path); - } - catch (System.SystemException e) - { - throw new ConfigValidationException("Invalid data root path", e); - } - } - } -} diff --git a/src/Spectre.Service/ConsoleCaptureService.cs b/src/Spectre.Service/ConsoleCaptureService.cs deleted file mode 100644 index 1b3bf1d..0000000 --- a/src/Spectre.Service/ConsoleCaptureService.cs +++ /dev/null @@ -1,173 +0,0 @@ -/* - * ConsoleCaptureService.cs - * Implementation of console capture. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; -using System.IO; -using System.Text; -using System.Threading; -using Spectre.Service.Abstract; -using Timer = System.Timers.Timer; - -namespace Spectre.Service -{ - /// - /// Captures console output. - /// - /// - [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)] - public class ConsoleCaptureService : IConsoleCaptureService - { - #region Fields - - /// - /// Minimal interval which should suffice for updates without scheduling too much jobs. - /// - public const double MinimalReasonableUpdateInterval = 50; - - /// - /// The internal writer. - /// - private readonly StringWriter _writer; - - /// - /// The global stdout. - /// - private readonly TextWriter _stdout; - - /// - /// The timer for update notification. - /// - private readonly Timer _timer; - - /// - /// Timer update interval. - /// - private readonly double _updateInterval; - - /// - /// If true, instance is useless. - /// - private bool _disposed; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// The update interval. - /// updateInterval lower than MinimalReasonableUpdateInterval - public ConsoleCaptureService(double updateInterval) - { - if (updateInterval < ConsoleCaptureService.MinimalReasonableUpdateInterval) - { - throw new TooSmallUpdateIntervalException(updateInterval); - } - _stdout = Console.Out; - var builder = new StringBuilder(); - _writer = new StringWriter(builder); - Console.SetOut(_writer); - _updateInterval = updateInterval; - _timer = new Timer(_updateInterval); - Content = string.Empty; - _timer.Elapsed += (sender, args) => - { -#pragma warning disable SA1305 // Field names must not use Hungarian notation - var upToDateContent = builder.ToString(); -#pragma warning restore SA1305 // Field names must not use Hungarian notation - var suffix = builder.ToString(Content.Length, length: upToDateContent.Length - Content.Length); - if (Content != upToDateContent) - { - Content = upToDateContent; - OnWritten(suffix); - } - }; - _timer.Start(); - } - - #endregion - - #region IConsoleCaptureService - - /// - /// Occurs when anything was written. - /// - public event EventHandler Written; - - /// - /// Gets the captured content. - /// - /// - /// The content. - /// - public string Content { get; private set; } - - #endregion - - #region IDisposable - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(obj: this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - if (_disposed) - { - return; - } - - Thread.Sleep(millisecondsTimeout: (int)_updateInterval + 1); - - Console.SetOut(_stdout); - if (disposing) - { - _writer.Dispose(); - _timer.Stop(); - _timer.Dispose(); - } - _disposed = true; - } - - #endregion - - #region OnWritten - - /// - /// Called when console was written. - /// - /// The entry. - protected virtual void OnWritten(string entry) - { - Written?.Invoke(sender: this, e: entry); - } - - #endregion - } -} diff --git a/src/Spectre.Service/DatasetDetailsFinderService.cs b/src/Spectre.Service/DatasetDetailsFinderService.cs deleted file mode 100644 index db6aa31..0000000 --- a/src/Spectre.Service/DatasetDetailsFinderService.cs +++ /dev/null @@ -1,124 +0,0 @@ -/* - * DatasetDetailsFinderService.cs - Class providing services for DatasetDetailsFinder. With use of this services - it is possible to use querries from DatasetDetailsFinder without creating - an instance of DatasetsContext manually. - - Copyright 2017 Roman Lisak - - 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 Spectre.Service -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Spectre.Database.Contexts; - using Spectre.Database.Utils; - using Spectre.Service.Abstract; - - /// - /// DatasetDetailsFinder service. - /// - /// - internal class DatasetDetailsFinderService : IDatasetDetailsFinderService - { - /// - /// Service translating hash to upload number. - /// - /// The hash. - /// - /// Returns upload number basing on Hash. - /// Null for not existing hash. - /// - public string HashToUploadNumberOrDefault(string hash) - { - using (var context = new DatasetsContext()) - { - DatasetDetailsFinder service = new DatasetDetailsFinder(context); - return service.HashToUploadNumberOrDefault(hash); - } - } - - /// - /// Service translating friendly name to upload number. - /// - /// The friendlyname. - /// - /// Returns upload number basing on friendly name. - /// Null for not existing friendly name. - /// - public string FriendlyNameToUploadNumberOrDefault(string friendlyname) - { - using (var context = new DatasetsContext()) - { - DatasetDetailsFinder service = new DatasetDetailsFinder(context); - return service.FriendlyNameToUploadNumberOrDefault(friendlyname); - } - } - - /// - /// Service translating uploadnumber to hash. - /// - /// The uploadnumber. - /// - /// Returns Hash basing on upload number. - /// Null for not existing upload number. - /// - public string UploadNumberToHashOrDefault(string uploadnumber) - { - using (var context = new DatasetsContext()) - { - DatasetDetailsFinder service = new DatasetDetailsFinder(context); - return service.UploadNumberToHashOrDefault(uploadnumber); - } - } - - /// - /// Query for translating hash to friendly name. - /// - /// The hash. - /// - /// Returns FriendlyName for Hash. - /// Null for not existing Hash. - /// - public string HashToFriendlyNameOrDefault(string hash) - { - using (var context = new DatasetsContext()) - { - DatasetDetailsFinder service = new DatasetDetailsFinder(context); - return service.HashToFriendlyNameOrDefault(hash); - } - } - - /// - /// Query for translating upload number to friendly name. - /// - /// The uploadnumber. - /// - /// Returns friendly name for given upload number. - /// Null for not existing upload number. - /// - public string UploadNumberToFriendlyNameOrDefault(string uploadnumber) - { - using (var context = new DatasetsContext()) - { - DatasetDetailsFinder service = new DatasetDetailsFinder(context); - return service.UploadNumberToFriendlyNameOrDefault(uploadnumber); - } - } - } -} diff --git a/src/Spectre.Service/DivikService.cs b/src/Spectre.Service/DivikService.cs deleted file mode 100644 index 271b320..0000000 --- a/src/Spectre.Service/DivikService.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * DivikService.cs - * Contains definition of service for calculating Divik. - * - Copyright 2017 Michał Wolny - - 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. -*/ - -using System; -using Spectre.Algorithms.Methods; -using Spectre.Algorithms.Parameterization; -using Spectre.Algorithms.Results; -using Spectre.Data.Datasets; -using Spectre.Service.Abstract; - -namespace Spectre.Service -{ - /// - /// Class for calaculating divik. - /// - internal class DivikService : IDivikService, IDisposable - { - /// - /// Private field for holding for the service. - /// - private readonly Segmentation _segmentation; - - /// - /// Initializes a new instance of the class. - /// Creates (MCR) instance for the service. - /// - public DivikService() - { - _segmentation = new Segmentation(); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - _segmentation.Dispose(); - } - - /// - /// Service method for calculating divik. - /// - /// The source dataset being passed to the target. - /// The options passed to the divik algorithm. - /// of a given divik calculation. - public DivikResult CalculateDivik(IDataset dataset, DivikOptions options) - { - return _segmentation.Divik(dataset, options); - } - } -} diff --git a/src/Spectre.Service/Loaders/DatasetFormatException.cs b/src/Spectre.Service/Loaders/DatasetFormatException.cs deleted file mode 100644 index 01194da..0000000 --- a/src/Spectre.Service/Loaders/DatasetFormatException.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * DatasetFormatException.cs - * Exception thrown when dataset loader fails to load dataset from a file. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ -using System; - -namespace Spectre.Service.Loaders -{ - /// - /// Thrown when dataset loader fails to load dataset from a file. - /// - /// - public class DatasetFormatException : FormatException - { - /// - /// Initializes a new instance of the class. - /// - /// The exception message. - /// The original exception thrown during validation. - public DatasetFormatException(string message, Exception innerException) : base(message, innerException) - { - } - } -} diff --git a/src/Spectre.Service/Loaders/DatasetLoader.cs b/src/Spectre.Service/Loaders/DatasetLoader.cs deleted file mode 100644 index 04923cc..0000000 --- a/src/Spectre.Service/Loaders/DatasetLoader.cs +++ /dev/null @@ -1,143 +0,0 @@ -/* - * DatasetLoader.cs - * Class loading datasets from either local root or remote root. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System.IO; -using System.IO.Abstractions; -using System.Linq; -using Ninject; -using Spectre.Data.Datasets; -using Spectre.Dependencies; -using Spectre.Service.Configuration; - -namespace Spectre.Service.Loaders -{ - /// - /// Class for loading datasets from specified directories. - /// - public class DatasetLoader - { - #region Fields - - /// - /// Root for local directory. - /// - private readonly string _localRoot; - - /// - /// Root for remote directory. - /// - private readonly string _remoteRoot; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// Validated configuration of needed directories. - public DatasetLoader(DataRootConfig dataRootConfig) - { - _localRoot = dataRootConfig.LocalPath; - _remoteRoot = dataRootConfig.RemotePath; - - FileSystem = DependencyResolver.GetService(); - } - #endregion - - #region Properties - - /// - /// Handle to file system. - /// - private IFileSystem FileSystem { get; } - - #endregion - - #region Loaders - - /// - /// Returns dataset basing directly on the name of the file. - /// - /// File name. - /// Found dataset. - /// Throws when the file is not found both locally and remotely. - /// Throws when the loader fails to create dataset from the file. - public IDataset GetFromName(string name) - { - string fullPathLocal; - - var foundLocalFiles = FileSystem.Directory.GetFiles(_localRoot, name + ".*"); - if (foundLocalFiles.Length == 0) - { - var foundRemoteFiles = FileSystem.Directory.GetFiles(_remoteRoot, name + ".*"); - if (foundRemoteFiles.Length == 0) - { - throw new DatasetNotFoundException("Dataset file not found neither locally nor remotely.", name); - } - - var foundRemotePath = foundRemoteFiles.First(); - fullPathLocal = _localRoot + name + Path.GetExtension(foundRemotePath); - FileSystem.File.Copy(foundRemotePath, fullPathLocal); - } - else - { - fullPathLocal = foundLocalFiles.First(); - } - - try - { - return new BasicTextDataset(fullPathLocal); - } - catch (IOException e) - { - FileSystem.File.Delete(fullPathLocal); - throw new DatasetFormatException($"Failed to load dataset from file '{name}'.", e); - } - } - - /* - // TODO: @dkuchta: complete the methods below when database access is available - /// - /// Returns dataset from database, translating hash of the file into file directory. - /// - /// Hash as a key to database. - /// Found dataset. - public IDataset GetFromHash(string hash) - { - string name = ""; - //translate hash to name from database - return GetFromName(name); - } - - /// - /// Returns dataset from database, translating ID of the file into file directory. - /// - /// ID as a key to database. - /// Found dataset. - public IDataset GetFromUserId(string userId) - { - string name = ""; - //translate userId to name from database - return GetFromName(name); - } - */ - #endregion - } -} diff --git a/src/Spectre.Service/Loaders/DatasetNotFoundException.cs b/src/Spectre.Service/Loaders/DatasetNotFoundException.cs deleted file mode 100644 index 3ad29f9..0000000 --- a/src/Spectre.Service/Loaders/DatasetNotFoundException.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * DatasetNotFoundException.cs - * Exception thrown when dataset loader fails to find file with dataset. - * - Copyright 2017 Dariusz Kuchta - - 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. -*/ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Spectre.Service.Loaders -{ - /// - /// Thrown when dataset loader fails to find file with dataset. - /// - public class DatasetNotFoundException : FileNotFoundException - { - /// - /// Initializes a new instance of the class. - /// - /// The exception message. - /// Name of file. - public DatasetNotFoundException(string message, string fileName) : base(message, fileName) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The exception message. - /// Name of file. - /// The original exception thrown during validation. - public DatasetNotFoundException(string message, string fileName, Exception innerException) : base(message, fileName, innerException) - { - } - } -} diff --git a/src/Spectre.Service/Properties/AssemblyInfo.cs b/src/Spectre.Service/Properties/AssemblyInfo.cs deleted file mode 100644 index a62cc75..0000000 --- a/src/Spectre.Service/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Ogólne informacje o zestawie są kontrolowane poprzez następujący -// zestaw atrybutów. Zmień wartości tych atrybutów, aby zmodyfikować informacje -// powiązane z zestawem. -[assembly: AssemblyTitle("Spectre.Service")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Spectre.Service")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Ustawienie elementu ComVisible na wartość false sprawia, że typy w tym zestawie są niewidoczne -// dla składników COM. Jeśli potrzebny jest dostęp do typu w tym zestawie z -// COM, ustaw wartość true dla atrybutu ComVisible tego typu. -[assembly: ComVisible(false)] - -// Następujący identyfikator GUID jest identyfikatorem biblioteki typów w przypadku udostępnienia tego projektu w modelu COM -[assembly: Guid("287a1a8d-c029-4d47-96bc-755c91b7985d")] - -// Informacje o wersji zestawu zawierają następujące cztery wartości: -// -// Wersja główna -// Wersja pomocnicza -// Numer kompilacji -// Rewizja -// -// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki -// przy użyciu symbolu „*”, tak jak pokazano poniżej: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spectre.Service/ServiceFactory.cs b/src/Spectre.Service/ServiceFactory.cs deleted file mode 100644 index 4d70c75..0000000 --- a/src/Spectre.Service/ServiceFactory.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ServiceFactory.cs - * Contains definition of Factory for creating services. - * - Copyright 2017 Michał Wolny, Grzegorz Mrukwa - - 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. -*/ - -using Spectre.Service.Abstract; - -namespace Spectre.Service -{ - /// - /// Class for creating new services. - /// - public class ServiceFactory : IServiceFactory - { - /// - /// Factory method for getting . - /// - /// New instance of - public IDivikService GetDivikService() - { - return new DivikService(); - } - - /// - /// Gets the console capture service. - /// - /// The update interval. - /// New instance of - public IConsoleCaptureService GetConsoleCaptureService(double updateInterval = 1000.0) - { - return new ConsoleCaptureService(updateInterval); - } - - /// - /// Gets the path finder service. - /// - /// - /// IPathFinderInstance - /// - public IDatasetDetailsFinderService GetDatasetDetailsFinderService() - { - return new DatasetDetailsFinderService(); - } - } -} diff --git a/src/Spectre.Service/Spectre.Service.csproj b/src/Spectre.Service/Spectre.Service.csproj deleted file mode 100644 index d09958c..0000000 --- a/src/Spectre.Service/Spectre.Service.csproj +++ /dev/null @@ -1,103 +0,0 @@ - - - - - Debug - x64 - {287A1A8D-C029-4D47-96BC-755C91B7985D} - Library - Properties - Spectre.Service - Spectre.Service - v4.6.1 - 512 - - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - ..\CSharpCodingConvention.ruleset - true - bin\x64\Debug\Spectre.Service.xml - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - ..\CSharpCodingConvention.ruleset - bin\x64\Release\Spectre.Service.xml - - - - - ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - - - - - ..\packages\System.IO.Abstractions.2.0.0.143\lib\net40\System.IO.Abstractions.dll - - - ..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.143\lib\net40\System.IO.Abstractions.TestingHelpers.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - {9a886aec-58db-410d-91b9-c62e157501fa} - Spectre.Algorithms - - - {b5b60f79-653c-4e41-9721-06c478ce9e7c} - Spectre.Database - - - {70C87AF7-3189-4F6C-AC85-93309CF7CFDC} - Spectre.Data - - - {2b9f4dfd-c222-477a-9107-1a3c356002a4} - Spectre.Dependencies - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Spectre.Service/TooSmallUpdateIntervalException.cs b/src/Spectre.Service/TooSmallUpdateIntervalException.cs deleted file mode 100644 index 8507453..0000000 --- a/src/Spectre.Service/TooSmallUpdateIntervalException.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* - * TooSmallUpdateIntervalException.cs - * Exception thrown on unreasonably small update interval. - * - Copyright 2017 Grzegorz Mrukwa - - 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. -*/ - -using System; - -namespace Spectre.Service -{ - /// - /// Thrown when update interval is unreasonably small, to avoid congestion. - /// - /// - public class TooSmallUpdateIntervalException : ArgumentOutOfRangeException - { - /// - /// Initializes a new instance of the class. - /// - /// The update interval. - public TooSmallUpdateIntervalException(double updateInterval) - { - UpdateInterval = updateInterval; - } - - /// - /// Gets the update interval. - /// - /// - /// The update interval. - /// - public double UpdateInterval { get; } - } -} diff --git a/src/Spectre.Service/packages.config b/src/Spectre.Service/packages.config deleted file mode 100644 index ab37047..0000000 --- a/src/Spectre.Service/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file