public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (this.isFetched)
            {
                args.ProceedGetValue();
                return;
            }
            else
            {
                this.isFetched = true;

                var stringValue = ConfigurationManager.AppSettings[this.settingName];

                if (!string.IsNullOrEmpty(stringValue))
                {
                    var value = Convert.ChangeType(stringValue, args.Location.LocationType);
                    args.SetNewValue(value);
                    args.Value = value;
                }
                else
                {
                    args.ProceedGetValue();
                }
            }
        }
        void LazyLoadValueFromDatabase(LocationInterceptionArgs args, LazyEntity lazyEntity)
        {
            lock (_writeLock) {
                args.ProceedGetValue();

                if (AlreadyLoaded)
                {
                    return;
                }

                if (IsValueAlreadySpecified(args))
                {
                    AlreadyLoaded = true;
                    return;
                }

                if (lazyEntity.Read == null)
                {
                    AlreadyLoaded = true; //?if Read callback is null - it means that entity was created by the client code, and not was getted from db, so it's not persisted at all.
                    return;
                }

                var value = GetValueFor(args, lazyEntity, lazyEntity.Read);
                args.SetNewValue(value);
                AlreadyLoaded = true;
                args.ProceedGetValue();
            }
        }
Esempio n. 3
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (this.isFetched)
            {
                args.ProceedGetValue();
                return;
            }
            else
            {
                this.isFetched = true;

                Console.WriteLine("Reading from registry");
                string stringValue = Registry.GetValue(this.keyName, this.valueName, null) as string;
                if (stringValue != null )
                {
                    object value = Convert.ChangeType(stringValue, args.Location.LocationType);
                    args.SetNewValue(value);
                    args.Value = value;
                }
                else
                {
                    args.ProceedGetValue();
                }
            }
        }
Esempio n. 4
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value == null)
     {
         args.Value = IoCContainer.Resolver.TryGetInstance(args.Location.LocationType);
     }
     args.ProceedGetValue();
 }
Esempio n. 5
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value != null)
     {
         return;
     }
     args.SetNewValue(Activator.CreateInstance(type));
     args.ProceedGetValue();
 }
Esempio n. 6
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            var locationInfo = args.Location;

            if (locationInfo.LocationType == typeof(string))
            {
                args.Value = CrossSettings.Current.GetValueOrDefault(args.LocationFullName, String.Empty);
                args.ProceedGetValue();

                return;
            }

            if (locationInfo.LocationType == typeof(double))
            {
                args.Value = CrossSettings.Current.GetValueOrDefault(args.LocationFullName, 0.0);
                args.ProceedGetValue();

                return;
            }

            if (locationInfo.LocationType == typeof(Int32))
            {
                args.Value = CrossSettings.Current.GetValueOrDefault(args.LocationFullName, 0);

                return;
            }

            if (locationInfo.LocationType == typeof(Int64))
            {
                args.Value = CrossSettings.Current.GetValueOrDefault(args.LocationFullName, 0);

                return;
            }

            if (locationInfo.LocationType == typeof(bool))
            {
                args.Value = CrossSettings.Current.GetValueOrDefault(args.LocationFullName, false);

                return;
            }

            if (locationInfo.LocationType == typeof(decimal))
            {
                CrossSettings.Current.GetValueOrDefault(args.LocationFullName, new decimal(0));
                return;
            }

            if (locationInfo.LocationType == typeof(DateTime))
            {
                args.Value = CrossSettings.Current.GetValueOrDefault(args.LocationFullName, new DateTime());

                return;
            }
        }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
     if (args.Value == null)
     {
         var activity = args.Instance as Activity;
         if (activity == null) throw new ArgumentException("LazyViewAttribute can only be used within Activities");
         args.SetNewValue(activity.FindViewById(_viewId));
         args.ProceedGetValue();
     }
 }
        /// <summary>
        /// Called on 'get' of the field or property, when it is the first 'get', and there was no 'set' before this get,
        /// we will return 'our' value
        /// </summary>
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (_isInitialized)
            {
                args.ProceedGetValue();
                return;
            }

            args.SetNewValue(Value);            // store the value using the property its setter
            args.ProceedGetValue();             // then proceed the 'get' as usual
        }
