Skip to content

Commit

Permalink
Merged PR 407: RELEASE: Version 3.2.17.2 released.
Browse files Browse the repository at this point in the history
FEAT: Property value overrides released as stable.
DATA: Updated Lite data files for May data.

Former-commit-id: 0706eaeaa8fc989228f4d7670612608596b3d6a3
  • Loading branch information
ben51degrees committed Jun 2, 2017
2 parents b870dc7 + 84701f9 commit ccabc13
Show file tree
Hide file tree
Showing 23 changed files with 966 additions and 80 deletions.
1 change: 1 addition & 0 deletions FoundationV3/FiftyOne.Foundation 4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<Compile Include="Mobile\Detection\Factories\EntityFactories.cs" />
<Compile Include="Mobile\Detection\Factories\CommonFactory.cs" />
<Compile Include="Mobile\Detection\Factories\EntityLoaderFactory.cs" />
<Compile Include="Mobile\Detection\Feature\PropertyValueOverride.cs" />
<Compile Include="Mobile\Detection\IDataSet.cs" />
<Compile Include="Mobile\Detection\IndirectDataSet.cs" />
<Compile Include="Mobile\Detection\ISimpleList.cs" />
Expand Down
68 changes: 67 additions & 1 deletion FoundationV3/Mobile/Detection/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,73 @@ internal SearchReadonlyList<Value, string> ValuesNameSearch
}
}
private SearchReadonlyList<Value, string> _valuesNameSearch = null;


#if !SQL_BUILD && !NETCORE_BUILD

/// <summary>
/// An array of the properties that are of type JavaScript.
/// </summary>
internal Property[] JavaScriptProperties
{
get
{
if (_javaScriptProperties == null)
{
lock (this)
{
if (_javaScriptProperties == null)
{
_javaScriptProperties = Properties.Where(i =>
i._valueType ==
Property.PropertyValueType.JavaScript).ToArray();
}
}
}
return _javaScriptProperties;
}
}
private Property[] _javaScriptProperties = null;

/// <summary>
/// Find all the properties that are of type JavaScript and are marked
/// with the property value override category.
/// </summary>
internal Property[] PropertyValueOverrideProperties
{
get
{
if (_propertyValueOverrideProperties == null)
{
lock (this)
{
if (_propertyValueOverrideProperties == null)
{
_propertyValueOverrideProperties =
JavaScriptProperties.Where(i =>
i.Category.Equals(
Constants.PropertyValueOverrideCategory)
).ToArray();
}
}
}
return _propertyValueOverrideProperties;
}
}
private Property[] _propertyValueOverrideProperties;

/// <summary>
/// Find all the properties that are of type JavaScript and are marked
/// with the property value override category.
/// </summary>
/// <returns>Array of JavaScript properties for this feature.</returns>
private static Property[] GetJavaScriptProperties()
{
return WebProvider.ActiveProvider.DataSet.JavaScriptProperties.
Where(i => i.Category.Equals(
Constants.PropertyValueOverrideCategory)).ToArray();
}

#endif
#endregion

#region Constructors
Expand Down
12 changes: 11 additions & 1 deletion FoundationV3/Mobile/Detection/DetectorModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ protected void Initialise(HttpApplication application)
// Configure the profile override component.
Feature.ProfileOverride.Init(application.Application);

// Configure the property value override component.
Feature.PropertyValueOverride.Init(application.Application);

// Register for an event to capture javascript requests
// for static resources and record bandwidth information.
application.BeginRequest += OnBeginRequestJavascript;
Expand Down Expand Up @@ -331,7 +334,14 @@ private static void AppendCoreJavaScript(HttpContext context, StringBuilder sb)
var profileOverrideJavascript = Feature.ProfileOverride.GetJavascript(context);
if (String.IsNullOrEmpty(profileOverrideJavascript) == false)
{
AppendJavascript(sb, Feature.ProfileOverride.GetJavascript(context));
AppendJavascript(sb, profileOverrideJavascript);
}

// Add property value override javascript if available for this request.
var propertyValueJavaScript = Feature.PropertyValueOverride.GetJavascript(context);
if (String.IsNullOrEmpty(propertyValueJavaScript) == false)
{
AppendJavascript(sb, propertyValueJavaScript);
}
}

Expand Down
26 changes: 25 additions & 1 deletion FoundationV3/Mobile/Detection/Entities/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,32 @@ internal Value(
_urlOffset = reader.ReadInt32();
}

/// <summary>
/// Constructs a new instance of <see cref="Value"/>.
/// </summary>
/// <param name="dataSet">
/// The data set the value is contained within.
/// </param>
/// <param name="property">
/// The property the dynamic value will relate to.
/// </param>
/// <param name="value">
/// The string name of the dynamic value.
/// </param>
internal Value(
DataSet dataSet,
Property property,
string value) : base(dataSet, -1)
{
_propertyIndex = property.Index;
_name = value;
_nameOffset = -1;
_descriptionOffset = -1;
_urlOffset = -1;
}

