Skip to content

Commit

Permalink
Refactor file association to use data provider and not data factory #…
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Sep 15, 2023
1 parent af9cc85 commit 0f1f5d7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Analogy.Common/Interfaces/IFactoriesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ IEnumerable<IAnalogyOfflineDataProvider> GetSupportedOfflineDataSourcesFromFacto
bool IsBuiltInFactory(Guid factoryId);
List<IAnalogyDataProviderSettings> GetProvidersSettings();
Image GetLargeImage(Guid componentId);
FactoryContainer GetFactoryContainer(Guid componentId);
List<FactoryContainer> GetFactoryContainer(Guid componentId);
Image? GetSmallImage(Guid componentId);
IEnumerable<IAnalogyExtension> GetExtensions(IAnalogyDataProvider dataProvider);
IEnumerable<IAnalogyExtension> GetAllExtensions();
Expand Down
4 changes: 2 additions & 2 deletions Analogy.Common/Managers/DefaultFactoriesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public Image GetLargeImage(Guid componentId)
return Resources.Analogy_image_32x32;
}

public FactoryContainer GetFactoryContainer(Guid componentId)
public List<FactoryContainer> GetFactoryContainer(Guid componentId)
{
return null;
return new List<FactoryContainer>();
}

public Image? GetSmallImage(Guid componentId)
Expand Down
15 changes: 8 additions & 7 deletions Analogy/Forms/FluentDesignMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ private async Task OpenOfflineFileWithSpecificDataProvider(string[] files)
var associations = Settings.GetDataProvidesForFilesAssociations(files);
if (associations.Any())
{
var parser = FactoriesManager.GetAllOfflineDataSources(associations).ToList();
if (parser.Count == 1)
var parsers = FactoriesManager.GetAllOfflineDataSources(associations).ToList();
if (parsers.Count == 1 || parsers.Select(p => p.Id).Distinct().Count() == 1)
{
LoadFactoryInAccordion(parser.First().Id);
await OpenOfflineLogs(files, parser.First());
LoadFactoryInAccordion(parsers.First().Id);
await OpenOfflineLogs(files, parsers.First());
}
else
{
Expand Down Expand Up @@ -691,7 +691,8 @@ private void LoadFactoryInAccordion(Guid factoryId)
}
accordionControl.BeginUpdate();
accordionControl.Clear();
FactoryContainer fc = FactoriesManager.GetFactoryContainer(factoryId) ?? FactoriesManager.GetBuiltInFactoryContainer(factoryId);
var containers = FactoriesManager.GetFactoryContainer(factoryId);
var fc = containers.Count == 1 ? containers.First() : FactoriesManager.GetBuiltInFactoryContainer(factoryId);
activeProvider = fc.Factory.FactoryId;
Settings.LastOpenedDataProvider = activeProvider;

Expand Down Expand Up @@ -902,8 +903,8 @@ void OnXtcLogsOnControlRemoved(object sender, DockPanelEventArgs arg)

#endregion

FactoryContainer container = FactoriesManager.GetFactoryContainer(offlineAnalogy.Id);
IAnalogyImages? images = container?.Images?.FirstOrDefault();
var containers = FactoriesManager.GetFactoryContainer(offlineAnalogy.Id);
IAnalogyImages? images = containers.Count == 1 ? containers.First()?.Images?.FirstOrDefault() : null;

var preDefinedFolderExist = !string.IsNullOrEmpty(offlineAnalogy.InitialFolderFullPath) &&
Directory.Exists(offlineAnalogy.InitialFolderFullPath);
Expand Down
29 changes: 16 additions & 13 deletions Analogy/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,26 +664,31 @@ private async Task OpenOfflineFileWithSpecificDataProvider(string[] files)
}
else
{
//try from file association:
//try from file association:
var associations = Settings.GetDataProvidesForFilesAssociations(files);
if (associations.Any())
{
var parsers = FactoriesManager.GetAllOfflineDataSources(associations).ToList();
if (parsers.Count == 1)
if (parsers.Count == 1 || parsers.Select(p => p.Id).Distinct().Count() == 1)
{
var parser = parsers.First();
var fc = FactoriesManager.GetFactoryContainer(parser.Id);
RibbonPage? page = Mapping.TryGetValue(fc.Factory.FactoryId, out RibbonPage? value)
? value
: null;
if (page is not null)
RibbonPage? page = null;
if (fc.Any())
{
ribbonControlMain.SelectPage(page);
page = Mapping.TryGetValue(fc.First().Factory.FactoryId, out RibbonPage? value)
? value
: null;
if (page is not null)
{
ribbonControlMain.SelectPage(page);
}
}
await OpenOfflineLogs(page, files, parser);
}
else
{

XtraMessageBox.Show($@"More than one data provider detected for this file.{Environment.NewLine}Please open it directly from the data provider menu", "Unable to open file",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
Expand Down Expand Up @@ -1477,10 +1482,8 @@ private void AddMultiplesOfflineDataSource(IAnalogyFactory primaryFactory, Ribbo

Guid factoryId = factory.FactoryId;
string factoryTitle = factory.Title;
FactoryContainer container = FactoriesManager.GetFactoryContainer(factoryId);
IAnalogyImages? images = container?.Images?.FirstOrDefault();


var containers = FactoriesManager.GetFactoryContainer(factoryId);
IAnalogyImages? images = containers.Count == 1 ? containers.First().Images?.FirstOrDefault() : null;

#region Actions
async Task OpenOffline(string titleOfDataSource, IAnalogyOfflineDataProvider dataProvider, string initialFolder,
Expand Down Expand Up @@ -1914,8 +1917,8 @@ void OnXtcLogsOnControlRemoved(object sender, DockPanelEventArgs arg)
dockManager1.ClosedPanel += OnXtcLogsOnControlRemoved;
}
#endregion
FactoryContainer container = FactoriesManager.GetFactoryContainer(offlineAnalogy.Id);
IAnalogyImages? images = container?.Images?.FirstOrDefault();
var containers = FactoriesManager.GetFactoryContainer(offlineAnalogy.Id);
IAnalogyImages? images = containers.Count == 1 ? containers.First().Images?.FirstOrDefault() : null;

var preDefinedFolderExist = !string.IsNullOrEmpty(offlineAnalogy.InitialFolderFullPath) &&
Directory.Exists(offlineAnalogy.InitialFolderFullPath);
Expand Down
8 changes: 6 additions & 2 deletions Analogy/Managers/FactoriesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public List<IAnalogyDataProviderSettings> GetProvidersSettings() => Factories
}
return null;
}
public FactoryContainer GetFactoryContainer(Guid componentId)
=> Factories.SingleOrDefault(f => f.ContainsDataProviderOrDataFactory(componentId));
public List<FactoryContainer> GetFactoryContainer(Guid componentId)
=> Factories.Where(f => f.ContainsDataProviderOrDataFactory(componentId)).ToList();

public Image? GetSmallImage(Guid componentId)
{
Expand Down Expand Up @@ -590,6 +590,10 @@ public IEnumerable<IAnalogyOfflineDataProvider> GetAllOfflineDataSources(IEnumer
{
foreach (var fc in Factories)
{
if (fc.FactorySetting.Status == DataProviderFactoryStatus.Disabled)
{
continue;
}
foreach (var dpf in fc.DataProvidersFactories)
{
IEnumerable<IAnalogyOfflineDataProvider> supported =
Expand Down

0 comments on commit 0f1f5d7

Please sign in to comment.