コード例 #1
0
 /// <summary>
 /// Update pin
 /// </summary>
 /// <param name="processType">Process type</param>
 /// <param name="pinHandle">Pin handle</param>
 /// <param name="userHandle">User handle</param>
 /// <param name="topicHandle">Topic handle</param>
 /// <param name="pinned">Pin status</param>
 /// <param name="topicPublisherType">Topic publisher type</param>
 /// <param name="topicUserHandle">Topic user handle</param>
 /// <param name="appHandle">App handle</param>
 /// <param name="lastUpdatedTime">Last updated time</param>
 /// <param name="pinLookupEntity">Pin lookup entity</param>
 /// <returns>Update pin task</returns>
 public async Task UpdatePin(
     ProcessType processType,
     string pinHandle,
     string userHandle,
     string topicHandle,
     bool pinned,
     PublisherType topicPublisherType,
     string topicUserHandle,
     string appHandle,
     DateTime lastUpdatedTime,
     IPinLookupEntity pinLookupEntity)
 {
     await this.pinsStore.UpdatePin(
         StorageConsistencyMode.Strong,
         pinHandle,
         userHandle,
         appHandle,
         topicHandle,
         topicUserHandle,
         pinned,
         lastUpdatedTime,
         pinLookupEntity);
 }
コード例 #2
0
        /// <summary>
        /// Update pin
        /// </summary>
        /// <param name="storageConsistencyMode">Consistency mode</param>
        /// <param name="pinHandle">Pin handle</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <param name="topicUserHandle">User handle of the topic owner</param>
        /// <param name="pinned">Pin status</param>
        /// <param name="lastUpdatedTime">Last updated time</param>
        /// <param name="readPinLookupEntity">Read pin lookup entity</param>
        /// <returns>Update pin task</returns>
        public async Task UpdatePin(
            StorageConsistencyMode storageConsistencyMode,
            string pinHandle,
            string userHandle,
            string appHandle,
            string topicHandle,
            string topicUserHandle,
            bool pinned,
            DateTime lastUpdatedTime,
            IPinLookupEntity readPinLookupEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Pins);

            ObjectTable lookupTable = this.tableStoreManager.GetTable(ContainerIdentifier.Pins, TableIdentifier.PinsLookup) as ObjectTable;
            FeedTable   feedTable   = this.tableStoreManager.GetTable(ContainerIdentifier.Pins, TableIdentifier.PinsFeed) as FeedTable;
            CountTable  countTable  = this.tableStoreManager.GetTable(ContainerIdentifier.Pins, TableIdentifier.PinsCount) as CountTable;
            Transaction transaction = new Transaction();

            PinFeedEntity pinFeedEntity = new PinFeedEntity()
            {
                PinHandle       = pinHandle,
                TopicHandle     = topicHandle,
                TopicUserHandle = topicUserHandle,
                AppHandle       = appHandle
            };

            if (readPinLookupEntity == null)
            {
                PinLookupEntity newPinLookupEntity = new PinLookupEntity()
                {
                    PinHandle       = pinHandle,
                    LastUpdatedTime = lastUpdatedTime,
                    Pinned          = pinned
                };

                transaction.Add(Operation.Insert(lookupTable, userHandle, topicHandle, newPinLookupEntity));

                if (pinned)
                {
                    transaction.Add(Operation.Insert(feedTable, userHandle, appHandle, pinHandle, pinFeedEntity));
                    transaction.Add(Operation.Insert(feedTable, userHandle, MasterApp.AppHandle, pinHandle, pinFeedEntity));
                    transaction.Add(Operation.InsertOrIncrement(countTable, userHandle, appHandle));
                    transaction.Add(Operation.InsertOrIncrement(countTable, userHandle, MasterApp.AppHandle));
                }
            }
            else
            {
                bool   oldPinned    = readPinLookupEntity.Pinned;
                string oldPinHandle = readPinLookupEntity.PinHandle;

                readPinLookupEntity.PinHandle       = pinHandle;
                readPinLookupEntity.Pinned          = pinned;
                readPinLookupEntity.LastUpdatedTime = lastUpdatedTime;

                transaction.Add(Operation.Replace(lookupTable, userHandle, topicHandle, readPinLookupEntity as PinLookupEntity));

                if (pinned == oldPinned)
                {
                    if (pinned && pinHandle != oldPinHandle)
                    {
                        transaction.Add(Operation.Delete(feedTable, userHandle, appHandle, oldPinHandle));
                        transaction.Add(Operation.Delete(feedTable, userHandle, MasterApp.AppHandle, oldPinHandle));
                        transaction.Add(Operation.Insert(feedTable, userHandle, appHandle, pinHandle, pinFeedEntity));
                        transaction.Add(Operation.Insert(feedTable, userHandle, MasterApp.AppHandle, pinHandle, pinFeedEntity));
                    }
                }
                else
                {
                    if (pinned)
                    {
                        transaction.Add(Operation.Insert(feedTable, userHandle, appHandle, pinHandle, pinFeedEntity));
                        transaction.Add(Operation.Insert(feedTable, userHandle, MasterApp.AppHandle, pinHandle, pinFeedEntity));
                        transaction.Add(Operation.Increment(countTable, userHandle, appHandle, 1));
                        transaction.Add(Operation.Increment(countTable, userHandle, MasterApp.AppHandle, 1));
                    }
                    else
                    {
                        transaction.Add(Operation.Delete(feedTable, userHandle, appHandle, oldPinHandle));
                        transaction.Add(Operation.Delete(feedTable, userHandle, MasterApp.AppHandle, oldPinHandle));
                        transaction.Add(Operation.Increment(countTable, userHandle, appHandle, -1.0));
                        transaction.Add(Operation.Increment(countTable, userHandle, MasterApp.AppHandle, -1.0));
                    }
                }
            }

            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }