Наследование: MonoBehaviour
Пример #1
0
        /// <summary>
        /// 创建实例
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="args">构造函数的参数列表</param>
        public static T CreateInstance <T>(Type type, params object[] args) where T : class, new()
        {
            //根据参数列表返回参数类型数组
            var parameterTypes = args.Select(c => c.GetType()).ToArray();

            return((T)CreateInstance(type, parameterTypes)(args));
        }
 public FastDeepClonerSettings()
 {
     OnCreateInstance = new CreateInstance((Type type) =>
     {
         return(type.Creator());
     });
 }
Пример #3
0
        public void InstanceCreated(CreateInstance instance)
        {
            //var list = (List<CreateInstance>)Clients.Caller.Instances;
            //list.Add(instance);

            //Clients.Caller.Instances = list;
        }
 public void CreateFromFile(string path)
 {
     instance  = MemoryMappedFile.CreateFromFile(path);
     this.path = path;
     ci        = CreateInstance.CreateFromFile;
     ni        = 0;
 }
        //initialize the popup window
        public static void Init(EditorWindow parent, CreateInstance OnSubmit, string defaultValue, string windowName, string valueLabel)
        {
            //check if a window is already open
            if (instance != null)
            {
                return;
            }


            //create window
            instance = ScriptableObject.CreateInstance <StringPopupWindow>();

            //cache the reference to the parent for later repaint
            instance.parent     = parent;
            instance.value      = defaultValue;
            instance.valueLabel = valueLabel;
            instance.OnSubmit   = OnSubmit;


            //calculate window position (center of the parent window)
            float x = parent.position.x + (parent.position.width - 350) * 0.5f;
            float y = parent.position.y + (parent.position.height - 75) * 0.5f;

            instance.position = new Rect(x, y, 350, 75);

            //show window as "utility"
            instance.ShowUtility();
        }
 public void OpenExistingstring(string mapName)
 {
     instance     = MemoryMappedFile.OpenExisting(mapName);
     this.mapName = mapName;
     ci           = CreateInstance.OpenExistingstring;
     ni           = 0;
 }
 public void CreateFromFile(string path, FileMode mode)
 {
     instance  = MemoryMappedFile.CreateFromFile(path, mode);
     this.path = path;
     this.mode = mode;
     ci        = CreateInstance.CreateFromFile;
     ni        = 1;
 }
 public void CreateOrOpen(string mapName, long capacity)
 {
     instance      = MemoryMappedFile.CreateOrOpen(mapName, capacity);
     this.mapName  = mapName;
     this.capacity = capacity;
     ci            = CreateInstance.CreateOrOpen;
     ni            = 0;
 }
 public void OpenExistingstring(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     instance                 = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights);
     this.mapName             = mapName;
     this.desiredAccessRights = desiredAccessRights;
     ci = CreateInstance.OpenExistingstring;
     ni = 1;
 }
 public void OpenExistingstring(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
 {
     instance                 = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights, inheritability);
     this.mapName             = mapName;
     this.desiredAccessRights = desiredAccessRights;
     this.inheritability      = inheritability;
     ci = CreateInstance.OpenExistingstring;
     ni = 2;
 }
Пример #11
0
        public void Connect(CreateInstance instance)
        {
            this.Host     = instance.Host;
            this.Port     = instance.Port;
            this.Password = instance.Password;
            this.GameType = instance.GameType;

            this.Initialize(instance);
        }
 public void CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access)
 {
     instance      = MemoryMappedFile.CreateOrOpen(mapName, capacity, access);
     this.mapName  = mapName;
     this.capacity = capacity;
     this.access   = access;
     ci            = CreateInstance.CreateOrOpen;
     ni            = 1;
 }
 public void CreateFromFile(string path, FileMode mode, string mapName, long capacity)
 {
     instance      = MemoryMappedFile.CreateFromFile(path, mode, mapName, capacity);
     this.path     = path;
     this.mode     = mode;
     this.mapName  = mapName;
     this.capacity = capacity;
     ci            = CreateInstance.CreateFromFile;
     ni            = 3;
 }
