Esempio n. 1
0
        private void HandleGetStatusRequest(IApiCall apiCall)
        {
            var eventArgs = new ApiRequestReceivedEventArgs(apiCall);

            StatusRequested?.Invoke(this, eventArgs);
            StatusRequestCompleted?.Invoke(this, eventArgs);
        }
Esempio n. 2
0
 public void GetSchedules(IApiCall apiCall)
 {
     lock (_schedules)
     {
         apiCall.Result = JObject.FromObject(_schedules);
     }
 }
Esempio n. 3
0
        public void GetStatus(IApiCall apiCall)
        {
            Dictionary <string, Func <object> > values;

            lock (_values)
            {
                values = new Dictionary <string, Func <object> >(_values);
            }

            var json = new JObject();

            foreach (var value in values)
            {
                var effectiveValue = value.Value();
                if (effectiveValue == null)
                {
                    json[value.Key] = JValue.CreateNull();
                }
                else
                {
                    json[value.Key] = JToken.FromObject(value.Value());
                }
            }

            apiCall.Result = json;
        }
Esempio n. 4
0
        public void SetTexts(IApiCall apiCall)
        {
            lock (_syncRoot)
            {
                var request = apiCall.Parameter.ToObject <SetTextsRequest>();
                if (request?.Resources == null || !request.Resources.Any())
                {
                    apiCall.ResultCode = ApiResultCode.InvalidParameter;
                    return;
                }

                foreach (var updatedResource in request.Resources)
                {
                    var existingResource = _resources.FirstOrDefault(r => r.Uri.Equals(updatedResource.Uri));
                    if (existingResource != null)
                    {
                        _resources.Remove(existingResource);
                    }

                    _resources.Add(updatedResource);
                }

                SaveResources();
            }
        }
Esempio n. 5
0
 public TableController(ILogger <TableController> logger, ITableService tableService, IApiCall apiCall)
 {
     _logger       = logger;
     _tableService = tableService;
     _apiCall      = apiCall;
     _logger.LogInformation("Constructor TableController");
 }
Esempio n. 6
0
 public void GetErrorLogEntries(IApiCall apiCall)
 {
     lock (_syncRoot)
     {
         CreateGetLogEntriesResponse(_errorLogEntries, apiCall);
     }
 }
Esempio n. 7
0
        private void HandleGetConfigurationRequest(IApiCall apiCall)
        {
            var eventArgs = new ApiRequestReceivedEventArgs(apiCall);

            ConfigurationRequested?.Invoke(this, eventArgs);
            ConfigurationRequestCompleted?.Invoke(this, eventArgs);
        }
Esempio n. 8
0
 public void ResetErrorLogEntries(IApiCall apiCall)
 {
     lock (_syncRoot)
     {
         _errorLogEntries.Clear();
     }
 }
Esempio n. 9
0
 public void GetWarningLogEntries(IApiCall apiCall)
 {
     lock (_syncRoot)
     {
         CreateGetLogEntriesResponse(_warningLogEntries, apiCall);
     }
 }
Esempio n. 10
0
 public void ResetWarningLogEntries(IApiCall apiCall)
 {
     lock (_syncRoot)
     {
         _warningLogEntries.Clear();
     }
 }
Esempio n. 11
0
        public Dictionary <String, List <Station> > getNearStations(string x, string y, int dist)
        {
            IApiCall apiCall = this.APICall;
            string   data    = apiCall.getData("http://data.metromobilite.fr/api/linesNear/json?x=" + x + "&y=" + y + "&dist=" + dist + "&details=true");

            List <Station> stations = JsonConvert.DeserializeObject <List <Station> >(data);
            Dictionary <String, List <Station> > sortedStations = new Dictionary <string, List <Station> >();


            foreach (Station station in stations)
            {
                if (!sortedStations.ContainsKey(station.name))
                {
                    List <Station> stationList = new List <Station>();
                    stationList.Add(station);
                    sortedStations.Add(station.name, stationList);
                }
                else
                {
                    sortedStations[station.name].Add(station);
                }
            }

            return(sortedStations);
        }
Esempio n. 12
0
        public void GetLatestMessageContext(IApiCall apiCall)
        {
            if (_latestMessageContext == null)
            {
                return;
            }

            apiCall.Result = JObject.FromObject(_latestMessageContext);
        }
        public ApiRequestReceivedEventArgs(IApiCall apiCall)
        {
            if (apiCall == null)
            {
                throw new ArgumentNullException(nameof(apiCall));
            }

            ApiContext = apiCall;
        }
Esempio n. 14
0
        private void CreateGetLogEntriesResponse(IEnumerable <LogEntry> source, IApiCall apiCall)
        {
            var response = new GetLogEntriesResponse
            {
                SessionId  = _sessionId,
                LogEntries = source.ToList()
            };

            apiCall.Result = JObject.FromObject(response);
        }
Esempio n. 15
0
        public string getLineInfo(string id)
        {
            IApiCall apiCall = this.APICall;
            string   data    = apiCall.getData("http://data.metromobilite.fr/api/routers/default/index/routes?codes=" + id);

            List <Ligne> lignes = JsonConvert.DeserializeObject <List <Ligne> >(data);

            string infos = lignes[0].type + " " + lignes[0].shortname + " Ligne : " + lignes[0].longName;

            return(infos);
        }
Esempio n. 16
0
        public void RestoreBackup(IApiCall apiCall)
        {
            if (apiCall.Parameter.Type != JTokenType.Object)
            {
                throw new NotSupportedException();
            }

            var eventArgs = new BackupEventArgs(apiCall.Parameter);

            RestoringBackup?.Invoke(this, eventArgs);
        }
