예제 #1
0
        /// <summary>
        /// Local "override" for base Dicationary's this[name] method.
        /// Gets the WPFValueAccessor associated with the given name, creating a new one if it does not exist already.
        /// </summary>
        /// <param name="name">The name/key of the WPFValueAccessor instance to get.</param>
        /// <returns>The WPFValueAccessor assocated with the given name.</returns>
        /// <exception cref="System.ArgumentNullException">name is null.</exception>
        public new WPFValueAccessor this[string name]
        {
            get
            {
                WPFValueAccessor wva = null;

                if ((name != null) && !base.ContainsKey(name))
                {
                    IValueAccessor iva = ivi.GetValueAccessor(name);
                    wva = new WPFValueAccessor(iva);

                    activeWvaList.Add(wva);
                    rebuildArrays = true;

                    base[name] = wva;
                }
                else
                {
                    wva = base[name];
                }

                return(wva);
            }
            set
            {
                throw new System.InvalidOperationException("Item[] setter cannot be used here");
            }
        }
예제 #2
0
 public IVAWrapper(IValueAccessor iva)
 {
     IVA = iva;
     SetValue(NamePropertyKey, Name);
     SetValue(IDPropertyKey, ID);
     Service(forceUpdate: true);
 }
예제 #3
0
        protected override ConvertResult <IValueAccessor> ConvertSupportedItem(ItemModel source)
        {
            ConvertResult <IValueAccessor> convertResult = base.ConvertSupportedItem(source);

            if (!convertResult.WasConverted)
            {
                return(convertResult);
            }
            string stringValue = this.GetStringValue(source, RedditFeedFieldValueValueAccessorItemModel.RedditFeedFieldName);

            if (string.IsNullOrWhiteSpace(stringValue))
            {
                return(this.NegativeResult(source, "The property name field must have a value specified.", string.Format("field: {0}", (object)RedditFeedFieldValueValueAccessorItemModel.RedditFeedFieldName)));
            }
            IValueAccessor convertedValue = convertResult.ConvertedValue;

            if (convertedValue == null)
            {
                return(this.NegativeResult(source, "A null value accessor was returned by the converter.", Array.Empty <string>()));
            }
            if (convertedValue.ValueReader == null)
            {
                PropertyValueReader propertyValueReader = new PropertyValueReader(stringValue);
                convertedValue.ValueReader = (IValueReader)propertyValueReader;
            }
            if (convertedValue.ValueWriter == null)
            {
                PropertyValueWriter propertyValueWriter = new PropertyValueWriter(stringValue);
                convertedValue.ValueWriter = (IValueWriter)propertyValueWriter;
            }
            return(this.PositiveResult(convertedValue));
        }
예제 #4
0
        bool WaitForP2ATransition(ref PassiveToActivePinBits trackBits, PassiveToActivePinBits waitForBits, PassiveToActivePinBits deltaPinsMask)
        {
            IValueAccessor p2aPinsStateIVA = SelectedPassiveToActivePinsStateIVA;

            PassiveToActivePinBits fixedPinsMask = PassiveToActivePinBits.PinsBitMask & ~deltaPinsMask;

            for (; ;)
            {
                IPassiveToActivePinsState p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

                PassiveToActivePinBits packedWord = p2aPinsState.PackedWord;

                if (packedWord == waitForBits)
                {
                    trackBits = packedWord;
                    return(true);
                }

                if ((packedWord & fixedPinsMask) != (trackBits & fixedPinsMask))
                {
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("{0}[{1}] failed: unexpected P2A pins transition to {2}", currentActivity, privateState.TransferProgressStr, p2aPinsState));
                    return(false);
                }

                if (!Spin())
                {
                    return(false);
                }
            }
        }
예제 #5
0
        public override IValueAccessor Convert(ItemModel source)
        {
            IValueAccessor valueAccessor = base.Convert(source);

            if (valueAccessor == null)
            {
                return((IValueAccessor)null);
            }
            ItemModel referenceAsModel = this.GetReferenceAsModel(source, "Field");

            if (referenceAsModel == null)
            {
                return((IValueAccessor)null);
            }
            string fieldName = referenceAsModel["ItemName"] as string;

            if (string.IsNullOrWhiteSpace(fieldName))
            {
                return((IValueAccessor)null);
            }
            string language = this.GetLanguage(source);

            valueAccessor.ValueWriter = new DateValueWriterML(fieldName, language)
            {
                Field = GetStringValue(referenceAsModel, ItemModel.ItemName)
            };

            return(valueAccessor);
        }
예제 #6
0
        public static IEnumerable <T> Select <TObject, T>(IValueAccessor <GraphQLNotNull <GraphQLList <TObject> > > value, DataReference dataReference, Func <TObject, DataReference, T> selector)
            where TObject : GraphQLObject
        {
            Check.IsNotNull(value, nameof(value));
            Check.IsNotNull(selector, nameof(selector));

            return(Select(value, dataReference, selector, value.GraphQLType.WrappedType.WrappedType));
        }
예제 #7
0
        public SubSelectionValueAccessor(IValueAccessor <T> parentValueAccessor, IValueAccessor <TOther> childValueAccessor)
        {
            Check.IsNotNull(parentValueAccessor, nameof(parentValueAccessor));
            Check.IsNotNull(childValueAccessor, nameof(childValueAccessor));

            this.parentValueAccessor = parentValueAccessor;
            this.childValueAccessor  = childValueAccessor;
        }
 private IValueReader GetValueReader(IValueAccessor config)
 {
     if (config == null)
     {
         return((IValueReader)null);
     }
     return(config.ValueReader);
 }
예제 #9
0
        public static IValueAccessor <TOther> Select <T, TOther>(this IValueAccessor <GraphQLNotNull <T> > valueAccessor, Func <T, IValueAccessor <TOther> > selector)
            where T : IGraphQLType
            where TOther : IGraphQLType
        {
            Check.IsNotNull(valueAccessor, nameof(valueAccessor));
            Check.IsNotNull(selector, nameof(selector));

            return(new SubSelectionValueAccessor <GraphQLNotNull <T>, TOther>(valueAccessor, selector(valueAccessor.GraphQLType.WrappedType)));
        }
예제 #10
0
        public override bool SetupCodeModule(Control parentWindow, IValueAccessor stepConfiguration)
        {
            bool Saved = false;
            //Show the Setup Form
            SetupForm a = new SetupForm(stepConfiguration);

            a.Show();
            return(Saved);
        }
예제 #11
0
        void ServiceResetActivity()
        {
            using (var eeLog = new Logging.EnterExitTrace(Log))
            {
                // clear the enable auto load and enable auto unload values

                if (enableAutoLoadIVA.Update().VC.GetValue <bool>(false))
                {
                    enableAutoLoadIVA.Set(false);
                }

                if (enableAutoUnloadIVA.Update().VC.GetValue <bool>(false))
                {
                    enableAutoUnloadIVA.Set(false);
                }

                IValueAccessor a2pPinsStateIVA = SelectedActiveToPassivePinsStateIVA;
                IValueAccessor p2aPinsStateIVA = SelectedPassiveToActivePinsStateIVA;

                IActiveToPassivePinsState a2pPinsState = new ActiveToPassivePinsState(a2pPinsStateIVA.Update().VC);
                IPassiveToActivePinsState p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

                if (!a2pPinsState.IsIdle)
                {
                    lastSetA2PPins           = new ActiveToPassivePinsState();
                    lastSetA2PPins.IFaceName = PartID;
                    lastSetA2PPins.XferILock = true;
                    a2pPinsStateIVA.Set(lastSetA2PPins as IActiveToPassivePinsState);
                }

                if (config.GetConfigKeyAccessOnce("E84Sim.ResetForcesESandHO").GetValue <bool>(false) && !p2aPinsState.IsSelectable)
                {
                    p2aPinsStateIVA.Set(new PassiveToActivePinsState(p2aPinsState)
                    {
                        ES = true, HO_AVBL = true
                    } as IPassiveToActivePinsState);
                }

                Spin(TimeSpan.FromSeconds(0.5));

                a2pPinsState = new ActiveToPassivePinsState(a2pPinsStateIVA.Update().VC);
                p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

                if (!p2aPinsState.IsSelectable)
                {
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("Reset complete with E84 P->A pins not selectable [{0}]", p2aPinsState));
                }
                else if (!a2pPinsState.IsIdle)
                {
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("Reset complete with E84 A->P pins not idle [{0}]", a2pPinsState));
                }
                else
                {
                    SetCurrentActivity(ActivitySelect.Ready, "Reset complete and Ready for select");
                }
            }
        }
