Skip to content

Commit

Permalink
Support gz archive files Fix #231
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Jul 17, 2020
1 parent 4cc1dac commit 2007e6d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Analogy.UnitTests/Analogy.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="MessageHandlerForTesting.cs" />
<Compile Include="MessagePackFormatTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadBuiltInFilesTests.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Analogy.LogViewer.Interfaces">
Expand All @@ -87,6 +88,17 @@
<Name>Analogy</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="example.ajson">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="example.ajson.gz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="example.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions Analogy.UnitTests/ReadBuiltInFilesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Analogy.UnitTests
{
[TestClass]
public class ReadBuiltInFilesTests
{
private CancellationTokenSource cancellationTokenSource;
private MessageHandlerForTesting handler = new MessageHandlerForTesting();
// [TestMethod]
public void TestWriteAndRead()
{
string fileName = "example.ajson";
cancellationTokenSource = new CancellationTokenSource();
FileProcessor fp = new FileProcessor(handler);

}
}
}
1 change: 1 addition & 0 deletions Analogy.UnitTests/example.ajson

Large diffs are not rendered by default.

Binary file added Analogy.UnitTests/example.ajson.gz
Binary file not shown.
Binary file added Analogy.UnitTests/example.zip
Binary file not shown.
1 change: 1 addition & 0 deletions Analogy/CommonChangeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static IEnumerable<AnalogyChangeLog> GetChangeLog()
{
return new List<AnalogyChangeLog>
{
new AnalogyChangeLog("Support gz archive files #231",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2020,07,17)),
new AnalogyChangeLog("Add .net framework 4.7.1 compilation target #236",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2020,07,16)),
new AnalogyChangeLog("Remove XML format for analogy. #230",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2020,07,13)),
new AnalogyChangeLog("Add search filters hints / indicators. #232",AnalogChangeLogType.Improvement,"Lior Banai",new DateTime(2020,07,13)),
Expand Down
2 changes: 1 addition & 1 deletion Analogy/FileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void UnzipGzFileIntoTempFolder(string zipPath, string extractPath)
FileInfo fileToDecompress = new FileInfo(zipPath);
using (FileStream originalFileStream = fileToDecompress.OpenRead())
{
string currentFileName = fileToDecompress.FullName;
string currentFileName = fileToDecompress.Name;
string newFileName = Path.Combine(extractPath, currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length));

using (FileStream decompressedFileStream = File.Create(newFileName))
Expand Down
2 changes: 1 addition & 1 deletion Analogy/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ private string GetOpenFilter(string openFilter)
}
if (!openFilter.Contains("*.gz",StringComparison.InvariantCultureIgnoreCase))
{
string compressedFilter = "|Compressed GZ Archive (*.gz)|*.gz";
string compressedFilter = "|Compressed Gzip Archive (*.gz)|*.gz";
openFilter = openFilter + compressedFilter;
}

Expand Down
7 changes: 4 additions & 3 deletions Analogy/Managers/FactoriesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public FactoriesManager()
var currentAssembly = Assembly.GetExecutingAssembly();
var analogyFactorySetting = UserSettingsManager.UserSettings.GetOrAddFactorySetting(analogyFactory);
analogyFactorySetting.FactoryName = analogyFactory.Title;
FactoryContainer fc = new FactoryContainer(currentAssembly, analogyFactory, analogyFactorySetting);
FactoryContainer fc = new FactoryContainer(currentAssembly, Environment.CurrentDirectory, analogyFactory, analogyFactorySetting);
fc.AddDataProviderFactory(new AnalogyOfflineDataProviderFactory());
fc.AddCustomActionFactory(new AnalogyCustomActionFactory());
BuiltInFactories.Add(fc);
Expand Down Expand Up @@ -287,15 +287,16 @@ private ExternalDataProviders()
{
try
{
Assembly assembly = Assembly.LoadFrom(Path.GetFullPath(aFile));
string path = Path.GetFullPath(aFile);
Assembly assembly = Assembly.LoadFrom(path);
var types = assembly.GetTypes().ToList();

foreach (var f in types.Where(aType => aType.GetInterface(nameof(IAnalogyFactory)) != null))
{
var factory = Activator.CreateInstance(f) as IAnalogyFactory;
var setting = UserSettingsManager.UserSettings.GetOrAddFactorySetting(factory);
setting.FactoryName = factory.Title;
FactoryContainer fc = new FactoryContainer(assembly, factory, setting);
FactoryContainer fc = new FactoryContainer(assembly, path, factory, setting);
if (Factories.Exists(fa => fa.Factory.FactoryId == factory.FactoryId))
{
Factories.Remove(Factories.FirstOrDefault(fa =>
Expand Down
3 changes: 2 additions & 1 deletion Analogy/Managers/FactoryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Analogy.Managers
{
public class FactoryContainer
{
public string AssemblyFullPath { get; }
public Assembly Assembly { get; }
public IAnalogyFactory Factory { get; }
public FactorySettings FactorySetting { get; }
Expand All @@ -19,7 +20,7 @@ public class FactoryContainer
public List<IAnalogyExtensionsFactory> ExtensionsFactories { get; }
public List<IAnalogyComponentImages> DataProviderImages { get; private set; }

public FactoryContainer(Assembly assembly, IAnalogyFactory factory, FactorySettings factorySetting)
public FactoryContainer(Assembly assembly,string assemblyFullPath, IAnalogyFactory factory, FactorySettings factorySetting)
{
Assembly = assembly;
Factory = factory;
Expand Down

0 comments on commit 2007e6d

Please sign in to comment.