예제 #1
0
        public void Calling_DeferRefresh_Inside_BeginInit_EndInite_Does_Not_Calls_Refresh_WhenProviderStateIsUpdated()
        {
            ISupportInitialize isi = this.provider;
            Exception          ex  = null;

            try
            {
                isi.BeginInit();

                using (provider.DeferRefresh())
                {
                    this.provider.AddPendingChangeToProvider();
                    provider.BlockUntilRefreshCompletes();
                    Assert.AreEqual(0, this.provider.RefreshCallCount);
                }

                provider.BlockUntilRefreshCompletes();
                Assert.AreEqual(0, this.provider.RefreshCallCount);

                isi.EndInit();
            }
            catch (Exception e)
            {
                ex = e;
            }

            Assert.IsNull(ex);
            Assert.AreEqual(1, this.provider.RefreshCallCount);
        }
예제 #2
0
        protected virtual void InitializeEditor(IInputEditor activeEditor)
        {
            GridCellElement currentCell = this.gridViewElement.CurrentView.CurrentCell;

            if (currentCell == null)
            {
                return;
            }
            ISupportInitialize supportInitialize = activeEditor as ISupportInitialize;

            supportInitialize?.BeginInit();
            EventDispatcher eventDispatcher = this.GridViewElement.Template.EventDispatcher;

            eventDispatcher.SuspendEvent(EventDispatcher.ValueChanging);
            eventDispatcher.SuspendEvent(EventDispatcher.ValueChanged);
            currentCell.ColumnInfo.InitializeEditor(activeEditor);
            activeEditor.Initialize((object)currentCell, currentCell.Value);
            eventDispatcher.ResumeEvent(EventDispatcher.ValueChanging);
            eventDispatcher.ResumeEvent(EventDispatcher.ValueChanged);
            GridViewCellEventArgs args = new GridViewCellEventArgs(currentCell.RowInfo, currentCell.ColumnInfo, activeEditor);

            this.gridViewElement.Template.EventDispatcher.RaiseEvent <GridViewCellEventArgs>(EventDispatcher.CellEditorInitialized, (object)this, args);
            if (TelerikHelper.IsMaterialTheme(this.gridViewElement.GridControl.ThemeName))
            {
                BaseInputEditor activeEditor1 = args.ActiveEditor as BaseInputEditor;
                if (activeEditor1 != null)
                {
                    activeEditor1.EditorElement.StretchVertically = true;
                }
            }
            supportInitialize?.EndInit();
        }
예제 #3
0
 public override void InitializationGuard(XamlType xamlType, object obj, bool begin)
 {
     try
     {
         ISupportInitialize initialize = obj as ISupportInitialize;
         if (initialize != null)
         {
             if (begin)
             {
                 initialize.BeginInit();
             }
             else
             {
                 initialize.EndInit();
             }
         }
     }
     catch (Exception exception)
     {
         if (CriticalExceptions.IsCriticalException(exception))
         {
             throw;
         }
         throw this.CreateException(System.Xaml.SR.Get("InitializationGuard", new object[] { xamlType }), exception);
     }
 }
        /// <summary>
        /// Adds the controls to the screensaver form.
        /// </summary>
        /// <param name="url">The URL to show</param>
        private void AddControls(string url)
        {
            PreviewKeyDown += HandleCloseEvent;

            //Create a new fixed web browser
            var browser = new WebView()
            {
                Bounds = Bounds,
                Dock   = DockStyle.Fill
            };

            ISupportInitialize initalisableBrowser = browser;

            initalisableBrowser.BeginInit();

            browser.IsScriptNotifyAllowed = true;

            browser.Click          += HandleCloseEvent;
            browser.PreviewKeyDown += HandleCloseEvent;

            browser.DOMContentLoaded += HandleBrowserLoadEvent;
            browser.ScriptNotify     += ScriptNotify;

            initalisableBrowser.EndInit();

            browser.Navigate(new Uri(url));

            //Add the controls to the form
            Controls.Add(browser);
        }
예제 #5
0
        /// <summary>
        /// Allow to use using() construct for initialization scope.
        /// </summary>
        public static IDisposable InitScope(this ISupportInitialize component)
        {
            component.BeginInit();
// ReSharper disable ConvertClosureToMethodGroup
            return(Disposable.Create(() => component.EndInit()));
// ReSharper restore ConvertClosureToMethodGroup
        }
