예제 #1
0
        private void RaiseViewSizeProperty(CachedProperty cachedProperty,
                                           Func <double> viewSizeDelegate)
        {
            double viewSize = viewSizeDelegate();

            RaiseViewSizeProperty(cachedProperty, viewSizeDelegate, viewSize);
        }
예제 #2
0
 /// <summary>
 /// Disconnects on adaptors OnTargetChange
 /// </summary>
 public void Disconnect()
 {
     if (dataCache != null)
     {
         dataCache.Disconnect();
     }
     dataCache = null;
     if (controlCache != null)
     {
         controlCache.Disconnect();
     }
     controlCache = null;
     if (IsSubItem == true)
     {
         MasterItem.Submappings.RemoveMapping(this);
     }
     else
     if (submappings != null)
     {
         submappings.Disconnect();
     }
     submappings = null;
     masterItem  = null;
     if (Adaptor != null)
     {
         Adaptor.TargetChanged -= TargetChanged;
         adaptor.Target         = null;
     }
     adaptor = null;
 }
예제 #3
0
 public CachedAssetBundle(Func <Action <AssetBundle>, Action <Exception>, AsyncTask> cacheProcess
                          , System.Action <AssetBundle> onSuccess = null
                          , System.Action <Exception> onFail      = null)
 {
     AssetBundle = new CachedProperty <UnityEngine.AssetBundle> (cacheProcess, onSuccess, onFail);
     ReferencedCount++;
 }
예제 #4
0
        /// <summary>
        /// Assign a value, try to convert it if it's not the same type as the property type.
        /// </summary>
        /// <param name="instance">Object containing the property</param>
        /// <param name="propertyName">Name of property</param>
        /// <param name="value">Value to convert and assign</param>
        /// <exception cref="InvalidOperationException">Failed to find property.</exception>
        /// <exception cref="InvalidCastException">Could not convert value type to property type.</exception>
        public void SetConvertedValue(object instance, string propertyName, object value)
        {
            CachedProperty property = GetProperty(propertyName);

            if (property == null)
            {
                return;
            }

            Type targetType = property.MemberType;

            if (!targetType.IsAssignableFrom(value.GetType()))
            {
                value = property.Convert(targetType, value);
            }

            // Value types cannot be null, let's get the default value for the value type.
            // Not the nicest solution, feel free to improve it.
            if (value == null && targetType.IsValueType)
            {
                object defaultValue;
                lock (_valueTypeDefaults)
                {
                    if (!_valueTypeDefaults.TryGetValue(targetType, out defaultValue))
                    {
                        defaultValue = Activator.CreateInstance(targetType);
                        _valueTypeDefaults[targetType] = defaultValue;
                    }
                }

                value = defaultValue;
            }

            _reflectorProvider.SetValue(property.MemberInfo, instance, value);
        }
예제 #5
0
        private static bool IsIgnored(CachedProperty property)
        {
            var attribute =
                property.PropertyInfo.GetCustomAttribute <IgnoredPropertyAttribute>();

            return(attribute != null);
        }
예제 #6
0
        /// <summary>
        /// Notification method activated from Adaptor
        /// </summary>
        /// <param name="aSender">
        /// Object that made change <see cref="System.Object"/>
        /// </param>
        public virtual void GetDataFromDataSource(object aSender)
        {
/*			if (Adaptor.FinalTarget == null) {
 *                              Visible = false;
 *                              Sensitive = false;
 *                              return;
 *                      }*/
//System.Data.Bindings.DebugInformation.ConsoleDebug.TraceStack ("GetData");
            object vis, sen;

            CachedProperty.UncachedGetValue(Adaptor.FinalTarget, VisibleMapping, out vis, false);
            CachedProperty.UncachedGetValue(Adaptor.FinalTarget, SensitiveMapping, out sen, false);
            if (firsttime == false)
            {
                if (((bool)vis == Visible) && ((bool)sen == Sensitive) && (lastTarget.Target == adaptor.FinalTarget))
                {
                    return;
                }
            }
//System.Console.WriteLine("AssignData (" + adaptor.FinalTarget + ") vis=" + (bool) vis + " sen=" + (bool) sen);
            Gtk.Application.Invoke(delegate {
                Visible   = (bool)vis;
                Sensitive = (bool)sen;
//System.Console.WriteLine("Set firsttime");
                firsttime         = false;
                lastTarget.Target = adaptor.FinalTarget;
            });
        }
