Beispiel #1
0
        private void OnObjectDataAccessManagerAdded(ObjectDataAccessManager odam)
        {
            m_objectAccess.Add(odam.Id, odam);
            odam.LayerDataRemoved -= this.Odam_LayerDataRemoved;
            odam.LayerDataRemoved += this.Odam_LayerDataRemoved;

            odam.LayerDataSet -= this.Odam_LayerDataSet;
            odam.LayerDataSet += this.Odam_LayerDataSet;
        }
Beispiel #2
0
        internal ObjectDataAccessManager EnsureDataAccess(Guid id)
        {
            if (!m_objectAccess.TryGetValue(id, out ObjectDataAccessManager accessManager))
            {
                accessManager = new ObjectDataAccessManager(this, id);
            }

            return(accessManager);
        }
Beispiel #3
0
        /// <summary>
        /// Directly set an object (indicated by id) property (indicated by property name) on the override layer (0-<see cref="OverrideLayerCount"/>) with the value specified.
        /// </summary>
        public bool SetOverridePropertyValue(int layer, Guid id, string property, object value)
        {
            if (!m_objectAccess.TryGetValue(id, out ObjectDataAccessManager accessManager))
            {
                accessManager = new ObjectDataAccessManager(this, id);
            }

            return(accessManager.SetOverrideValue(layer, property, value));
        }
Beispiel #4
0
        private void SetBaselineData(ObjectEvaluation objectEvaluation)
        {
            ObjectDataAccessManager accessManager = EnsureDataAccess(objectEvaluation.Id);

            foreach (KeyValuePair <string, object> property in objectEvaluation.ValueStorage)
            {
                accessManager.SetBaselineValue(property.Key, property.Value);
            }

            //#error using it
            foreach (ObjectEvaluation ancillary in objectEvaluation.AncillaryElements)
            {
                this.SetBaselineData(ancillary);
            }

            foreach (KeyValuePair <string, ObjectEvaluation> childObject in objectEvaluation.ChildObjectStorage)
            {
                accessManager.SetBaselineValue(childObject.Key, childObject.Value.Id);
                this.SetBaselineData(childObject.Value);
            }

            foreach (KeyValuePair <string, ObjectEvaluation.ListInfo> listProp in objectEvaluation.InsertGenerationLists)
            {
                if ((listProp.Value.Elements?.Length ?? 0) == 0)
                {
                    continue;
                }

                Type elementType    = listProp.Value.ElementType ?? listProp.Value.Elements[0].GetType();
                Type listAccessType = typeof(StrataPropertyListAccess <>).MakeGenericType(elementType);

                // In order to keep some kind of strong access of the method (for refactoring & compiling errors), using object
                //  as a sort of unknown sinceit's just to get nameof.
                string methodName = nameof(StrataPropertyListAccess <object> .GenerateStorageForBaselineListAccess);
                object storage    = ReflectionXT.RunStaticMethod(listAccessType, methodName, (object)(listProp.Value.Elements));
                this.SetBaselinePropertyValue(objectEvaluation.Id, listProp.Key, storage);
            }
        }
Beispiel #5
0
 private void OnObjectDataAccessManagerRemoved(ObjectDataAccessManager odam)
 {
     m_objectAccess.Remove(odam.Id);
     odam.LayerDataRemoved -= this.Odam_LayerDataRemoved;
     odam.LayerDataSet     -= this.Odam_LayerDataSet;
 }
Beispiel #6
0
        public void SetObjectWithProperties <T> (Guid objectId, T source)
        {
            Type sourceType = source.GetType();

            PropertyInfo[] allSettableProperties = sourceType
                                                   .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty)
                                                   .Where(p => !(p.GetAttributes <StrataIgnoreAttribute>().FirstOrDefault()?.WhenOutput ?? false))
                                                   .ToArray();

            ObjectDataAccessManager odam = this.GetAccessManager(objectId);

            if (odam == null)
            {
                return;
            }

            foreach (PropertyInfo settableProperty in allSettableProperties)
            {
                if (odam.SearchForFirstOverrideLayerIndexSet(this.OverrideLayerCount - 1, settableProperty.Name, out int overrideLayerIndex))
                {
                    _SetPropWithStratum(settableProperty, objectId, m_overrideStorageLayers[overrideLayerIndex]);
                }
                else if (odam.HasBaselineValueSet(settableProperty.Name))
                {
                    _SetPropWithStratum(settableProperty, objectId, m_baselineStorageLayer);
                }
            }

            void _SetPropWithStratum(PropertyInfo _propToSet, Guid _objId, Stratum _layer)
            {
                if (_layer.TryGetValue(objectId, out PseudoPropertyBag storedPropBag) &&
                    storedPropBag.TryGetValue(_propToSet.Name, out object storedPropValue))
                {
                    // Go through this BONKERS process to determine if it's list access backed data and set it that way
                    if (typeof(IEnumerable).IsAssignableFrom(_propToSet.PropertyType))
                    {
                        // Is it ListAccess backed?
                        Type propValueType = storedPropValue.GetType();
                        if (propValueType.IsGenericType && propValueType.GetGenericTypeDefinition() == typeof(ObservableCollectionX <>) &&
                            propValueType.GenericTypeArguments[0].IsGenericType &&
                            propValueType.GenericTypeArguments[0].GetGenericTypeDefinition() == typeof(StratabaseListInsertion <>))
                        {
                            // Ok it is, now use reflection to generate a StrataPropertyListAccess
                            Type itemType   = propValueType.GenericTypeArguments[0].GenericTypeArguments[0];
                            var  listAccess = (IDisposable)this.InvokeTemplatedMethod(
                                nameof(GenerateListPropertyAccess),
                                itemType, _objId, _propToSet.Name
                                );

                            // If we succeeded in making a list access, then grab the cache and try to set the value
                            if (listAccess != null)
                            {
                                IList elements = listAccess.GetComplexPropertyValue <IList>(nameof(StrataPropertyListAccess <int> .Elements));
                                if (elements != null)
                                {
                                    // Here's the tricky bit, we either are setting an array - or - we're setting something we assume
                                    //  activator.create instance can make for us, is an IList, which we can then add the items to.
                                    if (_propToSet.PropertyType.IsArray)
                                    {
                                        Array final = Array.CreateInstance(_propToSet.PropertyType.GenericTypeArguments[0], elements.Count);
                                        for (int index = 0; index < elements.Count; ++index)
                                        {
                                            final.SetValue(elements[index], index);
                                        }

                                        _propToSet.SetValue(source, final);
                                    }
                                    else if (typeof(IList).IsAssignableFrom(_propToSet.PropertyType))
                                    {
                                        IList final = (IList)Activator.CreateInstance(_propToSet.PropertyType);
                                        foreach (object obj in elements)
                                        {
                                            final.Add(obj);
                                        }

                                        _propToSet.SetValue(source, final);
                                    }
                                }

                                // Don't forget to dispose of hte list access
                                listAccess.Dispose();
                                return;
                            }
                        }
                    }

                    // Otherwise, try and see if the type is assignable, and assign it if it is
                    if (_propToSet.PropertyType.IsAssignableFrom(storedPropValue.GetType()))
                    {
                        _propToSet.SetValue(source, storedPropValue);
                    }
                }
            }
        }