Ejemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="callsign">The unique identification code of the resource</param>
 /// <param name="info">A container object that stores detailed appliance information</param>
 public Appliance(string callsign, ApplianceInfo info)
     : base(callsign, info.Name, info.MobilePhoneNumber, info.Base, info.CurrentAddress, info.CurrentResourceStatus, info.AssignedIncident)
 {
     this.applianceDatabase = Tools.ApplianceDB;
     this.info = info;
     //find the related incidentDataView object
     this.viewData = Tools.Appliances.Single(x => x.CallSign == callsign);
 }
Ejemplo n.º 2
0
        public bool OnApplianceTaken(IGameController gc, ApplianceInfo applianceInfo, ActiveDisease disease)
        {
            var treatedStage = disease.TreatedStage;

            if (treatedStage == null)
            {
                treatedStage = disease.GetActiveStage(gc.WorldTime.Value);
            }

            if (treatedStage == null)
            {
                return(false);
            }

            var isTreatedLevel = treatedStage.Level == _treatedLevel;
            var isApplied      = _treatments.Any(treatment => treatment.OnApplianceTaken(gc, applianceInfo, disease));

            if (isTreatedLevel)
            {
                if (_treatments.All(x => x.IsFinished))
                {
                    _isOverallHealingStarted = true;

                    disease.Invert();

                    disease.DeclareDiseaseTreated();

                    Events.NotifyAll(l => l.DiseaseHealed(disease.Disease));

                    return(true);
                }

                if (_treatments.All(x => x.IsStarted) && !_isOverallHealingStarted)
                {
                    _isOverallHealingStarted = true;

                    disease.Invert();

                    Events.NotifyAll(l => l.DiseaseTreatmentStarted(disease.Disease));

                    return(true);
                }

                if (isApplied && _isOverallHealingStarted)
                {
                    Events.NotifyAll(l => l.DiseaseHealingContinued(disease.Disease));
                }
            }

            return(isApplied);
        }
        /// <summary>
        /// Retrieves a resource using its unique call sign
        /// </summary>
        /// <param name="callSign">The call sign to retrieve</param>
        /// <returns>An object representing the resource.
        /// Note that this is the abstract base class and the returned object should be cast to an Appliance or Officer object.</returns>
        public Appliance GetAppliance(string callSign)
        {
            string statement = "SELECT * FROM  resource, appliance, address_resource, address, resource_status, status, ApplianceType, Base" + Environment.NewLine +
                               "INNER JOIN address AS base_address ON base.Id = base_address.Id" + Environment.NewLine +
                               "WHERE resource.CallSign = appliance.CallSign" + Environment.NewLine +
                               "AND resource.CallSign = address_resource.ResourceCallSign" + Environment.NewLine +
                               "AND address_resource.DateTime = ((SELECT MAX(Address_Resource.DateTime) FROM Address_Resource WHERE Address_Resource.ResourceCallSign = resource.CallSign))" + Environment.NewLine +
                               "AND address_resource.AddressId = address.Id" + Environment.NewLine +
                               "AND resource.CallSign = resource_status.ResourceCallSign" + Environment.NewLine +
                               "AND resource_status.StatusCode = status.Code" + Environment.NewLine +
                               "AND resource_status.DateTime = (SELECT MAX(resource_status.DateTime) FROM resource_status WHERE resource_status.ResourceCallSign = resource.CallSign)" + Environment.NewLine +
                               "AND appliance.ApplianceTypeName = ApplianceType.Name" + Environment.NewLine +
                               "AND resource.BaseLocationId = base.Id" + Environment.NewLine +
                               "AND resource.CallSign = @callsign;";

            MySqlCommand command = new MySqlCommand(statement, connection);

            command.Parameters.AddWithValue("@callsign", callSign);

            //execute the query
            MySqlDataReader myReader = null;

            try
            {
                // open the connection only if it is currently closed
                if (command.Connection.State == System.Data.ConnectionState.Closed)
                {
                    command.Connection.Open();
                }

                //close the reader if it currently exists
                if (myReader != null && !myReader.IsClosed)
                {
                    myReader.Close();
                }

                myReader = command.ExecuteReader();

                //read the data sent back from MySQL server
                while (myReader.Read())
                {
                    string name = myReader.GetString(2);

                    string mobile = string.Empty;
                    if (!myReader.IsDBNull(3))
                    {
                        mobile = myReader.GetString(3);
                    }

                    int attachedIncident = -1;
                    if (!myReader.IsDBNull(4))
                    {
                        attachedIncident = myReader.GetInt32(4);
                    }

                    string oic = string.Empty;
                    if (!myReader.IsDBNull(7))
                    {
                        oic = myReader.GetString(7);
                    }

                    int crew = -1;
                    if (!myReader.IsDBNull(8))
                    {
                        crew = myReader.GetInt32(8);
                    }

                    int ba = -1;
                    if (!myReader.IsDBNull(9))
                    {
                        ba = myReader.GetInt32(9);
                    }

                    #region Address Data

                    int addressId = -1;
                    if (!myReader.IsDBNull(14))
                    {
                        addressId = myReader.GetInt32(14);
                    }

                    string building = string.Empty;
                    if (!myReader.IsDBNull(15))
                    {
                        building = myReader.GetString(15);
                    }

                    string number = string.Empty;
                    if (!myReader.IsDBNull(16))
                    {
                        number = myReader.GetString(16);
                    }

                    string street = string.Empty;
                    if (!myReader.IsDBNull(17))
                    {
                        street = myReader.GetString(17);
                    }

                    string town = string.Empty;
                    if (!myReader.IsDBNull(18))
                    {
                        town = myReader.GetString(18);
                    }

                    string postcode = string.Empty;
                    if (!myReader.IsDBNull(19))
                    {
                        postcode = myReader.GetString(19);
                    }

                    string county = string.Empty;
                    if (!myReader.IsDBNull(20))
                    {
                        county = myReader.GetString(20);
                    }

                    double latitude  = myReader.GetDouble(21);
                    double longitude = myReader.GetDouble(22);

                    Address address = new Address(addressId, building, number, street, town, postcode, county, longitude, latitude);

                    #endregion

                    #region Status Data

                    int code = -1;
                    if (!myReader.IsDBNull(27))
                    {
                        code = myReader.GetInt32(27);
                    }

                    string codeDescription = string.Empty;
                    if (!myReader.IsDBNull(28))
                    {
                        codeDescription = myReader.GetString(28);
                    }

                    bool isAvail = false;
                    if (!myReader.IsDBNull(29))
                    {
                        isAvail = myReader.GetBoolean(29);
                    }

                    bool isMob = false;
                    if (!myReader.IsDBNull(30))
                    {
                        isMob = myReader.GetBoolean(30);
                    }

                    ResourceLogTime log = ResourceLogTime.Ignore;
                    if (!myReader.IsDBNull(31))
                    {
                        log = (ResourceLogTime)myReader.GetInt32(31);
                    }

                    ResourceStatus status = new ResourceStatus(code, codeDescription, isAvail, isMob, log);

                    #endregion

                    #region Appliance Type Data

                    string typeName = string.Empty;
                    if (!myReader.IsDBNull(32))
                    {
                        typeName = myReader.GetString(32);
                    }

                    string typeDescription = string.Empty;
                    if (!myReader.IsDBNull(33))
                    {
                        typeDescription = myReader.GetString(33);
                    }

                    ApplianceType type = new ApplianceType(typeName, typeDescription);

                    #endregion

                    #region Base Data

                    int baseId = -1;
                    if (!myReader.IsDBNull(34))
                    {
                        baseId = myReader.GetInt32(34);
                    }

                    int baseAddressId = -1;
                    if (!myReader.IsDBNull(35))
                    {
                        baseAddressId = myReader.GetInt32(35);
                    }

                    string office = string.Empty;
                    if (!myReader.IsDBNull(36))
                    {
                        office = myReader.GetString(36);
                    }

                    string baseName = string.Empty;
                    if (!myReader.IsDBNull(37))
                    {
                        name = myReader.GetString(37);
                    }


                    string baseBuilding = string.Empty;
                    if (!myReader.IsDBNull(39))
                    {
                        building = myReader.GetString(39);
                    }

                    string baseNumber = string.Empty;
                    if (!myReader.IsDBNull(40))
                    {
                        number = myReader.GetString(40);
                    }

                    string baseStreet = string.Empty;
                    if (!myReader.IsDBNull(41))
                    {
                        street = myReader.GetString(41);
                    }

                    string baseTown = string.Empty;
                    if (!myReader.IsDBNull(42))
                    {
                        town = myReader.GetString(42);
                    }

                    string basePostcode = string.Empty;
                    if (!myReader.IsDBNull(43))
                    {
                        postcode = myReader.GetString(43);
                    }

                    string baseCounty = string.Empty;
                    if (!myReader.IsDBNull(44))
                    {
                        county = myReader.GetString(44);
                    }

                    double baseLatitude  = myReader.GetDouble(45);
                    double baseLongitude = myReader.GetDouble(46);

                    Address baseAddress  = new Address(baseId, baseBuilding, baseNumber, baseStreet, baseTown, basePostcode, baseCounty, baseLongitude, baseLatitude);
                    Base    baseLocation = new Base(baseId, office, baseAddress, baseName);

                    #endregion

                    ApplianceInfo info = new ApplianceInfo(name, mobile, baseLocation, address, status, oic, crew, ba, type, attachedIncident);
                    return(new Appliance(callSign, info));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (myReader != null)
                {
                    myReader.Close();
                }
                command.Connection.Close();
            }
            return(null);
        }
Ejemplo n.º 4
0
        public bool OnApplianceTaken(IGameController gc, ApplianceInfo applianceInfo, ActiveDisease disease)
        {
            if (IsFinished)
            {
                return(false);
            }

            if (!gc.WorldTime.HasValue)
            {
                return(false);
            }

            if (disease.IsSelfHealing)
            {
                return(false);
            }

            var treatedStage = disease.TreatedStage;

            if (treatedStage == null)
            {
                treatedStage = disease.GetActiveStage(gc.WorldTime.Value);
            }

            if (treatedStage == null)
            {
                return(false);
            }

            var isTreatedLevel = treatedStage.Level == _treatedLevel;

            if (applianceInfo.Appliance.Name == _applianceName && (_bodyPart == null || applianceInfo.BodyPart == _bodyPart))
            {
                var currentTime = gc.WorldTime.Value;

                if (_consumedTimes.Count == 0)
                {
                    // First consume
                    _inTimeConsumedCount++;
                    _consumedTimes.Add(currentTime);

                    if (isTreatedLevel)
                    {
                        IsFinished = false;

                        CheckIfTreatmentFinished(disease);

                        if (OnTreatmentStarted != null)
                        {
                            OnTreatmentStarted.Invoke();
                        }

                        //("Disease appliance treatment started.");

                        IsStarted = true;

                        if (!IsNodePart && !IsFinished)
                        {
                            //("Overall disease treatment started.");

                            Events.NotifyAll(l => l.DiseaseTreatmentStarted(disease.Disease));

                            // We're starting to heal
                            disease.Invert();
                        }
                    }
                }
                else
                {
                    IsFinished = false;

                    var lastTime = _consumedTimes.Last();
                    var minutes  = (currentTime - lastTime).TotalMinutes;

                    if (minutes <= _timingInGameMinutes + TimingDeltaBetweenAllowedConsuming && minutes >= _timingInGameMinutes - TimingDeltaBetweenAllowedConsuming)
                    {
                        _inTimeConsumedCount++;

                        _consumedTimes.Add(currentTime);

                        if (isTreatedLevel)
                        {
                            CheckIfTreatmentFinished(disease);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
        private ObservableCollection<ApplianceInfo> GetApplianceList()
        {
            ObservableCollection<ApplianceInfo> list = new ObservableCollection<ApplianceInfo>();

            GenDatabase olwDb = GetDatabase();
            if (OwlDb != null)
            {
                GenConnection con = null;
                GenCommand cmd = null;
                GenDataReader reader = null;
                String selCmd =
                    "select addr, name, model " +
                    "from energy_sensor " +
                    "where addr is not null " +
                    "order by name ";

                try
                {
                    con = OwlDb.NewConnection();
                    cmd = new GenCommand(selCmd, con);
                    reader = (GenDataReader)cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        ApplianceInfo info = new ApplianceInfo();

                        info.ApplianceNo = reader.GetInt32(0);
                        string name = reader.IsDBNull(1) ? "" : reader.GetString(1);
                        string model = reader.IsDBNull(2) ? "" : reader.GetInt32(2).ToString();
                        if (name == "")
                            if (model == "")
                                info.Description = info.ApplianceNo.ToString();
                            else
                                info.Description = model + ": " + info.ApplianceNo.ToString();
                        else if (model == "")
                            info.Description = name + ": " + info.ApplianceNo.ToString();
                        else
                            info.Description = name + " / " + model + ": " + info.ApplianceNo.ToString();

                        list.Add(info);
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    if (con != null)
                    {
                        con.Close();
                        con.Dispose();
                    }
                    if (cmd != null)
                        cmd.Dispose();
                    if (reader != null)
                    {
                        reader.Close();
                        reader.Dispose();
                    }
                }
            }

            return list;
        }