예제 #7
0
        private void CacheScrollbarPeers()
        {
            IScrollProvider provider = (IScrollProvider)this;

            ScrollBar hscrollbar = scrollViewer.ElementHorizontalScrollBar;

            hCachedProperty = new CachedProperty();
            SetAutomationEvents(provider,
                                hscrollbar,
                                GetHorizontallyScrollable,
                                delegate { return(scrollViewer.ComputedHorizontalScrollBarVisibility); },
                                delegate { return(provider.HorizontalScrollPercent); },
                                delegate { return(provider.HorizontalViewSize); },
                                ScrollPatternIdentifiers.HorizontalScrollPercentProperty,
                                ScrollPatternIdentifiers.HorizontallyScrollableProperty,
                                ScrollPatternIdentifiers.HorizontalViewSizeProperty,
                                AutomationOrientation.Horizontal);

            ScrollBar vscrollbar = scrollViewer.ElementVerticalScrollBar;

            vCachedProperty = new CachedProperty();
            SetAutomationEvents(
                provider,
                vscrollbar,
                GetVerticallyScrollable,
                delegate { return(scrollViewer.ComputedVerticalScrollBarVisibility); },
                delegate { return(provider.VerticalScrollPercent); },
                delegate { return(provider.VerticalViewSize); },
                ScrollPatternIdentifiers.VerticalScrollPercentProperty,
                ScrollPatternIdentifiers.VerticallyScrollableProperty,
                ScrollPatternIdentifiers.VerticalViewSizeProperty,
                AutomationOrientation.Vertical);
        }
 public PropertyViewModel Create(CachedProperty cachedProperty)
 {
     return(new PropertyViewModel()
     {
         MemberCode = cachedProperty.MemberCode,
         Html = cachedProperty.Html
     });
 }
예제 #9
0
        private CachedProperty CacheProperty(Culture culture, Property property)
        {
            CachedProperty cachedProperty = new CachedProperty();

            cachedProperty.PropertyId = property.Id;
            cachedProperty.MemberCode = this.handler.Storage.GetRepository <IMemberRepository>().WithKey(property.MemberId).Code;
            cachedProperty.Html       = this.GetLocalizationValue(culture.Id, property.HtmlId);
            return(cachedProperty);
        }
예제 #10
0
        private void RaiseStructureChanged(CachedProperty cachedProperty,
                                           Func <Visibility> computedVisibilityDelegate)
        {
            bool visible = computedVisibilityDelegate() == Visibility.Visible;

            if (visible != cachedProperty.Visible)
            {
                cachedProperty.Visible = visible;
                RaiseAutomationEvent(AutomationEvents.StructureChanged);
            }
        }
예제 #11
0
        public WindowsGameHost(Game game, GraphicsContextFlags flags)
        {
            this.game           = game;
            base.Window         = new WindowsGameWindow(flags);
            Window.Activated   += OnActivated;
            Window.Deactivated += OnDeactivated;

            IntPtr handle = Window.Handle;

            IsActive = new CachedProperty <bool>(delegate { return(GetForegroundWindow().Equals(handle)); }, 50, true);
        }
예제 #12
0
        /// <summary>
        /// Get a property value.
        /// </summary>
        /// <param name="instance">Instance to get value from.</param>
        /// <param name="propertyName">Name of property.</param>
        /// <returns>Property value.</returns>
        public object GetValue(object instance, string propertyName)
        {
            CachedProperty property = GetProperty(propertyName);

            if (property == null)
            {
                return(null);
            }

            return(_reflectorProvider.GetValue(property.MemberInfo, instance));
        }