#endregion

#region Internal Methods

/// <summary>
Expand Down
104 changes: 90 additions & 14 deletions FoundationV3/Mobile/Detection/Entities/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public class Values : IList<Value>
/// </summary>
private readonly int[] _valueIndexes;

/// <summary>
/// An array of values to expose.
/// </summary>
private readonly IList<Value> _values;

#endregion

#region Properties
Expand All @@ -67,6 +72,19 @@ public bool IsDefault
}
}

/// <summary>
/// True if the value does not relate to a static one contained
/// in the data set and was created from an HTTP cookie set via
/// JavaScript or in some other manner.
/// </summary>
public bool IsDynamic
{
get
{
return _values != null;
}
}

#endregion

#region Constructor
Expand All @@ -78,14 +96,32 @@ public bool IsDefault
/// Property the values list relates to.
/// </param>
/// <param name="valueIndexes">
/// An array of values to use with the list.
/// An array of value indexes to use with the list.
/// </param>
internal Values(Property property, int[] valueIndexes)
{
_property = property;
_valueIndexes = valueIndexes;
_values = null;
}

/// <summary>
/// Constructs a new instance of the values list.
/// </summary>
/// <param name="property">
/// Property the values list relates to.
/// </param>
/// <param name="values">
/// An array of values to use with the list.
/// </param>
internal Values(Property property, IList<Value> values)
{
_property = property;
_values = values;
_valueIndexes = null;
}


#endregion

#region Public Methods
Expand All @@ -99,9 +135,16 @@ public Value this[string valueName]
{
get
{
var index = _property.DataSet.ValuesNameSearch.BinarySearch(
_valueIndexes, valueName);
return index >= 0 ? this[index] : null;
if (_valueIndexes != null)
{
var index = _property.DataSet.ValuesNameSearch.BinarySearch(
_valueIndexes, valueName);
return index >= 0 ? this[index] : null;
}
else
{
return _values.FirstOrDefault(i => valueName.Equals(i.Name));
}
}
}

Expand Down Expand Up @@ -189,13 +232,20 @@ public override string ToString()
/// <returns>The index of value if found in the list; otherwise, -1.</returns>
public int IndexOf(Value item)
{
for (var index = 0; index < _valueIndexes.Length; index++)
if (_valueIndexes != null)
{
if (_valueIndexes[index].Equals(item))
for (var index = 0; index < _valueIndexes.Length; index++)
{
return index;
if (_valueIndexes[index].Equals(item))
{
return index;
}
}
}
else if (_values != null)
{
return _values.IndexOf(item);
}
return -1;
}

Expand Down Expand Up @@ -228,7 +278,9 @@ public Value this[int index]
{
get
{
return _property.DataSet.Values[_valueIndexes[index]];
return _valueIndexes != null ?
_property.DataSet.Values[_valueIndexes[index]] :
_values[index];
}
set
{
Expand Down Expand Up @@ -260,7 +312,15 @@ public void Clear()
/// <returns>true if the value is found in the values list; otherwise, false.</returns>
public bool Contains(Value item)
{
return item != null && _valueIndexes.Contains(item.Index);
if (item != null)
{
if (_valueIndexes != null)
{
return _valueIndexes.Contains(item.Index);
}
return _values.Contains(item);
}
return false;
}

/// <summary>
Expand All @@ -270,9 +330,16 @@ public bool Contains(Value item)
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
public void CopyTo(Value[] array, int arrayIndex)
{
for (int i = arrayIndex; i < _valueIndexes.Length; i++)
if (_valueIndexes != null)
{
for (int i = arrayIndex; i < _valueIndexes.Length; i++)
{
array[i] = this[i];
}
}
else
{
array[i] = this[i];
_values.CopyTo(array, arrayIndex);
}
}

Expand All @@ -281,7 +348,12 @@ public void CopyTo(Value[] array, int arrayIndex)
/// </summary>
public int Count
{
get { return _valueIndexes.Length; }
get
{
return _valueIndexes != null ?
_valueIndexes.Length :
_values.Count;
}
}

/// <summary>
Expand All @@ -308,7 +380,11 @@ public bool Remove(Value item)
/// <returns>An IEnumerator&lt;<see cref="Value"/>&gt; object that can be used to iterate through the collection.</returns>
public IEnumerator<Value> GetEnumerator()
{
return _valueIndexes.Select(i => _property.DataSet.Values[i]).GetEnumerator();
if (_valueIndexes != null)
{
return _valueIndexes.Select(i => _property.DataSet.Values[i]).GetEnumerator();
}
return _values.GetEnumerator();
}

/// <summary>
Expand All @@ -317,7 +393,7 @@ public IEnumerator<Value> GetEnumerator()
/// <returns>An IEnumerator&lt;<see cref="Value"/>&gt; object that can be used to iterate through the collection.</returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _valueIndexes.GetEnumerator();
return GetEnumerator();
}

#endregion
Expand Down
Loading

0 comments on commit ccabc13

Please sign in to comment.