Beispiel #1
0
 private static void LoopCall(object obj)
 {
     var i = Convert.ToInt32(obj);
     var provider = new InstanceProvider<TaskBusiness>(LogDomain.Ui);
     while (true)
     {
         switch (i)
         {
             case (int) EnumTaskLevel.Minute:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.MinuteInvoke, provider, null,new LogOptions());
                 break;
             case (int) EnumTaskLevel.DoubleMinutes:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.DoubleMinuteInvoke, provider,null,new LogOptions());
                 break;
             case (int) EnumTaskLevel.FiveMinutes:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.FiveMinuteInvoke, provider, null,new LogOptions());
                 break;
             case (int) EnumTaskLevel.FifteenMinutes:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.FifteenMinuteInvoke, provider, null, new LogOptions());
                 break;
             case (int) EnumTaskLevel.HalfHour:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.HalfHourInvoke, provider, null, new LogOptions());
                 break;
             case (int) EnumTaskLevel.Hour:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.HourInvoke, provider, null, new LogOptions());
                 break;
             case (int) EnumTaskLevel.HalfDay:
                 CoreAccess<TaskBusiness>.TryCallAsync(provider.Client.HalfDayInvoke, provider, null, new LogOptions());
                 break;
         }
         Thread.Sleep(1000 * 60 * i);
     }
 }
            public void ShouldThrowArgumentNullExceptionForNullAsInstanceContext()
            {
                var instanceProvider = new InstanceProvider(ServiceLocator.Default, typeof (ITestService), typeof (TestService));

                var instance = new object();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => instanceProvider.ReleaseInstance(null, instance));
            }
 /// <summary>
 /// Gets the JS engine used to compile the script
 /// </summary>
 /// <returns></returns>
 internal IJavaScriptRuntime GetEngine()
 {
     var jsRuntime = new InstanceProvider<IJavaScriptRuntime>(() => new IEJavaScriptRuntime());
     var instance = jsRuntime.GetInstance();
     instance.Initialize();
     instance.LoadLibrary(JsLibs.typescript_min);
     instance.LoadLibrary(JsLibs.compiler);
     return instance;
 }
Beispiel #4
0
        /// <summary>
        /// Renders the logo of the specified instance or organization and the logo of the copyright holder company.
        /// </summary>
        /// <param name="writer">The System.Web.UI.HtmlTextWriter to render content to.</param>
        /// <param name="organizationId">The identifier of the organization to render logo of.</param>
        /// <param name="organizationId">The identifier of the instance to render logo of.</param>
        public static void RenderHeader(HtmlTextWriter writer, Guid organizationId, Guid instanceId)
        {
            if (FrameworkConfiguration.Current.WebApplication.MasterPage.Theme == Pages.MasterPageTheme.Modern)
            {
                return;
            }

            if (organizationId != Guid.Empty)
            {
                Organization org = OrganizationProvider.GetOrganization(organizationId);
                if (org != null)
                {
                    Instance inst = null;
                    if (FrameworkConfiguration.Current.WebApplication.EnableMultipleInstances)
                    {
                        if (instanceId != Guid.Empty)
                        {
                            inst = InstanceProvider.GetInstance(instanceId, organizationId);
                        }
                    }

                    HyperLink link = null;

                    CreateLogo(org, inst, ref link);

                    if (link != null)
                    {
                        RenderHeader(writer, link);
                    }
                }
                else
                {
                    RenderHeader(writer);
                }
            }
            else
            {
                RenderHeader(writer);
            }
        }
