Пример #1
0
        //------------------------------------------
        // EXECUTION
        //-----------------------------------------

        #region Execution

        /// <summary>
        /// Executes this instance with result.
        /// </summary>
        /// <param name="resultString">The result to get.</param>
        /// <param name="appScope">The application scope to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <param name="runtimeMode">The runtime mode to consider.</param>
        /// <returns>The log of execution log.</returns>
        public override ILog ExecuteWithResult(
            out string resultString,
            IAppScope appScope = null,
            IScriptVariableSet scriptVariableSet = null,
            RuntimeMode runtimeMode = RuntimeMode.Normal)
        {
            resultString = "";

            ILog log = appScope.Check(true);

            if (this.Reference == null)
            {
                log.AddWarning(
                    title: "Reference missing",
                    description: "No reference defined in command '" + this.Key() + "'.");
            }
            else if (!log.HasErrorsOrExceptions() && this.Reference != null)
            {
                scriptVariableSet.SetValue("currentItem", this.Reference.SourceElement.GetObject());
                scriptVariableSet.SetValue("currentElement", this.Reference.SourceElement);
                resultString = this.Reference.Get(appScope, scriptVariableSet, log)?.ToString();
            }

            return(log);
        }
Пример #2
0
 public NetworkIdentityRespondersDTO(NetworkIdentityEndpoints nie, RuntimeMode runtime)
 {
     Identity   = new NetworkIdentityResponseDTO(nie.Identity, runtime);
     Responders = nie.Endpoints
                  .Where(e => e.IsResponder)
                  .Select(n => new NetworkResponderDTO(n));
 }
Пример #3
0
        //------------------------------------------
        // EXECUTION
        //-----------------------------------------

        #region Execution

        /// <summary>
        /// Executes this instance with result.
        /// </summary>
        /// <param name="resultString">The result to get.</param>
        /// <param name="appScope">The application scope to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <param name="runtimeMode">The runtime mode to consider.</param>
        /// <returns>The log of execution log.</returns>
        public override ILog ExecuteWithResult(
            out string resultString,
            IAppScope appScope = null,
            IScriptVariableSet scriptVariableSet = null,
            RuntimeMode runtimeMode = RuntimeMode.Normal)
        {
            resultString = "";

            ILog log = appScope.Check(false);

            if (!log.HasErrorsOrExceptions())
            {
                if (string.IsNullOrEmpty(this._script))
                {
                    log.AddWarning(
                        title: "Script missing",
                        description: "No script defined in command '" + this.Key() + "'.");
                }
                else
                {
                    appScope.ScriptInterpreter.Evaluate(this._script, out resultString, scriptVariableSet, log);
                }
            }

            return(log);
        }
Пример #4
0
        public static RuntimeMode GetRuntimeMode()
        {
            RuntimeMode runtimeMode       = RuntimeMode.REALIMPL;
            string      runtimeModeString = ConfigurationManager.AppSettings["AccountResourceAccess_RuntimeMode"];

            if (!string.IsNullOrEmpty(runtimeModeString))
            {
                switch (runtimeModeString.ToUpper())
                {
                case "EMULATOR":
                    runtimeMode = RuntimeMode.EMULATOR;
                    break;

                case "SIMULATOR":
                    runtimeMode = RuntimeMode.SIMULATOR;
                    break;

                case "REALIMPL":
                    runtimeMode = RuntimeMode.REALIMPL;
                    break;

                default:
                    runtimeMode = RuntimeMode.REALIMPL;
                    break;
                }
            }
            return(runtimeMode);
        }
    /// <inheritdoc />
    public bool Validate(RuntimeMode runtimeMode, [NotNullWhen(false)] out string?validationErrorMessage)
    {
        if (runtimeMode == RuntimeMode.Production)
        {
            return(Validate(out validationErrorMessage));
        }

        validationErrorMessage = null;
        return(true);
    }
