예제 #1
0
        internal bool ValidateParams(IExtractKthCoreParamMgr paramMgr, out int kValue, out Exception ex)
        {
            bool isValid = true;
            kValue = 1;
            ex = null;
            string mssg = null;
            if (paramMgr == null)
            {
                mssg = Standard.Properties.Resources.MssgParamMgrIsNull;
                isValid = false;
            }
            else
            {
                var results = paramMgr.Validate();
                if (!results.IsValid)
                {
                    var q = from e in results.Errors
                            select e.ErrorMessage;

                    mssg = string.Join(";", q.ToArray());
                }
                else
                {
                    kValue = paramMgr.K;
                }
            }
            if (!isValid)
            {
                FxArgumentException argEx = new FxArgumentException(mssg);
                argEx.FxId = Id;
                argEx.ParentElementId = ParentId;
                argEx.FxTypeName = GetType().FullName;
                ex = argEx;
            }
            return isValid;
        }
예제 #2
0
        internal bool ValidateNetworkCopy(INetwork originalNetwork, INetwork copyNetwork, out Exception ex)
        {
            bool isValid = true;
            ex = null;
            string mssg = null;
            if (copyNetwork == null)
            {
                mssg = "Copy network [0] is null.";
                isValid = false;
            }
            else if (copyNetwork.NodeCount != originalNetwork.NodeCount)
            {
                mssg = "Copy network [0] does not match the original node count.";
                isValid = false;
            }

            if (!isValid)
            {
                FxArgumentException argEx = new FxArgumentException(mssg, "Copy network [0]");
                argEx.FxId = this.Id;
                argEx.ParentElementId = this.ParentId;
                argEx.FxTypeName = this.GetType().FullName;
                ex = argEx;
            }
            return isValid;
        }
예제 #3
0
        internal bool ValidateOutputNetwork0(INetwork network, int originalNodeCount, int numNodesRemoved, out Exception ex)
        {
            bool isValid = true;
            ex = null;
            string mssg = null;
            if (network == null)
            {
                mssg = "Output network [0] is null.";
                isValid = false;
            }
            else
            {
                int expectedCount = originalNodeCount - numNodesRemoved;
                if (network.NodeCount != expectedCount)
                {
                    mssg = string.Format("Output network [0] node count {0} does not match the expected count of {1}.", network.NodeCount, expectedCount);
                    isValid = false;
                }
            }

            if (!isValid)
            {
                FxArgumentException argEx = new FxArgumentException(mssg, "Output network [0]");
                argEx.FxId = this.Id;
                argEx.ParentElementId = this.ParentId;
                argEx.FxTypeName = this.GetType().FullName;
                ex = argEx;
            }
            return isValid;
        }
예제 #4
0
        internal bool ValidateInputNetwork(INetwork network, out Exception ex)
        {
            bool isValid = true;
            ex = null;
            string mssg = null;
            if (network == null)
            {
                mssg = string.Format(Standard.Properties.Resources.MssgInputNetworkIsNull, 0);
                isValid = false;
            }
            else if (network.IsEmpty)
            {
                mssg = string.Format(Standard.Properties.Resources.MssgInputNetworkIsEmpty, 0);
                isValid = false;
            }
            else if (!(network is IBasicAdjList))
            {
                mssg = string.Format(Standard.Properties.Resources.MssgInvalidNetworkStructure, 0, typeof(IBasicAdjList).Name);
                isValid = false;
            }

            if (!isValid)
            {
                FxArgumentException argEx = new FxArgumentException(mssg, "Input network [0]");
                argEx.FxId = this.Id;
                argEx.ParentElementId = this.ParentId;
                argEx.FxTypeName = this.GetType().FullName;
                ex = argEx;
            }
            return isValid;
        }