예제 #13
0
 public PropertyRecord(Context context, TypeRecord typeRecord, CachedProperty prop)
     : this(context, typeRecord)
 {
     DeclaringTypeId = prop.DeclaringTypeId;
     PropertyTag     = prop.Tag;
     EncodeTag       = EncodePropertyTag(DeclaringTypeId, PropertyTag);
     DataType        = prop.DataType;
     PropertyType    = prop.PropertyType;
     Property        = prop;
     Name            = prop.Name;
 }
예제 #14
0
        /// <summary>
        /// Assign value to a property
        /// </summary>
        /// <param name="instance">Object containing the property</param>
        /// <param name="propertyName">Name of property</param>
        /// <param name="value">Value to assign, must be of the same type as the property.</param>
        /// <exception cref="InvalidOperationException">Failed to find property.</exception>
        public void SetValue(object instance, string propertyName, object value)
        {
            CachedProperty property = GetProperty(propertyName);

            if (property == null)
            {
                return;
            }

            _reflectorProvider.SetValue(property.MemberInfo, instance, value);
        }
예제 #15
0
 private void RaiseViewSizeProperty(CachedProperty cachedProperty,
                                    Func <double> viewSizeDelegate,
                                    double viewSize)
 {
     if (cachedProperty.ViewSize != viewSize)
     {
         RaisePropertyChangedEvent(cachedProperty.ViewSizeProperty,
                                   cachedProperty.ViewSize,
                                   viewSize);
         cachedProperty.ViewSize = viewSize;
     }
 }
예제 #16
0
        private void RaiseScrollableProperty(CachedProperty cachedProperty,
                                             Func <bool> scrollableDelegate)
        {
            bool scrollable = scrollableDelegate();

            if (cachedProperty.Scrollable != scrollable)
            {
                RaisePropertyChangedEvent(cachedProperty.ScrollableProperty,
                                          cachedProperty.Scrollable,
                                          scrollable);
                cachedProperty.Scrollable = scrollable;
            }
        }
예제 #17
0
        private void SetPropertyValue <T>(T instance, CachedProperty property, IConfigurationSection section)
            where T : class
        {
            if (IsIgnored(property))
            {
                return;
            }
            var propertyConfiguration = GetPropertyConfiguration(property);
            var unparsedValue         = section[property.Name];
            var value = GetParsedValue <T>(property, unparsedValue, propertyConfiguration);

            property.SetValue(instance, value);
        }
예제 #18
0
        private void RaiseScrollPercentProperty(CachedProperty cachedProperty,
                                                Func <double> scrollPercentDelegate)
        {
            double percent = scrollPercentDelegate();

            if (cachedProperty.ScrollPercent != percent)
            {
                RaisePropertyChangedEvent(cachedProperty.ScrollPercentProperty,
                                          cachedProperty.ScrollPercent,
                                          percent);
                cachedProperty.ScrollPercent = percent;
            }
        }
예제 #19
0
    public TcpIpSystem(TcpIpSystemParam param) : base(param)
    {
        LocalHostPossibleGlobalIpAddressListCache =
            new AsyncCache <HashSet <IPAddress> >(CoresConfig.TcpIpSystemSettings.LocalHostPossibleGlobalIpAddressListCacheLifetime, CacheFlags.IgnoreUpdateError | CacheFlags.NoGc,
                                                  GetLocalHostPossibleGlobalIpAddressListMainAsync);

        DnsResolverSingleton = new Singleton <DnsResolver>(() => CreateDnsResolverImpl());

        this.HostInfoCache = new CachedProperty <TcpIpSystemHostInfo>(getter: () => this.GetHostInfo(true), expiresLifeTimeMsecs: CoresConfig.TcpIpSystemSettings.HostHostInfoCacheLifetime);

        this.EasyHostNameToIpCache = new AsyncCache <string, IPAddress>(CoresConfig.TcpIpSystemSettings.EasyHostNameToIpCacheLifetime, CacheFlags.IgnoreUpdateError | CacheFlags.NoGc,
                                                                        async(hostname, cancel) => await this.GetIpAsync(hostname, cancel: cancel, orderBy: ip => (long)ip.AddressFamily));
    }
