/// <summary>
 /// Adds a replacement document as the update modifier.
 /// </summary>
 /// <param name="nominalType">The nominal type of the replacement document</param>
 /// <param name="document">The document.</param>
 /// <returns>An UpdateWrapper.</returns>
 public static IMongoUpdate Replace(
     Type nominalType,
     object document
     )
 {
     return(UpdateWrapper.Create(nominalType, document));
 }
Exemple #2
0
        public void TestSerializeUpdateWrapped()
        {
            var c = new C {
                X = 1
            };
            var w        = UpdateWrapper.Create(c);
            var json     = w.ToJson();
            var expected = "{ 'X' : 1 }".Replace("'", "\"");

            Assert.Equal(expected, json);
        }
Exemple #3
0
        public void UpdateWrapperType()
        {
            var document = new BsonDocument
            {
                {
                    "$set", new BsonDocument
                    {
                        { "Age", 54 }
                    }
                }
            };
            var update = UpdateWrapper.Create(document);

            Console.WriteLine(update.ToBsonDocument());
        }
 /// <summary>
 /// Adds a replacement document as the update modifier.
 /// </summary>
 /// <typeparam name="TNominalType">The nominal type of the replacement document</typeparam>
 /// <param name="document">The document.</param>
 /// <returns>An UpdateWrapper.</returns>
 public static IMongoUpdate Replace <TNominalType>(
     TNominalType document
     )
 {
     return(UpdateWrapper.Create <TNominalType>(document));
 }
            private void SetTitle(UpdateWrapper wrapper)
            {
                if (string.IsNullOrWhiteSpace(_progressTitle))
                    return;

                if (string.IsNullOrWhiteSpace(_progressTitleKey))
                    return;

                var updateText = ReflectionUtilities.GetObjectPropertyText(wrapper, _progressTitle);

                if (!_deferTitleUpdates)
                    _settingsManager.BindingProxy.SettingProperty = new StringSettingWrapper(_progressTitleKey, updateText, null);

                _appearanceManager.ChangeTimedMessage(_progressTitleKey, updateText);
            }
            public void Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs)
            {
                var clearProgressFlag = false;
                try
                {
                    if (_updateInProgress) return;

                    _updateInProgress = true;
                    clearProgressFlag = true;
                    var wrapper = new UpdateWrapper(downloadJob) { TotalPercent = 100, UpdatePercent = 100, CurrentIndex = downloadJob.Updates.Count};
                    wrapper.AdjustValues(_lastWrapper);
                    _lastWrapper = wrapper;
                    SetTitle(wrapper);
                    SetText(wrapper);
                }
                catch (Exception e)
                {
                    Log.WarnFormat("An issue occurred while An issue occurred while handling a download updates progress completed event: {0}", e);
                }
                finally
                {
                    if (clearProgressFlag) _updateInProgress = false;
                }
            }
            public void Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs)
            {
                var clearProgressFlag = false;
                try
                {
                    if (_updateInProgress) return;

                    _updateInProgress = true;
                    clearProgressFlag = true;
                    var wrapper = new UpdateWrapper(downloadJob, callbackArgs);
                    wrapper.AdjustValues(_lastWrapper);
                    _lastWrapper = wrapper;
                    SetTitle(wrapper);
                    SetText(wrapper);
                }
                catch (Exception e)
                {
                    Log.WarnFormat("An issue occurred while handling a download updates progress changed event: {0}", e);
                }
                finally
                {
                    if (clearProgressFlag) _updateInProgress = false;
                }
            }
            public void AdjustValues(UpdateWrapper lastWrapper)
            {
                if (lastWrapper == null)
                    return;

                if (lastWrapper.TotalPercent > TotalPercent)
                    TotalPercent = lastWrapper.TotalPercent;

                if (TotalPercent > 100)
                    TotalPercent = 100;

                if (UpdatePercent > 100)
                    UpdatePercent = 100;
            }