public void Reset()
 {
     _connectedPump = null;
     _selectedPump  = null;
     _pairedPumps   = new ObservableCollection <PumpModel>();
     _newPumps      = new ObservableCollection <PumpModel>();
 }
        private void _bluetoothManager_PumpDiscovered(object sender, PumpDiscoveredEventArgs e)
        {
            // Do we know about this pump?
            PumpModel pump = _pairedPumps.Where(p => p.Id == e.Pump.Id).FirstOrDefault();

            if (pump != null)
            {
                // Set the name if this pump was found before
                e.Pump.Name = pump.Name;

                // If this is a pump we know about and have paired with, pair automatically
                if (!_bluetoothManager.IsPaired)
                {
                    _bluetoothManager.Connect(e.Pump);
                }
            }
            else
            {
                // Otherwise, add it as a new pump
                Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                {
                    if (!_newPumps.Contains(e.Pump))
                    {
                        _newPumps.Add(e.Pump);
                    }
                });
            }
        }
Ejemplo n.º 3
0
        private void PumpManager_PumpConnectedEvent(object sender, PumpConnectedEventArgs e)
        {
            try
            {
                PumpModel pump = PumpManager.Instance.ConnectedPump;

                // If a pump session is active go straight to the pumping screen
                if ((pump.ActualState == PumpState.Start) || (pump.ActualState == PumpState.Pause))
                {
                    if (SessionManager.Instance.CurrentSession == null)
                    {
                        SessionManager.Instance.ContinuePumping();
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                        {
                            PageManager.Me.SetPage(typeof(PumpSessionPage));
                        });
                    }
                }

                pump.PropertyChanged += Pump_PropertyChanged;

                if (_cloudSyncComplete)
                {
                    SyncPump();
                }
            }
            catch (Exception ex)
            {
                Debugger.Break();
                AnalyticsManager.Instance.TrackError(ex);
                throw;
            }
        }