예제 #12
0
 public SetupForm(IValueAccessor sc)
 {
     InitializeComponent();
     StepConfig           = sc;
     txt_url.Text         = sc.ReadString("BlazonURL", "");
     txt_temp.Text        = sc.ReadString("BlazonTempDIR", "");
     numericUpDown1.Value = Convert.ToDecimal(sc.ReadDouble("WaitTime", 5));
     chk_Clean.Checked    = sc.ReadBoolean("CleanUp", false);
 }
예제 #13
0
        /// <summary>internal Contructor.  Requires the corresponding IValueAccessor to which it is connected</summary>
        internal WPFValueAccessor(IValueAccessor iva)
        {
            ValueAccessor = iva;

            if (iva != null && iva.HasValueBeenSet)
            {
                NotifyValueHasBeenUpdated();
            }
        }
예제 #14
0
        public static T Select <TObject, T>(IValueAccessor <TObject> value, DataReference dataReference, Func <TObject, DataReference, T> selector)
            where TObject : GraphQLObject
        {
            Check.IsNotNull(value, nameof(value));
            Check.IsNotNull(selector, nameof(selector));

            var childReference = new DataReference(value.GetValue(dataReference));

            return(selector(value.GraphQLType, childReference));
        }
예제 #15
0
        private void Init()
        {
            Assembly assembly = EmitAssembly();

            _accessor = assembly.CreateInstance("PropertyAccessor") as IValueAccessor;

            if (_accessor == null)
            {
                throw new Exception("Unable to create property accessor.");
            }
        }
예제 #16
0
        void ServiceReadyActivity()
        {
            IValueAccessor a2pPinsStateIVA = SelectedActiveToPassivePinsStateIVA;
            IValueAccessor p2aPinsStateIVA = SelectedPassiveToActivePinsStateIVA;

            IActiveToPassivePinsState a2pPinsState = new ActiveToPassivePinsState(a2pPinsStateIVA.Update().VC);
            IPassiveToActivePinsState p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

            if (!a2pPinsState.IsIdle)
            {
                SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("A2P pins are no longer idle [{0}]", a2pPinsState));
                return;
            }

            if (!p2aPinsState.IsSelectable)
            {
                SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("P2A pins are no longer selectable [{0}]", p2aPinsState));
                return;
            }

            // interface is idle and is selectable.  detect auto trigger conditions and automatically request next transition accordingly.

            UpdateReadyToLoadAndUnload(false, true);

            if (nextActivitySelect == ActivitySelect.None)
            {
                PresentPlaced presentPlacedInput = lpmPresentPlacedInputIVA.Update().VC.GetValue <PresentPlaced>(false);

                if (presentPlacedInput.IsNeitherPresentNorPlaced() && enableAutoLoadIVA.Update().VC.GetValue <bool>(false))
                {
                    if (loadUnloadStartHoldoffTimer.StartIfNeeded(configValues.LoadUnloadStartHoldoff).IsTriggered)
                    {
                        nextActivitySelect = ActivitySelect.PerformLoad;
                        loadUnloadStartHoldoffTimer.Stop();
                    }
                }
                else if (presentPlacedInput.IsProperlyPlaced() && enableAutoUnloadIVA.Update().VC.GetValue <bool>(false))
                {
                    if (loadUnloadStartHoldoffTimer.StartIfNeeded(configValues.LoadUnloadStartHoldoff).IsTriggered)
                    {
                        nextActivitySelect = ActivitySelect.PerformUnload;
                        loadUnloadStartHoldoffTimer.Stop();
                    }
                }
                else
                {
                    loadUnloadStartHoldoffTimer.StopIfNeeded();
                }
            }
            else
            {
                loadUnloadStartHoldoffTimer.StopIfNeeded();
            }
        }
