コード例 #1
0
ファイル: MAObject.cs プロジェクト: jaypaw549/MimiTools
        public static async Task <IAccessor[]> GetSharedAccessors(params MAObject <T>[] objects)
        {
            IAccessor[] accessors = new IAccessor[objects.Length];
            Dictionary <TSObject, IAccessor> mapping = new Dictionary <TSObject, IAccessor>();
            bool incomplete = true;

            try
            {
                while (incomplete)
                {
                    incomplete = false;
                    foreach (MAObject <T> obj in objects.Distinct())
                    {
                        if (obj == null)
                        {
                            continue;
                        }
                        if (mapping.ContainsKey(obj))
                        {
                            continue;
                        }
                        IAccessor a = await obj.CreateSharedAccessor(100).ConfigureAwait(false);

                        if (a == null)
                        {
                            foreach (Accessor access in mapping.Values)
                            {
                                access.Dispose();
                            }
                            mapping.Clear();
                            mapping[obj] = await obj.CreateSharedAccessor().ConfigureAwait(false);

                            incomplete = true;
                            break;
                        }
                        mapping[obj] = a;
                    }
                }
                for (int i = 0; i < accessors.Length; i++)
                {
                    if (objects[i] != null)
                    {
                        accessors[i] = mapping[objects[i]];
                    }
                }
            }
            catch (Exception)
            {
                foreach (Accessor a in mapping.Values)
                {
                    a.Dispose();
                }
                throw;
            }
            return(accessors);
        }
コード例 #2
0
ファイル: MAObject.cs プロジェクト: jaypaw549/MimiTools
 private async void OnAccessorDisposing(SharedAccessor accessor)
 {
     await Sync.ExecuteAsync(async() =>
     {
         if (accessor.Accessor == Access && await base.Sync.Execute(() => Owner == Access) && --ActiveCount == 0)
         {
             Access.Dispose();
             Access       = null;
             SessionCount = 0;
         }
     });
 }