private async Task ClearBufferAsync(AccessRepo accessRepo, InformationBuffer _informationBuffer)
        {
            try
            {
                await accessRepo.DumpCache("buffer");

                _informationBuffer.Buffer.RemoveRange(0, _informationBuffer.Buffer.Count() - 1);
                await accessRepo.InsertData(_informationBuffer);
            }
            catch {; }
        }
        private async Task SendData(string message = "")
        {
            DeviceClient _deviceClient = null;

            try
            {
                SendDataFinished = false;

                var _informationBuffer = new InformationBuffer();
                _informationBuffer.Buffer = new List <DeviceInformation>();

                await AccessRepo.Semaphore.WaitAsync();

                try
                {
                    _informationBuffer = await BlobCache.UserAccount.GetObject <InformationBuffer>("buffer");
                }
                catch
                {
                    _informationBuffer.Buffer.Clear();
                }

                if (_informationBuffer.Buffer.Count() > 0)
                {
                    try
                    {
                        var bufferJson = Serialize(JsonConvert.SerializeObject(_informationBuffer));

                        var msg = new Message(bufferJson);
                        msg.Properties.Add(AppConstants.DEVICE_APP_PROP_MAP_SYSORI, AppConstants.DEVICE_DEFAULT_NAME);
                        msg.Properties.Add(AppConstants.DEVICE_APP_PROP_MAP_CODINT, AppConstants.DEVICE_DEFAULT_MSG_ID);

                        _deviceClient = DeviceClient.CreateFromConnectionString(ConnectionString, TransportType.Http1);
                        int count = _informationBuffer.Buffer.Count();

                        await _deviceClient.SendEventAsync(msg);

                        if (_informationBuffer.Buffer.Count() == count)
                        {
                            _informationBuffer.Buffer.Clear();
                            await accessRepo.DumpCache("buffer");

                            if (SendMsgFail > 0)
                            {
                                SendMsgFail = 0;
                                NotSentMsg  = "Aguard. Envio: " + SendMsgFail;
                            }
                        }
                        else
                        {
                            _informationBuffer.Buffer.RemoveRange(0, count);
                            await accessRepo.InsertData(_informationBuffer);

                            SendMsgFail = _informationBuffer.Buffer.Count();
                            NotSentMsg  = "Aguard. Envio: " + SendMsgFail;
                        }
                    }
                    catch
                    {
                        WakeUp();

                        SendMsgFail = _informationBuffer.Buffer.Count();
                        NotSentMsg  = "Aguard. Envio: " + SendMsgFail;
                    }
                }
            }
            finally
            {
                if (_deviceClient != null)
                {
                    await _deviceClient.CloseAsync();

                    _deviceClient.Dispose();
                }

                AccessRepo.Semaphore.Release();

                SendDataFinished = true;

                GC.Collect();
            }
        }