예제 #1
0
 /// <summary>
 /// Upload buffer to server if connection is available.
 /// </summary>
 /// <returns>True if uploading was successful, and false otherwise.</returns>
 public bool UploadBuffer()
 {
     // If network is available and buffer contains data.
     if (GetBufferedRowCount() > 0)
     {
         if (CanPingServer())
         {
             bool loggingSuccessful = false;
             do
             {
                 int maxRowId = -1;
                 ObservationPackage package = GetBufferedObservations(out maxRowId);
                 if (maxRowId != -1)
                 {
                     loggingSuccessful = base.LogObservations(package);
                     if (loggingSuccessful)
                     {
                         ClearBuffer(maxRowId);
                     }
                 }
             }while (loggingSuccessful && GetBufferedRowCount() > 0);
             return(loggingSuccessful);
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
예제 #2
0
        /// <summary>
        /// Stores observations in observation package in buffer and tries to upload buffer to server.
        /// </summary>
        /// <param name="package">>Observation data of type ObservationPackage.</param>
        /// <param name="uploadBuffer">True to upload buffer, False to bypass uploading.</param>
        /// <returns>True if uploading or buffering of observations was successful, false otherwise.</returns>
        public bool LogObservations(ObservationPackage package, bool uploadBuffer = true)
        {
            // Online, upload buffer and log package.
            if (uploadBuffer)
            {
                UploadSuccess = false;
                if (UploadBuffer())
                {
                    if (base.LogObservations(package))
                    {
                        UploadSuccess = true;
                        return(true);
                    }
                }
            }

            // Offline, store new package to buffer.
            foreach (IdentifiedObservations io in package.Observations)
            {
                if (!Store(io.ObservationId, io.Observations))
                {
                    return(false);  // Storing to buffer failed.
                }
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Logs an observation package containing identified observations on server.
        /// </summary>
        /// <param name="package">Observation data of type ObservationPackage.</param>
        /// <param name="notifyListeners">True notifies any listeners on this device, False just transfers data to storage without any messaging.</param>
        /// <returns>True if uploading was successful, False otherwise.</returns>
        public bool LogObservations(ObservationPackage package)
        {
            CompactObservationPackage cop = new CompactObservationPackage(package);
            string body = cop.ToString();
            string url  = string.Format(NotifyListenersOnUpload ? _addressDeviceObservations : _addressDeviceObservationsImport, _MID);

            return(PostMessage(url, body, "text/csv"));
        }