Ejemplo n.º 1
0
        public static void ProvideTestData(IHealthKitDataStorage dataStorage)
        {
            var records = SetUpMultipleHealthKitObjects();

            foreach (var record in records)
            {
                dataStorage.AddOrUpdateHealthKitDataToStorage(record);
            }
        }
 public TestableLightInjectBootstrapper(IHealthKitDataStorage dataStorage = null)
 {
     if (dataStorage != null)
     {
         m_dataStorage = dataStorage;
     }
     else
     {
         m_dataStorage = new HealthKitDataCache();
     }
 }
 public void Init()
 {
     m_dataStorage = new HealthKitDataCache();
 }
        public HealthKitServerModule(IHealthKitDataStorage dataStorage, ILogFactory logger) : base("/api/v1")
        {
            m_logger      = logger.GetLogger(GetType());
            m_dataStorage = dataStorage;

            Get ["/ping"] = parameters =>
            {
                var response = (Response)"pong";
                response.StatusCode = HttpStatusCode.OK;

                return(response);
            };

            Post["/addHealthKitData"] = parameters =>
            {
                try
                {
                    var person = this.Bind <HealthKitData>();
                    m_dataStorage.AddOrUpdateHealthKitDataToStorage(person);
                    var response = Response.AsJson(person);
                    response.StatusCode = HttpStatusCode.Created;
                    return(response);
                }
                catch (Exception e)
                {
                    m_logger.Error(e.Message, e);
                    var response = (Response)e.ToString();
                    response.StatusCode = HttpStatusCode.BadRequest;

                    return(response);
                }
            };

            Get["/getAllHealthKitData"] = parameters =>
            {
                var response = Response.AsJson(m_dataStorage.GetAllHealthKitData());
                response.StatusCode = HttpStatusCode.OK;
                return(response);
            };

            Get["/getHealthKitData"] = parameters =>
            {
                var            personId = this.Request.Query["id"];
                int            number;
                Nancy.Response response;
                if (int.TryParse(personId, out number))
                {
                    response            = Response.AsJson(m_dataStorage.GetSpesificHealthKitData(number));
                    response.StatusCode = HttpStatusCode.OK;
                    return(response);
                }
                response            = Response.AsText("Bad Request");
                response.StatusCode = HttpStatusCode.BadRequest;
                return(response);
            };

            Get["/getHealthKitDataRecord"] = parameters =>
            {
                var            personId       = this.Request.Query["id"];
                var            recordId       = this.Request.Query["recordId"];
                int            idNumber       = new int();
                int            recordIdNumber = new int();
                Nancy.Response response;
                if (int.TryParse(personId, out idNumber) && int.TryParse(recordId, out recordIdNumber))
                {
                    response            = Response.AsJson(m_dataStorage.GetSpesificHealthKitDataRecord(idNumber, recordIdNumber));
                    response.StatusCode = HttpStatusCode.OK;
                    return(response);
                }
                response            = Response.AsText("Bad Request");
                response.StatusCode = HttpStatusCode.BadRequest;
                return(response);
            };
        }
Ejemplo n.º 5
0
 public HealthKitDataStorageProfiler(IHealthKitDataStorage dataStorage, ILog logger)
 {
     m_dataStorage = dataStorage;
     m_logger      = logger;
 }