Beispiel #1
0
        public async Task <ActionResult <ElectricMeterModel> > Put(ElectricMeterModel itemModel, int id)
        {
            try
            {
                if (itemModel == null)
                {
                    return(BadRequest("ElectricMeter object is null"));
                }

                var dbItem = await _repository.GetElectricMeterAsync(id);

                if (dbItem == null)
                {
                    return(NotFound());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                ElectricMeter item = _mapper.Map <ElectricMeter>(itemModel);

                await _repository.UpdateElectricMeterAsync(dbItem, item);

                return(CreatedAtAction(nameof(Get),
                                       new { id = itemModel.Id }, item));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error: {ex.Message}"));
            }
        }
Beispiel #2
0
        public async Task <ActionResult <ElectricMeter> > Post(ElectricMeterModel itemModel)
        {
            try
            {
                if (itemModel == null)
                {
                    return(BadRequest("ElectricMeter object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                ElectricMeter item = _mapper.Map <ElectricMeter>(itemModel);

                await _repository.AddElectricMeterAsync(item);

                return(CreatedAtAction(nameof(Get),
                                       new { id = item.Id }, item));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error: {ex.Message}"));
            }
        }
    //Connects the meter to another meter.
    public void Connect(ElectricMeter meter)
    {
        //print ("Connecting to " + meter);

        if (meter != PowerSource)
        {
            Disconnect();
            PowerSource = meter;
        }

        //Check if source has electricity?
        if (AlwaysPowered)
        {
            powered(true);
        }

        if (PowerSource != null)
        {
            if (!PowerSource.Powering.Contains(this))
            {
                PowerSource.Powering.Add(this);
            }

            powered(PowerSource.HasPower && PowerSource.GivesPower);
        }
    }
Beispiel #4
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        ElectricMeter myScript = (ElectricMeter)target;


        if (GUILayout.Button("Switch On", GUILayout.Width(100)))
        {
            myScript.On();
        }

        if (GUILayout.Button("Switch Off", GUILayout.Width(100)))
        {
            myScript.Off();
        }

        if (GUILayout.Button("Toggle", GUILayout.Width(100)))
        {
            myScript.Toggle();
        }

        if (GUILayout.Button("Reset", GUILayout.Width(100)))
        {
            myScript.reset_energy();
        }

        if (GUILayout.Button("Connect", GUILayout.Width(100)))
        {
            myScript.Connect(myScript.PowerSource);
        }
    }
Beispiel #5
0
        /// <summary>
        /// Verifica el estado del medidor eléctrico y retorna una cadena con el ID del estado.
        /// </summary>
        /// <returns>
        ///     <list type="bullet">
        ///         <item>
        ///             <term>"-1"</term>
        ///             <description>Error de lectura.</description>
        ///         </item>
        ///         <item>
        ///             <term>"1"</term>
        ///             <description>Punto de carga lleno.</description>
        ///         </item>
        ///         <item>
        ///             <term>"2"</term>
        ///             <description>Requiere mantención.</description>
        ///         </item>
        ///         <item>
        ///             <term>"0"</term>
        ///             <description>Todo correcto.</description>
        ///         </item>
        ///     </list>
        /// </returns>
        private static string GetMeterState()
        {
            ElectricMeter _meter       = meter as ElectricMeter;
            ChargePoint   _chargePoint = station.ChargePoints[0];

            /* Los errores de lectura ocurren cuando hay más autos de los
             * que la estación permite tener, o  cuando está ocupando más
             * kw/h de los que tiene capacidad */
            if (_meter.CarsParked > _chargePoint.CarCapacity)
            {
                return("-1");
            }
            else if (_meter.KwhInUse > _chargePoint.KwhCapacity)
            {
                return("-1");
            }
            else if (_meter.RequiresMaintenance)
            {
                return("2");
            }
            else if (_meter.CarsParked == _chargePoint.CarCapacity)
            {
                return("1");
            }

            return("0");
        }
        public async Task <ElectricMeter> Add(ElectricMeter model)
        {
            var entry = await _context.ElectricMeters.AddAsync(model);

            await _context.SaveChangesAsync();

            return(entry.Entity);
        }
Beispiel #7
0
 public ActionResult AddMeter(ElectricMeter meter)
 {
     if (ModelState.IsValid)
     {
         _db.ElectricMeter.Add(meter);
         _db.SaveChanges();
     }
     return(RedirectToAction("AddMeter"));
 }
    public void AutoFindPowerSource()
    {
        ElectricMeter source;
        GameObject    parentObject;
        MainMeter     _mm;

        if (transform.parent == null)
        {
            _mm = MainMeter.GetInstance();

            if (_mm != null)
            {
                PowerSource = _mm;
            }

            return;
        }
        parentObject = this.transform.parent.gameObject;

        //Replaces commented section below
        PowerSource = transform.parent.GetComponentInParent <ElectricMeter>();
        if (PowerSource == null)
        {
            PowerSource = MainMeter.GetInstance();
        }

        /*while (true) {
         *
         *      //No more parents and nothing found
         *      if (parentObject == null) {
         *              _mm = MainMeter.GetInstance ();
         *
         *              if (_mm != null)
         *                      PowerSource = _mm;
         *              return;
         *      }
         *
         *      source = parentObject.GetComponent<ElectricMeter> ();
         *
         *      //If there is a hit use the first one.
         *      if (source != null) {
         *
         *              if (this != source) {
         *                      PowerSource = source;
         *                      return;
         *                      }
         *      }
         *
         *      parentObject = parentObject.transform.parent.gameObject;
         * }*/
    }
        /// <summary>
        /// BsonDocument转实体对象
        /// </summary>
        /// <param name="doc">Bson文档</param>
        /// <returns></returns>
        protected override ExpenseAccount DocToEntity(BsonDocument doc)
        {
            ExpenseAccount entity = new ExpenseAccount();

            entity.Id        = doc["_id"].ToString();
            entity.Name      = doc["name"].ToString();
            entity.ShortName = doc["shortName"].ToString();
            entity.ModelType = doc["modelType"].ToString();
            entity.Remark    = doc["remark"].ToString();
            entity.Status    = doc["status"].ToInt32();

            if (doc.Contains("parentId"))
            {
                entity.ParentId = doc["parentId"].ToString();
            }

            entity.EnergyType = new List <int>();
            if (doc.Contains("energyType"))
            {
                BsonArray array = doc["energyType"].AsBsonArray;
                foreach (var item in array)
                {
                    entity.EnergyType.Add(item.ToInt32());
                }
            }

            entity.ElectricMeters = new List <ElectricMeter>();
            if (doc.Contains("electricMeters"))
            {
                BsonArray array = doc["electricMeters"].AsBsonArray;
                foreach (BsonDocument item in array)
                {
                    ElectricMeter meter = new ElectricMeter();
                    meter.Name          = item["name"].ToString();
                    meter.Number        = item["number"].ToString();
                    meter.SectionNumber = item["sectionNumber"].ToString();
                    meter.AccountName   = item["accountName"].ToString();
                    meter.Address       = item["address"].ToString();
                    meter.Multiple      = item["multiple"].ToDecimal();
                    meter.Remark        = item["remark"].ToString();
                    meter.Status        = item["status"].ToInt32();

                    entity.ElectricMeters.Add(meter);
                }
            }

            entity.WaterMeters = new List <WaterMeter>();
            if (doc.Contains("waterMeters"))
            {
                BsonArray array = doc["waterMeters"].AsBsonArray;
                foreach (BsonDocument item in array)
                {
                    WaterMeter meter = new WaterMeter();
                    meter.Name        = item["name"].ToString();
                    meter.Number      = item["number"].ToString();
                    meter.AccountName = item["accountName"].ToString();
                    meter.Address     = item["address"].ToString();
                    meter.Remark      = item["remark"].ToString();
                    meter.Status      = item["status"].ToInt32();

                    entity.WaterMeters.Add(meter);
                }
            }

            return(entity);
        }