예제 #17
0
        private static IEnumerable <T> Select <TObject, T>(IValueAccessor value, DataReference dataReference, Func <TObject, DataReference, T> selector, TObject tObject)
            where TObject : GraphQLObject
        {
            if (value.GetValue(dataReference) is IEnumerable enumerable)
            {
                return(enumerable
                       .OfType <object>()
                       .Select(x => selector(tObject, new DataReference(x)))
                       .ToList());
            }

            throw new Exception("not an enumerable");
        }
예제 #18
0
        public void CreateValueAccessorFromPropertyInfo()
        {
            // Arrange
            PropertyInfo propertyInfo = typeof(Entity).GetProperty("PublicProperty");

            // Act
            IValueAccessor <Entity> valueAccessor = ValueAccessorFactory.Create <Entity>(propertyInfo);

            // Assert
            Assert.NotNull(valueAccessor);
            Assert.Equal(valueAccessor.Name, propertyInfo.Name);
            Assert.Equal(valueAccessor.Type, propertyInfo.PropertyType);
        }
예제 #19
0
        public void CreateValueAccessorFromFieldAccessor()
        {
            // Arrange
            FieldInfo fieldInfo = typeof(Entity).GetField("PublicField");

            // Act
            IValueAccessor <Entity> valueAccessor = ValueAccessorFactory.Create <Entity>(fieldInfo);

            // Assert
            Assert.NotNull(valueAccessor);
            Assert.Equal(valueAccessor.Name, fieldInfo.Name);
            Assert.Equal(valueAccessor.Type, fieldInfo.FieldType);
        }
예제 #20
0
        public TMonad GetValue(IContext <TMonad> ctx)
        {
            var overrideContext = ctx as OverrideContext <TMonad>;

            if (overrideContext.Overrides.TryGetValue(propName, out var v))
            {
                return(v);
            }
            if (baseAccessor == null && overrideContext.BaseContext.TryGetAccessor(propName, out var accessor))
            {
                baseAccessor = accessor;
            }
            return(baseAccessor == null
                ? ctx.Monad.Unit
                : baseAccessor.GetValue(overrideContext.BaseContext));
        }
예제 #21
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="member">Entity member.</param>
        internal TimestampProperty(MemberInfo member)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            IValueAccessor <T> accessor = ValueAccessorFactory.Create <T>(member);

            if (!_timestampTypes.Contains(accessor.Type))
            {
                throw new ArgumentOutOfRangeException(nameof(member), Resources.PropertyTimestampInvalidType);
            }

            _setValue = accessor.SetValue;
        }
예제 #22
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="member">Entity member.</param>
        internal RowKeyProperty(MemberInfo member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            IValueAccessor <T> accessor = ValueAccessorFactory.Create <T>(member);

            if (accessor.Type != _stringType)
            {
                throw new ArgumentOutOfRangeException(Resources.PropertyRowKeyInvalidType);
            }

            _getValue = accessor.GetValue;
            _setValue = accessor.SetValue;
        }
예제 #23
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="member">Entity member.</param>
        /// <param name="name">Member name.</param>
        internal RegularProperty(MemberInfo member, string name)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            IValueAccessor <T> accessor = ValueAccessorFactory.Create <T>(member);

            _getValue   = accessor.GetValue;
            _setValue   = accessor.SetValue;
            _memberName = name;
        }
예제 #24
0
        private void InitializePrivateState()
        {
            privateState = new TagRWSimEngineState()
            {
                Config           = new TagRWSimEngineConfig(CurrentConfig),
                ContentByteArray = (byte[])CurrentConfig.InitialPageContentsByteArray.Clone(),
                Count            = CurrentConfig.InitialCounterValue,
                TagIsPresent     = true,
            };

            stateIVA            = IVI.GetValueAccessor("{0}.State".CheckedFormat(PartID));
            tagIsPresentIVA     = IVI.GetValueAccessor("{0}.TagIsPresent".CheckedFormat(PartID)).Set(privateState.TagIsPresent);
            counterIsEnabledIVA = IVI.GetValueAccessor("{0}.CounterIsEnabled".CheckedFormat(PartID)).Set(true);
            isOnlineIVA         = IVI.GetValueAccessor("{0}.IsOnline".CheckedFormat(PartID)).Set(true);

            privateState.UpdateCounterPostfix();

            PublishPrivateState();
        }