Пример #6
0
 /// <summary>
 /// Método Construtor.
 /// </summary>
 /// <param name="runtimeMode">Modo de execução da API. Por padrão, é utilizado o modo de produção,
 /// porém este exige e consome recursos do serviço. Nos modos voltados ao desenvolvimento, esses dados são irrelevantes e
 /// o serviço não é efetivamente consumido (Mensagens não são enviadas ao destinatário).</param>
 /// <param name="urlCode">Código de URL que altera-se de tempos em tempos nos modos de depuração e testes.</param>
 public ZenviaApi(RuntimeMode runtimeMode = RuntimeMode.PRODUCTION, string urlCode = "")
 {
     this.RuntimeMode               = runtimeMode;
     this.BaseUrl                   = GetBaseUrl(urlCode);
     this.SendSmsUrl                = this.BaseUrl + "/services/send-sms";
     this.SendMultipleSmsUrl        = this.BaseUrl + "/services/send-sms-multiple";
     this.CancelSmsUrl              = this.BaseUrl + "/services/cancel-sms";
     this.GetSmsStatusUrl           = this.BaseUrl + "/services/get-sms-status";
     this.ListUnreadMessagesUrl     = this.BaseUrl + "/services/received/list";
     this.SearchReceivedMessagesUrl = this.BaseUrl + "/services/received/search";
 }
Пример #7
0
 public NetworkIdentityResponseDTO(NetworkIdentity n, RuntimeMode runtime)
 {
     Name           = n.Name;
     Abbreviation   = n.Abbreviation;
     Description    = n.Description;
     TotalPatients  = n.TotalPatients;
     Latitude       = n.Latitude;
     Longitude      = n.Longitude;
     PrimaryColor   = n.PrimaryColor;
     SecondaryColor = n.SecondaryColor;
     Runtime        = runtime;
 }
Пример #8
0
        private static GameMaster CreateGameMasterFrom(IEnumerable <string> parameters)
        {
            var addressFlag    = false;
            var port           = default(int);
            var gameConfigPath = default(string);
            var ipAddress      = default(IPAddress);
            var gameName       = default(string);
            var loggingMode    = LoggingMode.NonVerbose;

            _runtimeMode = RuntimeMode.Console;

            var options = new OptionSet
            {
                { "port=", "port number", (int p) => port = p },
                { "conf=", "configuration filename", c => gameConfigPath = c },
                { "address=", "server adress or hostname", a => addressFlag = IPAddress.TryParse(a, out ipAddress) },
                { "game=", "name of the game", g => gameName = g },
                { "verbose:", "logging mode", v => loggingMode = LoggingMode.Verbose },
                { "visualize:", "runtime mode", r => _runtimeMode = RuntimeMode.Visualization }
            };

            options.Parse(parameters);

            if (loggingMode == LoggingMode.Verbose && _runtimeMode == RuntimeMode.Visualization)
            {
                _runtimeMode = RuntimeMode.Console;
            }


            if (!addressFlag)
            {
                addressFlag = true;
                var ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                ipAddress = ipHostInfo.AddressList[0];
            }

            if (port == default(int) || gameConfigPath == default(string) || gameName == default(string) ||
                !addressFlag)
            {
                Usage(options);
            }

            var configLoader = new XmlLoader <GameConfiguration>();
            var config       = configLoader.LoadConfigurationFromFile(gameConfigPath);

            var communicationClient = new AsynchronousCommunicationClient(new IPEndPoint(ipAddress, port), TimeSpan.FromMilliseconds((int)config.KeepAliveInterval), MessageSerializer.Instance);

            return(new GameMaster(config, communicationClient, gameName, new ErrorsMessagesFactory(), loggingMode, new GameMasterMessageFactory()));
        }
