Beispiel #1
0
 protected override void InsertItem(int index, string item)
 {
     base.InsertItem(index, item);
     Added.AssertContainsOnly(item);
     Removed.AssertEmpty();
     Added.Clear();
 }
Beispiel #2
0
        public void Commit()
        {
            var transactionRequest = new ExecuteTransactionRequest
            {
                Requests = new OrganizationRequestCollection()
            };

            foreach (var entity in Added.Keys)
            {
                Added[entity].PersistAdded(entity);
            }
            foreach (var entity in Modified.Keys)
            {
                Modified[entity].PersistUpdated(entity);
            }
            foreach (var entity in Removed.Keys)
            {
                Removed[entity].PersistRemoved(entity);
            }

            Added.Clear();
            Modified.Clear();
            Removed.Clear();

            try
            {
                for (int i = 0; i < Requests.Count; i += _batchSize)
                {
                    var requestBatch = Requests.Skip(i).Take(_batchSize);

                    transactionRequest.Requests.AddRange(requestBatch);
                    _service.Execute(transactionRequest);

                    transactionRequest = new ExecuteTransactionRequest
                    {
                        Requests = new OrganizationRequestCollection()
                    };
                }
            }
            catch (FaultException <OrganizationServiceFault> fault)
            {
                if (fault.Detail.ErrorDetails.Contains("MaxBatchSize"))
                {
                    int maxBatchSize = Convert.ToInt32(fault.Detail.ErrorDetails["MaxBatchSize"]);
                    if (maxBatchSize < transactionRequest.Requests.Count)
                    {
                        var errMsg =
                            string.Format(
                                "The input request collection contains {0} requests, which exceeds the maximum allowed {1}",
                                transactionRequest.Requests.Count, maxBatchSize);
                        throw new InvalidOperationException(errMsg, fault);
                    }
                }

                throw;
            }
        }
Beispiel #3
0
        public void Reset()
        {
            MoreComing = false;

            Items.Clear();
            Added.Clear();
            Modified.Clear();
            Deleted.Clear();
        }
Beispiel #4
0
 public override bool Add(string item)
 {
     if (base.Add(item))
     {
         Added.AssertContainsOnly(item);
         Removed.AssertEmpty();
         Added.Clear();
         return(true);
     }
     else
     {
         Added.AssertEmpty();
         Removed.AssertEmpty();
         return(false);
     }
 }
Beispiel #5
0
        private void Save()
        {
            foreach (var o in Added)
            {
                GetTable(o.GetType()).Add(o);
            }

            foreach (var o in Removed)
            {
                var table = GetTable(o.GetType());
                if (!table.Contains(o))
                {
                    throw new InvalidOperationException("Removed untracked entity");
                }
                table.Remove(o);
            }

            Added.Clear();
            Updated.Clear();
            Removed.Clear();
        }
 public void Discard()
 {
     Added.Clear();
     Deleted.Clear();
 }