Beispiel #5
0
        internal static void LogInvokation(MethodInfo methodInfo, object[] parametersValue)
        {
            var logInstance = InstanceProvider.GetInstance <Logger>();

            if (logInstance.LogLevel != LogLevel.Debug && logInstance.LogLevel != LogLevel.Info)
            {
                return;
            }

            var sb = new StringBuilder();

            var counter = 0;

            foreach (var parameterInfo in methodInfo.GetParameters())
            {
                sb.Append(parameterInfo.Name);
                if (logInstance.LogLevel == LogLevel.Debug)
                {
                    sb.Append(" (");
                    sb.Append(JsonSerializer.Serialize(parametersValue[counter++]));
                    sb.Append(")");
                }
                sb.Append(", ");
            }

            if (counter > 0)
            {
                sb.Length = sb.Length - 2;
            }

            if (logInstance.LogLevel == LogLevel.Debug)
            {
                logInstance.LogDebug(string.Format("->[{0}]: {1}", methodInfo.Name, sb), null);
            }
            else
            {
                logInstance.LogInfo(string.Format("->[{0}]", methodInfo.Name), null);
            }
        }
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            // Durable instancing could not be used with
            // singleton instancing.
            ServiceBehaviorAttribute serviceBehavior =
                serviceDescription.Behaviors.Find<ServiceBehaviorAttribute>();

            if (serviceBehavior != null &&
                serviceBehavior.InstanceContextMode == InstanceContextMode.Single)
            {
                throw new InvalidOperationException(
                    ResourceHelper.GetString("ExSingeltonInstancingNotSupported"));
            }

            // Use the StorageManagerFactory to create an instance of a
            // storage manager.
            IStorageManager storageManager =
                StorageManagerFactory.GetStorageManager(storageManagerType);

            InstanceContextInitializer contextInitializer =
                new InstanceContextInitializer(storageManager);

            InstanceProvider instanceProvider =
                new InstanceProvider(serviceDescription.ServiceType);

            foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;

                if (cd != null)
                {
                    foreach (EndpointDispatcher ed in cd.Endpoints)
                    {
                        ed.DispatchRuntime.InstanceContextInitializers.Add(contextInitializer);
                        ed.DispatchRuntime.InstanceProvider = instanceProvider;
                    }
                }
            }
        }
