Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fixed issue #813 and #814 in DGML format #815

Merged
merged 4 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class DGMLOutputWriter : IReportWriter
FileExtension = ".dgml"
};

private readonly DGMLManager dgml = new DGMLManager();
private DGMLManager dgml;

public Task WriteStreamAsync(Stream stream, AnalyzeResponse response)
{
// Create a new dgml every time write to a new stream.
dgml = new DGMLManager();
ReferenceGraph rg = ReferenceGraph.CreateGraph(response);

ReportingResult analysisResult = response.ReportingResult;
Expand Down
78 changes: 39 additions & 39 deletions src/lib/Microsoft.Fx.Portability.Reports.DGML/ReferenceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,65 +66,65 @@ public double GetPortabilityIndexForReferences(int target)
if (Nodes.Count == 0)
return 1;

// reset all the nodes in the reference graph as not be searched.
ResetReferenceSearchGraph();

// sum up the number of calls to available APIs and the ones for not available APIs for references.
if (!TryGetAPICountFromReferences(target, out int availableApis, out int unavailableApis))
{
// Cycle detected
return 1;
}
else
{
// remove the calls from the current node.
availableApis -= UsageData[target].GetAvailableAPICalls();
unavailableApis -= UsageData[target].GetUnavailableAPICalls();
GetAPICountFromReferences(target, out int availableApis, out int unavailableApis);

// prevent Div/0
if (availableApis == 0 && unavailableApis == 0)
return 0;
// prevent Div/0. When availableApis is 0 and unavailableApis is 0, it likely means that it's references are all not resulted assemblies, return 0.
if (availableApis == 0 && unavailableApis == 0)
return 0;

return availableApis / ((double)availableApis + unavailableApis);
}
return availableApis / ((double)availableApis + unavailableApis);
}

public bool TryGetAPICountFromReferences(int target, out int availAPIs, out int unavailAPIs)
private void GetAPICountFromReferences(int target, out int availAPIs, out int unavailAPIs)
{
availAPIs = UsageData[target].GetAvailableAPICalls();
unavailAPIs = UsageData[target].GetUnavailableAPICalls();

// We are going to use a flag on the object to detect if we have a reference cycle while computing the APIs for the references.
if (_searchInGraph == true)
{
// Cycle!!!
_searchInGraph = false; // Reset this flag
return false;
}
else
{
_searchInGraph = true;
}
availAPIs = 0;
unavailAPIs = 0;

foreach (var item in Nodes)
{
if (item.UsageData == null)
// We are going to use the flag on the object to detect if we have run into this node in the reference graph while computing the APIs for the references,
// because we want to only count a reference node once if it is referenced in the graph more than once.
if (item._searchInGraph == true)
{
// skip the Node with no UsageData
continue;
}

if (!item.TryGetAPICountFromReferences(target, out int refCountAvail, out int refCountUnavail))
else
{
// Cycle!
_searchInGraph = false; // Reset this flag
item._searchInGraph = true;
}

return false;
if (item.UsageData != null)
{
availAPIs += item.UsageData[target].GetAvailableAPICalls();
unavailAPIs += item.UsageData[target].GetUnavailableAPICalls();
}

item.GetAPICountFromReferences(target, out int refCountAvail, out int refCountUnavail);

availAPIs += refCountAvail;
unavailAPIs += refCountUnavail;
}
}

/// <summary>
/// reset all the nodes in the reference graph as not be searched.
/// </summary>
private void ResetReferenceSearchGraph()
{
// if we don't have any outgoing references, done reset with this node
if (Nodes.Count == 0)
return;
foreach (var item in Nodes)
{
item._searchInGraph = false;
item.ResetReferenceSearchGraph();
}

_searchInGraph = false;
return true;
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Microsoft.Fx.Portability.Utils.JsonConverters
{
/// <summary>
/// Json.NET does not handle <see cref="IDictionary{TKey, TValue}"/> when TKey is a type other than string. This provides
/// Json.NET does not handle <see cref="IDictionary&lt;TKey, TValue&gt;"/> when TKey is a type other than string. This provides
/// a wrapper for these types to serialize in a Key/Value system (like DCJS).
/// </summary>
internal class JsonMultiDictionaryConverter<TKey, TValue> : JsonConverter<IDictionary<TKey, ICollection<TValue>>>
Expand Down