mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
Simplified usages in UIX project
This commit is contained in:
@@ -23,29 +23,29 @@ namespace Microsoft.Iris.Data
|
||||
|
||||
public Resource(string uri, bool forceSynchronous)
|
||||
{
|
||||
this._uri = uri;
|
||||
this._forceSynchronous = forceSynchronous;
|
||||
this._status = ResourceStatus.NeedsAcquire;
|
||||
_uri = uri;
|
||||
_forceSynchronous = forceSynchronous;
|
||||
_status = ResourceStatus.NeedsAcquire;
|
||||
}
|
||||
|
||||
public string Uri => this._uri;
|
||||
public string Uri => _uri;
|
||||
|
||||
public abstract string Identifier { get; }
|
||||
|
||||
public void Acquire() => this.Acquire(null);
|
||||
public void Acquire() => Acquire(null);
|
||||
|
||||
public void Acquire(ResourceAcquisitionCompleteHandler completeHandler)
|
||||
{
|
||||
++this._acquisitions;
|
||||
++_acquisitions;
|
||||
if (completeHandler != null)
|
||||
this._completeHandlers += completeHandler;
|
||||
if (this._status == ResourceStatus.Acquiring)
|
||||
_completeHandlers += completeHandler;
|
||||
if (_status == ResourceStatus.Acquiring)
|
||||
return;
|
||||
if (this._status != ResourceStatus.Available)
|
||||
if (_status != ResourceStatus.Available)
|
||||
{
|
||||
this._status = ResourceStatus.Acquiring;
|
||||
this._errorDetails = null;
|
||||
this.StartAcquisition(this._forceSynchronous);
|
||||
_status = ResourceStatus.Acquiring;
|
||||
_errorDetails = null;
|
||||
StartAcquisition(_forceSynchronous);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -55,39 +55,39 @@ namespace Microsoft.Iris.Data
|
||||
}
|
||||
}
|
||||
|
||||
public void Free() => this.Free(null);
|
||||
public void Free() => Free(null);
|
||||
|
||||
public void Free(ResourceAcquisitionCompleteHandler completeHandler)
|
||||
{
|
||||
--this._acquisitions;
|
||||
--_acquisitions;
|
||||
if (completeHandler != null)
|
||||
this._completeHandlers -= completeHandler;
|
||||
if (this._acquisitions != 0)
|
||||
_completeHandlers -= completeHandler;
|
||||
if (_acquisitions != 0)
|
||||
return;
|
||||
if (this._status == ResourceStatus.Acquiring)
|
||||
this.CancelAcquisition();
|
||||
else if (this._buffer != IntPtr.Zero)
|
||||
if (_status == ResourceStatus.Acquiring)
|
||||
CancelAcquisition();
|
||||
else if (_buffer != IntPtr.Zero)
|
||||
{
|
||||
if (this._requiresMemoryFree)
|
||||
FreeNativeBuffer(this._buffer);
|
||||
this._buffer = IntPtr.Zero;
|
||||
if (_requiresMemoryFree)
|
||||
FreeNativeBuffer(_buffer);
|
||||
_buffer = IntPtr.Zero;
|
||||
}
|
||||
this._status = ResourceStatus.NeedsAcquire;
|
||||
_status = ResourceStatus.NeedsAcquire;
|
||||
}
|
||||
|
||||
public ResourceStatus Status
|
||||
{
|
||||
get => this._status;
|
||||
set => this._status = value;
|
||||
get => _status;
|
||||
set => _status = value;
|
||||
}
|
||||
|
||||
public string ErrorDetails => this._errorDetails;
|
||||
public string ErrorDetails => _errorDetails;
|
||||
|
||||
public IntPtr Buffer => this._buffer;
|
||||
public IntPtr Buffer => _buffer;
|
||||
|
||||
public uint Length => this._length;
|
||||
public uint Length => _length;
|
||||
|
||||
public bool ForceSynchronous => this._forceSynchronous;
|
||||
public bool ForceSynchronous => _forceSynchronous;
|
||||
|
||||
protected abstract void StartAcquisition(bool forceSynchronous);
|
||||
|
||||
@@ -99,23 +99,23 @@ namespace Microsoft.Iris.Data
|
||||
bool requiresMemoryFree,
|
||||
string errorDetails)
|
||||
{
|
||||
this._buffer = buffer;
|
||||
this._length = length;
|
||||
this._requiresMemoryFree = requiresMemoryFree;
|
||||
_buffer = buffer;
|
||||
_length = length;
|
||||
_requiresMemoryFree = requiresMemoryFree;
|
||||
if (buffer != IntPtr.Zero)
|
||||
{
|
||||
this._status = ResourceStatus.Available;
|
||||
_status = ResourceStatus.Available;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._status = ResourceStatus.Error;
|
||||
_status = ResourceStatus.Error;
|
||||
if (errorDetails == null)
|
||||
errorDetails = string.Format("Failed to acquire resource '{0}'", Identifier);
|
||||
this._errorDetails = errorDetails;
|
||||
_errorDetails = errorDetails;
|
||||
}
|
||||
if (this._completeHandlers == null)
|
||||
if (_completeHandlers == null)
|
||||
return;
|
||||
this._completeHandlers(this);
|
||||
_completeHandlers(this);
|
||||
}
|
||||
|
||||
protected static IntPtr AllocNativeBuffer(uint length) => NativeApi.MemAlloc(length, false);
|
||||
@@ -124,12 +124,12 @@ namespace Microsoft.Iris.Data
|
||||
|
||||
private void FireAcquisitionCompleteHandlers()
|
||||
{
|
||||
if (this._completeHandlers == null)
|
||||
if (_completeHandlers == null)
|
||||
return;
|
||||
this._completeHandlers(this);
|
||||
this._completeHandlers = null;
|
||||
_completeHandlers(this);
|
||||
_completeHandlers = null;
|
||||
}
|
||||
|
||||
public override string ToString() => this._uri;
|
||||
public override string ToString() => _uri;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,24 +16,24 @@ namespace Microsoft.Iris.Data
|
||||
private Map<string, IResourceProvider> _sourcesTable;
|
||||
private static ResourceManager s_instance = new ResourceManager();
|
||||
|
||||
private ResourceManager() => this._sourcesTable = new Map<string, IResourceProvider>();
|
||||
private ResourceManager() => _sourcesTable = new Map<string, IResourceProvider>();
|
||||
|
||||
public static ResourceManager Instance => s_instance;
|
||||
|
||||
public void RegisterSource(string scheme, IResourceProvider source) => this._sourcesTable[scheme] = source;
|
||||
public void RegisterSource(string scheme, IResourceProvider source) => _sourcesTable[scheme] = source;
|
||||
|
||||
public void UnregisterSource(string scheme) => this._sourcesTable.Remove(scheme);
|
||||
public void UnregisterSource(string scheme) => _sourcesTable.Remove(scheme);
|
||||
|
||||
public bool IsRegisteredSource(string scheme) => this._sourcesTable.ContainsKey(scheme);
|
||||
public bool IsRegisteredSource(string scheme) => _sourcesTable.ContainsKey(scheme);
|
||||
|
||||
public Resource GetResource(string uri) => this.GetResource(uri, false);
|
||||
public Resource GetResource(string uri) => GetResource(uri, false);
|
||||
|
||||
public Resource GetResource(string uri, bool forceSynchronous)
|
||||
{
|
||||
Resource resource = null;
|
||||
if (this._redirects != null)
|
||||
if (_redirects != null)
|
||||
{
|
||||
foreach (ResourceManager.UriRedirect redirect in this._redirects)
|
||||
foreach (ResourceManager.UriRedirect redirect in _redirects)
|
||||
{
|
||||
if (uri.StartsWith(redirect.fromPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -42,7 +42,7 @@ namespace Microsoft.Iris.Data
|
||||
ErrorManager.ReportError("Resource {0} not found, but should have been located by a markup redirect", uri);
|
||||
return null;
|
||||
}
|
||||
resource = this.GetResourceWorker(redirect.toPrefix + uri.Substring(redirect.fromPrefix.Length), true);
|
||||
resource = GetResourceWorker(redirect.toPrefix + uri.Substring(redirect.fromPrefix.Length), true);
|
||||
if (resource != null)
|
||||
{
|
||||
resource.Acquire();
|
||||
@@ -57,7 +57,7 @@ namespace Microsoft.Iris.Data
|
||||
}
|
||||
}
|
||||
if (resource == null)
|
||||
resource = this.GetResourceWorker(uri, forceSynchronous);
|
||||
resource = GetResourceWorker(uri, forceSynchronous);
|
||||
return resource;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Microsoft.Iris.Data
|
||||
return null;
|
||||
}
|
||||
IResourceProvider resourceProvider;
|
||||
if (this._sourcesTable.TryGetValue(scheme, out resourceProvider))
|
||||
if (_sourcesTable.TryGetValue(scheme, out resourceProvider))
|
||||
resource = resourceProvider.GetResource(hierarchicalPart, uri, forceSynchronous);
|
||||
else
|
||||
ErrorManager.ReportWarning("Invalid resource protocol: '{0}'", scheme);
|
||||
@@ -100,9 +100,9 @@ namespace Microsoft.Iris.Data
|
||||
ResourceManager.UriRedirect uriRedirect = new ResourceManager.UriRedirect();
|
||||
uriRedirect.fromPrefix = fromPrefix;
|
||||
uriRedirect.toPrefix = toPrefix;
|
||||
if (this._redirects == null)
|
||||
this._redirects = new Vector<ResourceManager.UriRedirect>();
|
||||
this._redirects.Add(uriRedirect);
|
||||
if (_redirects == null)
|
||||
_redirects = new Vector<ResourceManager.UriRedirect>();
|
||||
_redirects.Add(uriRedirect);
|
||||
}
|
||||
|
||||
public static Resource AcquireResource(string uri)
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Microsoft.Iris.Data
|
||||
|
||||
public ArrayList Acquire()
|
||||
{
|
||||
ArrayList arrayList = this._list;
|
||||
this._list = null;
|
||||
ArrayList arrayList = _list;
|
||||
_list = null;
|
||||
if (arrayList == null)
|
||||
arrayList = new ArrayList();
|
||||
return arrayList;
|
||||
@@ -24,7 +24,7 @@ namespace Microsoft.Iris.Data
|
||||
public void Release(ArrayList list)
|
||||
{
|
||||
list.Clear();
|
||||
this._list = list;
|
||||
_list = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ namespace Microsoft.Iris.Data
|
||||
int newIndex,
|
||||
int count)
|
||||
{
|
||||
this._count = count;
|
||||
this._type = type;
|
||||
this._oldIndex = oldIndex;
|
||||
this._newIndex = newIndex;
|
||||
_count = count;
|
||||
_type = type;
|
||||
_oldIndex = oldIndex;
|
||||
_newIndex = newIndex;
|
||||
}
|
||||
|
||||
public UIListContentsChangedArgs(UIListContentsChangeType type, int oldIndex, int newIndex)
|
||||
@@ -32,13 +32,13 @@ namespace Microsoft.Iris.Data
|
||||
{
|
||||
}
|
||||
|
||||
public UIListContentsChangeType Type => this._type;
|
||||
public UIListContentsChangeType Type => _type;
|
||||
|
||||
public int OldIndex => this._oldIndex;
|
||||
public int OldIndex => _oldIndex;
|
||||
|
||||
public int NewIndex => this._newIndex;
|
||||
public int NewIndex => _newIndex;
|
||||
|
||||
public int Count => this._count;
|
||||
public int Count => _count;
|
||||
|
||||
public override string ToString() => string.Format("{0} type: {1}, old: {2}, new: {3}, count: {4}", base.ToString(), Type, OldIndex, NewIndex, Count);
|
||||
}
|
||||
|
||||
@@ -27,81 +27,81 @@ namespace Microsoft.Iris.Data
|
||||
|
||||
public UpdateHelper(IVirtualList virtualList)
|
||||
{
|
||||
this._virtualList = virtualList;
|
||||
this._itemsToUpdate = new List<int>();
|
||||
this._throttle = Environment.ProcessorCount * 2;
|
||||
this._outstandingUpdates = new List<int>();
|
||||
_virtualList = virtualList;
|
||||
_itemsToUpdate = new List<int>();
|
||||
_throttle = Environment.ProcessorCount * 2;
|
||||
_outstandingUpdates = new List<int>();
|
||||
}
|
||||
|
||||
public void AddIndex(int index)
|
||||
{
|
||||
this._itemsToUpdate.Add(index);
|
||||
this._listIsDirty = true;
|
||||
this.TriggerNextUpdate();
|
||||
_itemsToUpdate.Add(index);
|
||||
_listIsDirty = true;
|
||||
TriggerNextUpdate();
|
||||
}
|
||||
|
||||
public void AdjustIndices(int lowThreshold, int amount) => this.AdjustIndices(lowThreshold, int.MaxValue, amount);
|
||||
public void AdjustIndices(int lowThreshold, int amount) => AdjustIndices(lowThreshold, int.MaxValue, amount);
|
||||
|
||||
public void AdjustIndices(int lowThreshold, int highThreshold, int amt)
|
||||
{
|
||||
for (int index = 0; index < this._itemsToUpdate.Count; ++index)
|
||||
for (int index = 0; index < _itemsToUpdate.Count; ++index)
|
||||
{
|
||||
int num = this._itemsToUpdate[index];
|
||||
int num = _itemsToUpdate[index];
|
||||
if (num >= lowThreshold && num <= highThreshold)
|
||||
this._itemsToUpdate[index] = num + amt;
|
||||
_itemsToUpdate[index] = num + amt;
|
||||
}
|
||||
if (this._lastInterestIndex < lowThreshold || this._lastInterestIndex > highThreshold)
|
||||
if (_lastInterestIndex < lowThreshold || _lastInterestIndex > highThreshold)
|
||||
return;
|
||||
this._lastInterestIndex += amt;
|
||||
_lastInterestIndex += amt;
|
||||
}
|
||||
|
||||
public void Clear() => this._itemsToUpdate.Clear();
|
||||
public void Clear() => _itemsToUpdate.Clear();
|
||||
|
||||
public void RemoveIndex(int index)
|
||||
{
|
||||
int count = this._itemsToUpdate.Count;
|
||||
int count = _itemsToUpdate.Count;
|
||||
int index1 = 0;
|
||||
while (index1 < count && this._itemsToUpdate[index1] != index)
|
||||
while (index1 < count && _itemsToUpdate[index1] != index)
|
||||
++index1;
|
||||
if (index1 >= count)
|
||||
return;
|
||||
int index2 = index1;
|
||||
for (int index3 = index1 + 1; index3 < count; ++index3)
|
||||
{
|
||||
int num = this._itemsToUpdate[index3];
|
||||
int num = _itemsToUpdate[index3];
|
||||
if (num != index)
|
||||
{
|
||||
this._itemsToUpdate[index2] = num;
|
||||
_itemsToUpdate[index2] = num;
|
||||
++index2;
|
||||
}
|
||||
}
|
||||
this._itemsToUpdate.RemoveRange(index2, count - index2);
|
||||
_itemsToUpdate.RemoveRange(index2, count - index2);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this._timer == null)
|
||||
if (_timer == null)
|
||||
return;
|
||||
this._timer.Enabled = false;
|
||||
_timer.Enabled = false;
|
||||
}
|
||||
|
||||
private void TriggerNextUpdate()
|
||||
{
|
||||
this.EnsureTimer();
|
||||
this._timer.Enabled = true;
|
||||
EnsureTimer();
|
||||
_timer.Enabled = true;
|
||||
}
|
||||
|
||||
private void DeliverNextUpdate(object senderObject, EventArgs unusedArgs)
|
||||
{
|
||||
if (this._itemsToUpdate.Count == 0)
|
||||
if (_itemsToUpdate.Count == 0)
|
||||
return;
|
||||
if (this._outstandingUpdates.Count == this._throttle)
|
||||
if (_outstandingUpdates.Count == _throttle)
|
||||
{
|
||||
this.TriggerNextUpdate();
|
||||
TriggerNextUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
Repeater repeaterHost = this._virtualList.RepeaterHost;
|
||||
Repeater repeaterHost = _virtualList.RepeaterHost;
|
||||
if (repeaterHost == null)
|
||||
return;
|
||||
int index1 = -1;
|
||||
@@ -116,18 +116,18 @@ namespace Microsoft.Iris.Data
|
||||
if (index1 != -1)
|
||||
{
|
||||
int dataIndex;
|
||||
ListUtility.GetWrappedIndex(index1, this._virtualList.Count, out dataIndex, out int _);
|
||||
if (this._lastInterestIndex != dataIndex)
|
||||
this._listIsDirty = true;
|
||||
this._lastInterestIndex = dataIndex;
|
||||
ListUtility.GetWrappedIndex(index1, _virtualList.Count, out dataIndex, out int _);
|
||||
if (_lastInterestIndex != dataIndex)
|
||||
_listIsDirty = true;
|
||||
_lastInterestIndex = dataIndex;
|
||||
}
|
||||
if (this._listIsDirty)
|
||||
if (_listIsDirty)
|
||||
{
|
||||
if (this._itemDistanceComparer == null)
|
||||
this._itemDistanceComparer = new UpdateHelper.ItemDistanceComparer();
|
||||
this._itemDistanceComparer.Initialize(this._lastInterestIndex, this._virtualList.Count);
|
||||
this._itemsToUpdate.Sort(_itemDistanceComparer);
|
||||
this._listIsDirty = false;
|
||||
if (_itemDistanceComparer == null)
|
||||
_itemDistanceComparer = new UpdateHelper.ItemDistanceComparer();
|
||||
_itemDistanceComparer.Initialize(_lastInterestIndex, _virtualList.Count);
|
||||
_itemsToUpdate.Sort(_itemDistanceComparer);
|
||||
_listIsDirty = false;
|
||||
}
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
@@ -135,34 +135,34 @@ namespace Microsoft.Iris.Data
|
||||
do
|
||||
{
|
||||
++count;
|
||||
int index2 = this._itemsToUpdate[this._itemsToUpdate.Count - count];
|
||||
this._outstandingUpdates.Add(index2);
|
||||
this._virtualList.NotifyRequestSlowData(index2);
|
||||
int index2 = _itemsToUpdate[_itemsToUpdate.Count - count];
|
||||
_outstandingUpdates.Add(index2);
|
||||
_virtualList.NotifyRequestSlowData(index2);
|
||||
}
|
||||
while (stopwatch.ElapsedMilliseconds < 10L && this._itemsToUpdate.Count != count && this._outstandingUpdates.Count < this._throttle);
|
||||
this._itemsToUpdate.RemoveRange(this._itemsToUpdate.Count - count, count);
|
||||
if (this._itemsToUpdate.Count == 0)
|
||||
while (stopwatch.ElapsedMilliseconds < 10L && _itemsToUpdate.Count != count && _outstandingUpdates.Count < _throttle);
|
||||
_itemsToUpdate.RemoveRange(_itemsToUpdate.Count - count, count);
|
||||
if (_itemsToUpdate.Count == 0)
|
||||
return;
|
||||
this.TriggerNextUpdate();
|
||||
TriggerNextUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public int Throttle
|
||||
{
|
||||
get => this._throttle;
|
||||
set => this._throttle = value;
|
||||
get => _throttle;
|
||||
set => _throttle = value;
|
||||
}
|
||||
|
||||
public bool NotifySlowDataAcquireComplete(int index) => this._outstandingUpdates.Remove(index);
|
||||
public bool NotifySlowDataAcquireComplete(int index) => _outstandingUpdates.Remove(index);
|
||||
|
||||
private void EnsureTimer()
|
||||
{
|
||||
if (this._timer != null)
|
||||
if (_timer != null)
|
||||
return;
|
||||
this._timer = new DispatcherTimer();
|
||||
this._timer.AutoRepeat = false;
|
||||
this._timer.Interval = 100;
|
||||
this._timer.Tick += new EventHandler(this.DeliverNextUpdate);
|
||||
_timer = new DispatcherTimer();
|
||||
_timer.AutoRepeat = false;
|
||||
_timer.Interval = 100;
|
||||
_timer.Tick += new EventHandler(DeliverNextUpdate);
|
||||
}
|
||||
|
||||
private class ItemDistanceComparer : IComparer<int>
|
||||
@@ -173,18 +173,18 @@ namespace Microsoft.Iris.Data
|
||||
|
||||
public void Initialize(int focusedIndex, int totalCount)
|
||||
{
|
||||
this._focusedIndex = focusedIndex;
|
||||
this._totalCount = totalCount;
|
||||
this._midPoint = totalCount / 2;
|
||||
_focusedIndex = focusedIndex;
|
||||
_totalCount = totalCount;
|
||||
_midPoint = totalCount / 2;
|
||||
}
|
||||
|
||||
public int Compare(int left, int right) => this.GetDistance(right) - this.GetDistance(left);
|
||||
public int Compare(int left, int right) => GetDistance(right) - GetDistance(left);
|
||||
|
||||
private int GetDistance(int potential)
|
||||
{
|
||||
int num = Math.Abs(potential - this._focusedIndex);
|
||||
if (num > this._midPoint)
|
||||
num = this._totalCount - num + 1;
|
||||
int num = Math.Abs(potential - _focusedIndex);
|
||||
if (num > _midPoint)
|
||||
num = _totalCount - num + 1;
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user