示例#1
0
        public async Task <StatusMessage> MoveNodesSubtree(
            int nodeId,
            int newParentId
            )
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(nodeId);

            if (nodeIdValidationStatus.Failure())
            {
                return(nodeIdValidationStatus);
            }

            StatusMessage newParentIdValidationStatus = newParentId == 0
                ? StatusMessage.Ok //imaginary root id
                : await ValidateNodeId(newParentId);

            if (newParentIdValidationStatus.Failure())
            {
                return(nodeIdValidationStatus);
            }

            StatusMessage newParentIsInNodeSubtreeStatus =
                await FailIfNodeInSubtree(newParentId, nodeId);

            if (newParentIsInNodeSubtreeStatus.Failure())
            {
                return(newParentIsInNodeSubtreeStatus);
            }

            return(await Repo.MoveNodesSubtree(nodeId, newParentId));
        }
        public async Task <StatusMessage> UpdateTag(NodeTag tag)
        {
            StatusMessage tagIdValidationStatus = await ValidateTagId(tag.Id);

            if (tagIdValidationStatus.Failure())
            {
                return(tagIdValidationStatus);
            }

            StatusMessage tagValidationStatus = _validator.Validate(tag);

            if (tagValidationStatus.Failure())
            {
                return(tagValidationStatus);
            }

            StatusMessage nameExistsStatus =
                await FailIfTagNameExists(tag.Name, updatingTagId : tag.Id);

            if (nameExistsStatus.Failure())
            {
                return(nameExistsStatus);
            }

            return(await Repo.UpdateTag(_viewToEfConverter.Convert(tag)));
        }
示例#3
0
        public StatusMessage Validate(NtwkNode val)
        {
            StatusMessage nameValidationStatus = ValidationUtils.IsValidName(val.Name);

            if (nameValidationStatus.Failure())
            {
                return(nameValidationStatus);
            }

            StatusMessage ipFormatStatus = StatusMessage.Ok;

            try
            {
                Conversion.ConversionUtils.IpStrToUInt32(val.IpStr);
            }
            catch (ArgumentNullException)
            {
                ipFormatStatus = StatusMessage.IpAddressStringIsNull;
            }
            catch (FormatException)
            {
                ipFormatStatus = StatusMessage.IpAddressStringFormatIsInvalid;
            }

            return(ipFormatStatus);
        }
        public async Task <StatusMessage> CreateWebServiceBinding(
            int nodeId,
            int cwsId,
            string param1,
            string param2,
            string param3
            )
        {
            StatusMessage wsbValidationStatus = await CwsBindingValidationRoutine(
                nodeId, cwsId, param1, param2, param3
                );

            if (wsbValidationStatus.Failure())
            {
                return(wsbValidationStatus);
            }

            StatusMessage newUniqBindingStatus = await FailIfCwsBindingExists(cwsId, nodeId);

            if (newUniqBindingStatus.Failure())
            {
                return(newUniqBindingStatus);
            }

            return(await Repo.CreateWebServiceBinding(nodeId, cwsId, param1, param2, param3));
        }
        public async Task <StatusMessage> UpdateProfile(Profile profile)
        {
            StatusMessage profileIdValidationStatus = await ValidateProfileId(profile.Id);

            if (profileIdValidationStatus.Failure())
            {
                return(profileIdValidationStatus);
            }

            StatusMessage profileValidationStatus = _validator.Validate(profile);

            if (profileValidationStatus.Failure())
            {
                return(profileValidationStatus);
            }

            StatusMessage nameExistsStatus =
                await FailIfProfileNameExists(profile.Name, updatingProfileId : profile.Id);

            if (nameExistsStatus.Failure())
            {
                return(nameExistsStatus);
            }

            return(await Repo.UpdateProfile(_viewToEfConverter.Convert(profile)));
        }
