Exemple #1
0
        /// <summary>
        ///     Given the property name and its instance, it sets in the corresponding bit array at
        ///     the corresponding index (of the property) the value to true (modified)
        ///     Assumming that model is not a dirty model
        /// </summary>
        /// <param name="model">The instance of IChangesTrackeable</param>
        /// <param name="property">The name of the property</param>
        public void MarkAsModified(IStateObject model, string property)
        {
            if (model.UniqueID == null ||
                IsDirtyModel(model) ||
                !StateManager.AllBranchesAttached(model))
            {
                return;
            }

            PropertiesExDictionary typeProperties = TypePropertiesCache.GetPropertiesIndexPositionOfType(model.GetType());
            int propertyIndex;

            if (!typeProperties.TryGetValue(property, out propertyIndex))
            {
                return;
            }
            BitArray data;

            lock (modifiedLock)
            {
                if (!bitArrays.TryGetValue(model, out data))
                {
                    bitArrays.Add(model, data = new BitArray(typeProperties.PropertiesList.Count));
                }
                if (data == null)
                {
                    bitArrays[model] = data = new BitArray(typeProperties.PropertiesList.Count);
                }
            }
            data.Set(propertyIndex, true);
        }
Exemple #2
0
        /// <summary>
        ///     Given the property Index and its instance, it sets in the corresponding bit array at
        ///     the corresponding index (of the property) the value to true (modified)
        ///     Assumming that model is not a dirty model
        /// </summary>
        /// <param name="model">The instance of IChangesTrackeable</param>
        /// <param name="property">The name of the property</param>
        public void MarkAsModified(IStateObject model, int index)
        {
            if (model.UniqueID == null ||
                IsDirtyModel(model) ||
                !StateManager.AllBranchesAttached(model))
            {
                return;
            }
            BitArray data;

            lock (modifiedLock)
            {
                if (!bitArrays.TryGetValue(model, out data))
                {
                    int typePropertiesLength = TypePropertiesCache.GetArrayPropertiesCount(model.GetType());
                    bitArrays.Add(model, data = new BitArray(typePropertiesLength));
                }
                if (data == null)
                {
                    int typePropertiesLength = TypePropertiesCache.GetArrayPropertiesCount(model.GetType());
                    bitArrays[model] = data = new BitArray(typePropertiesLength);
                }
            }
            data.Set(index, true);
        }
Exemple #3
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            var props = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(value.GetType());

            for (int i = 0; i < props.Count; i++)
            {
                var propEx = props[i];
                if (propEx == null || propEx.mustIgnoreMemberForClient)
                {
                    continue;
                }
                PropertyInfo prop      = propEx.prop;
                var          propValue = prop.GetValue(value, null);
                //We should not send in the json for an object, any property that is an stateobject
                //they should travel independenly
                //This check is important because we have properties
                if (!(propValue is IStateObject))
                {
                    writer.WritePropertyName(prop.Name);
                    serializer.Serialize(writer, propValue);
                }
            }
            writer.WriteEndObject();
        }
Exemple #4
0
        public static IList <PropertyInfoEx> GetPropertyInfoExFor(Type typeName)
        {
            IList <PropertyInfoEx> tableInfo;

            TypePropertiesCache.VerifyInformationIsLoaded(typeName, out tableInfo);
            return(tableInfo);
        }
Exemple #5
0
        /// <summary>
        ///     Given the instance it tries to add the bit array to the dictionary of bit arrays
        ///     representing the state (modified or not) of the model properties.
        /// </summary>
        /// <param name="model">The instance of IChangesTrackeable</param>
        public void AddsBitArray(IStateObject model)
        {
            BitArray data;

            if (!bitArrays.TryGetValue(model, out data))
            {
                var props = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(model.GetType());
                bitArrays.Add(model, new BitArray(props.Count));
            }
            else
            {
                data.SetAll(false);
            }
        }