예제 #20
0
            public CachedType(Type type)
            {
                Type             = type;
                TypeId           = type.GetCustomAttribute <TypeIdAttribute>().Id;
                Properties       = new List <CachedProperty>();
                TaggedProperties = new Dictionary <int, CachedProperty>();

                foreach (
                    var prop in
                    Enumerable.Reverse(type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy |
                                                          BindingFlags.Instance | BindingFlags.Static)))
                {
                    var cachedProp = new CachedProperty(prop);
                    Properties.Add(cachedProp);
                    if (cachedProp.Tag != -1)
                    {
                        var encodeId = EncodePropertyTag(cachedProp.DeclaringTypeId, cachedProp.Tag);
                        TaggedProperties.Add(encodeId, cachedProp);
                    }
                }
                IsSingleton = typeof(ISingleton).IsAssignableFrom(type);

                if (IsSingleton)
                {
                    var getExisting = Type.GetCacheableMethod("GetExisting",
                                                              BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

                    if (getExisting == null)
                    {
                        throw new Exception("ISingleton is missing static GetExisting() method.");
                    }

                    GetInstance = getExisting
                                  .Compile();
                }
                else if (!IsAbstract && IsPublic)
                {
                    var ctor = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
                                                   null, new Type[0], null);
                    if (ctor == null)
                    {
                        return;
                    }
                    var lambda = Expression.Lambda <Func <object> >(Expression.New(ctor));
                    GetInstance = lambda.Compile();
                }
            }
예제 #21
0
        private object Parse(CachedProperty property, string unparsedValue,
                             PropertyConfigurationAttribute propertyConfiguration)
        {
            var    parser = GetParser(property.PropertyType, property.Name);
            object value;

            if (propertyConfiguration.AcceptInvalid)
            {
                value = parser.TryParse(unparsedValue,
                                        propertyConfiguration.DefaultValue);
            }
            else
            {
                value = parser.Parse(unparsedValue);
            }
            return(value);
        }
예제 #22
0
        public SqlQuery InsertQuery <T>(T entity) where T : class
        {
            IDictionary <string, object> expando = new ExpandoObject();

            foreach (var prop in CachedProperty.GetPropertiesExcluded <T>(TableInfo.PrimaryKey <T>()))
            {
                expando[prop.Name] = prop.GetValue(entity);
            }

            var columns = CachedProperty.GetPropertyNamesExcluded <T>(TableInfo.PrimaryKey <T>());

            var query = string.Format("INSERT INTO {0} ({1}) VALUES (@{2})",
                                      TableInfo.TableName <T>(),
                                      string.Join(",", columns),
                                      string.Join(",@", columns));

            return(new SqlQuery(query, expando));
        }
예제 #23
0
        public SqlQuery UpdateQuery <T>(T entity) where T : class
        {
            var idKey = TableInfo.PrimaryKey <T>();
            var propertiesExcluedPrimaryKey = CachedProperty.GetProperties <T>();

            IDictionary <string, object> expando = new ExpandoObject();

            foreach (var prop in propertiesExcluedPrimaryKey)
            {
                expando[prop.Name] = prop.GetValue(entity);
            }

            var updateProperties = propertiesExcluedPrimaryKey.Where(p => p.Name != idKey).Select(prop => prop.Name + "=@" + prop.Name).ToList();

            var query = string.Format("UPDATE {0} SET {1} WHERE {2}=@{2}", TableInfo.TableName <T>(), string.Join(",", updateProperties), TableInfo.PrimaryKey <T>());

            return(new SqlQuery(query, expando));
        }
예제 #24
0
        private object GetParsedValue <T>(CachedProperty property, string unparsedValue,
                                          PropertyConfigurationAttribute propertyConfiguration) where T : class
        {
            object value;

            if (unparsedValue == null)
            {
                if (propertyConfiguration.IsMandatory)
                {
                    throw new MissingMandatoryConfigurationException(typeof(T), property.Name);
                }
                value = propertyConfiguration.DefaultValue;
            }
            else
            {
                value = Parse(property, unparsedValue, propertyConfiguration);
            }
            return(value);
        }