예제 #6
0
 public override void InitializationGuard(XamlType xamlType, object obj, bool begin)
 {
     try
     {
         ISupportInitialize supportInit = obj as ISupportInitialize;
         if (supportInit != null)
         {
             if (begin)
             {
                 supportInit.BeginInit();
             }
             else
             {
                 supportInit.EndInit();
             }
         }
     }
     catch (Exception e)
     {
         if (CriticalExceptions.IsCriticalException(e))
         {
             throw;
         }
         throw CreateException(SR.Get(SRID.InitializationGuard, xamlType), e);
     }
 }
예제 #7
0
        private GlyphRun BuildGlyphRun(int column, int line, char c)
        {
            var paddingTop         = FontSize / 3;
            var glyphs             = new GlyphRun();
            ISupportInitialize isi = glyphs;

            isi.BeginInit();
            glyphs.GlyphTypeface       = glyphFace;
            glyphs.FontRenderingEmSize = FontSize;
            var chars = new[] { c };

            glyphs.Characters = chars;
            var codePoint  = (int)c;
            var glyphIndex = glyphFace.CharacterToGlyphMap[codePoint];
            var glyphWidth = glyphFace.AdvanceWidths[glyphIndex];

            glyphs.GlyphIndices  = new ushort[] { glyphIndex };
            glyphs.AdvanceWidths = new double[] { glyphWidth *FontSize };
            _cellWidth           = glyphWidth * FontSize;
            _cellHeight          = (glyphFace.Baseline * FontSize) + (paddingTop);

            glyphs.BaselineOrigin = new Point(
                glyphWidth * FontSize * column,
                (glyphFace.Baseline * FontSize * (line + 1)) + (paddingTop * line));

            isi.EndInit();

            return(glyphs);
        }
예제 #8
0
        private void Deserialise(object o, Type type, RegistryKey key, bool ignorePropertyErrors)
        {
            ISupportInitialize supportInitialize = o as ISupportInitialize;

            if (supportInitialize != null)
            {
                supportInitialize.BeginInit();
            }
            IRegistryKeySerialisable registryKeySerialisable = o as IRegistryKeySerialisable;

            if (registryKeySerialisable != null && !registryKeySerialisable.BeforeDeserialise(this, key))
            {
                return;
            }
            foreach (PropertyInfo propertyInfo in o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(RegistryValueAttribute), true);
                if (customAttributes.Length > 0)
                {
                    string name = ((RegistryValueAttribute)customAttributes[0]).Name ?? propertyInfo.Name;
                    object obj  = key.GetValue(name);
                    if (obj != null)
                    {
                        try
                        {
                            if (!propertyInfo.PropertyType.IsAssignableFrom(obj.GetType()))
                            {
                                obj = Convert.ChangeType(obj, propertyInfo.PropertyType);
                            }
                            propertyInfo.SetValue(o, obj, (object[])null);
                        }
                        catch (Exception ex)
                        {
                            if (!ignorePropertyErrors)
                            {
                                throw;
                            }
                            else
                            {
                                Trace.TraceError("Error converting property {0}.{1}: {2} Registry key is: {3}, Value is: {4}", (object)type.FullName, (object)propertyInfo.Name, (object)ex.Message, (object)key.Name, (object)obj.ToString());
                            }
                        }
                    }
                }
                else if (propertyInfo.GetCustomAttributes(typeof(RegistryKeyNameAttribute), true).Length > 0)
                {
                    propertyInfo.SetValue(o, (object)key.Name.Substring(key.Name.LastIndexOf('\\') + 1), (object[])null);
                }
            }
            if (registryKeySerialisable != null)
            {
                registryKeySerialisable.AfterDeserialise(this, key);
            }
            if (supportInitialize == null)
            {
                return;
            }
            supportInitialize.EndInit();
        }
예제 #9
0
        public static object FromStream(object message, MemoryStream stream)
        {
            // 这个message可以从池中获取,减少gc
            ((Google.Protobuf.IMessage)message).MergeFrom(stream.GetBuffer(), (int)stream.Position, (int)stream.Length);
            ISupportInitialize iSupportInitialize = message as ISupportInitialize;

            iSupportInitialize?.EndInit();
            return(message);
        }
예제 #10
0
        public static object FromStream(Type type, MemoryStream stream)
        {
            object message = Activator.CreateInstance(type);

            ((Google.Protobuf.IMessage)message).MergeFrom(stream.GetBuffer(), (int)stream.Position, (int)stream.Length);
            ISupportInitialize iSupportInitialize = message as ISupportInitialize;

            iSupportInitialize?.EndInit();
            return(message);
        }
