/// <summary> /// Gets the current data of the specified channels. /// </summary> public Dto <CurData> GetCurDataStep1(IdList cnlNums, bool useCache) { try { // request data CheckAccessRights(cnlNums); CurData curData = RequestCurData(cnlNums, 0, useCache); // write channel list to the cache if (useCache && curData.CnlListID != "0") { memoryCache.Set( PluginUtils.GetCacheKey("CnlList", curData.CnlListID), cnlNums, new MemoryCacheEntryOptions { SlidingExpiration = WebUtils.CacheExpiration }); } return(Dto <CurData> .Success(curData)); } catch (AccessDeniedException ex) { return(Dto <CurData> .Fail(ex.Message)); } catch (Exception ex) { webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(GetCurDataStep1))); return(Dto <CurData> .Fail(ex.Message)); } }
/// <summary> /// Gets the current data without formatting. /// </summary> public Dto <IEnumerable <CurDataPoint> > GetCurData(IdList cnlNums) { try { CheckAccessRights(cnlNums); int cnlCnt = cnlNums == null ? 0 : cnlNums.Count; CurDataPoint[] dataPoints = new CurDataPoint[cnlCnt]; if (cnlCnt > 0) { CnlData[] cnlData = clientAccessor.ScadaClient.GetCurrentData(cnlNums.ToArray(), false, out _); for (int i = 0, cnt = cnlNums.Count; i < cnt; i++) { dataPoints[i] = new CurDataPoint(cnlNums[i], cnlData[i]); } } return(Dto <IEnumerable <CurDataPoint> > .Success(dataPoints)); } catch (AccessDeniedException ex) { return(Dto <IEnumerable <CurDataPoint> > .Fail(ex.Message)); } catch (Exception ex) { webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(GetCurData))); return(Dto <IEnumerable <CurDataPoint> > .Fail(ex.Message)); } }
/// <summary> /// Gets the current data by the channel list ID returned in step 1. /// </summary> public Dto <CurData> GetCurDataStep2(long cnlListID) { try { IdList cnlNums = memoryCache.Get <IdList>(PluginUtils.GetCacheKey("CnlList", cnlListID)); CurData curData = RequestCurData(cnlNums, cnlListID, true); return(Dto <CurData> .Success(curData)); } catch (Exception ex) { webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(GetCurDataStep2))); return(Dto <CurData> .Fail(ex.Message)); } }
/// <summary> /// Получить свойства документа схемы. /// </summary> public Dto <DocumentPacket> GetSchemeDoc(int viewID, long viewStamp) { try { if (viewLoader.GetView(viewID, out SchemeView schemeView, out string errMsg)) { DocumentPacket documentPacket = new(schemeView); documentPacket.FillCnlProps(webContext.ConfigDatabase); return(Dto <DocumentPacket> .Success(documentPacket)); } else { return(Dto <DocumentPacket> .Fail(errMsg)); } }
/// <summary> /// Gets the current data by view. /// </summary> /// <remarks>Loads the specified view if it is not in the cache.</remarks> public Dto <CurData> GetCurDataByView(int viewID, long cnlListID) { try { if (viewLoader.GetView(viewID, out ViewBase view, out string errMsg)) { CurData curData = memoryCache.GetOrCreate(PluginUtils.GetCacheKey("CurData", viewID), entry => { entry.SetAbsoluteExpiration(DataCacheExpiration); return(RequestCurData(view.CnlNumList, cnlListID, true)); }); return(Dto <CurData> .Success(curData)); } else { return(Dto <CurData> .Fail(errMsg)); } }
public async Task <Dto> Logout() { try { if (pluginContext.Options.AllowAuthApi) { await loginService.LogoutAsync(); return(Dto.Success()); } else { return(Dto.Fail(WebPhrases.ActionNotAllowed)); } } catch (Exception ex) { webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(Logout))); return(Dto.Fail(ex.Message)); } }
public async Task <Dto> Login([FromBody] CredentialsDTO credentialsDTO) { try { if (pluginContext.Options.AllowAuthApi) { SimpleResult result = await loginService.LoginAsync( credentialsDTO.Username, credentialsDTO.Password, false); return(new Dto(result)); } else { return(Dto.Fail(WebPhrases.ActionNotAllowed)); } } catch (Exception ex) { webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(Login))); return(Dto.Fail(ex.Message)); } }