Exemple #6
0
        /// <summary>
        ///     It collects all the delta objects int the given instance
        /// </summary>
        /// <param name="instance">The instance</param>
        /// <returns>The changes found in the instance</returns>
        public object GetDeltas(IStateObject instance)
        {
            //  Arrayway
            BitArray bitArray;
            Delta    delta = null;

            // if model has been subscribed to any delta tracker
            if (bitArrays.TryGetValue(instance, out bitArray))
            {
                if (bitArray == null)
                {
                    return(null);
                }
                if (instance is IReturnWholeObjectAsDelta)
                {
                    return(instance);
                }
                var propertiesMatchingBitArrays = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(instance.GetType());
                var dataCount = bitArray.Count;
                for (var bitArrayPosition = 0; bitArrayPosition < dataCount; bitArrayPosition++)
                {
                    if (bitArray.Get(bitArrayPosition))
                    {
                        var propertyInfoEx = propertiesMatchingBitArrays[bitArrayPosition];
                        if (!propertyInfoEx.mustIgnoreMemberForClient)
                        {
                            object propValue = propertyInfoEx.prop.GetValue(instance);
                            if (delta == null)
                            {
                                delta = new Delta();
                            }
                            delta.Add(propertyInfoEx.prop.Name, propValue);
                        }
                    }
                }
            }
            if (delta != null)
            {
                //We are including the UniqueID in the delta
                if (delta.Count > 0)
                {
                    delta["UniqueID"] = instance.UniqueID;
                }
            }
            return(delta);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            Type valueType = value.GetType();

            if (writeTypeInfo)
            {
                writer.WritePropertyName("__type");

                string assemblyQualifiedName = valueType.AssemblyQualifiedName;
                writer.WriteValue(assemblyQualifiedName);
            }
            var propArr = TypePropertiesCache.GetArrayPropertiesOrderedByIndex(valueType);

            for (var i = 0; i < propArr.Count; i++)
            {
                var propEx = propArr[i];
                if (propEx == null)
                {
                    continue;
                }
                var prop = propEx.prop;
                if (propEx.mustIgnoreMemberForClient)
                {
                    continue;
                }
                object propValue = null;
                try
                {
                    propValue = prop.GetValue(value, null);
                    writer.WritePropertyName(prop.Name);
                    serializer.Serialize(writer, propValue);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Problem while writing JSON for object of type " + valueType + " property " + prop.Name);
                    Debug.WriteLine("Error " + ex.Message);
                }
            }

            writer.WriteEndObject();
        }
        protected override List <MemberInfo> GetSerializableMembers(Type type)
        {
            if (TypeCacheUtils.IsAnStructType(type) ||
                (type == typeof(CurrentState)) ||
                (type == typeof(ViewsState)) ||
                (type == typeof(ClientCommand)))
            {
                return(base.GetSerializableMembers(type));
            }

            List <MemberInfo> props = new List <MemberInfo>();

            foreach (var propEx in TypePropertiesCache.GetArrayPropertiesOrderedByIndex(type))

            {
                if (propEx != null && !propEx.IsExcludedPropertyForSerialization(serverSide, skipUniqueId, skipObjectProperties))
                {
                    props.Add(propEx.prop);
                }
            }
            return(props);
        }
        /// <summary>
        /// Performs several initialization tasks, related to the IoCContainer setup
        /// All types are registered here for interception.
        /// </summary>
        /// <returns></returns>
        public static void Initialize(Assembly mainAssembly = null)
        {
            //System.Web.HttpContext.Current.ApplicationInstance.BeginRequest -= ApplicationInstance_BeginRequest;
            //System.Web.HttpContext.Current.ApplicationInstance.BeginRequest += ApplicationInstance_BeginRequest;


            if (initialized)
            {
                return;
            }

            Debug.WriteLine("WebMap Application not initialized. Starting initialization");
            TypePropertiesCache.SetupInterceptionDelegates(
                new InterceptionDelegates()
            {
                isASupportedValueTypeForIListDelegate = TypeCacheUtils.IsSupportedGenericTypeForList,
                ProcessGetterNoAction = LazyBehaviours.ProcessGetterNoAction,
                ProcessGetterNonTopLevelIStateObject = LazyBehaviours.ProcessGetterNonTopLevelIStateObject,
                ProcessGetterStrongReference         = LazyBehaviours.ProcessGetterStrongReference,
                ProcessGetterSurrogate            = LazyBehaviours.ProcessGetterSurrogate,
                ProcessGetterTopLevelIStateObject = LazyBehaviours.ProcessGetterTopLevelIStateObject,
                ProcessGetterWeakReference        = LazyBehaviours.ProcessGetterWeakReference,
                ProcessSetterMostCases            = LazyBehaviours.ProcessSetterMostCases,
                ProcessSetterObjectReference      = LazyBehaviours.ProcessSetterObjectReference,
                ProcessSetterSimpleTypes          = LazyBehaviours.ProcessSetterSimpleTypes,
                ProcessSetterStrongReference      = LazyBehaviours.ProcessSetterStrongReference,
                ProcessSetterSurrogate            = LazyBehaviours.ProcessSetterSurrogate,
                ProcessSetterWeakReference        = LazyBehaviours.ProcessSetterWeakReference,
                ProcessSetterVisibleState         = LazyBehaviours.ProcessSetterVisibleState
            });
            SurrogatesDirectory.TypeToContractedString = TypeCacheUtils.AssemblyQualifiedNameCache;
            SurrogatesDirectory.ContractedStringToType = TypeCacheUtils.GetType;

            var aliasConfig  = System.Configuration.ConfigurationManager.AppSettings["UniqueIDAliasEnabled"];
            var aliasEnabled = false;

            if (aliasConfig != null)
            {
                aliasEnabled = Convert.ToBoolean(aliasConfig);
            }
            TypePropertiesCache.ALIAS_ENABLED = aliasEnabled;

            //Connect delegates that are required by Dictionary implementations
            DictionaryUtils.Current       = StateManager.GetCurrent;
            DictionaryUtils.CreatePromise = EventPromiseInfo.CreateEventInstancePromise;
            DictionaryUtils.RetrieveDelegateFromPromise = PromiseUtils.RetrieveDelegateFromPromise;
            DictionaryUtils.GetObjectContainingMethod   = EventPromiseInfo.GetObjectContainingMethod;

            MEFManager.PlatformInitializer().Initialize();

            BaseClassFindInit._findMethod = (_baseType, parameters, types) =>
            {
                Type[] paramsTypes = new Type[] { };
                if (types != null)
                {
                    paramsTypes = types;
                }
                var initCandidates = new List <MethodInfo>();

                var methods = _baseType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var methodInfo in methods)
                {
                    if (InitializationHelpers.IsMethodValidCandidate(methodInfo, paramsTypes)) //explicit interface implementation
                    {
                        initCandidates.Add(methodInfo);
                    }
                }
                var selectedInit = InitializationHelpers.GetSelectedInit(initCandidates, paramsTypes);
                return(selectedInit);
            };

            IocContainerImplWithUnity.InitializeResolver();
            var container = IocContainerImplWithUnity.Current;


            RegisterAllTypes(container, mainAssembly);
            TypeCacheUtils.LoadClientTypeMetadataTable();
            initialized = true;
            Debug.WriteLine("WebMap Runtime Initialization DONE!");
        }