Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var logger = new ConsoleLogger(LogLevel.Debug);

            logger.LogInfo("STARTING Moesif API Management Event Processor. Reading environment variables");
            // Load configuration paramaters from Environment
            string eventHubConnectionString = ParamConfig.loadNonEmpty(AzureAppParamNames.EVENTHUB_CONN_STRING);
            string eventHubName             = ParamConfig.loadNonEmpty(AzureAppParamNames.EVENTHUB_NAME);
            string storageAccountName       = ParamConfig.loadNonEmpty(AzureAppParamNames.STORAGEACCOUNT_NAME);
            string storageAccountKey        = ParamConfig.loadNonEmpty(AzureAppParamNames.STORAGEACCOUNT_KEY);
            // This App utilizes the "$Default" Eventhub consumer group
            // In future, we should make this configurable via environment variables
            string eventHubConsumerGroupName = EventHubConsumerGroup.DefaultGroupName;
            // Create connection string for azure storage account to store checkpoints
            string storageConnectionString = makeStorageAccountConnString(storageAccountName,
                                                                          storageAccountKey);
            string eventProcessorHostName = Guid.NewGuid().ToString();
            var    eventProcessorHost     = new EventProcessorHost(
                eventProcessorHostName,
                eventHubName,
                eventHubConsumerGroupName,
                eventHubConnectionString,
                storageConnectionString);

            logger.LogDebug("Registering EventProcessor...");
            var httpMessageProcessor = new MoesifHttpMessageProcessor(logger);

            eventProcessorHost.RegisterEventProcessorFactoryAsync(
                new ApimHttpEventProcessorFactory(httpMessageProcessor, logger));

            logger.LogInfo("Process is running. Press enter key to end...");
            Console.ReadLine();
            logger.LogInfo("STOPPING Moesif API Management Event Processor");
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
        public async Task <IActionResult> GetUpdate([FromQuery] ParamConfig param)
        {
            string sign = string.Empty;

            if (!string.IsNullOrEmpty(param.AppId))
            {
                sign = await _service.GetAppSign(param.AppId);
            }

            if (!param.IsValidate(sign))
            {
                return(Unauthorized());
            }

            var list = await _service.GetAllPublishs();

            var temp = (from item in list
                        where item.AppId.Equals(param.AppId) &&
                        item.EnvId.Equals(param.Env)
                        select item).ToList();
            var lastPublish = temp.OrderByDescending(x => x.PublishTimespan).FirstOrDefault();

            await _service.SaveRequest(new EntityReq
            {
                AppEnv         = param.Env,
                AppId          = param.AppId,
                ClientIp       = GetClientIp(),
                FirstDate      = DateTime.Now,
                LastDate       = DateTime.Now,
                LastConfigDate =
                    lastPublish == null ? DateTime.MinValue : BeeUtils.ConvertToDateTime(lastPublish.PublishTimespan)
            });

            if (lastPublish == null)
            {
                return(StatusCode(202));
            }

            if (lastPublish.PublishTimespan > param.Lastupdate)
            {
                Dictionary <string, string> dicConfig = new Dictionary <string, string>();
                var configs = JsonConvert.DeserializeObject <List <EntityConfig> >(lastPublish.Data);
                configs.ForEach(item =>
                {
                    dicConfig.Add(item.ConfigId, item.ConfigValue);
                });


                return(Ok(new DtoBeeConfig
                {
                    BeeConfigAppId = param.AppId,
                    BeeConfigData = dicConfig,
                    BeeConfigEnvironment = param.Env,
                    BeeConfigLastUpdate = lastPublish.PublishTimespan
                }));
            }

            return(StatusCode(304));
        }
Exemplo n.º 3
0
 public Range_NPCAttack_1(ICharacter character) {
     if (false == ParamConfig.TryGetNPCReach((NPCType)character.config.npc_type, out reach)) reach = 1;
     // end if
     this.character = character;
     character.config.TryGetSoundPath(id, out soundPath);
     if (character.config.TryGetEffectPath(id, out effectPath)) return;
     // end if
     effectPath = "npc_arrow";
 } // end Range_NPCAttack_1
        public MoesifHttpMessageProcessor(ILogger logger)
        {
            var appId = ParamConfig.loadNonEmpty(MoesifAppParamNames.APP_ID);

            _MoesifClient    = new MoesifApiClient(appId);
            _SessionTokenKey = ParamConfig.loadDefaultEmpty(MoesifAppParamNames.SESSION_TOKEN);
            _ApiVersion      = ParamConfig.loadDefaultEmpty(MoesifAppParamNames.API_VERSION);
            _Logger          = logger;
            ScheduleWorkerToFetchConfig();
        }
Exemplo n.º 5
0
 public NPCChase(ICharacter character)
 {
     if (false == ParamConfig.TryGetNPCReach((NPCType)character.config.npc_type, out reach))
     {
         reach = 2;
     }
     // end if
     scope          = reach + 2;
     scope          = scope < 10 ? 10 : scope;
     this.character = character;
 } // end NPCChase
