Example #1
0
        async Task <SynchronizedType> Ensure(string typeID, CancellationToken cancelToken)
        {
            using (await CrossThreadLockScope.Enter(m_lock))
            {
                WeakReference <SynchronizedType> viewRef = null;
                SynchronizedType view = null;
                if (m_views.TryGetValue(typeID, out viewRef))
                {
                    viewRef.TryGetTarget(out view);
                }
                if (view != null)
                {
                    return(view);
                }

                view = new SynchronizedType(this, typeID);
                await view.Load();

                if (viewRef == null)
                {
                    viewRef = new WeakReference <SynchronizedType>(view);
                }
                else
                {
                    viewRef.SetTarget(view);
                }
                m_views[typeID] = viewRef;
                return(view);
            }
        }
        async Task <ItemQuery> GetSyncQuery(ISynchronizedView view)
        {
            if (!view.IsStale(m_maxAgeInSeconds))
            {
                return(null);
            }

            SynchronizedType sType = view as SynchronizedType;

            if (sType != null && await sType.HasPendingChangesAsync())
            {
                return(null);
            }

            return(view.GetSynchronizationQuery());
        }
Example #3
0
        internal async Task Load()
        {
            string viewName = SynchronizedType.MakeViewName(m_typeID);

            m_items = await this.Store.GetViewAsync(viewName);

            if (m_items == null)
            {
                m_items = this.Store.CreateView(viewName, ItemQuery.QueryForTypeID(m_typeID));
                await this.SaveAsync();
            }

            m_items.PublicSyncDisabled = true;
            m_items.ItemsAvailable    += OnItemsAvailable;
            m_items.ItemsNotFound     += OnItemsNotFound;
            m_items.Error += OnError;
        }
Example #4
0
        public IAsyncOperation <IList <SynchronizedType> > GetMultipleAsync(IList <string> typeIDs)
        {
            if (typeIDs.IsNullOrEmpty())
            {
                throw new ArgumentException("typeIDs");
            }

            return(AsyncInfo.Run <IList <SynchronizedType> >(async cancelToken =>
            {
                List <SynchronizedType> sTypes = new List <SynchronizedType>();
                foreach (string typeID in typeIDs)
                {
                    SynchronizedType type = await this.Ensure(typeID, cancelToken);
                    sTypes.Add(type);
                }

                return sTypes;
            }));
        }
Example #5
0
        internal async Task OnChangeCommittedAsync(RecordItemChange change)
        {
            if (change.ChangeType != RecordItemChangeType.Put)
            {
                return;
            }

            try
            {
                SynchronizedType sType = await this.GetAsync(change.TypeID);

                await sType.OnPutCommittedAsync(change);

                this.TypeUpdated.SafeInvokeInUIThread(this, change.TypeID);
            }
            catch
            {
            }
        }
        async Task UpdateKeys(ISynchronizedView view, ItemQueryResult queryResult)
        {
            ViewKeyCollection keys = null;

            if (queryResult != null)
            {
                keys = ViewKeyCollection.FromQueryResult(queryResult);
            }
            else
            {
                keys = new ViewKeyCollection();
            }
            view.UpdateKeys(keys);

            SynchronizedType sType = view as SynchronizedType;

            if (sType != null)
            {
                await sType.SaveAsync();
            }
        }
Example #7
0
 internal RecordItemEditOperation(SynchronizedType sType, IItemDataTyped data, RecordItemLock rLock)
 {
     m_sType = sType;
     m_rLock = rLock;
     m_data  = data.Item.DeepClone().TypedData;
 }
        async Task<SynchronizedType> Ensure(string typeID, CancellationToken cancelToken)
        {
            using(await CrossThreadLockScope.Enter(m_lock))
            {
                WeakReference<SynchronizedType> viewRef = null;
                SynchronizedType view = null;
                if (m_views.TryGetValue(typeID, out viewRef))
                {
                    viewRef.TryGetTarget(out view);
                }
                if (view != null)
                {
                    return view;
                }

                view = new SynchronizedType(this, typeID);
                await view.Load();
                if (viewRef == null)
                {
                    viewRef = new WeakReference<SynchronizedType>(view);
                }
                else
                {
                    viewRef.SetTarget(view);
                }
                m_views[typeID] = viewRef;
                return view;
            }    
        }
 internal RecordItemEditOperation(SynchronizedType sType, IItemDataTyped data, RecordItemLock rLock)
 {
     m_sType = sType;
     m_rLock = rLock;
     m_data = data.Item.DeepClone().TypedData;
 }