Esempio n. 17
0
 public void Import(IApiCall apiCall)
 {
     if (apiCall.Parameter.Type == JTokenType.Object)
     {
         var request = apiCall.Parameter.ToObject <SettingsServiceApiRequest>();
         ImportRawSettings(request.Uri, request.Settings);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 18
0
 public void GetSettings(IApiCall apiCall)
 {
     if (apiCall.Parameter.Type == JTokenType.Object)
     {
         var request = apiCall.Parameter.ToObject <SettingsServiceApiRequest>();
         apiCall.Result = GetSettings(request.Uri);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 19
0
        public void Create(IApiCall apiCall)
        {
            var parameter = apiCall.Parameter.ToObject <ApiParameterForCreate>();

            if (parameter == null)
            {
                apiCall.ResultCode = ApiResultCode.InvalidParameter;
                return;
            }

            Create(parameter.Type, parameter.Text, parameter.TimeToLive);
        }
Esempio n. 20
0
        public void GetLastReceivedCode(IApiCall apiCall)
        {
            if (_lastReceivedLpd433MhzCode == null)
            {
                return;
            }

            lock (_syncRoot)
            {
                apiCall.Result = JObject.FromObject(_lastReceivedLpd433MhzCode);
            }
        }
Esempio n. 21
0
        public void Ask(IApiCall apiCall)
        {
            var text = (string)apiCall.Parameter["Message"];

            if (string.IsNullOrEmpty(text))
            {
                apiCall.ResultCode = ApiResultCode.InvalidParameter;
                return;
            }

            apiCall.Result["Answer"] = ProcessTextMessage(text);
        }
Esempio n. 22
0
        public void Send(IApiCall apiCall)
        {
            var adapterDeviceId = apiCall.Parameter["AdapterDeviceId"].ToObject <string>();
            var code            = apiCall.Parameter["Code"].ToObject <Lpd433MhzCode>();

            if (code == null)
            {
                apiCall.ResultCode = ApiResultCode.InvalidParameter;
                return;
            }

            SendCode(adapterDeviceId, code);
        }
 public OrchestratorService(
     ILogService logService,
     IAmqService amqService,
     IApiCall apiCall)
 {
     connectionFactory = new NMSConnectionFactory(Urls.ActiveMQ);
     connection        = connectionFactory.CreateConnection();
     connection.Start();
     session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
     _logService = logService;
     _amqService = amqService;
     _apiCall    = apiCall;
 }
Esempio n. 24
0
        public void ExecuteScriptCode(IApiCall apiCall)
        {
            var request = apiCall.Parameter.ToObject <ExecuteScriptCodeRequest>();

            if (request == null)
            {
                apiCall.ResultCode = ApiResultCode.InvalidParameter;
                return;
            }

            var result = ExecuteScriptInternal(request.ScriptCode, request.EntryMethodName);

            apiCall.Result = JObject.FromObject(result);
        }
Esempio n. 25
0
        private void HandleGetActionsRequest(IApiCall apiCall)
        {
            var actions = new JArray();

            lock (_actions)
            {
                foreach (var action in _actions)
                {
                    actions.Add(action.Key);
                }
            }

            apiCall.Result.Add("Actions", actions);
        }
Esempio n. 26
0
        public void GetTexts(IApiCall apiCall)
        {
            lock (_syncRoot)
            {
                var request = apiCall.Parameter.ToObject <GetTextsRequest>();

                var matchingResources = _resources;
                if (!string.IsNullOrEmpty(request.Category))
                {
                    matchingResources = _resources.Where(r => r.Uri.StartsWith(request.Category + ".")).ToList();
                }

                apiCall.Result["Resources"] = JToken.FromObject(matchingResources);
            }
        }
Esempio n. 27
0
        public void CreateBackup(IApiCall apiCall)
        {
            var backup = new JObject
            {
                ["Type"]      = "HA4IoT.Backup",
                ["Timestamp"] = DateTime.Now.ToString("O"),
                ["Version"]   = 1
            };

            var eventArgs = new BackupEventArgs(backup);

            CreatingBackup?.Invoke(this, eventArgs);

            apiCall.Result = backup;
        }
Esempio n. 28
0
        public void ProcessSkillServiceRequest(IApiCall apiCall)
        {
            var request = apiCall.Parameter.ToObject <SkillServiceRequest>();

            var messageContextFactory = new MessageContextFactory(_areaService, _componentsRegistry, _settingsService);
            var messageContext        = messageContextFactory.Create(request);

            ProcessMessage(messageContext);

            var response = new SkillServiceResponse();

            response.Response.OutputSpeech.Text = messageContext.Reply;

            apiCall.Result = JObject.FromObject(response);
        }
Esempio n. 29
0
 public void ImportMultiple(IApiCall apiCall)
 {
     if (apiCall.Parameter.Type == JTokenType.Object)
     {
         var request = apiCall.Parameter.ToObject <Dictionary <string, JObject> >();
         foreach (var item in request)
         {
             ImportSettings(item.Key, item.Value);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
        public Startup(IConfiguration configuration)
        {
            _Configuration = configuration;

            var appName            = _Configuration.GetValue <string>("ApplicationName");
            var metricsUrl         = _Configuration.GetValue <string>("Metrics:UrlEndpoint");
            var apiKey             = _Configuration.GetValue <string>("Metrics:ApiKey");
            var apiCallTimeoutinMs = _Configuration.GetValue <int>("ApiCall:TimeoutInMilliseconds");

            // Set up ApiCall object
            _ApiCall = new ApiCall(apiCallTimeoutinMs);

            // populate config
            _ConfigProvider = new ConfigProvider();
        }
 public void RegisterApiCall(IApiCall call)
 {
     call.RequestComplete += RequestComplete;
 }