Beispiel #1
0
        public override PathInfo GetFormula(ConnectionLine l, PathInfo path)
        {
            if (IsStartNode && ConnectionLines.Count == 0)
            {
                throw new Exception(String.Format(Properties.Resources.ErrorStartNode, Name));
            }


            if (IsEndNode && ConnectionLines.Count == 0)
            {
                throw new Exception(String.Format(Properties.Resources.ErrorEndNode, Name));
            }


            if (ConnectionLines.Count <= 1 && !IsStartNode && !IsEndNode)
            {
                throw new Exception(String.Format(Properties.Resources.ErrorStartNode, Name));
            }

            var rez           = "";
            var pathInfoTable = new List <PathInfo>();

            foreach (var uiElement in Path.AllDeletedObjects)
            {
                if (uiElement.GetType().Name == "ConnectionLine")
                {
                    this.ConnectionLines = this.ConnectionLines.Where(w => w.Name != (uiElement as ConnectionLine).Name).ToList();
                }
            }

            Node endBranch = null;

            if (this.ConnectionLines.Count > 2 && this != path?.EndBranch)
            {
                endBranch = FindEndNode();
            }

            if (path == null || path.Start == null)
            {
                foreach (var line in ConnectionLines)
                {
                    if (!Schema.CheckedList.Contains(line))
                    {
                        PathInfo patrhInfo = new PathInfo()
                        {
                            Start     = this,
                            Parent    = this,
                            EndBranch = endBranch
                        };
                        line.GetFormula(this, patrhInfo);
                        pathInfoTable.Add(patrhInfo);
                    }
                }
            }
            else
            {
                path.End = this;
                return(path);
            }

            var newTable = new List <PathInfo>();

            for (int i = 0; i < pathInfoTable.Count; i++)
            {
                if (pathInfoTable[i].Formula == "")
                {
                    if (!pathInfoTable[i].End.IsEndNode)
                    {
                        pathInfoTable[i] = pathInfoTable[i].End.GetFormula(null, new PathInfo {
                            Parent = this
                        });
                    }
                    //pathInfoTable[i].Start.IsStartNode = true;
                }
            }

            string orString = "";

            foreach (PathInfo pathInfo in pathInfoTable)
            {
                if (pathInfo.Formula != "")
                {
                    rez     += orString + "(" + pathInfo.Formula + ")";
                    orString = " OR ";
                }
            }

            if (pathInfoTable.Count == 0)
            {
                return(new PathInfo()
                {
                    Formula = rez
                });
            }

            pathInfoTable = new List <PathInfo>()
            {
                new PathInfo()
                {
                    Start   = pathInfoTable[0].Start,
                    End     = pathInfoTable[0].End,
                    Formula = rez
                }
            };

            if (pathInfoTable.Count == 0)
            {
                pathInfoTable.Add(new PathInfo
                {
                    Formula = ""
                }
                                  );
            }

            if ((pathInfoTable[0].Formula != "") && pathInfoTable[0].End != null && !pathInfoTable[0].End.IsEndNode)
            {
                var end = pathInfoTable[0].End.GetFormula(null, new PathInfo {
                    Parent = this
                });
                pathInfoTable[0].Formula += end.ToString() != "" && end.ToString() != "()"? " AND (" + end + ")":"";
                pathInfoTable[0].End      = end.End;
            }
            return(pathInfoTable[0]);
        }