예제 #5
0
        internal bool ValidateParams(IRandomNetGenParamMgr paramMgr, 
            out int nodeCount, 
            out int edgeCount, 
            out bool isDirected,
            out string networkName, 
            out bool allowCycles,
            out bool allowSelfLoops,
            out bool allowMultiEdges, 
            out Exception ex)
        {
            bool isValid = true;
            nodeCount = edgeCount =0;
            isDirected = false;
            networkName = null;
            allowCycles = allowSelfLoops = allowMultiEdges = true;
            ex = null;

            string mssg = null;
            if (paramMgr == null)
            {
                mssg = Standard.Properties.Resources.MssgParamMgrIsNull;
                isValid = false;
            }
            else
            {
                nodeCount = paramMgr.NodeCount;
                edgeCount = paramMgr.EdgeCount;
                isDirected = paramMgr.IsDirected;
                networkName = paramMgr.NetworkName;
                allowCycles = paramMgr.AllowCycles;
                allowSelfLoops = paramMgr.AllowSelfLoops;
                allowMultiEdges = paramMgr.AllowMultiEdges;

                if (nodeCount<0)
                {
                    mssg = string.Format(BlueSpider.Element.Standard.Properties.Resources.MssgNodeCountLessThan0, "NodeCount", nodeCount);
                    isValid = false;
                }
                else if (edgeCount < 0)
                {
                    mssg = string.Format(BlueSpider.Element.Standard.Properties.Resources.MssgEdgeCountLessThan0, "EdgeCount", edgeCount);
                    isValid = false;
                }
            }
            if (!isValid)
            {
                FxArgumentException argEx = new FxArgumentException(mssg);
                argEx.FxId = this.Id;
                argEx.ParentElementId = this.ParentId;
                argEx.FxTypeName = this.GetType().FullName;
                ex = argEx;
            }
            return isValid;
        }
예제 #6
0
 internal bool ValidateOutputNetwork(INetwork network, int nodeCount, int edgeCount, bool directed, out Exception ex)
 {
     bool isValid = true;
     ex = null;
     string mssg = null;
     if (network == null)
     {
         mssg = "Output network [0] is null.";
         isValid = false;
     }
     else if (network.NodeCount != nodeCount)
     {
         mssg = string.Format("Node count of random network: {0} does not match expected node count set in parameters: {1}.", network.NodeCount, nodeCount);
         isValid = false;
     }
     else if (network.EdgeCount != edgeCount)
     {
         mssg = string.Format("Edge count of random network: {0} does not match expected edge count set in parameters: {1}.", network.EdgeCount, edgeCount);
         isValid = false;
     }
     else if (network.IsDirected != directed)
     {
         mssg = string.Format("Directedness of random network: {0} does not match expected directedness set in parameters: {1}.", network.IsDirected, directed);
         isValid = false;
     }
     if (!isValid)
     {
         FxArgumentException argEx = new FxArgumentException(mssg);
         argEx.FxId = this.Id;
         argEx.ParentElementId = this.ParentId;
         argEx.FxTypeName = this.GetType().FullName;
         ex = argEx;
     }
     return isValid;
 }
예제 #7
0
        public void ValidateInputNetwork_ReturnsFalseWhenNetworkIsEmpty()
        {
            var mockInNet = new Mock<IBasicAdjList>();
            FxArgumentException returnEx = new FxArgumentException("message", new Exception());
            Exception ex = null;

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(mockInNet.IsEmpty, true);
                ex = returnEx;
            }

            bool result = _fx.ValidateInputNetwork(mockInNet, out ex);
            Assert.False(result);
            Assert.NotNull(ex);
            MockManager.Verify();
        }
예제 #8
0
        internal bool ValidateParams(IExportNetworkParamMgr paramMgr, out string fileName, out bool exportNodeAttribs, out bool exportEdgeAttribs, out NetworkFileTypes fileType, out Exception ex)
        {
            bool isValid = true;
            fileName = null;
            exportNodeAttribs = false;
            exportEdgeAttribs = false;
            fileType = NetworkFileTypes.GraphML;

            ex = null;
            string mssg = null;
            if (paramMgr == null)
            {
                mssg = Standard.Properties.Resources.MssgParamMgrIsNull;
                isValid = false;
            }
            else
            {
                fileName = paramMgr.FileName;
                exportNodeAttribs = paramMgr.ExportNodeAttributes;
                exportEdgeAttribs = paramMgr.ExportEdgeAttributes;
                fileType = paramMgr.FileType;
                if (!IsValidFileName(fileName))
                {
                    mssg = string.Format("Invalid output file: \"{0}\".", (fileName ?? "null"));
                    isValid = false;
                }
            }
            if (!isValid)
            {
                FxArgumentException argEx = new FxArgumentException(mssg);
                argEx.FxId = this.Id;
                argEx.ParentElementId = this.ParentId;
                argEx.FxTypeName = this.GetType().FullName;
                ex = argEx;
            }
            return isValid;
        }