Esempio n. 9
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
     if (args.Value == null)
     {
         var activity = args.Instance as Activity;
         if (activity == null)
         {
             throw new ArgumentException("LazyViewAttribute can only be used within Activities");
         }
         args.SetNewValue(activity.FindViewById(_viewId));
         args.ProceedGetValue();
     }
 }
Esempio n. 10
0
        /// <inheritdoc/>
        public sealed override void OnGetValue(LocationInterceptionArgs args)
        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (this == null)             //Look at NullAspectTest for more explanation.
            {
                args.ProceedGetValue();
                return;
            }

            ReactiveManager.Evaluate(this, () =>
            {
                args.ProceedGetValue();
                return(true);
            });
        }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();
            if (AlreadyLoaded)
            {
                return;
            }

            if (IsValueAlreadySpecified(args))
            {
                AlreadyLoaded = true;
                return;
            }

            var lazyEntity = (LazyEntity)args.Instance;

            if (!lazyEntity.Context.IsLoadingAllowed)
            {
                if (!IsCollection || args.Value != null)
                {
                    return;
                }

                //? then property is collection - we initialize it with empty collection if it now initialized yet, to avoid null reference exceptions
                InitializeCollectionPropertyWithEmptyCollection(args);
                return;
            }


            LazyLoadValueFromDatabase(args, lazyEntity);
        }
        /// <summary>
        ///   Method executed when the field or property is being read.
        /// </summary>
        /// <param name="args">Description of the current operation.</param>
        public void OnGetValue(LocationInterceptionArgs args)
        {
            RequirePermission(args.Location.FieldInfo ?? (MemberInfo)args.Location.PropertyInfo, OperationSemantic.Read, 0,
                              args.Instance);

            args.ProceedGetValue();
        }
    private void GetValue(LocationInterceptionArgs args, bool propagate = false)
    {
        var properties = args.Instance.GetType().GetProperties();
        // JSONObject is just an object with string KEY and string VALUE, you can add dummy data here using a Dictionary<string, string>
        IEnumerable <JSONObject> result = API.Methods.GetCharsetData(id, Charset).Result;

        if (result.Count() > 0)
        {
            foreach (PropertyInfo propertyInfo in properties)
            {
                CatalogueLazyLoad attribute = propertyInfo.GetCustomAttribute <CatalogueLazyLoad>();
                if (attribute != null && attribute.Charset == Charset)
                {
                    propertyInfo.SetValue(args.Instance,
                                          Convert.ChangeType(result.Where(x => x.Key == attribute.Name).Select(x => x.Value).FirstOrDefault(), propertyInfo.PropertyType, CultureInfo.CurrentCulture),
                                          null);
                }
            }
            if (propagate)
            {
                this.LoadedCategoriesProperty.Get().Add(this.Charset);
            }
            args.ProceedGetValue();
        }
    }
Esempio n. 14
0
 /// <summary>
 /// Method invoked <i>instead</i> of the <c>Get</c> semantic of the field or property to which the current aspect is applied,
 /// i.e. when the value of this field or property is retrieved.
 /// </summary>
 /// <param name="args">Advice arguments.</param>
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value == null)
     {
         if (string.IsNullOrEmpty(this.Token))
         {
             if (string.IsNullOrEmpty(this.TokenProperty))
             {
                 args.Value = IoC.Get(args.Location.LocationType);
             }
             else
             {
                 object value = ObjectProxyFactory.Get(args.Instance).GetValue(args.Instance, this.TokenProperty);
                 if (value == null)
                 {
                     args.Value = IoC.Get(args.Location.LocationType);
                 }
                 else
                 {
                     args.Value = IoC.Get(args.Location.LocationType, value.ToString());
                 }
             }
         }
         else
         {
             args.Value = IoC.Get(args.Location.LocationType, this.Token);
         }
         args.ProceedSetValue();
     }
 }