Beispiel #7
0
        private static IRowConstructor <TRow> CreateSimpleRowConstructor <TRow>(
            MemoryPool <char> pool,
            InstanceProvider instanceProvider,
            IEnumerable <DeserializableMember> members
            )
        {
            var rowType = typeof(TRow).GetTypeInfo();

            var instanceDel = MakeInstanceProviderDelegate(instanceProvider);

            var arr = ImmutableArray.CreateBuilder <(string Name, MemberRequired Required, ParseAndSetOnDelegate <TRow> Setter)>();

            foreach (var sp in members)
            {
                var name        = sp.Name;
                var required    = sp.IsRequired ? MemberRequired.Yes : MemberRequired.No;
                var parseAndSet = (ParseAndSetOnDelegate <TRow>)MakeParseAndSetDelegate(rowType, sp.Parser, sp.Setter, sp.Reset, instanceProvider.ConstructsNullability);

                arr.Add((name, required, parseAndSet));
            }

            return(new SimpleRowConstructor <TRow>(pool, instanceDel, arr.ToImmutable()));
Beispiel #8
0
        internal static IRowConstructor <TRow> Create <TRow>(
            MemoryPool <char> pool,
            InstanceProvider instanceProvider,
            IEnumerable <DeserializableMember> setters
            )
        {
            if (IsAheadOfTime(instanceProvider, setters, out var aotType))
            {
                return(AheadOfTimeRowConstructor <TRow> .Create(aotType));
            }

            var settersWithIndex = setters.Select((s, ix) => (Index: ix, Member: s));

            var needHolding = settersWithIndex.Where(s => s.Member.Setter.Mode == BackingMode.ConstructorParameter).ToList();
            var noHolding   = settersWithIndex.Where(s => s.Member.Setter.Mode != BackingMode.ConstructorParameter).ToList();

            if (!needHolding.Any())
            {
                return(CreateSimpleRowConstructor <TRow>(pool, instanceProvider, setters));
            }

            foreach (var nh in needHolding)
            {
                var member = nh.Member;

                if (member.Reset.HasValue)
                {
                    var reset = member.Reset.Value;

                    if (reset.RowType.HasValue || !reset.IsStatic)
                    {
                        Throw.InvalidOperationException($"Cannot attach a {nameof(Reset)} that requires the row be available to a member whose {nameof(Setter)} is backed by a constructor parameter; found {member.Reset} associated with {member.Setter}");
                    }
                }
            }

            return(CreateNeedsHoldRowConstructor <TRow>(pool, instanceProvider, needHolding, noHolding));
        }
Beispiel #9
0
 public void SendBackHeatbeatSignal()
 {
     InstanceProvider.GetServiceLogger().AppendLine("HeartBeatSender started.");
     while (keepalive)
     {
         heartbeatRecieved = false;
         while (!heartbeatRecieved)
         {
             Thread.Sleep(100);
             heartbeatFailTimeout++;
             if (heartbeatFailTimeout > heartbeatFailTimeoutLimit)
             {
                 if (!firstHeartbeatRecieved)
                 {
                     try
                     {
                         SendData(NetworkMessageSource.Service, NetworkMessageDestination.Client, NetworkMessageTypes.Heartbeat);
                         heartbeatFailTimeout = 0;
                     }
                     catch
                     {
                         InstanceProvider.GetServiceLogger().AppendLine("HeartBeatSender exited.");
                         return;
                     }
                 }
                 DisconnectClient();
                 InstanceProvider.GetServiceLogger().AppendLine("HeartBeatSender exited.");
                 return;
             }
         }
         heartbeatRecieved    = false;
         heartbeatFailTimeout = 0;
         SendData(NetworkMessageSource.Service, NetworkMessageDestination.Client, NetworkMessageTypes.Heartbeat);
         Thread.Sleep(3000);
     }
     InstanceProvider.GetServiceLogger().AppendLine("HeartBeatSender exited.");
 }
Beispiel #10
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            object    obj            = null;
            ArrayList list           = null;
            Guid      organizationId = UserContext.Current.OrganizationId;

            if (GroupListRow.Visible)
            {
                list = GroupIdArrayList;
            }
            else if (UserListRow.Visible)
            {
                obj  = Support.ConvertStringToType(UserList.SelectedValue, typeof(Guid));
                list = UserProvider.GetUserGroupIdList(organizationId, ((obj == null) ? Guid.Empty : (Guid)obj));
            }

            Settings.GroupIdList.Clear();
            if (list != null)
            {
                Settings.GroupIdList.AddRange(list);
            }
            if (FrameworkConfiguration.Current.WebApplication.EnableMultipleInstances)
            {
                obj = Support.ConvertStringToType(InstanceList.SelectedValue, typeof(Guid));
                Settings.InstanceId = ((obj == null) ? Guid.Empty : (Guid)obj);
            }
            else
            {
                Instance firstInstance = InstanceProvider.GetFirstInstance(organizationId);
                if (firstInstance != null)
                {
                    Settings.InstanceId = firstInstance.InstanceId;
                }
            }
            Settings.Visible = true;
            Settings.DataBind();
        }
Beispiel #11
0
        public InstanceProvider?GetInstanceProvider(TypeInfo forType)
        {
            var paired = GetPairedType(forType, DESERIALIZER_KIND);

            if (paired == null)
            {
                return(null);
            }

            var instanceMtd = paired.GetMethodNonNull("__InstanceProvider", PublicStatic);

#pragma warning disable CS0618 // This obsolete to prevent clients from using them, but they are fine for us.
            var forConstructorAttrs = instanceMtd.GetCustomAttributes <ConstructorInstanceProviderAttribute>();
#pragma warning restore CS0618

            if (forConstructorAttrs.Any())
            {
                var consOnTypes = forConstructorAttrs.Select(x => x.ForType).Distinct().ToImmutableArray();
                if (consOnTypes.Length > 1)
                {
                    Throw.ImpossibleException($"Generated type {paired} (for {forType}) claims multiple constructors for an InstanceProvider.");
                }

                var consOnType = consOnTypes.Single();
                var consParams = forConstructorAttrs.OrderBy(x => x.ParameterIndex).Select(i => i.ParameterType).ToArray();

                var cons = consOnType.GetConstructor(AllInstance, null, consParams, null);
                if (cons == null)
                {
                    Throw.ImpossibleException($"Generated type {paired} (for {forType}) claims a constructor for an InstanceProvider that could not be found.");
                }

                return(InstanceProvider.ForConstructorWithParametersInner(cons, paired));
            }

            return(InstanceProvider.ForMethodInner(instanceMtd, paired));
        }