Exemplo n.º 6
0
 public Melee_NPCAttack_1(ICharacter character)
 {
     if (false == ParamConfig.TryGetNPCReach((NPCType)character.config.npc_type, out reach))
     {
         reach = 2;
     }
     // end if
     this.character = character;
     character.config.TryGetSoundPath(id, out soundPath);
     character.config.TryGetEffectPath(id, out effectPath);
 } // end Melee_NPCAttack_1
        public void runConfigFreshnessCheck()
        {
            int fetchInterval = ParamConfig.loadWithDefault(
                MoesifAppParamNames.CONFIG_FETCH_INTERVAL_MINS,
                RunParams.CONFIG_FETCH_INTERVAL_MINUTES);

            if (lastWorkerRun.AddMinutes(fetchInterval) < DateTime.UtcNow)
            {
                _Logger.LogDebug("Scheduling worker thread. lastWorkerRun=" + lastWorkerRun.ToString("o"));
                ScheduleWorkerToFetchConfig();
            }
        }
Exemplo n.º 8
0
        // Read loglevel from environment, else use system default.
        // APIMEVENTS_LOG_LEVEL takes priority over DEFAULT_LOG_LEVEL
        // if neither are configured, use warning as log level.
        public static ConsoleLogger GetLogger()
        {
            var aloglevelparam = ParamConfig.loadDefaultEmpty(AppExecuteParams.APIMEVENTS_LOG_LEVEL);
            var logLevel       = LogLevelUtil.getLevelFromString(aloglevelparam, LogLevel.Warning);
            var infoLogger     = new ConsoleLogger(LogLevel.Info);

            infoLogger.LogInfo("Setting loglevel to: [ "
                               + logLevel.ToString()
                               + " ] | '" + AppExecuteParams.APIMEVENTS_LOG_LEVEL + "': [ "
                               + aloglevelparam
                               + " ]"
                               );
            var logger = new ConsoleLogger(logLevel);

            return(logger);
        }
        public object Create(object parent, object configContext, XmlNode section)
        {
            var dic = new Dictionary <string, ParamConfig>();
            IEnumerable <XmlNode> configs;

            try
            {
                configs = section.ChildNodes.Cast <XmlNode>();
            }
            catch (Exception)
            {
                return(new List <ParamConfig>());
            }
            foreach (var config in configs)
            {
                IEnumerable <XmlNode> classes;
                try
                {
                    var path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + ((XmlElement)config).GetAttribute("configSource");
                    var doc  = new XmlDocument();
                    doc.Load(path);
                    classes = doc.SelectSingleNode(config.Name).ChildNodes.Cast <XmlNode>(); //config.ChildNodes.Cast<XmlNode>();
                }
                catch (Exception)
                {
                    continue;
                }
                foreach (var c in classes)
                {
                    if (c.Name != "class")
                    {
                        continue;
                    }
                    foreach (var m in c.ChildNodes.Cast <XmlNode>())
                    {
                        if (m.Name != "method")
                        {
                            continue;
                        }
                        var pc = new ParamConfig
                        {
                            Params      = new Dictionary <string, ParamInfo>(),
                            GroupParams = new Dictionary <string, ParamInfo>(),
                            Sorts       = new Dictionary <string, ParamInfo>()
                        };
                        foreach (var p in m.ChildNodes.Cast <XmlNode>())
                        {
                            switch (p.Name)
                            {
                            case "param":
                                pc.Params.Add(((XmlElement)p).GetAttribute("key"), new ParamInfo
                                {
                                    Name       = ((XmlElement)p).GetAttribute("name"),
                                    TypeString = ((XmlElement)p).GetAttribute("type"),
                                    Symbol     = ((XmlElement)p).GetAttribute("symbol")
                                });
                                break;

                            case "groupParam":
                                pc.GroupParams.Add(((XmlElement)p).GetAttribute("key"), new ParamInfo
                                {
                                    Name       = ((XmlElement)p).GetAttribute("name"),
                                    TypeString = (((XmlElement)p).GetAttribute("type")),
                                    Symbol     = ((XmlElement)p).GetAttribute("symbol")
                                });
                                break;

                            case "sort":
                                var key = ((XmlElement)p).GetAttribute("key");
                                if (string.IsNullOrEmpty(key))
                                {
                                    key = Guid.NewGuid().ToString();
                                }
                                pc.Sorts.Add(key, new ParamInfo
                                {
                                    Name   = ((XmlElement)p).GetAttribute("name"),
                                    Symbol = ((XmlElement)p).GetAttribute("symbol")
                                });
                                break;
                            }
                        }
                        var dickey = ((XmlElement)c).GetAttribute("key") + "." + ((XmlElement)m).GetAttribute("key");
                        if (!dic.ContainsKey(dickey))
                        {
                            dic.Add(dickey, pc);
                        }
                    }
                }
            }
            return(dic);
        }