Пример #14
0
 /**
  * Get a pooled instance. Will be activated. If not found, call delegate.
  */
 public static GameObject GetInstance(string poolType, CreateInstance instanceFunction)
 {
     if (Pool.InstanceAvailable(poolType))
     {
         return(GetInstance(poolType, Vector3.zero));
     }
     else
     {
         return(instanceFunction());
     }
 }
 public void CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access, HandleInheritability inheritability, bool leaveOpen)
 {
     instance            = MemoryMappedFile.CreateFromFile(fileStream, mapName, capacity, access, inheritability, leaveOpen);
     this.fileStream     = fileStream;
     this.mapName        = mapName;
     this.capacity       = capacity;
     this.inheritability = inheritability;
     this.leaveOpen      = leaveOpen;
     ci = CreateInstance.CreateFromFile;
     ni = 5;
 }
 public void CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, HandleInheritability inheritability)
 {
     instance            = MemoryMappedFile.CreateOrOpen(mapName, capacity, access, options, inheritability);
     this.mapName        = mapName;
     this.capacity       = capacity;
     this.access         = access;
     this.options        = options;
     this.inheritability = inheritability;
     ci = CreateInstance.CreateOrOpen;
     ni = 2;
 }
Пример #17
0
        /// <summary>
        /// 创建实例
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="args">构造函数的参数列表</param>
        public static object CreateInstance(Type type, params object[] args)
        {
            // 缓存
            var key = type.GetHashCode();

            //根据参数列表返回参数类型数组
            Type[] parameterTypes = null;
            if (args != null && args.Length > 0)
            {
                parameterTypes = new Type[args.Length];
                for (var i = 0; i < args.Length; i++)
                {
                    parameterTypes[i] = args[i].GetType(); key += parameterTypes[i].GetHashCode();
                }
            }
            if (DicInstanceList.ContainsKey(key))
            {
                return(DicInstanceList[key](args));
            }
            return(CreateInstance(key, type, parameterTypes)(args));
        }
Пример #18
0
 public static object GetInstance(Type type, CreateInstance createInstance)
 {
     if (instance == null)
     {
         lock (syncRoot)
         {
             if (instance == null)
             {
                 instance = createInstance(type);
             }
         }
     }
     return(instance);
 }
Пример #19
0
        void InitializeInstance()
        {
            InstanceAdminClient instanceAdminClient = InstanceAdminClient.Create();

            try
            {
                string   name     = $"projects/{_fixture.ProjectId}/instances/{_fixture.InstanceId}";
                Instance response = instanceAdminClient.GetInstance(name);
            }
            catch (RpcException ex) when(ex.Status.StatusCode == StatusCode.NotFound)
            {
                CreateInstance.SpannerCreateInstance(_fixture.ProjectId, _fixture.InstanceId);
            }
        }
Пример #20
0
        void InitializeInstance()
        {
            InstanceAdminClient instanceAdminClient = InstanceAdminClient.Create();

            try
            {
                InstanceName instanceName = InstanceName.FromProjectInstance(_fixture.ProjectId, _fixture.InstanceId);
                Instance     response     = instanceAdminClient.GetInstance(instanceName);
            }
            catch (RpcException ex) when(ex.Status.StatusCode == StatusCode.NotFound)
            {
                CreateInstance.SpannerCreateInstance(_fixture.ProjectId, _fixture.InstanceId);
            }
        }
        public void Setup()
        {
            var presentationModel = new CreateInstance<PricePresentationModel>();
            var presentationModelMock = new Mock<ICreateInstance<PricePresentationModel>>();
            presentationModelMock.Setup(x => x.Create()).Returns(new PricePresentationModel());

            var viewModelBuilderMock = new Mock<ICollectViewBuilders>();
            var headerViewModelBuilder = new HeaderViewModelBuilder();
            var footerViewModelBuilder = new FooterViewModelBuilder();
            var itemsToReturn = new ViewModel[] { new HeaderViewModel(), new FooterViewModel() };
            viewModelBuilderMock.Setup(x => x.GetViewModels(It.IsAny<Context>(),It.IsAny<IViewModelBuilder[]>())).Returns(itemsToReturn);

            _presentationModelBuilder = new PricePresentationModelBuilder(presentationModel, viewModelBuilderMock.Object, headerViewModelBuilder, footerViewModelBuilder);
        }