示例#6
0
        public async Task <DataActionResult <NtwkNode> > CreateNodeWithParent(
            NtwkNode node,
            int parentId
            )
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(parentId);

            if (nodeIdValidationStatus.Failure())
            {
                return(DataActionResult <NtwkNode> .Failed(nodeIdValidationStatus));
            }

            StatusMessage nodeValidationStatus = _validator.Validate(node);

            if (nodeValidationStatus.Failure())
            {
                return(DataActionResult <NtwkNode> .Failed(nodeValidationStatus));
            }

            StatusMessage nameExistsStatus = await FailIfNodeNameExists(node.Name);

            if (nameExistsStatus.Failure())
            {
                return(DataActionResult <NtwkNode> .Failed(nameExistsStatus));
            }

            return(FailOrConvert(
                       await Repo.CreateNodeWithParent(_viewToEfConverter.Convert(node), parentId),
                       n => _efToViewConverter.Convert(n)
                       ));
        }
        public async Task <StatusMessage> UpdateCustomWebService(
            CustomWebService cws
            )
        {
            StatusMessage idExistsStatus =
                (await GetCwsParamNumber(cws.Id)).Status;

            if (idExistsStatus.Failure())
            {
                return(idExistsStatus);
            }

            StatusMessage validationStatus = _validator.Validate(cws);

            if (validationStatus.Failure())
            {
                return(validationStatus);
            }

            StatusMessage nameExistsStatus =
                await FailIfCwsNameExists(cws.Name, cws.Id);

            if (nameExistsStatus.Failure())
            {
                return(nameExistsStatus);
            }

            return(await Repo.UpdateCustomWebService(_viewToEfConverter.Convert(cws)));
        }
示例#8
0
        public async Task <StatusMessage> UpdateNode(
            NtwkNode node
            )
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(node.Id);

            if (nodeIdValidationStatus.Failure())
            {
                return(nodeIdValidationStatus);
            }

            StatusMessage nodeValidationStatus = _validator.Validate(node);

            if (nodeValidationStatus.Failure())
            {
                return(nodeValidationStatus);
            }

            StatusMessage nameExistsStatus =
                await FailIfNodeNameExists(node.Name, updatingNodeId : node.Id);

            if (nameExistsStatus.Failure())
            {
                return(nameExistsStatus);
            }

            return(await Repo.UpdateNode(_viewToEfConverter.Convert(node)));
        }
示例#9
0
        public async Task <DataActionResult <string> > GetCwsBoundingString(
            int nodeId,
            int cwsId
            )
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(nodeId);

            if (nodeIdValidationStatus.Failure())
            {
                return(DataActionResult <string> .Failed(nodeIdValidationStatus));
            }

            StatusMessage cwsIdValidationStatus =
                (await GetCwsParamNumber(cwsId)).Status;

            if (cwsIdValidationStatus.Failure())
            {
                return(DataActionResult <string> .Failed(cwsIdValidationStatus));
            }

            StatusMessage cwsBindingExistsStatus =
                await FailIfCWSBinding_DOES_NOT_Exist(nodeId, cwsId);

            if (cwsBindingExistsStatus.Failure())
            {
                return(DataActionResult <string> .Failed(cwsBindingExistsStatus));
            }

            return(await Repo.GetCwsBoundingString(nodeId, cwsId));
        }
 protected ActionResult ObserveDataOperationStatus(
     StatusMessage status
     )
 {
     if (status.Failure())
     {
         return(BadRequest(_errAssembler.AssembleReport(status)));
     }
     return(NoContent());
 }
        public async Task <DataActionResult <TagFilterData> > GetProfileMonitorTagFilterData(int profileId)
        {
            StatusMessage profileIdValidationStatus = await ValidateProfileId(profileId);

            if (profileIdValidationStatus.Failure())
            {
                return(DataActionResult <TagFilterData> .Failed(profileIdValidationStatus));
            }

            return(await Repo.GetProfileMonitorTagFilterData(profileId));
        }
