Ejemplo n.º 1
0
 private bool Modify(KnowledgeBase knowledgeBase)
 {
     if (systemIdentifier == Identifier.Unique)
     {
         SystemIdentifier = knowledgeBase.Commands.GenerateUniqueSysIdentifier(Address, prefix);
     }
     return(knowledgeBase.Commands.SetSysIdentifier(Address, SystemIdentifier));
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
 private void CreateNew(KnowledgeBase knowledgeBase)
 {
     Address = knowledgeBase.Commands.CreateLink();
     knowledgeBase.Commands.SetLinkContent(Address, linkContent);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// ctor.
 /// </summary>
 /// <param name="knowledgeBase">база знаний</param>
 public Commands(KnowledgeBase knowledgeBase)
 {
     this.knowledgeBase = knowledgeBase;
 }
Ejemplo n.º 10
0
 private void CreateNew(KnowledgeBase knowledgeBase)
 {
     Address = knowledgeBase.Commands.CreateNode(Type);
 }
Ejemplo n.º 11
0
        private void CreateNew(KnowledgeBase knowledgeBase)
        {
#warning См. комментарий.
            //добавлять в соответствующие коллекции элементов перед использованием в виде вершин дуг
            Address = knowledgeBase.Commands.CreateArc(Type, beginElement.Address, endElement.Address);
        }
Ejemplo n.º 12
0
 private static Node loadNode(KnowledgeBase knowledgeBase, ScAddress address)
 {
     return(Node.Load(knowledgeBase, address));
 }
Ejemplo n.º 13
0
 private static Link loadLink(KnowledgeBase knowledgeBase, ScAddress address)
 {
     return(Link.Load(knowledgeBase, address));
 }
Ejemplo n.º 14
0
 private static Arc loadArc(KnowledgeBase knowledgeBase, ScAddress address)
 {
     return(Arc.Load(knowledgeBase, address));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// ctor,
 /// </summary>
 /// <param name="knowledgeBase">база знаний</param>
 internal ElementCollection(KnowledgeBase knowledgeBase)
 {
     this.knowledgeBase = knowledgeBase;
     objectsCache       = new Dictionary <ScAddress, T>();
 }
Ejemplo n.º 16
0
 private bool Modify(KnowledgeBase knowledgeBase)
 {
     return(knowledgeBase.Commands.SetLinkContent(Address, linkContent));
 }
Ejemplo n.º 17
0
 private bool Delete(KnowledgeBase knowledgeBase)
 {
     return(knowledgeBase.Commands.DeleteElement(Address));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Сохранение.
 /// </summary>
 /// <param name="knowledgeBase">база знаний</param>
 /// <returns><b>true</b>, если сохранено успешно, иначе - <b>false</b></returns>
 internal abstract bool Save(KnowledgeBase knowledgeBase);