예제 #11
0
        public static object FromBytes(object instance, byte[] bytes, int index, int count)
        {
            object message = instance;

            ((Google.Protobuf.IMessage)message).MergeFrom(bytes, index, count);
            ISupportInitialize iSupportInitialize = message as ISupportInitialize;

            iSupportInitialize?.EndInit();
            return(message);
        }
예제 #12
0
 protected override void OnDispose(bool inIsDisposing)
 {
     if (inIsDisposing)
     {
         if (_supportInitialize != null)
         {
             _supportInitialize.EndInit();
         }
     }
 }
예제 #13
0
        public void Dispose()
        {
            _supportInitialize.EndInit();

            // ReSharper disable once SuspiciousTypeConversion.Global
            if (_supportInitialize is Freezable freezable)
            {
                freezable.Freeze();
            }
        }
예제 #14
0
 protected override void InitializeEditor(
     BaseListViewVisualItem visualItem,
     ISupportInitialize initializable,
     IInputEditor editor)
 {
     this.ActiveEditor.Initialize((object)visualItem, this.SelectedItem[this.CurrentColumn]);
     initializable?.EndInit();
     this.OnEditorInitialized(new ListViewItemEditorInitializedEventArgs(visualItem, (IValueEditor)editor));
     this.ActiveEditor.BeginEdit();
     this.cachedOldValue = this.SelectedItem[this.CurrentColumn];
 }
예제 #15
0
    public static System.Object Decode(object msgObj, byte[] msgBytes)
    {
        ((Google.Protobuf.IMessage)msgObj).MergeFrom(msgBytes, 0, msgBytes.Length);
        ISupportInitialize iSupportInitialize = msgObj as ISupportInitialize;

        if (iSupportInitialize != null)
        {
            iSupportInitialize.EndInit();
        }
        return(msgObj);
    }
예제 #16
0
        public static System.Object Decode(object hotfixMsg, byte[] bodyData)
        {
            ((Google.Protobuf.IMessage)hotfixMsg).MergeFrom(bodyData, 0, bodyData.Length);
            ISupportInitialize iSupportInitialize = hotfixMsg as ISupportInitialize;

            if (iSupportInitialize != null)
            {
                iSupportInitialize.EndInit();
            }
            return(hotfixMsg);
        }
예제 #17
0
        public static object FromStream(Type type, Stream stream)
        {
            object             t = Serializer.NonGeneric.Deserialize(type, stream);
            ISupportInitialize iSupportInitialize = t as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(t);
            }
            iSupportInitialize.EndInit();
            return(t);
        }
예제 #18
0
    public static T FromJson <T>(string str)
    {
        T t = JsonMapper.ToObject <T>(str);
        ISupportInitialize iSupportInitialize = t as ISupportInitialize;

        if (iSupportInitialize == null)
        {
            return(t);
        }
        iSupportInitialize.EndInit();
        return(t);
    }
예제 #19
0
파일: JsonHelper.cs 프로젝트: zzonee/ET
        public static object FromJson(Type type, string str)
        {
            object             t = JsonMapper.ToObject(type, str);
            ISupportInitialize iSupportInitialize = t as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(t);
            }
            iSupportInitialize.EndInit();
            return(t);
        }
예제 #20
0
        public static System.Object Decode(System.Type msgType, byte[] bodyData)
        {
            object message = Activator.CreateInstance(msgType);

            ((Google.Protobuf.IMessage)message).MergeFrom(bodyData, 0, bodyData.Length);
            ISupportInitialize iSupportInitialize = message as ISupportInitialize;

            if (iSupportInitialize != null)
            {
                iSupportInitialize.EndInit();
            }
            return(message);
        }
예제 #21
0
        public static object Deserialize(object message, MemoryStream stream)
        {
            // 这个message可以从池中获取,减少gc
            ((Google.Protobuf.IMessage)message).MergeFrom(stream.GetBuffer(), (int)stream.Position, (int)(stream.Length - stream.Position));
            ISupportInitialize iSupportInitialize = message as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(message);
            }
            iSupportInitialize.EndInit();
            return(message);
        }
예제 #22
0
        static void EndPopulate(IList target, ISupportInitialize supportInitialize)
        {
            ILockable lockable = target as ILockable;

            if (lockable != null)
            {
                lockable.EndUpdate();
            }
            if (supportInitialize != null)
            {
                supportInitialize.EndInit();
            }
        }