Ejemplo n.º 4
0
        private void SyncPump()
        {
            try
            {
                if (!_pumpSyncComplete)
                {
                    HistoryManager historyManager = HistoryManager.Instance;
                    PumpModel      pump           = PumpManager.Instance.ConnectedPump;

                    if (pump != null)
                    {
                        // Sync preset experiences to the pump
                        pump.PresetExperiences = ExperienceManager.Instance.PresetExperiences;

                        // Sync user experiences to the pump
                        pump.UserExperiences = ExperienceManager.Instance.UserExperiences;

                        // Add these sessions to the History Manager to sync locally and with the cloud
                        foreach (HistoryModel pumpSession in pump.PumpingSessions)
                        {
                            historyManager.AddSession(pumpSession);
                        }

                        _pumpSyncComplete = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Debugger.Break();
                AnalyticsManager.Instance.TrackError(ex);
            }
        }
        List <PumpModel> MockedPumps()
        {
            var pumps = new List <PumpModel>();

            for (int i = 0; i < 5; i++)
            {
                var pump = new PumpModel()
                {
                    ActualPumpingMode = PumpMode.Expression,
                    ActualSpeed       = 9,
                    ActualState       = PumpState.Start,
                    ActualSuction     = 9,
                    AdvertisedName    = "Pump A",
                    AlertMessages     = new ObservableCollection <string>()
                    {
                        "Hello", "world"
                    },
                    BatteryLevel       = 9,
                    ChargeState        = true,
                    CurrentDuration    = TimeSpan.FromSeconds(9),
                    DesiredExperience  = 8,
                    DesiredPumpingMode = PumpMode.Expression,
                    DesiredSpeed       = 8,
                    DesiredState       = PumpState.Pause,
                    DesiredSuction     = 8,
                    Device             = null,
                    FirmwareRevision   = "Hello world version",
                    HardwareRevision   = "Hello world hardware version",
                    HasAlerts          = false,
                    Id                   = Guid.NewGuid(),
                    Index                = 0,
                    InUse                = true,
                    IsConnected          = true,
                    IsFocused            = true,
                    IsSelected           = false,
                    IsUpdateAvailable    = true,
                    IsUpdating           = true,
                    LeftBreastMilkLevel  = 90,
                    Logs                 = new List <LogEntryModel>(),
                    ModelNumber          = "Duck model number",
                    Name                 = $"Pump {i}",
                    PresetExperiences    = new ObservableCollection <ExperienceModel>(),
                    PumpingSessions      = new List <HistoryModel>(),
                    RightBreastMilkLevel = 80,
                    SerialNumber         = "Cat dog duck serial number",
                    SoftwareRevision     = "Duck software version",
                    Storage              = StorageType.Fridge,
                    TagBool1             = true,
                    TagDouble1           = 32,
                    UpdatePercent        = 4,
                    UserExperiences      = new ObservableCollection <ExperienceModel>()
                };

                pumps.Add(pump);
            }

            return(pumps);
        }
 private void _bluetoothManager_PumpDisconnected(object sender, PumpDisconnectedEventArgs e)
 {
     if (_connectedPump != null)
     {
         _connectedPump.IsConnected = false;
         _connectedPump.InUse       = false;
     }
     _connectedPump = null;
     PumpDisconnectedEvent?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 7
0
        public ActionResult getPumpData(PumpModel data)
        {
            var context                = new RRRoadwaysDBContext();
            int pumpid                 = Convert.ToInt32(data.PumpId);
            int vehicleNumber          = Convert.ToInt32(data.VehicleNumber);
            List <PumpReport> griddata = new List <PumpReport>();
            var pumpdata               = context.Vehicle
                                         .Join(context.Voucher,
                                               v => v.Id,
                                               vo => vo.VehicleNumber,
                                               (v, vo) => new { v, vo })
                                         .Join(context.VoucherDieselDetails,
                                               c => c.vo.Id,
                                               vdd => vdd.VoucherId,
                                               (c, vdd) => new
            {
                VoucherNumber = c.vo.VoucherNumber,
                PumpId        = vdd.StationId,
                Date          = vdd.Date,
                VehicleNumber = c.v.Id,
                Vehicle       = c.v.VehicleNumber,
                Litre         = vdd.Litre,
                Rate          = vdd.Rate,
                Amount        = vdd.Amount,
                OilAndOthers  = vdd.OilAndOthers,
            }).Where(c => data.PumpId != "-1" ? c.PumpId == pumpid : 1 == 1)
                                         .Where(c => data.VehicleNumber != "-1" ? c.VehicleNumber == vehicleNumber : 1 == 1)
                                         .Where(c => c.Date.Value.Date >= data.StartDate.Date)
                                         .Where(c => c.Date.Value.Date <= data.EndDate.Date).ToList();


            if (pumpdata.Count > 0)
            {
                foreach (var item in pumpdata)
                {
                    PumpReport obj = new PumpReport()
                    {
                        SerialNo      = griddata.Count + 1,
                        VoucherNumber = item.VoucherNumber,
                        Date          = item.Date.Value.Date,
                        Vehicle       = item.Vehicle,
                        Litre         = item.Litre,
                        Rate          = item.Rate,
                        Amount        = (item.Litre * item.Rate),
                        OilAndOther   = item.OilAndOthers,
                        OilAmount     = item.Amount,
                        Total         = (item.Litre * item.Rate) + item.Amount,
                    };

                    griddata.Add(obj);
                }
            }
            return(Json(new { data = griddata }, new Newtonsoft.Json.JsonSerializerSettings()));
        }
        public void ContinuePumping()
        {
            ExperienceModel experience;

            // If we have not started a session and a pump is connected
            if ((_sessionModel == null) && (_pumpManager.ConnectedPump != null))
            {
                DateTime startTime = DateTime.UtcNow;

                _pumpModel = _pumpManager.ConnectedPump;

                _isPaused        = (_pumpModel.ActualState == PumpState.Pause) ? true : false;
                _durationSeconds = Convert.ToInt32(_pumpModel.CurrentDuration.TotalSeconds);
                _timerActive     = false;

                experience = ExperienceManager.Instance.GetFromExperienceId(_pumpModel.DesiredExperience);

                if (experience != null)
                {
                    _currentExperience = experience;
                }
                else
                {
                    _currentExperience = ExperienceManager.Instance.CurrentExperience;
                }

                _sessionModel = new SessionModel()
                {
                    StartTime            = startTime,
                    LeftBreastStartTime  = startTime,
                    RightBreastStartTime = startTime,
                    SessionType          = SessionType.Pump,
                    CurrentExperience    = _currentExperience,
                    PumpPhase            = (_pumpModel.ActualPumpingMode == PumpMode.Stimulation) ? PumpPhase.Stimulation : PumpPhase.Expression,
                    Storage = _currentExperience.Storage
                };

                _pumpModel.Storage             = StorageType.Unspecified;
                _sessionModel.PropertyChanged -= _sessionModel_PropertyChanged;
                _pumpModel.PropertyChanged    -= _pumpModel_PropertyChanged;
                _sessionModel.PropertyChanged += _sessionModel_PropertyChanged;
                _pumpModel.PropertyChanged    += _pumpModel_PropertyChanged;
                //_pumpModel.DesiredExperience = _currentExperience.ExperienceId;
                //_pumpModel.DesiredPumpingMode = PumpMode.ExperienceControlled;
                _sessionModel.DesiredSpeed   = _pumpModel.DesiredSpeed;
                _sessionModel.DesiredSuction = _pumpModel.DesiredSuction;
                _sessionModel.ActualSpeed    = _pumpModel.ActualSpeed;
                _sessionModel.ActualSuction  = _pumpModel.ActualSuction;
                //_sessionModel.Duration = _pumpModel.CurrentDuration;
                _sessionModel.ActualState = _pumpModel.ActualState;
                //_pumpModel.DesiredState = PumpState.Start;
                _sessionActive = true;
            }
        }
        /// <summary>
        /// Sets the BL pump model to setup in this page
        /// </summary>
        /// <param name="model"></param>
        public void SetPump(PumpModel model)
        {
            //if (_pumpModel != null)
            //{
            //}

            _pumpModel = model;

            //if (_pumpModel != null)
            //{
            //}

            BindingContext = model;
        }
Ejemplo n.º 10
0
        private async void _bluetoothManager_PumpConnected(object sender, PumpConnectedEventArgs e)
        {
            _connectedPump             = e.Pump;
            _connectedPump.IsConnected = true;
            _connectedPump.InUse       = true;

            PumpModel proxyPump = _pairedPumps.Where(p => p.Id == e.Pump.Id).FirstOrDefault();

            // We have not saved this pump to our paired list yet
            if (proxyPump == null)
            {
                _pairedPumps.Add(_connectedPump);

                DataManager dataManager = DataManager.Instance;
                User        user        = (await dataManager.User.ToEnumerableAsync()).FirstOrDefault();

                if (user != null)
                {
                    Pump pump = new Pump()
                    {
                        Id         = Guid.NewGuid().ToString(),
                        Name       = _connectedPump.Name,
                        Identifier = _connectedPump.Id.ToString(),
                        ProfileId  = user.DefaultProfileId
                    };

                    await dataManager.AddUpdatePump(pump);
                }
            }
            else
            {
                // Replace the proxy pump
                _pairedPumps.Remove(proxyPump);
                _pairedPumps.Add(_connectedPump);
            }

            // Convert log entries to history entries
            ConvertLogEntriesToPumpingHistory();

            // Check if update is available
            CheckForUpdates();

            PumpConnectedEvent?.Invoke(this, new PumpConnectedEventArgs()
            {
                Pump = _connectedPump
            });
        }
Ejemplo n.º 11
0
        public void Pair(PumpModel pump)
        {
            // TODO: Implement pairing
            if (_connectedPump == null)
            {
                // Remove the pump from the new and not pairde list
                Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                {
                    if (_newPumps.Contains(pump))
                    {
                        _newPumps.Remove(pump);
                    }
                });

                _bluetoothManager.Connect(pump);
            }
        }
Ejemplo n.º 12
0
        private void Instance_ExperienceAddedEvent(object sender, ExperienceAddedEventArgs e)
        {
            try
            {
                PumpModel pump = PumpManager.Instance.ConnectedPump;

                if (pump != null)
                {
                    pump.UserExperiences = ExperienceManager.Instance.UserExperiences;
                }
            }
            catch (Exception ex)
            {
                Debugger.Break();
                AnalyticsManager.Instance.TrackError(ex);
            }
        }
        private IEnumerable <PumpModel> CreatePumpModelFromPumps(List <Pump> pumps)
        {
            var pumpList = new List <PumpModel>();

            foreach (var pump in pumps.Where(p => p.State == 1).OrderBy(p => p.Time).ToList())
            {
                var stop = pumps.OrderBy(p => p.Time).FirstOrDefault(p => p.Time > pump.Time && p.State == 0);
                if (stop != null)
                {
                    var pumpModel = new PumpModel()
                    {
                        Start    = pump.Time,
                        Duration = stop.Time - pump.Time
                    };
                    pumpList.Add(pumpModel);
                }
            }
            return(pumpList);
        }
Ejemplo n.º 14
0
        public void Remove(PumpModel pumpModel)
        {
            Pump pump = _knownPumps.Where(p => Guid.Parse(p.Identifier) == pumpModel.Id).FirstOrDefault();

            Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
            {
                if (_pairedPumps.Contains(pumpModel))
                {
                    _pairedPumps.Remove(pumpModel);
                }
            });

            if (pump != null)
            {
                DataManager dataManager = DataManager.Instance;
                dataManager.DeletePump(pump);
                _knownPumps.Remove(pump);
            }

            _bluetoothManager.Disconnect();
        }
        public void StartPumping()
        {
            // If we have not started a session and a pump is connected
            if ((_sessionModel == null) && (_pumpManager.ConnectedPump != null))
            {
                DateTime startTime = DateTime.UtcNow;

                _isPaused        = false;
                _durationSeconds = 0;
                _timerActive     = false;

                _sessionModel = new SessionModel()
                {
                    StartTime            = startTime,
                    LeftBreastStartTime  = startTime,
                    RightBreastStartTime = startTime,
                    SessionType          = SessionType.Pump,
                    CurrentExperience    = _currentExperience,
                    PumpPhase            = PumpPhase.Stimulation,
                    Storage = _currentExperience.Storage
                };

                _pumpModel                     = _pumpManager.ConnectedPump;
                _pumpModel.Storage             = StorageType.Unspecified;
                _sessionModel.PropertyChanged -= _sessionModel_PropertyChanged;
                _pumpModel.PropertyChanged    -= _pumpModel_PropertyChanged;
                _sessionModel.PropertyChanged += _sessionModel_PropertyChanged;
                _pumpModel.PropertyChanged    += _pumpModel_PropertyChanged;
                _pumpModel.DesiredExperience   = _currentExperience.ExperienceId;
                _pumpModel.DesiredPumpingMode  = PumpMode.ExperienceControlled;
                _sessionModel.DesiredSpeed     = _currentExperience.StimulationSpeed;
                _sessionModel.DesiredSuction   = _currentExperience.StimulationSuction;
                _sessionModel.ActualSpeed      = _currentExperience.StimulationSpeed;
                _sessionModel.ActualSuction    = _currentExperience.StimulationSuction;
                _pumpModel.DesiredState        = PumpState.Start;
                _sessionActive                 = true;
            }
        }
Ejemplo n.º 16
0
        private void Pump_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            try
            {
                HistoryManager historyManager = HistoryManager.Instance;
                PumpModel      pump           = PumpManager.Instance.ConnectedPump;

                if (e.PropertyName == "PumpingSessions")
                {
                    // Add these sessions to the History Manager to sync locally and with the cloud
                    foreach (HistoryModel pumpSession in pump.PumpingSessions)
                    {
                        historyManager.AddSession(pumpSession);
                    }
                }
                else if (e.PropertyName == "ActualState")
                {
                    if (pump.ActualState == PumpState.Start)
                    {
                        if (SessionManager.Instance.CurrentSession == null)
                        {
                            SessionManager.Instance.ContinuePumping();
                            Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                            {
                                PageManager.Me.SetPage(typeof(PumpSessionPage));
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debugger.Break();
                AnalyticsManager.Instance.TrackError(ex);
                throw;
            }
        }
Ejemplo n.º 17
0
        public async Task Initialize()
        {
            DataManager dataManager = DataManager.Instance;
            PumpModel   pumpModel;

            // Build the paired list from those pumps
            _knownPumps = (await dataManager.GetAllPumps()).ToList();

            foreach (Pump pump in _knownPumps)
            {
                //if (pump.InUse)
                //{
                //    _hasPumpsInUse = true;
                //}

                pumpModel = new PumpModel()
                {
                    Name  = pump.Name,
                    Id    = Guid.Parse(pump.Identifier),
                    InUse = false
                };
                _pairedPumps.Add(pumpModel);
            }
        }
Ejemplo n.º 18
0
        public C_WellParas(List <C_WellPara> paras)
        {
            AllParas = paras;
            UnitCat.Clear();
            Loc.Clear();
            TubeMat.Clear();
            PumpModel.Clear();
            UseFor.Clear();

            if (paras == null)
            {
                return;
            }
            if (paras.Count == 0)
            {
                return;
            }

            foreach (C_WellPara node in paras)
            {
                switch (node.Type)
                {
                case E_WellParaType.Loc:
                    Loc.Add(node);
                    break;

                case E_WellParaType.PumpModel:
                    PumpModel.Add(node);
                    break;

                case E_WellParaType.TubeMat:
                    TubeMat.Add(node);
                    break;

                case E_WellParaType.UnitCat:
                    UnitCat.Add(node);
                    break;

                case E_WellParaType.UseFor:
                    UseFor.Add(node);
                    break;

                default:
                    break;
                }
            }

            if (UnitCat.Count != 0)
            {
                UnitCatIndex = UnitCat[0];
            }
            if (Loc.Count != 0)
            {
                LocIndex = Loc[0];
            }
            if (PumpModel.Count != 0)
            {
                PumpModelIndex = PumpModel[0];
            }
            if (TubeMat.Count != 0)
            {
                TubeMatIndex = TubeMat[0];
            }
            if (UseFor.Count != 0)
            {
                UseForIndex = UseFor[0];
            }
        }