Пример #1
0
        /// <summary>
        /// Writes the users records to the glucose records table and attaches them to their userid.
        /// </summary>
        /// <param name="records">Glucose records from the users meter.</param>
        /// <param name="user">User information obtained from validating login with the webservice.</param>
        /// <param name="MeterType">Meter type id that corresponds with the primary key in the MeterTypes database table</param>
        /// <returns>Were the records successfully written to the database.</returns>
        public bool PostGlucoseRecords(Records records, Common user, int MeterType)
        {
            bool result = false;

            if (user.sp_GetLogin == null)
            {
                return(result);
            }

            lock (Authenticated)
            {
                if (Authenticated.Count > 0 && Authenticated.Contains(user.sp_GetLogin.FirstOrDefault().sessionid))
                {
                    UpdateLastSync(user);

                    //authenticated session so allow post
                    Common.sp_GetLoginRow userinfo = null;
                    try
                    {
                        userinfo = user.sp_GetLogin.First();
                    }
                    catch (Exception ex)
                    {
                        if (userinfo == null)
                        {
                            throw new FaultException("PostGlucoseRecords-1: Invalid or blank user information detected.");
                        }
                        else
                        {
                            throw new FaultException("PostGlucoseRecords-1: " + ex.Message);
                        }
                    }

                    try
                    {
                        using (CommonTableAdapters.QueriesTableAdapter queries = new CommonTableAdapters.QueriesTableAdapter())
                        {
                            foreach (Records.RecordRow row in records.Record)
                            {
                                //write record to database attaching to user
                                try
                                {
                                    queries.sp_PostGlucoseResult(row.Timestamp, row.Glucose, row.Units, userinfo.user_id, MeterType);
                                }//try
                                catch (Exception ex)
                                {
                                    if (ex.Message.ToLowerInvariant().Contains("violation of unique key constraint"))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new FaultException("PostGlucoseRecords-2: " + ex.Message);
                    }

                    result = true;
                }
                else
                {
                    //not authenticated
                    throw new FaultException("PostGlucoseRecords-3: Session not authenticated.");
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Writes the users records to the glucose records table and attaches them to their userid.
        /// </summary>
        /// <param name="records">Glucose records from the users meter.</param>
        /// <param name="user">User information obtained from validating login with the webservice.</param>
        /// <param name="MeterType">Meter type id that corresponds with the primary key in the MeterTypes database table</param>
        /// <returns>Were the records successfully written to the database.</returns>
        public bool PostGlucoseRecords(Records records, Common user, int MeterType)
        {
            bool result = false;

            if (user.sp_GetLogin == null)
            {
                return result;
            }

            lock (Authenticated)
            {
                if (Authenticated.Count > 0 && Authenticated.Contains(user.sp_GetLogin.FirstOrDefault().sessionid))
                {
                    UpdateLastSync(user);

                    //authenticated session so allow post
                    Common.sp_GetLoginRow userinfo = null;
                    try
                    {
                        userinfo = user.sp_GetLogin.First();
                    }
                    catch(Exception ex)
                    {
                        if (userinfo == null)
                        {
                            throw new FaultException("PostGlucoseRecords-1: Invalid or blank user information detected.");
                        }
                        else
                        {
                            throw new FaultException("PostGlucoseRecords-1: " + ex.Message);
                        }
                    }
                    
                    try
                    {
                        using (CommonTableAdapters.QueriesTableAdapter queries = new CommonTableAdapters.QueriesTableAdapter())
                        {
                            foreach (Records.RecordRow row in records.Record)
                            {
                                //write record to database attaching to user
                                try
                                {
                                    queries.sp_PostGlucoseResult(row.Timestamp, row.Glucose, row.Units, userinfo.user_id, MeterType);
                                }//try
                                catch (Exception ex)
                                {
                                    if (ex.Message.ToLowerInvariant().Contains("violation of unique key constraint"))
                                        continue;
                                    else
                                        throw;
                                }
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        throw new FaultException("PostGlucoseRecords-2: " + ex.Message);
                    }

                    result = true;
                }
                else
                {
                    //not authenticated
                    throw new FaultException("PostGlucoseRecords-3: Session not authenticated.");
                }
            }

            return result;
        }