예제 #25
0
        private SyncItem AddSyncItemAndPerformInitialPropagation(IValueAccessor iva, IConfigKeyAccess cka, string ivaLookupName, string ivaFromCkaMappedName, string ckaFromIvaMappedName, string ckaLookupKeyName)
        {
            SyncItem syncItem = new SyncItem()
            {
                iva = iva, icka = cka, ivaLookupName = ivaLookupName, ivaFromCkaMappedName = ivaFromCkaMappedName, ckaFromIvaMappedName = ckaFromIvaMappedName, ckaLookupKeyName = ckaLookupKeyName
            };

            syncItemList.Add(syncItem);
            syncItemArray = null;
            ivaArray      = null;

            // add syncItem to both maps using both original names and found names, in case target is using name mapping and has applied it to this name.
            ivaNameToSyncItemDictionary[ivaLookupName]          = syncItem;
            ivaNameToSyncItemDictionary[iva.Name]               = syncItem;
            configKeyNameToSyncItemDictionary[ckaLookupKeyName] = syncItem;
            configKeyNameToSyncItemDictionary[cka.Key]          = syncItem;

            ivaArray = null;

            if (cka.HasValue)
            {
                ValueContainer vc = cka.VC;
                if (!iva.VC.IsEqualTo(vc))
                {
                    ValueTraceEmitter.Emit("Propagating initial cka '{0}' to iva '{1}'", cka, iva);
                    iva.Set(vc);
                }
                else
                {
                    ValueTraceEmitter.Emit("Initial cka '{0}' matches initial iva '{1}'", cka, iva);
                }
            }
            else if (iva.HasValueBeenSet)
            {
                ValueContainer vc = iva.VC;
                ValueTraceEmitter.Emit("Propagating initial iva '{0}' to cka '{1}'", iva, cka);
                cka.SetValue(vc, "{0}: Propagating initial value from iva '{1}'".CheckedFormat(PartID, iva));
            }

            syncItem.UpdateCopyInSet(ReferenceSet);

            return(syncItem);
        }
예제 #26
0
        public override bool SetupCodeModule(Control parentWindow, IValueAccessor stepConfiguration)
        {
            //Setup the code module
            using (SetupForm s = new SetupForm())
            {
                //First read the existing values
                s.tempPath    = stepConfiguration.ReadString("TempPath");
                s.Compression = stepConfiguration.ReadDouble("Compression");
                if (s.ShowDialog() == DialogResult.OK)
                {
                    stepConfiguration.WriteString("TempPath", s.tempPath);
                    stepConfiguration.WriteDouble("Compression", s.Compression);
                    return(true);
                }
            }

            // No changes were made.
            return(false);
        }
예제 #27
0
        void ServiceWaitForPinsReadyActivity()
        {
            IValueAccessor a2pPinsStateIVA = SelectedActiveToPassivePinsStateIVA;
            IValueAccessor p2aPinsStateIVA = SelectedPassiveToActivePinsStateIVA;

            IActiveToPassivePinsState a2pPinsState = new ActiveToPassivePinsState(a2pPinsStateIVA.Update().VC);
            IPassiveToActivePinsState p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

            if (!a2pPinsState.IsIdle)
            {
                privateState.TransferProgressStr = Utils.Fcns.CheckedFormat("Wait A2P Idle: {0}", a2pPinsState);
            }
            else if (!p2aPinsState.IsSelectable)
            {
                privateState.TransferProgressStr = Utils.Fcns.CheckedFormat("Wait P2A Selectable: {0}", p2aPinsState);
            }
            else
            {
                SetCurrentActivity(ActivitySelect.Ready, "A2P pins are selectable now");
            }
        }
