示例#1
0
 public async Task UpdateVariables()
 {
     await Task.Run(() =>
     {
         var variableApi = new VariableApi();
         var manager     = new VariableManager(_context.PviService, variableApi);
         manager.ConnectVariables();
     });
 }
        private void CpuService_CpusLoaded(object sender, CpusLoadedEventArgs e)
        {
            var variable = new VariableApi();
            var task     = variable.AddCpuRange(e.Cpus.ToArray()).ConfigureAwait(false);

            var manager = new VariableManager(PviService, variable, _notifier);

            manager.ConnectVariables();
        }
示例#3
0
        public async Task <DataResponse> GetCpuData(string cpuName)
        {
            var dataResponse = await Task.Run(() =>
            {
                dynamic variables = new ExpandoObject();
                var variableDict  = (IDictionary <string, object>)variables;

                var service      = _context.PviService;
                var variableApi  = new VariableApi();
                var variableInfo = variableApi.FindByCpuName(cpuName);

                if (variableInfo.Errors != null || !service.Cpus.ContainsKey(cpuName))
                {
                    return(new DataResponse
                    {
                        Name = cpuName,
                        Data = null,
                        Error = new ErrorResponse
                        {
                            Error = $"A Cpu with the name {cpuName} is not found"
                        }
                    });
                }

                var manager = new VariableManager(_context.PviService, variableApi);
                var values  = manager.ReadVariables(cpuName);

                foreach (var tuple in values)
                {
                    variableDict.Add(tuple.Item1, tuple.Item2);
                }

                return(new DataResponse
                {
                    Name = cpuName,
                    Data = variableDict as ExpandoObject
                });
            }).ConfigureAwait(false);

            return(dataResponse);
        }