示例#12
0
        public StatusMessage Validate(Profile profile)
        {
            StatusMessage nameValidationStatus =
                ValidationUtils.IsValidName(profile.Name);

            if (nameValidationStatus.Failure())
            {
                return(nameValidationStatus);
            }

            return(StatusMessage.Ok);
        }
示例#13
0
        public async Task <DataActionResult <IEnumerable <int> > > GetTaggedNodesIDs(
            int tagId
            )
        {
            StatusMessage tagIdValidationStatus = await ValidateTagId(tagId);

            if (tagIdValidationStatus.Failure())
            {
                return(DataActionResult <IEnumerable <int> > .Failed(tagIdValidationStatus));
            }

            return(await Repo.GetTaggedNodesIDs(tagId));
        }
        public async Task <StatusMessage> SetProfileMonitorTagsSelectionToProfileViewTagsSelection(int profileId)
        {
            StatusMessage profileIdValidationStatus = await ValidateProfileId(profileId);

            if (profileIdValidationStatus.Failure())
            {
                return(profileIdValidationStatus);
            }

            return(await Repo.SetProfileMonitorTagsSelectionToProfileViewTagsSelection(
                       profileId
                       ));
        }
        public async Task <DataActionResult <NodeTag> > RemoveTag(int tagId)
        {
            StatusMessage tagIdValidationStatus = await ValidateTagId(tagId);

            if (tagIdValidationStatus.Failure())
            {
                return(DataActionResult <NodeTag> .Failed(tagIdValidationStatus));
            }

            return(FailOrConvert(
                       await Repo.RemoveTag(tagId),
                       t => _efToViewConverter.Convert(t)
                       ));
        }
示例#16
0
        public async Task <DataActionResult <NtwkNode> > RemoveNode(int nodeId)
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(nodeId);

            if (nodeIdValidationStatus.Failure())
            {
                return(DataActionResult <NtwkNode> .Failed(nodeIdValidationStatus));
            }

            return(FailOrConvert(
                       await Repo.RemoveNode(nodeId),
                       n => _efToViewConverter.Convert(n)
                       ));
        }
        public async Task <DataActionResult <Profile> > RemoveProfile(int profileId)
        {
            StatusMessage profileIdValidationStatus = await ValidateProfileId(profileId);

            if (profileIdValidationStatus.Failure())
            {
                return(DataActionResult <Profile> .Failed(profileIdValidationStatus));
            }

            return(FailOrConvert(
                       await Repo.RemoveProfile(profileId),
                       p => _efToViewConverter.Convert(p)
                       ));
        }
示例#18
0
        public async Task <DataActionResult <IPAddress> > GetNodeIp(int nodeId)
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(nodeId);

            if (nodeIdValidationStatus.Failure())
            {
                return(DataActionResult <IPAddress> .Failed(nodeIdValidationStatus));
            }

            return(FailOrConvert(
                       await Repo.GetNodeIp(nodeId),
                       nIp => new IPAddress(nIp)
                       ));
        }
示例#19
0
        public async Task <DataActionResult <IEnumerable <MonitoringSession> > > GetSessionsForProfile(int profileId)
        {
            StatusMessage profIdValidationStatus =
                await ValidateProfileId(profileId);

            if (profIdValidationStatus.Failure())
            {
                return(DataActionResult <IEnumerable <MonitoringSession> > .Failed(
                           profIdValidationStatus
                           ));
            }

            return(FailOrConvert(
                       await Repo.GetSessionsForProfile(profileId),
                       sessions => sessions.Select(s => _efToViewConverter.Convert(s))
                       ));
        }
        public async Task <DataActionResult <CustomWebService> > RemoveCustomWebService(
            int cwsId
            )
        {
            StatusMessage idExistsStatus =
                (await GetCwsParamNumber(cwsId)).Status;

            if (idExistsStatus.Failure())
            {
                return(DataActionResult <CustomWebService> .Failed(idExistsStatus));
            }

            return(FailOrConvert(
                       await Repo.RemoveCustomWebService(cwsId),
                       cws => _efToViewConverter.Convert(cws)
                       ));
        }