예제 #28
0
        public TMonad Evaluate(IContext <TMonad> context)
        {
            var cType = context.GetType();

            if (cType == lastType)
            {
                return(lastAccessor.GetValue(context));
            }

            if (!accessors.TryGetValue(cType, out var accessor))
            {
                if (!context.TryGetAccessor(Name, out accessor))
                {
                    accessor = new UnitAccessor <TMonad>(Monad);
                }
                accessors[cType] = accessor;
            }
            lastType     = cType;
            lastAccessor = accessor;

            return(accessor.GetValue(context));
        }
예제 #29
0
        private SyncItem AddSyncItemAndPerformInitialPropagation(IValueAccessor iva1, IValueAccessor iva2, string iva1LookupName, string iva1FromIVA2MappedName, string iva2FromIVA1MappedName, string iva2LookupName)
        {
            SyncItem syncItem = new SyncItem()
            {
                iva1 = iva1, iva2 = iva2, iva1LookupName = iva1LookupName, iva1FromIVA2MappedName = iva1FromIVA2MappedName, iva2FromIVA1MappedName = iva2FromIVA1MappedName, iva2LookupName = iva2LookupName
            };

            syncItemList.Add(syncItem);
            syncItemArray   = null;
            iva1Array       = null;
            iva1ArrayLength = 0;

            // add syncItem to both maps using both original names and found names, in case target is using name mapping and has applied it to this name.
            iva1NameToSyncItemDictionary[iva1LookupName] = syncItem;
            iva1NameToSyncItemDictionary[iva1.Name]      = syncItem;
            iva2NameToSyncItemDictionary[iva2LookupName] = syncItem;
            iva2NameToSyncItemDictionary[iva2.Name]      = syncItem;

            iva1Array       = null;
            iva2Array       = null;
            iva1ArrayLength = 0;
            iva2ArrayLength = 0;

            if (iva1.HasValueBeenSet)
            {
                ValueContainer vc = iva1.VC;
                ValueTraceEmitter.Emit("Propagating initial iva1 '{0}' to iva2 '{1}'", iva1, iva2);
                iva2.Set(vc);
            }
            else if (iva2.HasValueBeenSet)
            {
                ValueContainer vc = iva2.VC;
                ValueTraceEmitter.Emit("Propagating initial iva2 '{0}' to iva1 '{1}'", iva2, iva1);
                iva1.Set(vc);
            }

            return(syncItem);
        }
예제 #30
0
        public FieldSelection(
            string name,
            string alias,
            IEnumerable <Argument> arguments,
            IEnumerable <Directive> directives,
            IEnumerable <FieldSelection> selectionSet,
            Schema.Field field,
            GraphQLLocation location,
            IValueAccessor valueAccessor)
        {
            Check.IsNotNullOrWhiteSpace(name, nameof(name));
            Check.IsNotNull(field, nameof(field));
            Check.IsNotNull(location, nameof(location));
            Check.IsNotNull(valueAccessor, nameof(valueAccessor));

            Name          = name;
            Alias         = alias;
            Arguments     = arguments;
            Directives    = directives;
            SelectionSet  = selectionSet;
            Field         = field;
            Location      = location;
            ValueAccessor = valueAccessor;
        }
예제 #31
0
		private static Action<IInvocation> GetInvokeValueAccessorSet(PropertyInfo property, IValueAccessor accessor)
		{
			return (invocation) => accessor.SetValue(
				new ValueAccessorContext 
				{ 
					Instance = invocation.InvocationTarget as IInterceptableType, 
					Property = property, 
					BackingPropertyGetter = () => { throw new NotSupportedException("Getting property not supported while setting"); },
					BackingPropertySetter = (value) => { invocation.Arguments[0] = value; invocation.Proceed(); } 
				}, 
				property.Name, 
				invocation.Arguments[0]);
		}
예제 #32
0
		private static Action<IInvocation> GetValueAccessorGet(PropertyInfo property, IValueAccessor accessor)
		{
			return (invocation) => invocation.ReturnValue = accessor.GetValue(
				new ValueAccessorContext 
				{ 
					Instance = invocation.InvocationTarget as IInterceptableType, 
					Property = property, 
					BackingPropertyGetter = () => { invocation.Proceed(); return invocation.ReturnValue; },
					BackingPropertySetter = (value) => { throw new NotSupportedException("Setting property not supported while getting"); },
				}, 
				property.Name);
		}
