Example #1
0
        private void WriteLivePoint(LivePoint_DTO livepoint)
        {
            try
            {
                tblElement element = get_tblElement_by_Id(livepoint.Point_Id);

                if (element == null)
                {
                    throw new ArgumentNullException($"Invalid Element Id, No element found against this element ID {livepoint.Point_Id} ");
                }

                ILiveVariable liveVariable = new Obix(StringEncryDecry.Decrypt(element.tblConnector.Server_Name, element.tblConnector.SessionID),
                                                      StringEncryDecry.Decrypt(element.tblConnector.User_Name, element.tblConnector.SessionID),
                                                      StringEncryDecry.Decrypt(element.tblConnector.Password, element.tblConnector.SessionID));

                if (livepoint.Current_Value.dValue.HasValue)
                {
                    liveVariable.SetValueLiveVariable <decimal>(element.Source_Element_Name_Live, livepoint.Current_Value.dValue.Value);
                }
                else if (livepoint.Current_Value.bValue.HasValue)
                {
                    liveVariable.SetValueLiveVariable <bool>(element.Source_Element_Name_Live, livepoint.Current_Value.bValue.Value);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public bool UpdateLivePoint(LivePoint_DTO livepoint, string user_id)
        {
            try
            {
                if (!livepoint.IsRead_Only)
                {
                    WriteLivePoint(livepoint);
                    //We do not need to wait for save aduit that's why use Task
                    Task.Factory.StartNew(() => SaveAduit(user_id,
                                                          livepoint.Point_Id.ToString(),
                                                          nameof(tblElement),
                                                          livepoint.Current_Value.Old_Value,
                                                          livepoint.Live_Value,
                                                          ""));
                    //End audit

                    return(true);
                }
                else
                {
                    throw new Exception("Point is read only, If you want to change this point from the portal, please change IsRead_Only false");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
 private void ReadLivePoint(tblElement element, LivePoint_DTO livepoint)
 {
     if (element.tblConnector.Gateway_Type == DataGatewayType.Obix.ToString())
     {
         try
         {
             if (_connection_id != element.tblConnector.ID)
             {
                 _connection_id = element.tblConnector.ID;
                 _liveVariable  = new Obix(
                     StringEncryDecry.Decrypt(element.tblConnector.Server_Name, element.tblConnector.SessionID),
                     StringEncryDecry.Decrypt(element.tblConnector.User_Name, element.tblConnector.SessionID),
                     StringEncryDecry.Decrypt(element.tblConnector.Password, element.tblConnector.SessionID));
             }
             LivePoint_ResponseDTO response_dto = new LivePoint_ResponseDTO();
             if (_liveVariable.Is_Connected)
             {
                 response_dto            = _liveVariable.ReadLiveVariable(element.Source_Element_Name_Live);
                 livepoint.Current_Value = response_dto;
             }
             else
             {
                 livepoint.Error_Info = Error_Internal.SetError("Connection Error");
             }
         }
         catch (Exception ex) { }
     }
     else
     {
         throw new Exception("Invalid GatewayType");
     }
 }
Example #4
0
        public LivePoint_DTO GetLivePoint(long Id)
        {
            tblElement    tblelement    = get_tblElement_by_Id(Id);
            LivePoint_DTO livepoint_dto = LivePoint_Conversion.Convert_Tbl_Element_To_LivePoint_DTO(tblelement);

            ReadLivePoint(tblelement, livepoint_dto);
            GetLastAudit(livepoint_dto.Point_Id.ToString(), nameof(tblElement), livepoint_dto);
            return(livepoint_dto);
        }
        protected Audit_DTO GetLastAudit(string row_id, string table_name, LivePoint_DTO livepoint_dto)
        {
            _dbcontext = new InnonAnalyticsEngineEntities();
            tblAudit _audit = _dbcontext.tblAudits.Where(audit => audit.Table_Row_Id == row_id && audit.Table_Name == table_name).OrderByDescending(order => order.Last_Update).FirstOrDefault();

            if (_audit != null)
            {
                livepoint_dto.Last_Changes = $"Previous value {_audit.Old_Values}, Change by {_audit.User_Id}";
                livepoint_dto.Last_Updated = _audit.Last_Update;
            }

            return(Convert_Aduit.Convert(_audit));
        }
 public ActionResult UpdateLive_Value([DataSourceRequest] DataSourceRequest request, LivePoint_DTO livepoint_dto)
 {
     try
     {
         if (_iElementRepository.UpdateLivePoint(livepoint_dto, User.Identity.GetUserName()))
         {
             livepoint_dto = _iElementRepository.GetLivePoint(livepoint_dto.Point_Id);
             return(Json(new[] { livepoint_dto }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
         }
         else
         {
             throw new Exception("fail to update the live point value");
         }
     }
     catch (Exception ex)
     {
         return(Json(new[] { ex }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
     }
 }