Пример #9
0
 public CohortCounter(
     IOptions <RuntimeOptions> opts,
     PanelConverter converter,
     PanelValidator validator,
     IPatientCohortService counter,
     ICohortCacheService cohortCache,
     IUserContext user,
     ILogger <CohortCounter> log)
 {
     this.runtime     = opts.Value.Runtime;
     this.converter   = converter;
     this.validator   = validator;
     this.counter     = counter;
     this.cohortCache = cohortCache;
     this.user        = user;
     this.log         = log;
 }
Пример #10
0
        public AccountManager()
        {
            RuntimeMode runtimeMode = Configuration.GetRuntimeMode();

            switch (runtimeMode)
            {
            case RuntimeMode.EMULATOR:
                m_AccountManager = JerniganObjectFactory.GetAccountManagerEmulatorProxy();
                break;

            case RuntimeMode.REALIMPL:
                m_AccountManager = JerniganObjectFactory.GetAccountManagerRealImplProxy();
                break;

            default:
                m_AccountManager = JerniganObjectFactory.GetAccountManagerRealImplProxy();
                break;
            }
        }
Пример #11
0
        public JerniganResourceAccess()
        {
            RuntimeMode runtimeMode = Configuration.GetRuntimeMode();

            switch (runtimeMode)
            {
            case RuntimeMode.EMULATOR:
                m_JerniganResourceAccess = JerniganObjectFactory.GetJerniganResourceAccessEmulatorProxy();
                break;

            case RuntimeMode.REALIMPL:
                m_JerniganResourceAccess = JerniganObjectFactory.GetJerniganResourceAccessRealImplProxy();
                break;

            default:
                m_JerniganResourceAccess = JerniganObjectFactory.GetJerniganResourceAccessRealImplProxy();
                break;
            }
        }
Пример #12
0
        public RuntimeOptions WithRuntime(string value)
        {
            var tmp = value.ToUpper();

            if (!ValidRuntime(tmp))
            {
                throw new LeafConfigurationException($"{value} is not a supported a runtime mode");
            }

            switch (tmp)
            {
            case Full:
                Runtime = RuntimeMode.Full;
                break;

            case Gateway:
                Runtime = RuntimeMode.Gateway;
                break;
            }

            return(this);
        }
Пример #13
0
        // ------------------------------------------
        // EXECUTING
        // ------------------------------------------

        #region Executing

        /// <summary>
        /// Executes this instance with result.
        /// </summary>
        /// <param name="resultString">The result to get.</param>
        /// <param name="appScope">The application scope to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <param name="runtimeMode">The runtime mode to consider.</param>
        /// <returns>The log of execution log.</returns>
        public override ILog ExecuteWithResult(
            out string resultString,
            IAppScope appScope = null,
            IScriptVariableSet scriptVariableSet = null,
            RuntimeMode runtimeMode = RuntimeMode.Normal)
        {
            resultString = "";

            ILog log = appScope.Check(true);

            if (string.IsNullOrEmpty(this.FileName))
            {
                log.AddWarning(
                    title: "File name missing",
                    description: "No file name defined in command '" + this.Key() + "'.");
            }
            else if (!log.HasErrorsOrExceptions())
            {
                try
                {
                    Process process = new Process();
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.FileName         = this.FileName;
                    process.StartInfo.Arguments        = this.ArgumentString;
                    process.StartInfo.WorkingDirectory = this.WorkingDirectory;
                    process.Start();
                    resultString = process.StandardOutput.ReadToEnd();
                    process.WaitForExit();
                }
                catch (Exception ex)
                {
                    log.AddException(ex);
                }
            }

            return(log);
        }