示例#21
0
        public async Task <DataActionResult <MonitoringSession> > GetNewSession(
            int profileId
            )
        {
            StatusMessage profIdValidationStatus =
                await ValidateProfileId(profileId);

            if (profIdValidationStatus.Failure())
            {
                return(DataActionResult <MonitoringSession> .Failed(profIdValidationStatus));
            }

            return(FailOrConvert(
                       await Repo.GetNewSession(profileId),
                       session => _efToViewConverter.Convert(session)
                       ));
        }
示例#22
0
        //includes messages
        public async Task <DataActionResult <IEnumerable <MonitoringPulseResult> > > GetSessionReport(
            int monitoringSessionId)
        {
            StatusMessage sessionIdValidationStatus =
                await ValidateSessionId(monitoringSessionId);

            if (sessionIdValidationStatus.Failure())
            {
                return(DataActionResult <IEnumerable <MonitoringPulseResult> > .Failed(
                           sessionIdValidationStatus
                           ));
            }

            return(FailOrConvert(
                       await Repo.GetSessionReport(monitoringSessionId),
                       pulses => pulses.Select(ConvertPulseResult)
                       ));
        }
        public async Task <StatusMessage> SetProfileMonitorTagsSelection(int profileId, IEnumerable <int> tagIDs)
        {
            StatusMessage profileIdValidationStatus = await ValidateProfileId(profileId);

            if (profileIdValidationStatus.Failure())
            {
                return(profileIdValidationStatus);
            }

            IEnumerable <int> tagsIDs = tagIDs as int[] ?? tagIDs.ToArray();
            StatusMessage     tagsIDsValidationStatus = await ValidateTagsIDs(tagsIDs);

            if (tagsIDsValidationStatus.Failure())
            {
                return(tagsIDsValidationStatus);
            }

            return(await Repo.SetProfileMonitorTagsSelection(profileId, tagsIDs));
        }
        public async Task <DataActionResult <Profile> > CreateProfile(Profile profile)
        {
            StatusMessage profileValidationStatus = _validator.Validate(profile);

            if (profileValidationStatus.Failure())
            {
                return(DataActionResult <Profile> .Failed(profileValidationStatus));
            }

            StatusMessage nameExistsStatus = await FailIfProfileNameExists(profile.Name);

            if (nameExistsStatus.Failure())
            {
                return(DataActionResult <Profile> .Failed(nameExistsStatus));
            }

            return(FailOrConvert(
                       await Repo.CreateProfile(_viewToEfConverter.Convert(profile)),
                       p => _efToViewConverter.Convert(p)
                       ));
        }
        public async Task <StatusMessage> UpdateWebServiceBinding(
            int nodeId,
            int cwsId,
            string param1,
            string param2,
            string param3
            )
        {
            StatusMessage validationStatus = await CwsBindingValidationRoutine(
                nodeId, cwsId, param1, param2, param3
                );

            if (validationStatus.Failure())
            {
                return(validationStatus);
            }

            return(await Repo.UpdateWebServiceBinding(
                       nodeId, cwsId, param1, param2, param3
                       ));
        }
        public async Task <DataActionResult <NodeTag> > CreateTag(NodeTag tag)
        {
            StatusMessage tagValidationStatus = _validator.Validate(tag);

            if (tagValidationStatus.Failure())
            {
                return(DataActionResult <NodeTag> .Failed(tagValidationStatus));
            }

            StatusMessage nameExistsStatus = await FailIfTagNameExists(tag.Name);

            if (nameExistsStatus.Failure())
            {
                return(DataActionResult <NodeTag> .Failed(nameExistsStatus));
            }

            return(FailOrConvert(
                       await Repo.CreateTag(_viewToEfConverter.Convert(tag)),
                       t => _efToViewConverter.Convert(t)
                       ));
        }
