示例#1
0
        /// <summary>
        /// Sets up HTTP methods mappings.
        /// </summary>
        /// <param name="service">Service handling requests</param>
        public VariablesModule(VariablesService service) : base("/")
        {
            Get["/api/program/{programId}/environment/{environmentId}/variables"] = parameters =>
            {
                var programId     = Parameters.ValueOf <string>(parameters, Context.Request, "programId", ParameterType.Path);
                var environmentId = Parameters.ValueOf <string>(parameters, Context.Request, "environmentId", ParameterType.Path);
                var xGwImsOrgId   = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header);
                var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header);
                var xApiKey       = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header);
                Preconditions.IsNotNull(programId, "Required parameter: 'programId' is missing at 'GetEnvironmentVariables'");

                Preconditions.IsNotNull(environmentId, "Required parameter: 'environmentId' is missing at 'GetEnvironmentVariables'");

                Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'GetEnvironmentVariables'");

                Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'GetEnvironmentVariables'");

                Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'GetEnvironmentVariables'");

                return(service.GetEnvironmentVariables(Context, programId, environmentId, xGwImsOrgId, authorization, xApiKey));
            };

            Patch["/api/program/{programId}/environment/{environmentId}/variables"] = parameters =>
            {
                var programId     = Parameters.ValueOf <string>(parameters, Context.Request, "programId", ParameterType.Path);
                var environmentId = Parameters.ValueOf <string>(parameters, Context.Request, "environmentId", ParameterType.Path);
                var xGwImsOrgId   = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header);
                var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header);
                var xApiKey       = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header);
                var contentType   = Parameters.ValueOf <string>(parameters, Context.Request, "contentType", ParameterType.Header);
                var body          = this.Bind <List <Variable> >();
                Preconditions.IsNotNull(programId, "Required parameter: 'programId' is missing at 'PatchEnvironmentVariables'");

                Preconditions.IsNotNull(environmentId, "Required parameter: 'environmentId' is missing at 'PatchEnvironmentVariables'");

                Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'PatchEnvironmentVariables'");

                Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'PatchEnvironmentVariables'");

                Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'PatchEnvironmentVariables'");

                Preconditions.IsNotNull(contentType, "Required parameter: 'contentType' is missing at 'PatchEnvironmentVariables'");

                Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'PatchEnvironmentVariables'");

                return(service.PatchEnvironmentVariables(Context, programId, environmentId, xGwImsOrgId, authorization, xApiKey, contentType, body));
            };
        }
示例#2
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            _api              = host.Services.GetRequiredService <IEliteDangerousApi>();
            _socketHandler    = host.Services.GetRequiredService <WebSocketHandler>();
            _variableService  = host.Services.GetRequiredService <VariablesService>();
            _eliteVaInstaller = host.Services.GetRequiredService <EliteVaInstaller>();
            _log              = host.Services.GetRequiredService <ILogger <Program> >();

            await _api.InitializeAsync();

            // Sub to events
            _api.Events.AllEvent += async(sender, e) => await Broadcast("Event", e, true, false);

            // Sub to statuses
            _api.Cargo.OnChange += async(sender, e) => await Broadcast("Cargo", _api.Cargo, true, true);

            _api.Market.OnChange += async(sender, e) => await Broadcast("Market", _api.Market, true, true);

            _api.Modules.OnChange += async(sender, e) => await Broadcast("Modules", _api.Modules, true, true);

            _api.Outfitting.OnChange += async(sender, e) => await Broadcast("Outfitting", _api.Outfitting, true, true);

            _api.Shipyard.OnChange += async(sender, e) => await Broadcast("Shipyard", _api.Shipyard, true, true);

            _api.Ship.OnChange += async(sender, e) => await Broadcast("Status", _api.Ship, true, true);

            _api.NavRoute.OnChange += async(sender, e) => await Broadcast("NavRoute", _api.NavRoute, true, true);

            _api.Backpack.OnChange += async(sender, e) => await Broadcast("Backpack", _api.Backpack, true, true);

            // Sub to options
            _api.Bindings.OnChange += async(sender, e) => await _socketHandler.Broadcast(new WebSocketMessage("Bindings", RemoveLineEndings(_api.Bindings.ToXml())), true, true);

            // Send userprofile
            await _socketHandler.Broadcast(new WebSocketMessage("UserProfile", UserProfile.Get()), true, true);

            // Send latest eliteva version
            await _socketHandler.Broadcast(new WebSocketMessage("EliteVA.Latest", await _eliteVaInstaller.GetLatestVersion()), true, true);

            await _api.StartAsync();

            await host.RunAsync();
        }
示例#3
0
        public void SaveUarc()
        {
            VariablesService paraService = new VariablesService();
            //Parameter param = paraService.Get("uarclastupdatetime");

            //if (param != null)
            //{
            //    this.SaveDiffUarc(param.Value);
            //}
            //else
            //{
            //    /*数据库没有上传记录就是第一次全部获取,否则取最后一次获取数据的日期经行差异获取*/
            //    this.SaveAllUarc();
            //    param = new Parameter();
            //    param.Key = "uarclastupdatetime";
            //    param.Value = DateTime.Now.ToString("yyyy-MM-dd");
            //    paraService.Add(param);
            //}
        }
        protected string ReplaceVariables(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            var keys = Regex.Matches(text, @"\{\{[\w._-]+\}\}").Select(m => m.Value).Join(",");

            if (!string.IsNullOrEmpty(keys))
            {
                var dic      = VariablesService.GetQueryFromCache(v => keys.Contains(v.Key)).ToDictionary(v => v.Key, v => v.Value);
                var template = Template.Create(text);
                foreach (var(key, value) in dic)
                {
                    template.Set(key, value);
                }

                return(template.Render());
            }

            return(text);
        }
示例#5
0
        protected string ReplaceVariables(string text, int depth = 0)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            var location = Request.Location();
            var template = Template.Create(text).Set("clientip", ClientIP).Set("location", location.Address).Set("network", location.Network);

            if (text.Contains("{{browser}}") || text.Contains("{{os}}"))
            {
                var agent = UserAgent.Parse(Request.Headers[HeaderNames.UserAgent] + "");
                template.Set("browser", agent.Browser + " " + agent.BrowserVersion).Set("os", agent.Platform);
            }

            var pattern = @"\{\{[\w._-]+\}\}";
            var keys    = Regex.Matches(template.Render(), pattern).Select(m => m.Value.Trim('{', '}')).ToArray();

            if (keys.Length > 0)
            {
                var dic = VariablesService.GetQueryFromCache(v => keys.Contains(v.Key)).ToDictionary(v => v.Key, v => v.Value);
                foreach (var(key, value) in dic)
                {
                    string valve = value;
                    if (Regex.IsMatch(valve, pattern) && depth < 32)
                    {
                        valve = ReplaceVariables(valve, depth++);
                    }

                    template.Set(key, valve);
                }
            }

            return(template.Render());
        }
示例#6
0
 public EventProvider(ILogger <EventProvider> log, VariablesService variables)
 {
     _log       = log;
     _variables = variables;
     _assembly  = Assembly.GetExecutingAssembly();
 }
示例#7
0
 public VariablesController()
 {
     variablesService = new VariablesService();
 }