Ejemplo n.º 1
0
 /// <summary>
 /// Creates an instance of the attribute
 /// </summary>
 /// <param name="name">Display Name for the Addin</param>
 /// <param name="description">Description for the Addin</param>
 /// <param name="loadBehavior">LoadBehavior for the Addin</param>
 public COMAddinAttribute(string name, string description, LoadBehavior loadBehavior)
 {
     Name            = name;
     Description     = description;
     LoadBehavior    = Convert.ToInt32(loadBehavior);
     CommandLineSafe = -1;
 }
Ejemplo n.º 2
0
 internal Level(string n, LoadBehavior loadBehavior, Behavior updateBehavior,
                Behavior endBehavior, Condition winCondition)
 {
     mName          = n;
     LoadBehavior   = loadBehavior;
     UpdateBehavior = updateBehavior;
     EndBehavior    = endBehavior;
     WinCondition   = winCondition;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoadResult{TEntity}"/> class.
        /// </summary>
        /// <param name="query">The entity query which was completed.</param>
        /// <param name="loadBehavior">The load behavior used for load.</param>
        /// <param name="entities">Top level entities loaded.</param>
        /// <param name="allEntities">All entities loaded.</param>
        /// <param name="totalEntityCount">The total entity count.</param>
        public LoadResult(EntityQuery <TEntity> query, LoadBehavior loadBehavior, IEnumerable <TEntity> entities, IReadOnlyCollection <Entity> allEntities, int totalEntityCount)
        {
            _loadedEntites = (entities as Data.ReadOnlyObservableLoaderCollection <TEntity>) ?? new Data.ReadOnlyObservableLoaderCollection <TEntity>(entities.ToList());

            EntityQuery      = query;
            LoadBehavior     = loadBehavior;
            AllEntities      = allEntities;
            TotalEntityCount = totalEntityCount;
        }
Ejemplo n.º 4
0
        public override LoadOperation Load(EntityQuery query, LoadBehavior loadBehavior, Action <LoadOperation> callback, object userState)
        {
            if (this._loadCallback != null)
            {
                this._loadCallback(query, loadBehavior, userState);
            }

            return(base.Load(query, loadBehavior, callback, userState));
        }
Ejemplo n.º 5
0
 internal FrostbyteLevel(string n, LoadBehavior loadBehavior, Behavior updateBehavior,
                         Behavior endBehavior, Condition winCondition = null)
     : base(n, loadBehavior, updateBehavior, endBehavior, winCondition)
 {
     if (winCondition == null)
     {
         WinCondition = delegate() { return(LevelCompleted); };
     }
 }
Ejemplo n.º 6
0
 internal ExportDefinition(string application, string baseDirectory, string entryPoint, string entryPoint32, string entryPoint64, LoadBehavior loadBehavior)
 {
     Application   = application;
     _entryPoint   = entryPoint;
     _entryPoint32 = entryPoint32;
     _entryPoint64 = entryPoint64;
     BaseDirectory = baseDirectory;
     LoadBehavior  = loadBehavior;
 }
Ejemplo n.º 7
0
        public override LoadOperation Load(EntityQuery query, LoadBehavior loadBehavior, Action<LoadOperation> callback, object userState)
        {
            if (this._loadCallback != null)
            {
                this._loadCallback(query, loadBehavior, userState);
            }

            return base.Load(query, loadBehavior, callback, userState);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadOperation"/> class.
 /// </summary>
 /// <param name="query">The query to load.</param>
 /// <param name="loadBehavior"><see cref="LoadBehavior"/> to use for the load operation.</param>
 /// <param name="userState">Optional user state for the operation.</param>
 /// <param name="supportCancellation"><c>true</c> to enable <see cref="OperationBase.CancellationToken"/> to be cancelled when <see cref="OperationBase.Cancel"/> is called</param>
 private protected LoadOperation(EntityQuery query, LoadBehavior loadBehavior, object userState, bool supportCancellation)
     : base(userState, supportCancellation)
 {
     if (query == null)
     {
         throw new ArgumentNullException(nameof(query));
     }
     this._query        = query;
     this._loadBehavior = loadBehavior;
 }
Ejemplo n.º 9
0
        public virtual LoadBehavior GetLoadBehavior(IClassMap classMap)
        {
            LoadBehavior loadBehavior = classMap.GetLoadBehavior();

            if (loadBehavior == LoadBehavior.Default)
            {
                loadBehavior = this.Context.LoadBehavior;
            }
            return(loadBehavior);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadOperation"/> class.
 /// </summary>
 /// <param name="query">The query to load.</param>
 /// <param name="loadBehavior"><see cref="LoadBehavior"/> to use for the load operation.</param>
 /// <param name="userState">Optional user state for the operation.</param>
 internal LoadOperation(EntityQuery query, LoadBehavior loadBehavior, object userState)
     : base(userState)
 {
     if (query == null)
     {
         throw new ArgumentNullException("query");
     }
     this._query        = query;
     this._loadBehavior = loadBehavior;
 }
        /// <summary>
        /// Applies the specified state to the specified object taking the specified LoadBehavior into account.
        /// </summary>
        /// <param name="o">The object to apply state to.</param>
        /// <param name="stateToApply">The state dictionary.</param>
        /// <param name="originalState">The original state map for the modified object.</param>
        /// <param name="loadBehavior">The LoadBehavior to govern property merge behavior.</param>
        internal static void ApplyState(object o, IDictionary<string, object> stateToApply, IDictionary<string, object> originalState, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            MetaType metaType = MetaType.GetMetaType(o.GetType());

            bool isMerging = (o as Entity) == null ? (o as ComplexObject) != null && (o as ComplexObject).IsMergingState : (o as Entity).IsMergingState; 

            foreach (MetaMember metaMember in metaType.DataMembers)
            {
                PropertyInfo propertyInfo = metaMember.Member;
                object newValue;

                if ((isMerging && metaMember.IsMergable || !isMerging) && stateToApply.TryGetValue(propertyInfo.Name, out newValue))
                {
                    if (newValue != null && metaMember.IsComplex && !metaMember.IsCollection)
                    {
                        object currValue = propertyInfo.GetValue(o, null);
                        IDictionary<string, object> newValueState = (IDictionary<string, object>)newValue;
                        if (currValue != null)
                        {
                            // if the current and new values are both non-null, we have to do a merge
                            object complexTypeOriginalValues = null;
                            if (originalState != null)
                            {
                                originalState.TryGetValue(propertyInfo.Name, out complexTypeOriginalValues);
                            }
                            ApplyState(currValue, newValueState, (IDictionary<string, object>)complexTypeOriginalValues, loadBehavior);
                        }
                        else
                        {
                            // We do this lazy to avoid rehydrating the instance if we don't have to
                            Lazy<object> lazy = new Lazy<object>(
                                delegate
                                {
                                    // Rehydrate an instance from the state dictionary.
                                    object newInstance = Activator.CreateInstance(propertyInfo.PropertyType);
                                    ApplyState(newInstance, newValueState);
                                    return newInstance;
                                });
                            ApplyValue(o, lazy, propertyInfo, originalState, loadBehavior);
                        }
                    }
                    else
                    {
                        ApplyValue(o, newValue, propertyInfo, originalState, loadBehavior);
                    }
                }
            }  // end foreach 
        }
Ejemplo n.º 12
0
        public void Load(EntityQuery query, LoadBehavior loadBehavior)
        {
            Action <LoadOperation> callback = delegate(LoadOperation lo)
            {
                if (lo.HasError)
                {
                    lo.MarkErrorAsHandled();
                }
            };

            this.loadOperation = this.ctxt.Load(query, loadBehavior, callback, null);
        }
Ejemplo n.º 13
0
            public void OutputXml(XmlWriter writer)
            {
                writer.WriteStartElement("visio", "PublishAddin", "http://schemas.microsoft.com/wix/Visio");

                if (ProgId != null)
                {
                    writer.WriteAttributeString("ProgId", ProgId);
                }

                if (FriendlyName != null)
                {
                    writer.WriteAttributeString("FriendlyName", FriendlyName);
                }

                if (Description != null)
                {
                    writer.WriteAttributeString("Description", Description);
                }

                writer.WriteAttributeString("CommandLineSafe", CommandLineSafe != 0 ? "yes" : "no");

                writer.WriteAttributeString("LoadBehavior", LoadBehavior.ToString());

                switch ((VisioEdition)VisioEditionAttribute)
                {
                case VisioEdition.X86:
                    writer.WriteAttributeString("VisioEdition", "x86");
                    break;

                case VisioEdition.X64:
                    writer.WriteAttributeString("VisioEdition", "x64");
                    break;
                }

                switch ((AddinType)Type)
                {
                case AddinType.COM:
                    writer.WriteAttributeString("Type", "COM");
                    break;

                case AddinType.VSTO:
                    writer.WriteAttributeString("Type", "VSTO");
                    break;
                }

                writer.WriteEndElement();
            }
        private ExportDefinition ReadExport(XmlReader reader, string baseDirectory)
        {
            //Move to <Export> element
            MoveToElement(reader, ExportElementName);

            //Prepare Export properties
            string       application  = string.Empty;
            string       entryPoint   = string.Empty;
            string       entryPoint32 = string.Empty;
            string       entryPoint64 = string.Empty;
            LoadBehavior loadBehavior = LoadBehavior.OnDemand;

            //Read Export attributes
            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case ApplicationAttributeName:
                    application = reader.ReadContentAsString();
                    break;

                case EntryPointAttributeName:
                    entryPoint = reader.ReadContentAsString();
                    break;

                case EntryPoint32AttributeName:
                    entryPoint32 = reader.ReadContentAsString();
                    break;

                case EntryPoint64AttributeName:
                    entryPoint64 = reader.ReadContentAsString();
                    break;

                case LoadBehaviorAttributeName:
                    loadBehavior = reader.ReadContentAsEnum <LoadBehavior>();
                    break;
                }
            }

            //Move back to <Export> element
            reader.MoveToElement();

            ExportDefinition definition = new ExportDefinition(application, baseDirectory, entryPoint, entryPoint32, entryPoint64, loadBehavior);

            return(definition);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a strongly typed <see cref="LoadOperation"/> for the specified Type.
        /// </summary>
        /// <typeparam name="TEntity">The entity Type.</typeparam>
        /// <param name="query">The query to load.</param>
        /// <param name="loadBehavior"><see cref="LoadBehavior"/> to use for the load operation.</param>
        /// <param name="completeAction">Action to execute when the operation completes.</param>
        /// <param name="userState">Optional user state for the operation.</param>
        /// <param name="cancelAction">Action to execute when the operation is canceled. If null, cancellation will not be supported.</param>
        /// <returns>The operation instance created.</returns>
        internal static LoadOperation Create <TEntity>(EntityQuery <TEntity> query, LoadBehavior loadBehavior,
                                                       Action <LoadOperation> completeAction, object userState,
                                                       Action <LoadOperation> cancelAction) where TEntity : Entity
        {
            Action <LoadOperation <TEntity> > wrappedCompleteAction = null;
            Action <LoadOperation <TEntity> > wrappedCancelAction   = null;

            if (completeAction != null)
            {
                wrappedCompleteAction = arg => completeAction(arg);
            }
            if (cancelAction != null)
            {
                wrappedCancelAction = arg => cancelAction(arg);
            }

            return(new LoadOperation <TEntity>(query, loadBehavior, wrappedCompleteAction, userState, wrappedCancelAction));
        }
        /// <summary>
        /// Method that synchronizes the current graph with the provided graph by copying properties and entity states
        /// from the entities in give graph to the current graph. The way that property values are merged is specified by loadBehavior.
        /// </summary>
        /// <param name="srcGraph">The graph to synchronize from</param>
        /// <param name="loadBehavior">The LoadBehavior to apply. When specifying LoadBehavior.KeepCurrent, Synchronize will have no effect.</param>
        public void Synchronize(EntityGraph srcGraph, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }
            if (loadBehavior == LoadBehavior.RefreshCurrent)
            {
                Synchronize(srcGraph);
            }
            if (EntityGraphEqual(srcGraph, EntityTypeComparer) == false)
            {
                throw new Exception("Source graph entity graph must be a copy or a clone of present entity graph.");
            }
            var elements = srcGraph.Zip(this, (src, tgt) => new { src = src, tgt = tgt });

            foreach (var pair in elements)
            {
                MergeIntoCurrent(pair.src, pair.tgt);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Load the specified collection of entities into this <see cref="EntityContainer"/>.
        /// </summary>
        /// <param name="entities">The entities to load</param>
        /// <param name="loadBehavior">The <see cref="LoadBehavior"/> to use</param>
        /// <returns>The set of entities loaded. In cases where entities in the set
        /// are already cached locally, the return set will contain the cached instances.</returns>
        public IEnumerable LoadEntities(IEnumerable entities, LoadBehavior loadBehavior)
        {
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }

            // group the entities by type, and load each group into it's entity
            // list (ensuring we don't modify the relative ordering of each sequence
            // of results per type).  We group by root entity type so that all derived
            // entities belong to the same group.
            List <Entity> loadedEntities = new List <Entity>();
            var           entityGroups   = entities.Cast <Entity>().GroupBy(p => (this.GetEntitySet(p.GetType())));

            foreach (var group in entityGroups)
            {
                EntitySet set = group.Key;
                loadedEntities.AddRange(set.LoadEntities(group, loadBehavior));
            }

            return(loadedEntities);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadingDataEventArgs"/> class.
 /// </summary>
 /// <param name="query">Default query that will be used for the load operation</param>
 /// <param name="loadBehavior">Default load behavior that will be used for the load operation</param>
 internal LoadingDataEventArgs(EntityQuery query, LoadBehavior loadBehavior)
 {
     this.Query               = query;
     this.LoadBehavior        = loadBehavior;
     this.RestoreLoadSettings = true;
 }
Ejemplo n.º 19
0
        private void ApplyState(IDictionary<string, object> entityStateToApply, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            try
            {
                // We use this state to suppress validation during property sets
                this._isApplyingState = true;

                ObjectStateUtility.ApplyState(this, entityStateToApply, this._originalValues, loadBehavior);
            }
            catch (TargetInvocationException tie)
            {
                if (tie.InnerException != null)
                {
                    throw tie.InnerException;
                }
                throw;
            }
            finally
            {
                this._isApplyingState = false;
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Merge differs from ApplyState in that its the merge of an entire
        /// entity as opposed to an arbitrary set (possibly subset) of values.
        /// Change tracking is suspended for the entity during the merge.
        /// </summary>
        /// <param name="otherEntity">The entity to merge into the current instance</param>
        /// <param name="loadBehavior">The load behavior to use</param>
        internal void Merge(Entity otherEntity, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            // set this flag so change tracking and edit enforcement
            // is suspended during the merge
            this._isMerging = true;

            IDictionary<string, object> otherState = otherEntity.ExtractState();
            this.ApplyState(otherState, loadBehavior);

            // after the merge update our original state based on the
            // load behavior selected
            if (this._originalValues != null)
            {
                if (loadBehavior == LoadBehavior.RefreshCurrent)
                {
                    // when refreshing, the entity should no longer be
                    // considered modfied, so we wipe out original values
                    this._originalValues = null;

                    if (this.EntityState == EntityState.Modified && this.CustomMethodInvocation == null && !this.HasChildChanges)
                    {
                        // we've just reverted all property edits. If we're not modified for
                        // any other reason, transition to Unmodified
                        this.EntityState = EntityState.Unmodified;
                    }
                }
                else
                {
                    this._originalValues = otherState;
                }
            }

            this._isMerging = false;
            this.OnLoaded(false);
        }
Ejemplo n.º 21
0
 public static void LoadAllScripts(AddBehavior existsAlready  = AddBehavior.Ignore,
                                   LoadBehavior alreadyLoaded = LoadBehavior.Reload)
 {
     CheckSetUp();
     _LoadScripts(_scriptList.Keys, alreadyLoaded);
 }
Ejemplo n.º 22
0
 /// <summary>
 ///  Helepr method to invoke generic LoadAsync when the type of the result is not known at compile time
 /// </summary>
 private async Task <ILoadResult> LoadAsyncHelper <T>(EntityQuery <T> query, LoadBehavior loadBehavior, CancellationToken cancellationToken)
     where T : Entity
 {
     return(await this.DomainContext.LoadAsync(query, loadBehavior, cancellationToken));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadingDataEventArgs"/> class.
 /// </summary>
 /// <param name="query">Default query that will be used for the load operation</param>
 /// <param name="loadBehavior">Default load behavior that will be used for the load operation</param>
 internal LoadingDataEventArgs(EntityQuery query, LoadBehavior loadBehavior)
 {
     this.Query = query;
     this.LoadBehavior = loadBehavior;
     this.RestoreLoadSettings = true;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// 初始化 <see cref="RelationOptions"/> 类的新实例。
 /// </summary>
 /// <param name="loadBehavior">加载行为。</param>
 public RelationOptions(LoadBehavior loadBehavior)
 {
     LoadBehavior = loadBehavior;
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Applies the specified state to the specified object taking the specified LoadBehavior into account.
        /// </summary>
        /// <param name="o">The object to apply state to.</param>
        /// <param name="stateToApply">The state dictionary.</param>
        /// <param name="originalState">The original state map for the modified object.</param>
        /// <param name="loadBehavior">The LoadBehavior to govern property merge behavior.</param>
        internal static void ApplyState(object o, IDictionary <string, object> stateToApply, IDictionary <string, object> originalState, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            MetaType metaType = MetaType.GetMetaType(o.GetType());

            bool isMerging = (o as Entity) == null ? (o as ComplexObject) != null && (o as ComplexObject).IsMergingState : (o as Entity).IsMergingState;

            foreach (MetaMember metaMember in metaType.DataMembers)
            {
                object newValue;

                if ((isMerging && metaMember.IsMergable || !isMerging) && stateToApply.TryGetValue(metaMember.Name, out newValue))
                {
                    if (newValue != null && metaMember.IsComplex && !metaMember.IsCollection)
                    {
                        object currValue = metaMember.GetValue(o);
                        IDictionary <string, object> newValueState = (IDictionary <string, object>)newValue;
                        if (currValue != null)
                        {
                            // if the current and new values are both non-null, we have to do a merge
                            object complexTypeOriginalValues = null;
                            if (originalState != null)
                            {
                                originalState.TryGetValue(metaMember.Name, out complexTypeOriginalValues);
                            }
                            ApplyState(currValue, newValueState, (IDictionary <string, object>)complexTypeOriginalValues, loadBehavior);
                        }
                        else
                        {
                            // We do this lazy to avoid rehydrating the instance if we don't have to
                            Lazy <object> lazy = new Lazy <object>(
                                delegate
                            {
                                // Rehydrate an instance from the state dictionary.
                                object newInstance = Activator.CreateInstance(metaMember.PropertyType);
                                ApplyState(newInstance, newValueState);
                                return(newInstance);
                            });
                            ApplyValue(o, lazy, metaMember, originalState, loadBehavior);
                        }
                    }
                    else
                    {
                        ApplyValue(o, newValue, metaMember, originalState, loadBehavior);
                    }
                }
            }  // end foreach
        }
Ejemplo n.º 26
0
 internal Level(string n, LoadBehavior loadBehavior, Behavior updateBehavior,
     Behavior endBehavior, Condition winCondition)
 {
     mName = n;
     LoadBehavior = loadBehavior;
     UpdateBehavior = updateBehavior;
     EndBehavior = endBehavior;
     WinCondition = winCondition;
 }
        /// <summary>
        /// Method used to apply a value taking the specified LoadBehavior into account.
        /// </summary>
        /// <param name="o">The target object</param>
        /// <param name="value">The value to apply</param>
        /// <param name="propertyInfo">The property to apply the value to</param>
        /// <param name="originalState">The original state map for the object</param>
        /// <param name="loadBehavior">The LoadBehavior to govern property merge behavior.</param>
        private static void ApplyValue(object o, object value, PropertyInfo propertyInfo, IDictionary<string, object> originalState, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            Lazy<object> lazyValue = value as Lazy<object>;
            if (loadBehavior == LoadBehavior.RefreshCurrent)
            {
                // overwrite value with the new value
                if (lazyValue != null)
                {
                    value = lazyValue.Value;
                }
                propertyInfo.SetValue(o, value, null);
            }
            else if (loadBehavior == LoadBehavior.MergeIntoCurrent)
            {
                if (!PropertyHasChanged(o, originalState, propertyInfo))
                {
                    // set the value only if our value hasn't been modified
                    if (lazyValue != null)
                    {
                        value = lazyValue.Value;
                    }
                    propertyInfo.SetValue(o, value, null);
                }
            }
        }
 public void MissingAttribute(IQueryable<City> query, LoadBehavior loadBehavior, object userState)
 {
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Loads the query.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="query">The query.</param>
        /// <param name="domainContext">The domain context.</param>
        /// <param name="loadBehavior">The load behavior.</param>
        /// <returns> Observable operation loading</returns>
        public static IObservable <IEnumerable <TEntity> > ToObservable <TEntity>(this EntityQuery <TEntity> query, DomainContext domainContext, LoadBehavior loadBehavior = LoadBehavior.KeepCurrent)
            where TEntity : Entity
        {
            return(Observable.Defer(
                       () =>
            {
                var asyncSubject = new AsyncSubject <IEnumerable <TEntity> >();

                domainContext.Load(
                    query,
                    loadBehavior,
                    loadOperation =>
                {
                    if (loadOperation.HasError)
                    {
                        asyncSubject.OnError(new OperationException(loadOperation.Error, loadOperation));
                        loadOperation.MarkErrorAsHandled();
                    }
                    else
                    {
                        asyncSubject.OnNext(loadOperation.Entities);
                        asyncSubject.OnCompleted();
                    }
                },
                    null);

                return asyncSubject;
            }));
        }
 public override LoadOperation <TEntity> Load <TEntity>(EntityQuery <TEntity> query, LoadBehavior loadBehavior, Action <LoadOperation <TEntity> > callback, object userState)
 {
     this.LoadCalled = true;
     return(base.Load(query, loadBehavior, callback, userState));
 }
Ejemplo n.º 31
0
        private static void _LoadScripts(IEnumerable <string> scriptPaths, LoadBehavior alredyLoaded = LoadBehavior.Reload)
        {
            SceneManager.AddSceneToStack(_loadingKey);
            Task.Run(() =>
            {
                var loadingScreen = (LoadingScreenTemplate)SceneManager.GetScene(_loadingKey);
                var tempDic       = new Dictionary <string, ScriptingTemplate>();

                foreach (var scriptPath in scriptPaths)
                {
                    var scriptData = _scriptList[scriptPath];
                    if (scriptData.IsLoaded)
                    {
                        switch (alredyLoaded)
                        {
                        case LoadBehavior.Ignore:
                            continue;

                        case LoadBehavior.Reload:
                            break;

                        case LoadBehavior.ThrowException:
                            throw new Exception("Script already loaded \"" + scriptPath + "\"");

                        default:
                            throw new ArgumentOutOfRangeException(nameof(alredyLoaded), alredyLoaded, null);
                        }
                    }

                    loadingScreen.CurrentlyLoading(scriptPath);

                    var scriptCode = File.ReadAllText(scriptPath);
                    var script     = CSharpScript.Create(scriptCode,
                                                         ScriptOptions
                                                         .Default.WithReferences(Assembly.GetCallingAssembly(),
                                                                                 Assembly
                                                                                 .GetExecutingAssembly(),
                                                                                 Assembly
                                                                                 .GetAssembly(typeof(Game
                                                                                                     )),
                                                                                 _runningAssembly));
                    script.Compile();
                    var tempScriptType = script.RunAsync().Result.ReturnValue;
                    if (!(tempScriptType is Type))
                    {
                        throw new Exception("Return type of Script \"" + scriptPath + "\n is not correct");
                    }

                    var scriptType = (Type)tempScriptType;

                    tempDic[scriptPath] = (ScriptingTemplate)Activator.CreateInstance(scriptType);
                }


                foreach (var tempDicKey in tempDic.Keys)
                {
                    var data                = _scriptList[tempDicKey];
                    data.Template           = tempDic[tempDicKey];
                    data.IsLoaded           = true;
                    _scriptList[tempDicKey] = data;
                }
                loadingScreen.LoadingDone();
            });
        }
 public override Task <LoadResult <TEntity> > LoadAsync <TEntity>(EntityQuery <TEntity> query, LoadBehavior loadBehavior,
                                                                  CancellationToken cancellationToken = new CancellationToken())
 {
     LoadAsyncCalled = true;
     return(base.LoadAsync(query, loadBehavior, cancellationToken));
 }
 public virtual LoadBehavior GetListCountLoadBehavior(LoadBehavior loadBehavior, IPropertyMap propertyMap)
 {
     if (loadBehavior == LoadBehavior.Default)
     {
         loadBehavior = propertyMap.ListCountLoadBehavior;
         if (loadBehavior == LoadBehavior.Default)
         {
             loadBehavior = propertyMap.ClassMap.ListCountLoadBehavior;
             if (loadBehavior == LoadBehavior.Default)
             {
                 loadBehavior = propertyMap.ClassMap.DomainMap.ListCountLoadBehavior;
                 if (loadBehavior == LoadBehavior.Default)
                 {
                     loadBehavior = this.listCountLoadBehavior ;
                     if (loadBehavior == LoadBehavior.Default)
                     {
                         loadBehavior = LoadBehavior.Eager;
                     }
                 }
             }
         }
     }
     return loadBehavior;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Method used to apply a value taking the specified LoadBehavior into account.
        /// </summary>
        /// <param name="o">The target object</param>
        /// <param name="value">The value to apply</param>
        /// <param name="member">The property to apply the value to</param>
        /// <param name="originalState">The original state map for the object</param>
        /// <param name="loadBehavior">The LoadBehavior to govern property merge behavior.</param>
        private static void ApplyValue(object o, object value, MetaMember member, IDictionary <string, object> originalState, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            Lazy <object> lazyValue = value as Lazy <object>;

            if (loadBehavior == LoadBehavior.RefreshCurrent)
            {
                // overwrite value with the new value
                if (lazyValue != null)
                {
                    value = lazyValue.Value;
                }
                member.SetValue(o, value);
            }
            else if (loadBehavior == LoadBehavior.MergeIntoCurrent)
            {
                if (!PropertyHasChanged(o, originalState, member))
                {
                    // set the value only if our value hasn't been modified
                    if (lazyValue != null)
                    {
                        value = lazyValue.Value;
                    }
                    member.SetValue(o, value);
                }
            }
        }
Ejemplo n.º 35
0
        // Token: 0x060013FE RID: 5118 RVA: 0x0001E6FC File Offset: 0x0001D6FC
        protected override WorkflowElement CreateBody()
        {
            StateGraph stateGraph = new StateGraph(string.Format("OpponentPursuit: {0}", base.Entrant.Opponent.OpponentName));
            State      state      = new State("initial");
            State      state2     = new State("countdown");
            State      state3     = new State("inpursuit");
            State      state4     = new State("cooldown");
            State      state5     = new State("busted");
            State      state6     = new State("evaded");
            State      state7     = new State("post");

            new State("aborted");
            State state8 = new State("done");

            GameCore.Activities.Entrant.Components.CloseOnReceive <OnPursuitEngaged> activity  = new GameCore.Activities.Entrant.Components.CloseOnReceive <OnPursuitEngaged>(base.InstancedEvent, base.Entrant, Ports.Gameplay);
            GameCore.Activities.Components.CloseOnReceive <OnPursuitBusted>          activity2 = new GameCore.Activities.Components.CloseOnReceive <OnPursuitBusted>(Ports.Gameplay);
            EntrantFinished      activity3 = new EntrantFinished(base.InstancedEvent, base.Entrant, -8193);
            EntrantFinished      activity4 = new EntrantFinished(base.InstancedEvent, base.Entrant, 8202);
            OnUpdateTick         activity5 = new OnUpdateTick(base.InstancedEvent, base.Entrant);
            Conclude             item      = new Conclude(base.InstancedEvent, base.Entrant);
            FlushCops            item2     = new FlushCops();
            LoadBehavior         item3     = new LoadBehavior(base.InstancedEvent, base.Entrant, "BEHAVIOR_GAMEPLAY_PURSUIT", "PursuitMonitorBehavior");
            EntrantLoaded        item4     = new EntrantLoaded(base.InstancedEvent, base.Entrant, "Entrants.Loading");
            PrepareScoringMethod item5     = new PrepareScoringMethod(base.InstancedEvent, base.Entrant);
            EnableLoadingScreen  item6     = new EnableLoadingScreen(false);
            HandleTutorial       item7     = new HandleTutorial(base.InstancedEvent, base.Entrant, TutorialSource.kTutorialSource_Pursuit);
            Launch item8 = new Launch(base.InstancedEvent, base.Entrant);
            AssignPursuitEscalation item9 = new AssignPursuitEscalation(base.Event.EventDef.PursuitEscalation().GetKey());

            state.EnterActivity.Activities.Add(item3);
            state.Transitions.Add(new Transition("countdown"));
            LockEntrant                 item10    = new LockEntrant(base.InstancedEvent, base.Entrant, true);
            EnableKeyboard              item11    = new EnableKeyboard(true);
            FlushTraffic                item12    = new FlushTraffic();
            LoadBlackBoards             item13    = new LoadBlackBoards(base.Event, BlackBoardFlag.kBlackBoardFlag_Running);
            Countdown                   activity6 = new Countdown(base.InstancedEvent, base.Entrant);
            TryPerfectLaunch            item14    = new TryPerfectLaunch(base.InstancedEvent, base.Entrant);
            LockEntrant                 item15    = new LockEntrant(base.InstancedEvent, base.Entrant, false);
            LaunchPursuitByOpponentHeat item16    = new LaunchPursuitByOpponentHeat(base.InstancedEvent, base.Entrant);

            state2.EnterActivity.Activities.Add(item10);
            state2.EnterActivity.Activities.Add(item9);
            state2.EnterActivity.Activities.Add(item5);
            state2.EnterActivity.Activities.Add(item4);
            state2.EnterActivity.Activities.Add(item11);
            state2.EnterActivity.Activities.Add(item12);
            state2.EnterActivity.Activities.Add(item6);
            state2.EnterActivity.Activities.Add(item13);
            state2.EnterActivity.Activities.Add(item7);
            state2.Transitions.Add(new Transition("inpursuit", activity6));
            state2.ExitActivity.Activities.Add(item14);
            state2.ExitActivity.Activities.Add(item8);
            state2.ExitActivity.Activities.Add(item15);
            state2.ExitActivity.Activities.Add(item16);
            VisualEffect           item17 = new VisualEffect(EffectType.ENTER_COP_PURSUIT);
            EnablePointsOfInterest item18 = new EnablePointsOfInterest(4291711951u, true);

            GameCore.Activities.Entrant.Components.CloseOnReceive <OnPursuitCooldown> activity7 = new GameCore.Activities.Entrant.Components.CloseOnReceive <OnPursuitCooldown>(base.InstancedEvent, base.Entrant, Ports.Gameplay);
            EnablePointsOfInterest item19 = new EnablePointsOfInterest(4291711951u, false);

            state3.EnterActivity.Activities.Add(item17);
            state3.EnterActivity.Activities.Add(item18);
            state3.Transitions.Add(new Transition("cooldown", activity7));
            state3.Transitions.Add(new Transition("busted", activity2));
            state3.Transitions.Add(new Transition("done", activity4));
            state3.Transitions.Add(new Transition(activity5));
            state3.ExitActivity.Activities.Add(item19);
            EnablePointsOfInterest item20 = new EnablePointsOfInterest(3470858927u, true);

            GameCore.Activities.Entrant.Components.CloseOnReceive <OnPursuitEvaded> activity8 = new GameCore.Activities.Entrant.Components.CloseOnReceive <OnPursuitEvaded>(base.InstancedEvent, base.Entrant, Ports.Gameplay);
            EnablePointsOfInterest item21 = new EnablePointsOfInterest(3470858927u, false);
            HandleTutorial         item22 = new HandleTutorial(base.InstancedEvent, base.Entrant, TutorialSource.kTutorialSource_PursuitCooldown);

            state4.EnterActivity.Activities.Add(item20);
            state4.EnterActivity.Activities.Add(item22);
            state4.Transitions.Add(new Transition("inpursuit", activity));
            state4.Transitions.Add(new Transition("evaded", activity8));
            state4.Transitions.Add(new Transition("busted", activity2));
            state4.Transitions.Add(new Transition("done", activity4));
            state4.Transitions.Add(new Transition(activity5));
            state4.ExitActivity.Activities.Add(item21);
            FinishEntrant activity9 = new FinishEntrant(base.InstancedEvent, base.Entrant, FinishReason.Evaded);
            HardwareBlinkingEffectEntrant item23 = new HardwareBlinkingEffectEntrant(base.InstancedEvent, base.Entrant, 4278216447u, 3.8f, 0.4f);

            state6.EnterActivity.Activities.Add(item23);
            state6.Transitions.Add(new Transition("post", activity3));
            state6.Transitions.Add(new Transition("done", activity4));
            state6.Transitions.Add(new Transition(activity9));
            state6.ExitActivity.Activities.Add(item);
            FinishEntrant activity10             = new FinishEntrant(base.InstancedEvent, base.Entrant, FinishReason.Busted);
            HardwareBlinkingEffectEntrant item24 = new HardwareBlinkingEffectEntrant(base.InstancedEvent, base.Entrant, 4294901760u, 3f, 0.1f);
            Bust item25 = new Bust(base.InstancedEvent, base.Entrant);

            state5.EnterActivity.Activities.Add(item24);
            state5.Transitions.Add(new Transition("post", activity3));
            state5.Transitions.Add(new Transition("done", activity4));
            state5.Transitions.Add(new Transition(activity10));
            state5.ExitActivity.Activities.Add(item25);
            OverrideVehicleControl item26     = new OverrideVehicleControl(base.Entrant.Opponent.Vehicle, OverrideVehicleControl.Control.Stop);
            ReleaseBehavior        item27     = new ReleaseBehavior(base.InstancedEvent, base.Entrant, "BEHAVIOR_GAMEPLAY_PURSUIT");
            PostEventScreen        activity11 = new PostEventScreen(base.InstancedEvent, base.Entrant, Ports.Gameplay);
            ChangeBlackBoard       item28     = new ChangeBlackBoard(BlackBoardChannel.kBlackBoard_Audio, 3114481865u);
            ChangeBlackBoard       item29     = new ChangeBlackBoard(BlackBoardChannel.kBlackBoard_AI, 331198907u);

            state7.EnterActivity.Activities.Add(item28);
            state7.EnterActivity.Activities.Add(item29);
            state7.EnterActivity.Activities.Add(item26);
            state7.EnterActivity.Activities.Add(item2);
            state7.EnterActivity.Activities.Add(item12);
            state7.EnterActivity.Activities.Add(item27);
            state7.Transitions.Add(new Transition("done", activity11));
            OverrideVehicleControl item30 = new OverrideVehicleControl(base.Entrant.Opponent.Vehicle, OverrideVehicleControl.Control.Release);
            CleanupScoringMethod   item31 = new CleanupScoringMethod(base.InstancedEvent, base.Entrant);

            state8.EnterActivity.Activities.Add(item30);
            state8.EnterActivity.Activities.Add(item31);
            stateGraph.InitialState = "initial";
            stateGraph.DoneState    = "done";
            stateGraph.States.Add(state);
            stateGraph.States.Add(state2);
            stateGraph.States.Add(state3);
            stateGraph.States.Add(state4);
            stateGraph.States.Add(state5);
            stateGraph.States.Add(state6);
            stateGraph.States.Add(state7);
            stateGraph.States.Add(state8);
            return(stateGraph);
        }
Ejemplo n.º 36
0
 public TableAttribute(string tableName, LoadBehavior loadBehavior)
 {
     TableName    = tableName;
     LoadBehavior = loadBehavior;
 }
        public static IEnumerable <T> Import <T>(this EntitySet <T> collection, IList <EntityStateSet> stateSet, LoadBehavior loadBehavior) where T : Entity, new()
        {
            List <T> loadedEntities = new List <T>();
            Dictionary <object, T> identityCache = new Dictionary <object, T>();

            foreach (T currentEntity in collection)
            {
                identityCache.Add(currentEntity.GetIdentity(), currentEntity);
            }
            foreach (EntityStateSet currentStateSet in stateSet)
            {
                T existingEntity;
                identityCache.TryGetValue(currentStateSet.OriginalKey, out existingEntity);
                if (existingEntity == null && currentStateSet.ModifiedKey != null)
                {
                    identityCache.TryGetValue(currentStateSet.ModifiedKey, out existingEntity);
                }
                if (existingEntity == null)
                {
                    T newEntity = new T();
                    if (currentStateSet.ModifiedState != null)
                    {
                        collection.Attach(newEntity);
                    }
                    newEntity.ApplyState(currentStateSet.OriginalState, currentStateSet.ModifiedState);
                    if (currentStateSet.ModifiedState == null)
                    {
                        collection.Attach(newEntity);
                    }
                    if (currentStateSet.IsDelete)
                    {
                        collection.Attach(newEntity);
                        collection.Remove(newEntity);
                    }
                    else
                    {
                        loadedEntities.Add(newEntity);
                    }
                }
                else if (loadBehavior == LoadBehavior.RefreshCurrent)
                {
                    if (currentStateSet.IsDelete)
                    {
                        collection.Remove(existingEntity);
                    }
                    else
                    {
                        existingEntity.ApplyState(currentStateSet.OriginalState, currentStateSet.ModifiedState);
                        loadedEntities.Add(existingEntity);
                    }
                }
            }
            return(new ReadOnlyCollection <T>(loadedEntities));
        }