コード例 #1
0
        private void uploadData(object oMeter)
        {
            if (settings != null)
            {
                string assemblyName = Assembly.GetCallingAssembly().GetName().Name;
                using (WebService.GTServiceClient client = new WebService.GTServiceClient())
                {
                    //upload meter info to database via web service
                    Settings.LoginRow loginRow = settings.Login.FirstOrDefault();
                    if (loginRow != null && !loginRow.IsUsernameNull() && !loginRow.IsPasswordNull())
                    {
                        WebService.Common userinfo = null;
                        try
                        {
                            EventLog.WriteEntry("Validating User: Begin", EventLogEntryType.Information);

                            //validate user
                            userinfo = client.ValidateLogin(StringCipher.Encrypt(assemblyName), StringCipher.Encrypt(appId),
                                                            StringCipher.Encrypt(loginRow.Username), StringCipher.Encrypt(loginRow.Password));
                        }
                        catch (Exception ex)
                        {
                            //could not validate user
                            Errors.ServiceError(ex);
                            Detector.ReportException("W0007", ex);
                        }
                        finally
                        {
                            EventLog.WriteEntry("Validating User: End", EventLogEntryType.Information);
                        }

                        try
                        {
                            WebService.Records recordsToUpload = new WebService.Records();

                            foreach (Records.RecordRow row in ((AbstractMeter)oMeter).Records)
                            {
                                ((WebService.Records.RecordDataTable)(recordsToUpload.Tables[0])).AddRecordRow(row.Timestamp, row.Glucose, row.Units);
                            }

                            EventLog.WriteEntry("Uploading Data: Begin", EventLogEntryType.Information);

                            client.PostGlucoseRecords(recordsToUpload, userinfo, ((AbstractMeter)oMeter).ID);

                            EventLog.WriteEntry("Uploading Data: End", EventLogEntryType.Information);

                            pipeWrite("MSG", "Sent Glucose Readings", "to BloodSpider website", 1);
                        }
                        catch (Exception ex)
                        {
                            Errors.ServiceError(ex);
                            Detector.ReportException("W0008", ex);
                        }
                    }
                    else
                    {
                        Exception ex = new Exception("uploadData-2: Could not upload data due to settings not being populated.");
                        Errors.ServiceError(ex);
                        Detector.ReportException("W0009", ex);
                    }
                }
            }
            else
            {
                Exception ex = new Exception("uploadData-1: Could not upload data due to settings not being populated.");
                Errors.ServiceError(ex);
                Detector.ReportException("W000A", ex);
            }
        }
コード例 #2
0
ファイル: Detector.cs プロジェクト: barnhill/BloodSpider
        private void uploadData(object oMeter)
        {
            if (settings != null)
            {
                string assemblyName = Assembly.GetCallingAssembly().GetName().Name;
                using (WebService.GTServiceClient client = new WebService.GTServiceClient())
                {
                    //upload meter info to database via web service
                    Settings.LoginRow loginRow = settings.Login.FirstOrDefault();
                    if (loginRow != null && !loginRow.IsUsernameNull() && !loginRow.IsPasswordNull())
                    {
                        WebService.Common userinfo = null;
                        try
                        {
                            EventLog.WriteEntry("Validating User: Begin", EventLogEntryType.Information);
                            
                            //validate user
                            userinfo = client.ValidateLogin(StringCipher.Encrypt(assemblyName), StringCipher.Encrypt(appId), 
                                                            StringCipher.Encrypt(loginRow.Username), StringCipher.Encrypt(loginRow.Password));
                        }
                        catch (Exception ex)
                        {
                            //could not validate user
                            Errors.ServiceError(ex);
                            Detector.ReportException("W0007", ex);
                        }
                        finally 
                        {
                            EventLog.WriteEntry("Validating User: End", EventLogEntryType.Information);
                        }

                        try
                        {
                            WebService.Records recordsToUpload = new WebService.Records();

                            foreach (Records.RecordRow row in ((AbstractMeter)oMeter).Records)
                            {
                                ((WebService.Records.RecordDataTable)(recordsToUpload.Tables[0])).AddRecordRow(row.Timestamp, row.Glucose, row.Units);
                            }
                            
                            EventLog.WriteEntry("Uploading Data: Begin", EventLogEntryType.Information);

                            client.PostGlucoseRecords(recordsToUpload, userinfo, ((AbstractMeter)oMeter).ID);

                            EventLog.WriteEntry("Uploading Data: End", EventLogEntryType.Information);

                            pipeWrite("MSG", "Sent Glucose Readings", "to BloodSpider website", 1);
                        }
                        catch(Exception ex)
                        {
                            Errors.ServiceError(ex);
                            Detector.ReportException("W0008", ex);
                        }
                    }
                    else
                    {
                        Exception ex = new Exception("uploadData-2: Could not upload data due to settings not being populated.");
                        Errors.ServiceError(ex);
                        Detector.ReportException("W0009", ex);
                    }
                }
            }
            else
            {
                Exception ex = new Exception("uploadData-1: Could not upload data due to settings not being populated.");
                Errors.ServiceError(ex);
                Detector.ReportException("W000A", ex);
            }
        }