Beispiel #12
0
        public void PlayerConnected(string username, string xuid, ServerInfo serverInstance)
        {
            Player playerFound = serverInstance.KnownPlayers.FirstOrDefault(ply => ply.XUID == xuid);

            if (playerFound != null)
            {
                playerFound.LastConnectedTime = DateTime.Now.Ticks.ToString();
                if (playerFound.FirstConnectedTime == null)
                {
                    playerFound.FirstConnectedTime = playerFound.LastConnectedTime;
                }
                InstanceProvider.GetConfigManager().SaveKnownPlayerDatabase(serverInstance);
            }
            else
            {
                playerFound = new Player(xuid, username)
                {
                    FirstConnectedTime = DateTime.Now.Ticks.ToString()
                };
                playerFound.LastConnectedTime = playerFound.FirstConnectedTime;
                serverInstance.KnownPlayers.Add(playerFound);
                InstanceProvider.GetConfigManager().SaveKnownPlayerDatabase(serverInstance);
            }
        }
Beispiel #13
0
 private void RestartServer(string payload, bool performBackup)
 {
     if (InstanceProvider.GetBedrockServer(payload).CurrentServerStatus == BedrockServer.ServerStatus.Started)
     {
         InstanceProvider.GetBedrockServer(payload).CurrentServerStatus = BedrockServer.ServerStatus.Stopping;
         while (InstanceProvider.GetBedrockServer(payload).CurrentServerStatus == BedrockServer.ServerStatus.Stopping)
         {
             Thread.Sleep(100);
         }
         if (performBackup)
         {
             if (InstanceProvider.GetBedrockServer(payload).Backup())
             {
                 SendData(NetworkMessageSource.Service, NetworkMessageDestination.Client, NetworkMessageTypes.Backup, NetworkMessageStatus.Passed);
             }
             else
             {
                 SendData(NetworkMessageSource.Service, NetworkMessageDestination.Client, NetworkMessageTypes.Backup, NetworkMessageStatus.Failed);
             }
         }
         InstanceProvider.GetBedrockServer(payload).CurrentServerStatus = BedrockServer.ServerStatus.Starting;
         Thread.Sleep(1000);
     }
 }
Beispiel #14
0
 public ConfigObject Done()
 {
     InstanceProvider.Configure(_moduleName, _pluginConfiguration);
     return(new ConfigObject(_moduleName));
 }
Beispiel #15
0
 public T ActivateFacade <T>()
 {
     ActivateCurrentThread();
     return(InstanceProvider.GetInstance <Instances.IoC.Container>().Resolve <T>());
 }
 public void Fatal()
 {
     InstanceProvider.GetInstance <Instances.Log.Logger>().LogFatal(_message, _exception);
 }
Beispiel #17
0
 public ApiResult<PublicKeyDto> GetPublicKey(int size)
 {
     var provider = new InstanceProvider<IKeyManager>(typeof(KeyManagerService), ControllerHelper.EDomain);
     return CoreAccess<IKeyManager>.Call(provider.Client.GetPublicKey, size, provider, new LogOptions<ApiResult<PublicKeyDto>>(ControllerHelper.CallSuccess));
 }
 private static IJavaScriptCompiler GetCompiler()
 {
     var jsRuntimeProvider = new InstanceProvider<IJavaScriptRuntime>(() => new IEJavaScriptRuntime());
     var compilerProvider = new InstanceProvider<IJavaScriptCompiler>(() => new CoffeeScriptCompiler(jsRuntimeProvider));
     return compilerProvider.GetInstance();
 }