Beispiel #2
0
        public string GetFormula(DraggingElement invoker, PathInfo path)
        {
            foreach (var uiElement in Path.AllDeletedObjects)
            {
                if (uiElement.GetType().Name == "Node")
                {
                    var node = (uiElement as Node);

                    if (Element1?.Name == node?.Name)
                    {
                        Element1 = null;
                    }

                    if (Element2?.Name == node?.Name)
                    {
                        Element2 = null;
                    }
                }
                else if (uiElement.GetType().Name == "Module")
                {
                    var module = (uiElement as Module);

                    if (Element1?.Name == module?.Name)
                    {
                        Element1 = null;
                    }

                    if (Element2?.Name == module?.Name)
                    {
                        Element2 = null;
                    }
                }
            }

            Schema.CheckedList.Add(this);

            if (Element1 == null)
            {
                throw new Exception(String.Format(Properties.Resources.ErrorInputLine, Name));
            }
            if (Element2 == null)
            {
                throw new Exception(String.Format(Properties.Resources.ErrorOutputLine, Name));
            }


            if (Element1 is Module && Element2 is Module)
            {
                path.IsM2MConnection = true;
            }
            else
            {
                path.IsM2MConnection = false;
            }


            if (Element1 is Node && Element2 is Node)
            {
                Path.PathNodes.Add(new Segment {
                    StartNode = Element1 as Node, EndNode = Element2 as Node, SubCondition = string.Empty, IsCompletedNodePath = true, Id = Path.PathNodes.Count + 1
                });
            }

            if (Element1 is Node && Element2 is Module)
            {
                var element2 = Element2 as Module;

                if (!ConfigurationHelper.Modules.Select(s => s.Name).Contains(element2.Name))
                {
                    ConfigurationHelper.Modules.Add(new ShortModule()
                    {
                        M = element2.Mu, L = element2.Lambda, Name = element2.Name, RepairCount = element2.RepairCount
                    });
                }

                var nodes = Path.PathNodes.Where(w => w.LastModuleName == element2.Name).ToList();

                if (nodes.Count == 0)
                {
                    var newNodePath = new Segment();
                    newNodePath.StartNode = Element1 as Node;

                    var nextModule = Element2 as Module;
                    newNodePath.LastModuleName = nextModule.Name;
                    newNodePath.Modules.Add(nextModule);
                    newNodePath.SubCondition = nextModule.Name;
                    newNodePath.Id           = Path.PathNodes.Count + 1;
                    Path.PathNodes.Add(newNodePath);
                }
                else
                {
                    foreach (var pathNode in nodes)
                    {
                        pathNode.StartNode = Element1 as Node;
                    }
                }
            }

            if (path.IsM2MConnection)
            {
                var element1 = Element1 as Module;
                var element2 = Element2 as Module;

                if (!ConfigurationHelper.Modules.Select(s => s.Name).Contains(element1.Name))
                {
                    ConfigurationHelper.Modules.Add(new ShortModule()
                    {
                        M = element1.Mu, L = element1.Lambda, Name = element1.Name, RepairCount = element1.RepairCount
                    });
                }

                if (!ConfigurationHelper.Modules.Select(s => s.Name).Contains(element2.Name))
                {
                    ConfigurationHelper.Modules.Add(new ShortModule()
                    {
                        M = element2.Mu, L = element2.Lambda, Name = element2.Name, RepairCount = element2.RepairCount
                    });
                }

                foreach (var pathNode in Path.PathNodes.Where(w => w.LastModuleName == element1.Name))
                {
                    var nextModule = Element2 as Module;
                    pathNode.LastModuleName = nextModule.Name;
                    pathNode.Modules.Add(nextModule);
                    pathNode.SubCondition = $"{pathNode.SubCondition} AND {nextModule.Name}";
                }
            }

            if (Element1 is Module && Element2 is Node)
            {
                var element1 = Element1 as Module;

                if (!ConfigurationHelper.Modules.Select(s => s.Name).Contains(element1.Name))
                {
                    ConfigurationHelper.Modules.Add(new ShortModule()
                    {
                        M = element1.Mu, L = element1.Lambda, Name = element1.Name, RepairCount = element1.RepairCount
                    });
                }

                var nodes = Path.PathNodes.Where(w => w.LastModuleName == element1.Name).ToList();


                if (nodes.Count == 0)
                {
                    var newNodePath = new Segment();
                    newNodePath.EndNode = Element2 as Node;

                    var nextModule = Element1 as Module;
                    newNodePath.LastModuleName = nextModule.Name;
                    newNodePath.Modules.Add(nextModule);
                    newNodePath.SubCondition = nextModule.Name;
                    newNodePath.Id           = Path.PathNodes.Count + 1;
                    Path.PathNodes.Add(newNodePath);
                }
                else
                {
                    foreach (var pathNode in nodes)
                    {
                        var endNode = Element2 as Node;
                        pathNode.LastModuleName      = null;
                        pathNode.EndNode             = endNode;
                        pathNode.IsCompletedNodePath = true;
                    }
                }
            }



            var rez = "";// +Name + " -";

            if (invoker == Element1)
            {
                rez += (Element2 as DraggingElement).GetFormula(this, path);
            }
            if (invoker == Element2)
            {
                rez += (Element1 as DraggingElement).GetFormula(this, path);
            }

            return(rez);
        }
Beispiel #3
0
 public override PathInfo GetFormula(ConnectionLine invoker, PathInfo path)
 {
     throw new NotImplementedException();
 }