예제 #23
0
        public static IList <T> CreateOrUpdate <T>(IEnumerable destinationItemsSource, IEnumerable <T> source)
        {
            ObservableCollection <T> observableCollection = destinationItemsSource as ObservableCollection <T>;

            if (observableCollection == null && destinationItemsSource != null)
            {
                throw new ArgumentException("destinationItemsSource must be ObservableCollection<T> or null");
            }
            if (observableCollection == null)
            {
                if (source == null)
                {
                    return((IList <T>)null);
                }
                return((IList <T>) new ObservableCollectionSupportingInitialization <T>(source));
            }
            if (source == null)
            {
                observableCollection.Clear();
                return((IList <T>)observableCollection);
            }
            ISupportInitialize supportInitialize = observableCollection as ISupportInitialize;

            if (supportInitialize != null)
            {
                supportInitialize.BeginInit();
            }
            int index = 0;

            foreach (T obj in source)
            {
                if (index < observableCollection.Count)
                {
                    observableCollection[index] = obj;
                }
                else
                {
                    observableCollection.Add(obj);
                }
                ++index;
            }
            while (index < observableCollection.Count)
            {
                observableCollection.RemoveAt(observableCollection.Count - 1);
            }
            if (supportInitialize != null)
            {
                supportInitialize.EndInit();
            }
            return((IList <T>)observableCollection);
        }
예제 #24
0
    public static T FromBytes <T>(byte[] bytes) where T : Google.Protobuf.IMessage
    {
        object message = Activator.CreateInstance(typeof(T));

        ((Google.Protobuf.IMessage)message).MergeFrom(bytes);//, 0, bytes.Length);
        ISupportInitialize iSupportInitialize = message as ISupportInitialize;

        if (iSupportInitialize == null)
        {
            return((T)message);
        }
        iSupportInitialize.EndInit();
        return((T)message);
    }
예제 #25
0
    public static object FromBytes(Type type, byte[] bytes, int index, int count)
    {
        object message = Activator.CreateInstance(type);

        ((Google.Protobuf.IMessage)message).MergeFrom(bytes, index, count);
        ISupportInitialize iSupportInitialize = message as ISupportInitialize;

        if (iSupportInitialize == null)
        {
            return(message);
        }
        iSupportInitialize.EndInit();
        return(message);
    }
예제 #26
0
 private static void InitializeProviders()
 {
     foreach (ReportProviderAttribute attr in typeof(ReportGenerator).GetCustomAttributes(typeof(ReportProviderAttribute), false))
     {
         IReportProvider provider = (IReportProvider)Activator.CreateInstance(attr.ProviderType);
         if (provider is ISupportInitialize)
         {
             ISupportInitialize supportInit = provider as ISupportInitialize;
             supportInit.BeginInit();
             supportInit.EndInit();
         }
         s_Providers.Add(provider);
     }
 }
예제 #27
0
		public static T FromBytes<T>(byte[] bytes, int index, int length)
		{
			T t;
			using (MemoryStream ms = new MemoryStream(bytes, index, length))
			{
				t = Serializer.Deserialize<T>(ms);
			}
			ISupportInitialize iSupportInitialize = t as ISupportInitialize;
			if (iSupportInitialize == null)
			{
				return t;
			}
			iSupportInitialize.EndInit();
			return t;
		}
예제 #28
0
        public static T FromBytes <T>(byte[] bytes, int index, int length)
        {
            T t;

            using (MemoryStream ms = recyclableMemoryStreamManager.GetStream("protobuf", bytes, index, length))
            {
                t = Serializer.Deserialize <T>(ms);
            }
            ISupportInitialize iSupportInitialize = t as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(t);
            }
            iSupportInitialize.EndInit();
            return(t);
        }
예제 #29
0
        public static object FromBytes(Type type, byte[] bytes)
        {
            object t;

            using (MemoryStream ms = new MemoryStream(bytes, 0, bytes.Length))
            {
                t = Serializer.NonGeneric.Deserialize(type, ms);
            }
            ISupportInitialize iSupportInitialize = t as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(t);
            }
            iSupportInitialize.EndInit();
            return(t);
        }
예제 #30
0
        public static object FromBytes(Type type, byte[] bytes, int index, int length)
        {
            object t;

            using (MemoryStream ms = recyclableMemoryStreamManager.GetStream("protobuf", bytes, index, length))
            {
                t = Serializer.NonGeneric.Deserialize(type, ms);
            }
            ISupportInitialize iSupportInitialize = t as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(t);
            }
            iSupportInitialize.EndInit();
            return(t);
        }