예제 #25
0
        /// <summary>
        /// Resoves PropertyInfo from connected object
        /// </summary>
        public bool Resolve()
        {
#if NEWCACHE
            if (dataCache == null)
            {
                dataCache = new CachedProperty(Adaptor.FinalTarget, Name);
            }
            if (resetResolve == true)
            {
                dataCache.SetObject(Adaptor.FinalTarget);
                dataCache.SetProperty(Name.Trim());
            }

/*			if (dataCache.IsAccessValid == EPropertyAccess.Invalid)
 *                              if (Adaptor.FinalTarget != null)	{
 *                                      dataCache.SetObject (Adaptor.FinalTarget);
 *                                      dataCache.SetProperty (Name.Trim());
 *                              }*/
            return(dataCache.IsAccessValid == EPropertyAccess.Valid);
#endif
#if OLDCACHE
            if (cached == true)
            {
                return(true);
            }

            if (name == "")
            {
                return(false);
            }

            cached     = false;
            cachedInfo = null;
            if (Adaptor.FinalTarget != null)
            {
                cachedInfo = ConnectionProvider.ResolveMappingProperty(Adaptor.FinalTarget, Name, false);
            }

            cached  = (cachedInfo != null);
            invalid = (cachedInfo == null);
            return(cachedInfo != null);
#endif
        }
        public TextArea2DComponentManipulator()
        {
            var textDataField = UnityTypes.AdvPage.ClrType.GetField("textData", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            set_textData = CustomFastReflectionHelper.CreateFastFieldSetter <object, object>(textDataField);

            var statusField = UnityTypes.AdvPage.ClrType.GetField("status", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            set_status = CustomFastReflectionHelper.CreateFastFieldSetter <object, object>(statusField);

            var isInputSendMessageField = UnityTypes.AdvPage.ClrType.GetField("isInputSendMessage", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            set_isInputSendMessage = CustomFastReflectionHelper.CreateFastFieldSetter <object, bool>(isInputSendMessageField);

            var nameTextField = UnityTypes.AdvPage.ClrType.GetField("nameText", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            set_nameText = CustomFastReflectionHelper.CreateFastFieldSetter <object, object>(nameTextField);

            _text     = UnityTypes.TextArea2D.ClrType.CachedProperty("text");
            _TextData = UnityTypes.TextArea2D.ClrType.CachedProperty("TextData");
        }
예제 #27
0
        /// <summary>
        /// Resolves final target for Adaptor
        /// </summary>
        /// <returns>
        /// Object of the final target this adaptor is pointing to <see cref="System.Object"/>
        /// </returns>
        protected override object DoGetFinalTarget(out bool aCallControl)
        {
            aCallControl = false;
            if (GetDefaultProperty() == null)
            {
                return(null);
            }
            object res = base.DoGetFinalTarget(out aCallControl);

            finalTarget.Target = null;
            if (res == null)
            {
                return(null);
            }
            // Resolve forward if mapped property is adaptor
            object tgt = null;

            if (GetDefaultProperty() == null)
            {
                return(null);
            }
            if (CachedProperty.UncachedGetValue(res, GetDefaultProperty().Name, out tgt) == false)
            {
                tgt = ConnectionProvider.ResolveTargetForObject(tgt);
            }
            // set checks
            if (DataSourceType != null)
            {
                if (TypeValidator.IsCompatible(tgt.GetType(), DataSourceType) == true)
                {
                    return(tgt);
                }
                return(null);
            }
            else
            {
                return(tgt);
            }
        }
예제 #28
0
		private void RaiseStructureChanged (CachedProperty cachedProperty,
		                                    Func<Visibility> computedVisibilityDelegate)
		{
			bool visible = computedVisibilityDelegate () == Visibility.Visible;
			if (visible != cachedProperty.Visible) {
				cachedProperty.Visible = visible;
				RaiseAutomationEvent (AutomationEvents.StructureChanged); 
			}
		}
예제 #29
0
		private void RaiseScrollPercentProperty (CachedProperty cachedProperty,
		                                         Func<double> scrollPercentDelegate)
		{
			double percent = scrollPercentDelegate ();
			if (cachedProperty.ScrollPercent != percent) {
				RaisePropertyChangedEvent (cachedProperty.ScrollPercentProperty, 
							   cachedProperty.ScrollPercent,
			                	           percent); 
				cachedProperty.ScrollPercent = percent;
			}
		}
예제 #30
0
		private void RaiseViewSizeProperty (CachedProperty cachedProperty, 
		                                    Func<double> viewSizeDelegate, 
						    double viewSize)
		{
			if (cachedProperty.ViewSize != viewSize) {
				RaisePropertyChangedEvent (cachedProperty.ViewSizeProperty, 
							   cachedProperty.ViewSize,
			        	                   viewSize);
				cachedProperty.ViewSize = viewSize;
			}
		}
예제 #31
0
		private void RaiseViewSizeProperty (CachedProperty cachedProperty, 
		                                    Func<double> viewSizeDelegate)
		{
			double viewSize = viewSizeDelegate ();
			RaiseViewSizeProperty (cachedProperty, viewSizeDelegate, viewSize);
		}
예제 #32
0
 public FairyGUITextComponentManipulator()
 {
     _html     = ClrTypes.TextField.CachedField("html") ?? ClrTypes.TextField.CachedFieldByIndex(3, typeof(bool), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     _text     = ClrTypes.TextField.CachedProperty("text");
     _htmlText = ClrTypes.TextField.CachedProperty("htmlText");
 }
 public DefaultTextComponentManipulator(Type type)
 {
     _type     = type;
     _property = type.CachedProperty(TextPropertyName);
 }
예제 #34
0
 /// <summary>
 /// Throws Exception
 /// </summary>
 /// <param name="aProperty">
 /// Property which failed on GetValue <see cref="CachedProperty"/>
 /// </param>
 public ExceptionCachedPropertyGetValueFailed(CachedProperty aProperty)
     : base("Property was cached, but CachedProperty.GetValue() did not succedd????")
 {
 }
예제 #35
0
		private void CacheScrollbarPeers ()
		{
			IScrollProvider provider = (IScrollProvider) this;
			
			ScrollBar hscrollbar = scrollViewer.ElementHorizontalScrollBar;
			hCachedProperty = new CachedProperty ();
			SetAutomationEvents (provider,
			                     hscrollbar,
			                     GetHorizontallyScrollable,
			                     delegate { return scrollViewer.ComputedHorizontalScrollBarVisibility; },
			                     delegate { return provider.HorizontalScrollPercent; },
			                     delegate { return provider.HorizontalViewSize; },
					     ScrollPatternIdentifiers.HorizontalScrollPercentProperty,
					     ScrollPatternIdentifiers.HorizontallyScrollableProperty,
					     ScrollPatternIdentifiers.HorizontalViewSizeProperty,
					     AutomationOrientation.Horizontal);
			
			ScrollBar vscrollbar = scrollViewer.ElementVerticalScrollBar;
			vCachedProperty = new CachedProperty ();
			SetAutomationEvents (
			                     provider,
			                     vscrollbar,
			                     GetVerticallyScrollable,
			                     delegate { return scrollViewer.ComputedVerticalScrollBarVisibility; },
			                     delegate { return provider.VerticalScrollPercent; },
			                     delegate { return provider.VerticalViewSize; },
					     ScrollPatternIdentifiers.VerticalScrollPercentProperty,
					     ScrollPatternIdentifiers.VerticallyScrollableProperty,
					     ScrollPatternIdentifiers.VerticalViewSizeProperty,
					     AutomationOrientation.Vertical);
		}
예제 #36
0
		private void RaiseScrollableProperty (CachedProperty cachedProperty,
		                                      Func<bool> scrollableDelegate)
		{
			bool scrollable = scrollableDelegate ();
			if (cachedProperty.Scrollable != scrollable) {
				RaisePropertyChangedEvent (cachedProperty.ScrollableProperty, 
							   cachedProperty.Scrollable,
				                           scrollable); 
				cachedProperty.Scrollable = scrollable;
			}
		}