Пример #14
0
        private static Player CreatePlayerFrom(IEnumerable <string> parameters)
        {
            bool teamFlag = false, roleFlag = false, addressFlag = false;
            var  ipAddress                 = default(IPAddress);
            var  port                      = default(int);
            var  gameConfigPath            = default(string);
            var  gameName                  = default(string);
            var  team                      = default(TeamColor);
            var  role                      = default(PlayerType);
            var  loggingMode               = LoggingMode.NonVerbose;
            var  blueStrategyGroupTypeFlag = true;
            var  redStrategyGroupTypeFlag  = true;
            var  blueStrategyGroupType     = StrategyGroupType.Basic;
            var  redStrategyGroupType      = StrategyGroupType.Basic;

            _runtimeMode = RuntimeMode.Console;

            var options = new OptionSet
            {
                { "port=", "port number", (int p) => port = p },
                { "conf=", "configuration filename", c => gameConfigPath = c },
                { "address=", "server adress or hostname", a => addressFlag = IPAddress.TryParse(a, out ipAddress) },
                { "game=", "name of the game", g => gameName = g },
                { "team=", "red|blue", t => teamFlag = Enum.TryParse(t, true, out team) },
                { "role=", "leader|player", r => roleFlag = Enum.TryParse(r, true, out role) },
                {
                    "blueStrategy=", "strategy options",
                    s => blueStrategyGroupTypeFlag = Enum.TryParse(s, true, out blueStrategyGroupType)
                },
                {
                    "redStrategy=", "strategy options",
                    s => redStrategyGroupTypeFlag = Enum.TryParse(s, true, out redStrategyGroupType)
                },
                { "verbose:", "logging mode", v => loggingMode = LoggingMode.Verbose },
                { "visualize:", "runtime mode", r => _runtimeMode = RuntimeMode.Visualization }
            };

            options.Parse(parameters);

            if (loggingMode == LoggingMode.Verbose && _runtimeMode == RuntimeMode.Visualization)
            {
                _runtimeMode = RuntimeMode.Console;
            }

            if (!addressFlag)
            {
                addressFlag = true;
                var ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                ipAddress = ipHostInfo.AddressList[0];
            }

            if (port == default(int) || gameConfigPath == default(string) || gameName == default(string) ||
                !addressFlag || !teamFlag || !roleFlag || !blueStrategyGroupTypeFlag || !redStrategyGroupTypeFlag)
            {
                Usage(options);
            }


            var configLoader = new XmlLoader <GameConfiguration>();
            var config       = configLoader.LoadConfigurationFromFile(gameConfigPath);

            var keepAliveInterval   = TimeSpan.FromMilliseconds((int)config.KeepAliveInterval);
            var communicationClient = new AsynchronousCommunicationClient(new IPEndPoint(ipAddress, port),
                                                                          keepAliveInterval,
                                                                          MessageSerializer.Instance);
            var strategyGroups = new Dictionary <TeamColor, StrategyGroup>
            {
                {
                    TeamColor.Blue, StrategyGroupFactory.Create(blueStrategyGroupType)
                },
                {
                    TeamColor.Red, StrategyGroupFactory.Create(redStrategyGroupType)
                }
            };
            var player = new Player(communicationClient, gameName, team, role, new ErrorsMessagesFactory(), loggingMode,
                                    strategyGroups);

            return(player);
        }
Пример #15
0
 /// <summary>
 /// Check if Node instance is in specified runtime mode.
 /// </summary>
 /// <param name="runtimeMode">Runtime mode.</param>
 /// <returns></returns>
 public bool IsIn(RuntimeMode runtimeMode)
 {
     RequireNodeIsConfigured();
     return Configuration.RuntimeMode == runtimeMode;
 }
Пример #16
0
        //------------------------------------------
        // EXECUTION
        //-----------------------------------------

        #region Execution

        /// <summary>
        /// Executes this instance with result.
        /// </summary>
        /// <param name="resultString">The result to get.</param>
        /// <param name="appScope">The application scope to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <param name="runtimeMode">The runtime mode to consider.</param>
        /// <returns>The log of execution log.</returns>
        public abstract ILog ExecuteWithResult(
            out string resultString,
            IAppScope appScope = null,
            IScriptVariableSet scriptVariableSet = null,
            RuntimeMode runtimeMode = RuntimeMode.Normal);
Пример #17
0
 static RuntimeConfiguration()
 {
     Mode = RuntimeMode.None;
 }