예제 #33
0
 private void Init()
 {
     Assembly assembly = EmitAssembly();
     
     _accessor = assembly.CreateInstance("PropertyAccessor") as IValueAccessor;
     
     if (_accessor == null)
     {
         throw new Exception("Unable to create property accessor.");
     }
 }
예제 #34
0
        /// <summary>
        /// Initializes the node.
        /// </summary>
        /// <param name="context">The parent.</param>
        private void InitializeNode(object context)
        {
            Type contextType = (context == null || context is Type ? context as Type : context.GetType());

            if (accessor == null || accessor.RequiresRefresh(contextType))
            {
                memberName = this.getText();

                // clear cached member info if context type has changed (for example, when ASP.NET page is recompiled)
                if (accessor != null && accessor.RequiresRefresh(contextType))
                {
                    accessor = null;
                }

                // initialize this node if necessary
                if (contextType != null && accessor == null)
                {
                    // try to initialize node as ExpandoObject value
#if NET_4_0
                    if (contextType == typeof(System.Dynamic.ExpandoObject))
#else
                    if(context.ToString() == "System.Dynamic.ExpandoObject")
#endif
                    {
                        accessor = new ExpandoObjectValueAccessor(memberName);
                    }
                    // try to initialize node as enum value first
                    else if (contextType.IsEnum)
                    {
                        try
                        {
                            accessor = new EnumValueAccessor(Enum.Parse(contextType, memberName, true));
                        }
                        catch (ArgumentException)
                        {
                            // ArgumentException will be thrown if specified member name is not a valid
                            // enum value for the context type. We should just ignore it and continue processing,
                            // because the specified member could be a property of a Type class (i.e. EnumType.FullName)
                        }
                    }

                    // then try to initialize node as property or field value
                    if (accessor == null)
                    {
                        // check the context type first
                        accessor = GetPropertyOrFieldAccessor(contextType, memberName, BINDING_FLAGS);

                        // if not found, probe the Type type
                        if (accessor == null && context is Type)
                        {
                            accessor = GetPropertyOrFieldAccessor(typeof(Type), memberName, BINDING_FLAGS);
                        }
                    }
                }

                // if there is still no match, try to initialize node as type accessor
                if (accessor == null)
                {
                    try
                    {
                        accessor = new TypeValueAccessor(TypeResolutionUtils.ResolveType(memberName));
                    }
                    catch (TypeLoadException)
                    {
                        if (context == null)
                        {
                            throw new NullValueInNestedPathException("Cannot initialize property or field node '" +
                                                                     memberName +
                                                                     "' because the specified context is null.");
                        }
                        else
                        {
                            throw new InvalidPropertyException(contextType, memberName,
                                                               "'" + memberName +
                                                               "' node cannot be resolved for the specified context [" +
                                                               context + "].");
                        }
                    }
                }
            }
        }
예제 #35
0
 private bool StoreValueAccessorValue(PropertyInfo property, MethodInfo getter, MethodInfo setter, IValueAccessor accessor, IInterceptableType interceptable)
 {
     var value = getter.Invoke(interceptable, null);
     var context = new ValueAccessorContext
     {
         Instance = interceptable,
         Property = property,
         BackingPropertyGetter = () => { throw new NotSupportedException("Getting property not supported while setting"); },
         BackingPropertySetter = (v) => setter.Invoke(interceptable, new[] { v })
     };
     return accessor.SetValue(context, property.Name, value);
 }
예제 #36
0
		/// <summary>
		/// This method generates creates a new assembly containing
		/// the Type that will provide dynamic access.
		/// </summary>
		private void Init()
		{
			this.InitTypes();

			// Create the assembly and an instance of the 
			// property accessor class.
			Assembly assembly = EmitAssembly();

			mEmittedValueAccessor = 
				assembly.CreateInstance("Field") as IValueAccessor;

			if(mEmittedValueAccessor == null)
			{
				throw new Exception("Unable to create property accessor.");
			}
		}