Esempio n. 15
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            var form = (UserForm)args.Instance;  // this form is only used here to write to a listbox for demonstration

            args.ProceedGetValue();
            if (args.Value == null)
            {
                form.LogListBox.Items.Add("Instantiating UserService");
                args.SetNewValue(Activator.CreateInstance(_type));
                args.ProceedGetValue();
            }
            else
            {
                form.LogListBox.Items.Add("Using a UserService that has already been created");
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Method invoked <i>instead</i> of the <c>Get</c> semantic of the field or property to which the current aspect is applied,
 /// i.e. when the value of this field or property is retrieved.
 /// </summary>
 /// <param name="args">Advice arguments.</param>
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value == null)
     {
         if (string.IsNullOrEmpty(this.Token))
         {
             if (string.IsNullOrEmpty(this.TokenProperty))
             {
                 args.Value = IoC.Get(args.Location.LocationType);
             }
             else
             {
                 object value = ObjectProxyFactory.Get(args.Instance).GetValue(args.Instance, this.TokenProperty);
                 if (value == null)
                 {
                     args.Value = IoC.Get(args.Location.LocationType);
                 }
                 else
                 {
                     args.Value = IoC.Get(args.Location.LocationType, value.ToString());
                 }
             }
         }
         else
         {
             args.Value = IoC.Get(args.Location.LocationType, this.Token);
         }
         args.ProceedSetValue();
     }
 }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (!_valueSet)
     {
         _valueSet = true;
         if (IsGuid)
         {
             //Console.WriteLine("Initializing Guid"); 
             if (args.Location.LocationType == typeof(string))
                 args.SetNewValue(Guid.NewGuid().ToString());
             else if (args.Location.LocationType == typeof(Guid))
                 args.SetNewValue(Guid.NewGuid());
         }
         else if (_defaultValue != null)
         {
             args.SetNewValue(_defaultValue);
             //Console.WriteLine("Initialized {0} to |{1}|", args.LocationName, args.GetCurrentValue()); 
         }
         else if (args.Location.PropertyInfo.GetType().IsClass)
         {
             var t = args.Location.PropertyInfo.PropertyType;
             if (t.GetConstructor(Type.EmptyTypes) != null)
             {
                 //Console.WriteLine("Initializing {0}", args.LocationName);
                 args.SetNewValue(Activator.CreateInstance(t));
             }
             else throw new InvalidOperationException(string.Format("The property {0} (type {1}) has no default constructor and must either be provided with a default value or have the [Initialize] attribute removed", args.LocationFullName, t));
         }
     }
     //Console.WriteLine("Before get called.  Current value is |{0}|", args.GetCurrentValue());
     args.ProceedGetValue();
     //Console.WriteLine("After get called.  Current value is |{0}|", args.Value);
 }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (args.GetCurrentValue() == null)
     {
         args.SetNewValue(_value);
     }
     args.ProceedGetValue();
 }
Esempio n. 19
0
 public sealed override void OnGetValue(LocationInterceptionArgs args)
 {
     ReactiveManager.Evaluate(new CompositeReactiveObject(args.Instance, property), () =>
     {
         args.ProceedGetValue();
         return(true);
     });
 }
Esempio n. 20
0
 /// <summary>
 /// Method invoked <i>instead</i> of the <c>Get</c> semantic of the field or property to which the current aspect is applied,
 /// i.e. when the value of this field or property is retrieved.
 /// </summary>
 /// <param name="args">Advice arguments.</param>
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value == null)
     {
         args.Value = LogManager.GetLogger(args.Location.DeclaringType);
         args.ProceedSetValue();
     }
 }
Esempio n. 21
0
 /// <summary>
 /// Method invoked <i>instead</i> of the <c>Get</c> semantic of the field or property to which the current aspect is applied,
 /// i.e. when the value of this field or property is retrieved.
 /// </summary>
 /// <param name="args">Advice arguments.</param>
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value == null)
     {
         args.Value = LogManager.GetLogger(args.Location.DeclaringType);
         args.ProceedSetValue();
     }
 }
Esempio n. 22
0
        public void OnPropertyGet(LocationInterceptionArgs args)
        {
            foreach (var propertyAccessRule in this.propertyAccessRules)
            {
                propertyAccessRule.OnPropertyGet(args.Location.PropertyInfo);
            }

            args.ProceedGetValue();
        }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();

            if (args.Value != null && args.Value is string)
            {
                args.Value = SampleEncryptor.Decrypt((string)args.Value);
            }
        }
