Beispiel #1
0
 private bool Modify(KnowledgeBase knowledgeBase)
 {
     if (systemIdentifier == Identifier.Unique)
     {
         SystemIdentifier = knowledgeBase.Commands.GenerateUniqueSysIdentifier(Address, prefix);
     }
     return(knowledgeBase.Commands.SetSysIdentifier(Address, SystemIdentifier));
 }
Beispiel #2
0
        internal static Node Load(KnowledgeBase knowledgeBase, ScAddress scAddress)
        {
            var node = new Node(ElementType.Unknown, Identifier.Invalid);

            if (knowledgeBase.Commands.IsElementExist(scAddress))
            {
                node.Address          = scAddress;
                node.SystemIdentifier = knowledgeBase.Commands.GetNodeSysIdentifier(scAddress);
                node.Type             = knowledgeBase.Commands.GetElementType(scAddress);
                node.State            = ElementState.Synchronized;
            }
            return(node);
        }
Beispiel #3
0
        internal static Link Load(KnowledgeBase knowledgeBase, ScAddress scAddress)
        {
            var link = new Link(LinkContent.Invalid);

            if (knowledgeBase.Commands.IsElementExist(scAddress))
            {
                ElementType type = knowledgeBase.Commands.GetElementType(scAddress);
                if (type.IsType(ElementType.Link_a))
                {
                    link.Address     = scAddress;
                    link.LinkContent = knowledgeBase.Commands.GetLinkContent(scAddress);
                    link.Type        = ElementType.Link_a;
                    link.State       = ElementState.Synchronized;
                }
            }
            return(link);
        }
Beispiel #4
0
        internal static Type GetElementType(KnowledgeBase knowledgeBase, ScAddress scAddress)
        {
            ElementType type = knowledgeBase.Commands.GetElementType(scAddress);

            if (type.HasAnyType(ElementType.ArcMask_c))
            {
                return(typeof(Arc));
            }
            if (type.IsType(ElementType.Link_a))
            {
                return(typeof(Link));
            }
            else
            {
                return(typeof(Node));
            }
        }
Beispiel #5
0
        internal static ElementBase LoadElement(KnowledgeBase knowledgeBase, ScAddress scAddress)
        {
            ElementBase loadedElement = null;

            if (GetElementType(knowledgeBase, scAddress) == typeof(Node))
            {
                loadedElement = Node.Load(knowledgeBase, scAddress);
            }
            if (GetElementType(knowledgeBase, scAddress) == typeof(Link))
            {
                loadedElement = Link.Load(knowledgeBase, scAddress);
            }
            if (GetElementType(knowledgeBase, scAddress) == typeof(Arc))
            {
                loadedElement = Arc.Load(knowledgeBase, scAddress);
            }
            return(loadedElement);
        }
Beispiel #6
0
        internal override bool Save(KnowledgeBase knowledgeBase)
        {
#warning Непрозрачная логика метода. Можно одновременно создать, отредактировать и удалить. Confusing зело.
#warning Вынести в родительский класс, так как дублирование кода.
            bool isSaved = false;
            if (State.HasAnyState(ElementState.New))
            {
                CreateNew(knowledgeBase);
                State = State.RemoveState(ElementState.New);
            }
            if (State.HasAnyState(ElementState.Edited))
            {
                Modify(knowledgeBase);
                State = State.RemoveState(ElementState.Edited);
            }
            if (State.HasAnyState(ElementState.Deleted))
            {
                Delete(knowledgeBase);
                State = State.RemoveState(ElementState.Deleted);
            }
            State = State.AddState(ElementState.Synchronized);
            return(isSaved);
        }
Beispiel #7
0
        internal static Arc Load(KnowledgeBase knowledgeBase, ScAddress scAddress)
        {
            Arc arc = null;

            if (knowledgeBase.Commands.IsElementExist(scAddress))
            {
                ElementType type = knowledgeBase.Commands.GetElementType(scAddress);
                if (type.HasAnyType(ElementType.ArcMask_c))
                {
#warning здесь возможна бесконечная цикла если элементы дуги тоже дуги бесконечно
                    var command      = new GetArcElementsCommand(scAddress);
                    var response     = (GetArcElementsResponse)knowledgeBase.ExecuteCommand(command);
                    var beginElement = LoadElement(knowledgeBase, response.BeginElementAddress);
                    var endElement   = LoadElement(knowledgeBase, response.EndElementAddress);
                    arc = new Arc(type, beginElement, endElement)
                    {
                        Address = scAddress,
                        State   = ElementState.Synchronized
                    };
                }
            }
            return(arc);
        }
Beispiel #8
0
 private void CreateNew(KnowledgeBase knowledgeBase)
 {
     Address = knowledgeBase.Commands.CreateLink();
     knowledgeBase.Commands.SetLinkContent(Address, linkContent);
 }
Beispiel #9
0
 /// <summary>
 /// ctor.
 /// </summary>
 /// <param name="knowledgeBase">база знаний</param>
 public Commands(KnowledgeBase knowledgeBase)
 {
     this.knowledgeBase = knowledgeBase;
 }
Beispiel #10
0
 private void CreateNew(KnowledgeBase knowledgeBase)
 {
     Address = knowledgeBase.Commands.CreateNode(Type);
 }
Beispiel #11
0
        private void CreateNew(KnowledgeBase knowledgeBase)
        {
#warning См. комментарий.
            //добавлять в соответствующие коллекции элементов перед использованием в виде вершин дуг
            Address = knowledgeBase.Commands.CreateArc(Type, beginElement.Address, endElement.Address);
        }
 private static Node loadNode(KnowledgeBase knowledgeBase, ScAddress address)
 {
     return(Node.Load(knowledgeBase, address));
 }
 private static Link loadLink(KnowledgeBase knowledgeBase, ScAddress address)
 {
     return(Link.Load(knowledgeBase, address));
 }
 private static Arc loadArc(KnowledgeBase knowledgeBase, ScAddress address)
 {
     return(Arc.Load(knowledgeBase, address));
 }
 /// <summary>
 /// ctor,
 /// </summary>
 /// <param name="knowledgeBase">база знаний</param>
 internal ElementCollection(KnowledgeBase knowledgeBase)
 {
     this.knowledgeBase = knowledgeBase;
     objectsCache       = new Dictionary <ScAddress, T>();
 }
Beispiel #16
0
 private bool Modify(KnowledgeBase knowledgeBase)
 {
     return(knowledgeBase.Commands.SetLinkContent(Address, linkContent));
 }
Beispiel #17
0
 private bool Delete(KnowledgeBase knowledgeBase)
 {
     return(knowledgeBase.Commands.DeleteElement(Address));
 }
Beispiel #18
0
 /// <summary>
 /// Сохранение.
 /// </summary>
 /// <param name="knowledgeBase">база знаний</param>
 /// <returns><b>true</b>, если сохранено успешно, иначе - <b>false</b></returns>
 internal abstract bool Save(KnowledgeBase knowledgeBase);