Пример #22
0
    /// <summary>
    /// Retourne une liste des différents Personnages
    /// </summary>
    /// <returns>
    /// Une liste des différents Personnages
    /// </returns>
    public static List <Personnage> RetournerPersonnages()
    {
        List <Personnage> personnages = new List <Personnage>();
        var types = System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(Personnage));


        foreach (System.Type type in types)
        {
            personnages.Add((Personnage)CreateInstance.MagicallyCreateInstance(type.ToString()));
        }


        return(personnages);
    }
Пример #23
0
    /// <summary>
    /// Retourne une liste des différents Rôles
    /// </summary>
    /// <returns>
    /// Une liste des différents Rôles
    /// </returns>
    public static List <Role> RetournerRole()
    {
        List <Role> roles = new List <Role>();
        var         types = System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(Role));


        foreach (System.Type type in types)
        {
            roles.Add((Role)CreateInstance.MagicallyCreateInstance(type.ToString()));
        }


        return(roles);
    }
Пример #24
0
        private void SetupSkynet(CreateInstance instance = null)
        {
            if (instance == null)
            {
                instance = new CreateInstance()
                {
                    GameType = this.GameType,
                    Host     = this.Host,
                    Password = this.Password,
                    Port     = this.Port
                };
            }

            #region Realtime handlers
            // The actual method call for the connection to remote server
            var inGameMessage = skynet.On <SendIngameMessage>("IngameMessage", msg =>
            {
                if (msg.ServerName.Equals(this.InstanceName))
                {
                    if (msg.Target.Name.ToLower().Equals("all"))
                    {
                        Connection.Command("admin.say", msg.Message, msg.Target.Name.ToLower());
                        msg = null;
                    }
                    else
                    {
                        Connection.Command("admin.say", msg.Message, msg.Target.Name.ToLower(), msg.Target.TargetName);
                        msg = null;
                    }
                }
            });
            #endregion

            #region Startup calls
            skynet.Invoke <CreateInstance>("InstanceCreated", instance).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("{0} {1}", DateTime.Now, "Unable to notify thor about instance");
                    Console.WriteLine(task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("{0} {1}", DateTime.Now, "thor has been notified about instance");
                }
            }).Wait();
            #endregion
        }
        public async Task <IActionResult> PutInstance(int id, DateTime startTime, CreateInstance instanceData)
        {
            if (startTime != instanceData.StartTime)
            {
                return(BadRequest());
            }

            bool updatedInstance = await instanceRepository.UpdateInstance(id, startTime, instanceData);

            if (!updatedInstance)
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public async Task <InstanceDTO> SaveNewInstance(int id, CreateInstance instanceData)
        {
            var instance = new Instance
            {
                GoalId    = id,
                StartTime = instanceData.StartTime,
                EndTime   = instanceData.EndTime,
                Comment   = instanceData.Comment,
            };

            _context.Instance.Add(instance);
            await _context.SaveChangesAsync();

            var newInstance = await GetInstanceById(instance.Id);

            return(newInstance);
        }
Пример #27
0
    /// <summary>
    /// Affiche les différents Personnages dans la console
    /// </summary>
    public static void AfficherPersonnages()
    {
        List <Personnage> personnages = new List <Personnage>();
        var types = System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(Personnage));


        foreach (System.Type type in types)
        {
            personnages.Add((Personnage)CreateInstance.MagicallyCreateInstance(type.ToString()));
        }


        foreach (Personnage personnage in personnages)
        {
            Debug.Log(personnage.nom);
        }
    }
Пример #28
0
    /// <summary>
    /// Affiche les différents Rôles dans la console
    /// </summary>
    public static void AfficherRoles()
    {
        List <Role> roles = new List <Role>();
        var         types = System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(Role));


        foreach (System.Type type in types)
        {
            roles.Add((Role)CreateInstance.MagicallyCreateInstance(type.ToString()));
        }


        foreach (Role role in roles)
        {
            Debug.Log(role.titre);
        }
    }
        /// <summary>
        /// Executing triggeredMethod ExecuteOn_BenchReady_Through_StartTriggeringRulesBench
        /// </summary>
        public static void ExecuteOn_BenchReady_Through_StartTriggeringRulesBench(XComponent.BenchSimpleFork.UserObject.StartTriggeringRulesBench startTriggeringRulesBench, object object_PublicMember, object object_InternalMember, Context context, IStartTriggeringRulesBenchStartTriggeringRulesBenchOnBenchReadyBenchManagerSenderInterface sender)
        {
            CreateInstance createInstance;

            for (int i = 0; i < startTriggeringRulesBench.NbInstances - 1; i++)
            {
                createInstance = new CreateInstance {
                    Id = i
                };
                sender.CreateInstance(context, createInstance);
            }
            createInstance = new CreateInstance {
                Id = startTriggeringRulesBench.NbInstances - 1
            };
            createInstance.IsLast = true;
            sender.CreateInstance(context, createInstance);
        }