Esempio n. 24
0
        /// <inheritdoc/>
        public sealed override void OnGetValue(LocationInterceptionArgs args)
        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (this != null)             //This is because of the case in TestPropertyAccessDuringConstructionReflection
            {
                ReactiveManager.WasRead(this);
            }

            args.ProceedGetValue();
        }
    public override void OnGetValue(LocationInterceptionArgs args)
    {
        if (backing == null)
        {
            args.ProceedGetValue();
            backing = args.Value;
        }

        args.Value = backing;
    }
        public void OnPropertyGet(LocationInterceptionArgs args)
        {
            if (args.Location.PropertyInfo.GetSetMethod(true) != null &&
                !this.propertySetList.Contains(args.LocationName))
            {
                throw new PropertyNotInitializedException(args.LocationFullName);
            }

            args.ProceedGetValue();
        }
        public override sealed void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();
            if (args.Value == null)     // lazy loading
            {
                var context = args.Instance as Context;
                if(context == null) throw new Exception("The IoC Aspect can only be used on a field within an Activity (or Context) object");

                ResolveContextDependency((Context)args.Instance);

                var dependencyType = args.Location.LocationType;
                var instantiation = ServiceLocator.Get(dependencyType);

                if (instantiation != null)
                {
                    args.SetNewValue(instantiation);
                }
                args.ProceedGetValue();
            }
        }
        void InitializeCollectionPropertyWithEmptyCollection(LocationInterceptionArgs args)
        {
            lock (_writeLock) {
                args.ProceedGetValue();

                if (AlreadyLoaded)
                {
                    return;
                }

                if (args.Value != null)
                {
                    return;
                }

                var targetCollection = Activator.CreateInstance(TargetCollectionType);
                args.SetNewValue(targetCollection);
                args.ProceedGetValue();
            }
        }
    public override void OnGetValue(LocationInterceptionArgs args)
    {
        args.ProceedGetValue();
        if (args.Value != null)
        {
            return;
        }

        args.Value = DefaultValue;
        args.ProceedSetValue();
    }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (args.Value != null)
     {
         args.ProceedGetValue();
     }
     if (!args.Location.LocationType.IsInterface)
     {
         return;
     }
     args.Value = DependencyResolver.Current.GetService(args.Location.LocationType);
 }
        public void OnLocationGetValue(LocationInterceptionArgs args)
        {
            var proxy = GetProxy(args);

            if (proxy != null)
            {
                args.Value = proxy.InterceptGet(args.Binding);
                return;
            }

            args.ProceedGetValue();
        }
Esempio n. 32
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (_backingField == null)
     {
         lock (_syncRoot)
             if (_backingField == null)
             {
                 args.ProceedGetValue();
                 _backingField = args.Value;
             }
     }
     args.Value = _backingField;
 }
Esempio n. 33
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (!_fetchedFromRegistry)
     {
         var value = Registry.GetValue(KeyName, ValueName, DefaultValue);
         args.SetNewValue(value);
         args.Value = value;
     }
     else
     {
         args.ProceedGetValue();
     }
 }
Esempio n. 34
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            var form = (ProductForm)args.Instance; // this form is only used here to write to a listbox for demonstration

            args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
            if (args.Value == null)
            {
                form.LogListBox.Items.Add("Instantiating ProductService");
                var locationType = args.Location.LocationType;
                var instantiation = ObjectFactory.GetInstance(locationType);

                if (instantiation != null)
                {
                    args.SetNewValue(instantiation);
                }
                args.ProceedGetValue();
            }
            else
            {
                form.LogListBox.Items.Add("Using a ProductService that has already been instantiated");
            }
        }
        public sealed override void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();
            if (args.Value == null)     // lazy loading
            {
                var context = args.Instance as Context;
                if (context == null)
                {
                    throw new Exception("The IoC Aspect can only be used on a field within an Activity (or Context) object");
                }

                ResolveContextDependency((Context)args.Instance);

                var dependencyType = args.Location.LocationType;
                var instantiation  = ServiceLocator.Get(dependencyType);

                if (instantiation != null)
                {
                    args.SetNewValue(instantiation);
                }
                args.ProceedGetValue();
            }
        }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (isFetched)
            {
                args.ProceedGetValue();
            }
            else
            {
                isFetched = true;

                var stringValue = Registry.GetValue(keyFullName, valueName, null) as string;
                if (stringValue != null)
                {
                    var value = Convert.ChangeType(stringValue, args.Location.LocationType);
                    args.SetNewValue(value);
                    args.Value = value;
                }
                else
                {
                    args.ProceedGetValue();
                }
            }
        }