Beispiel #19
0
 public virtual void Save(T entity)
 {
     InstanceProvider.GetInstance <Instances.Persistence.Persistence>().Save(entity);
 }
Beispiel #20
0
 public virtual IList <T> Get()
 {
     return(InstanceProvider.GetInstance <Instances.Persistence.Persistence>().Get <T>());
 }
 public T1 Into <T1>()
 {
     return(InstanceProvider.GetInstance <Instances.Translation.Translator>().Translate <T, T1>(_obj));
 }
Beispiel #22
0
 public ApiResult<string> GetToken(string clientId)
 {
     var provider = new InstanceProvider<IKeyManager>(typeof(KeyManagerService), ControllerHelper.EDomain);
     return CoreAccess<IKeyManager>.Call(provider.Client.GetToken, clientId, provider, new LogOptions<ApiResult<string>>(ControllerHelper.CallSuccess));
 }
 public void IsValid()
 {
     InstanceProvider.GetInstance <Instances.Validation.Validator>().IsValid(_entity);
 }
 public UglifyMinifier()
 {
     var instanceProvider = new InstanceProvider<IJavaScriptRuntime>(() => new IEJavaScriptRuntime());
     _compiler = new UglifyCompiler(instanceProvider);
 }
 public _BadTypeDescribers(InstanceProvider ip, IEnumerable <DeserializableMember> dm, IEnumerable <SerializableMember> sm)
 {
     InstanceProvider      = ip;
     DeserializableMembers = dm;
     SerializableMembers   = sm;
 }
Beispiel #26
0
 public InstanceSteps(InstanceProvider provider, Core.ScenarioContext context)
 {
     this.provider = provider;
     this.context  = context;
 }
 public IList <string> HasMessages()
 {
     return(InstanceProvider.GetInstance <Instances.Validation.Validator>().GetMessages(_entity));
 }
 public static T Resolve <T>()
 {
     return(InstanceProvider.GetInstance <Instances.IoC.Container>().Resolve <T>());
 }
Beispiel #29
0
 public static IContractInvoker Use <TContract, TContractImplementation>(
     this IBoltRouteHandler bolt,
     Action <ConfigureContractContext> configure = null) where TContractImplementation : TContract
 {
     return(bolt.Use <TContract>(InstanceProvider.From <TContractImplementation>(), configure));
 }
 public static void Register <T, T1>() where T1 : T
 {
     InstanceProvider.GetInstance <Instances.IoC.Container>().Register <T, T1>();
 }
 public T1 To <T1>(T1 obj)
 {
     return(InstanceProvider.GetInstance <Instances.Translation.Translator>().Translate(_obj, obj));
 }
 public void Debug()
 {
     InstanceProvider.GetInstance <Instances.Log.Logger>().LogDebug(_message, _exception);
 }
Beispiel #33
0
 protected object GetUnderlayerPersistence()
 {
     return(InstanceProvider.GetInstance <Instances.Persistence.Persistence>().GetUnderlayerPersistenceObject());
 }
 public void Info()
 {
     InstanceProvider.GetInstance <Instances.Log.Logger>().LogInfo(_message, _exception);
 }
 public object At(string key)
 {
     return(InstanceProvider.GetInstance <Instances.Caching.Cache>().GetData(key));
 }
 public void Warn()
 {
     InstanceProvider.GetInstance <Instances.Log.Logger>().LogWarn(_message, _exception);
 }
Beispiel #37
0
 public CreateOrUseExistingInstanceChannelPolicy(InstanceProvider <T, TChannel> missingInstanceProvider)
 {
     _missingInstanceProvider = missingInstanceProvider;
 }
 public void Error()
 {
     InstanceProvider.GetInstance <Instances.Log.Logger>().LogError(_message, _exception);
 }