示例#27
0
        public async Task <StatusMessage> SetNodeTags(
            int nodeId,
            IEnumerable <int> tagIDs
            )
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(nodeId);

            if (nodeIdValidationStatus.Failure())
            {
                return(nodeIdValidationStatus);
            }

            IEnumerable <int> tagsIDs = tagIDs as int[] ?? tagIDs.ToArray();
            StatusMessage     tagsIDsValidationStatus = await ValidateTagsIDs(tagsIDs);

            if (tagsIDsValidationStatus.Failure())
            {
                return(tagsIDsValidationStatus);
            }

            return(await Repo.SetNodeTags(nodeId, tagsIDs));
        }
        async Task <StatusMessage> CwsBindingValidationRoutine(
            int nodeId,
            int cwsId,
            string param1,
            string param2,
            string param3
            )
        {
            StatusMessage idValidationStatus = await ValidateNodeId(nodeId);

            if (idValidationStatus.Failure())
            {
                return(idValidationStatus);
            }

            DataActionResult <int> paramNumResult =
                await GetCwsParamNumber(cwsId);

            if (paramNumResult.Status.Failure())
            {
                return(paramNumResult.Status);
            }

            int n = paramNumResult.Result;

            return((
                       (n != 0 && param1 == null) ||
                       (n > 1 && param2 == null) ||
                       (n == 3 && param3 == null)
                       )
                ? StatusMessage.ServiceBindingSetParementersValueCanNotBeNull
                : (
                       (n < 3 && param3 != null) ||
                       (n < 2 && param2 != null) ||
                       (n == 0 && param1 != null)
                       )
                    ? StatusMessage.RedundantParameterValuesInServiceBinding
                    : StatusMessage.Ok);
        }
        public async Task <StatusMessage> RemoveWebServiceBinding(
            int nodeId,
            int cwsId
            )
        {
            StatusMessage nodeIdValidationStatus = await ValidateNodeId(nodeId);

            if (nodeIdValidationStatus.Failure())
            {
                return(nodeIdValidationStatus);
            }

            StatusMessage cwsIdValidationStatus =
                (await GetCwsParamNumber(cwsId)).Status;

            if (cwsIdValidationStatus.Failure())
            {
                return(cwsIdValidationStatus);
            }

            return(await Repo.RemoveWebServiceBinding(nodeId, cwsId));
        }
示例#30
0
        public async Task <DataActionResult <MonitoringPulseResult> > SavePulseResult(
            int sessionId,
            MonitoringPulseResult pulseResult,
            IEnumerable <MonitoringMessage> messages
            )
        {
            StatusMessage sessionIdValidationStatus =
                await ValidateSessionId(sessionId);

            if (sessionIdValidationStatus.Failure())
            {
                return(DataActionResult <MonitoringPulseResult> .Failed(sessionIdValidationStatus));
            }

            IEnumerable <MonitoringMessage> monitoringMessages = messages as MonitoringMessage[] ?? messages.ToArray();

            foreach (MonitoringMessage message in monitoringMessages)
            {
                StatusMessage messageValidationStatus = _validator.Validate(message);
                if (messageValidationStatus.Failure())
                {
                    return(DataActionResult <MonitoringPulseResult> .Failed(
                               messageValidationStatus
                               ));
                }
            }

            EFDbModel.MonitoringPulseResult convertedPulseResult =
                _viewToEfConverter.Convert(pulseResult);
            IEnumerable <EFDbModel.MonitoringMessage> convertedMessages = monitoringMessages
                                                                          .Select(m => _viewToEfConverter.Convert(m));

            return(FailOrConvert(
                       await Repo.SavePulseResult(sessionId, convertedPulseResult, convertedMessages),
                       ConvertPulseResult
                       ));
        }