Esempio n. 37
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (_backingField == null)
     {
         lock (_syncRoot)
         {
             if (_backingField == null)
             {
                 args.ProceedGetValue();     //继续像往常那样执行get
                 _backingField = args.Value; //将get获得的属性值保存到支持字段中
             }
         }
     }
     args.Value = _backingField;//因为支持字段中已经有值了,直接赋值即可
 }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();

            var isMaskable = (args.Value != null) && (args.Value is string);

            if (!isMaskable)
            {
                return;
            }

            if (!UserIsLoggedInAndHasPermission(RequiredPerm))
            {
                args.Value = new String('*', ((string)args.Value).Length);
            }
        }
 public sealed override void OnGetValue(LocationInterceptionArgs args)
 {
     if (IsSet)
     {
         ReactiveManager.WasRead(this);
         args.Value = Value;
     }
     else
     {
         Value = ReactiveManager.Evaluate(this, () =>
         {
             args.ProceedGetValue();
             return(args.Value);
         });
         IsSet = true;
     }
 }
        /// <summary>
        /// This method is invoked whenever an associated property's "get"
        /// accessor is called. We have the opportunity to carry out additional
        /// action, as well as call the actual "get"
        /// </summary>
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            // Attempt to fetch the desired property from the ASP.NET Cache.
            String cacheKey            = String.Format(CACHE_KEY_TEMPLATE, args.LocationName);
            Object remotePropertyValue = HttpContext.Current.Cache[cacheKey];

            // Did we get anything back?
            if (remotePropertyValue == null)
            {
                // Pause here by locking to ensure that only one caller actually makes
                // the call to retrieve the property value.
                lock (_remotePropertyLockObject)
                {
                    remotePropertyValue = HttpContext.Current.Cache[cacheKey];
                    if (remotePropertyValue == null)
                    {
                        // The property value isn't available in the Cache, so we need to
                        // fetch it, store it, and pass it back.
                        args.ProceedGetValue();
                        LoggingSupport.WriteToLog(args.LocationName + " property value fetched from source.");
                        HttpContext.Current.Cache.Insert(cacheKey, args.Value);
                    }
                    else
                    {
                        // Property wasn't initially in cache, but another thread (in ahead of the
                        // current one) populated it.
                        LoggingSupport.WriteToLog(args.LocationName + " property value fetched from ASP.NET Cache.");
                        args.Value = remotePropertyValue;
                    }
                }
            }
            else
            {
                // Simply assign the property value from the Cache.
                LoggingSupport.WriteToLog(args.LocationName + " property value fetched from ASP.NET Cache.");
                args.Value = remotePropertyValue;
            }
        }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (_hasBeenLoaded)
     {
         // Job already done
         args.Value = _backingField;
         return;
     }
     lock (_locker)
     {
         // Once the lock passed, we must check if the aspect has been loaded meanwhile or not.
         if (_hasBeenLoaded)
         {
             args.Value = _backingField;
             return;
         }
         // First call to the getter => need to load it.
         args.ProceedGetValue();
         // Indicate that we Loaded it
         _hasBeenLoaded = true;
         // store the result.
         _backingField = args.Value;
     }
 }
        /// <summary>
        /// Called on 'get' of the field or property, when it is the first 'get', and there was no 'set' before this get,
        /// we will return 'our' value
        /// </summary>
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (_isInitialized)
            {
                args.ProceedGetValue();
                return;
            }

            args.SetNewValue(Value); // store the value using the property its setter
            args.ProceedGetValue(); // then proceed the 'get' as usual
        }
Esempio n. 43
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     Console.WriteLine("Property 'getter' was used");
     args.ProceedGetValue();
 }
        public void OnPropertyGet(LocationInterceptionArgs args)
        {
            foreach (var propertyAccessRule in this.propertyAccessRules)
            {
                propertyAccessRule.OnPropertyGet(args.Location.PropertyInfo);
            }

            args.ProceedGetValue();
        }
        public void OnPropertyGet( LocationInterceptionArgs args )
        {
            args.ProceedGetValue();

            this.childPropertyChangedProcessor.HandleGetProperty(args);
        }
Esempio n. 46
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
      if(_backingField == null)
         lock(_syncRoot)
             if(_backingField == null)
             {
                 args.ProceedGetValue();
                 _backingField = args.Value;
             }
     args.Value = _backingField;
 }