Пример #30
0
        private void Initialize(CreateInstance instance = null)
        {
            Connection        = new RConnection();
            this.InstanceName = string.Concat(this.Host, ":", this.Port);

            Connection.HostName          = this.Host;
            Connection.Port              = (ushort)this.Port;
            Connection.PlaintextPassword = this.Password;

            Connection.Connected      += Connection_Connected;
            Connection.Error          += Connection_Error;
            Connection.Disconnected   += Connection_Disconnected;
            Connection.PacketReceived += Connection_PacketReceived;
            Connection.PacketSent     += Connection_PacketSent;

            RunClient();
        }
        public async Task <bool> UpdateInstance(int id, DateTime startTime, CreateInstance instanceData)
        {
            var instance = await _context.Instance
                           .FirstOrDefaultAsync(instance => instance.Id == id && instance.StartTime == instanceData.StartTime);

            if (instance is null)
            {
                return(false);
            }
            instance.StartTime = instanceData.StartTime;
            instance.EndTime   = instanceData.EndTime;
            instance.Comment   = instanceData.Comment;

            _context.Entry(instance).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(true);
        }
Пример #32
0
        public object BuildInstance(ResolutionInfo resolutionInfo, TypeInformation resolveType)
        {
            if (this.metaInfoProvider.HasInjectionMethod || this.containerExtensionManager.HasPostBuildExtensions)
            {
                if (this.constructorDelegate != null && !this.isConstructorDirty) return this.ResolveType(containerContext, resolutionInfo, resolveType);

                lock (this.syncObject)
                {
                    if (this.constructorDelegate != null && !this.isConstructorDirty) return this.ResolveType(containerContext, resolutionInfo, resolveType);

                    ResolutionConstructor constructor;
                    if (!this.metaInfoProvider.TryChooseConstructor(out constructor, resolutionInfo,
                            this.injectionParameters))
                        throw new ResolutionFailedException(this.metaInfoProvider.TypeTo.FullName);
                    this.constructorDelegate = ExpressionDelegateFactory.CreateConstructorExpression(this.containerContext, constructor, this.GetResolutionMembers());
                    this.resolutionConstructor = constructor;
                    this.isConstructorDirty = false;
                    return this.ResolveType(containerContext, resolutionInfo, resolveType);
                }

            }

            if (this.createDelegate != null && !this.isConstructorDirty) return this.createDelegate(resolutionInfo);
            this.createDelegate = this.containerContext.DelegateRepository.GetOrAdd(this.registrationName, () =>
            {
                ResolutionConstructor constructor;
                if (!this.metaInfoProvider.TryChooseConstructor(out constructor, resolutionInfo,
                    this.injectionParameters))
                    throw new ResolutionFailedException(this.metaInfoProvider.TypeTo.FullName);

                var parameter = Expression.Parameter(typeof(ResolutionInfo));
                this.createDelegate = Expression.Lambda<Func<ResolutionInfo, object>>(this.GetExpressionInternal(constructor, resolutionInfo, parameter), parameter).Compile();
                this.resolutionConstructor = constructor;
                this.isConstructorDirty = false;
                return this.createDelegate;
            }, this.isConstructorDirty);

            return this.createDelegate(resolutionInfo);
        }
Пример #33
0
 public void CleanUp()
 {
     this.constructorDelegate = null;
 }
 public void should_create_new_instance_of_given_type()
 {
     ICreateInstance<PricePresentationModel> instanceFactory = new CreateInstance<PricePresentationModel>();
     var instance = instanceFactory.Create();
     Assert.IsNotNull(instance);
 }