Exemple #1
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);
        }
        /// <summary>
        /// Генерирация уникального системного идентификатора для узла на основе адреса узла и префикса.
        /// </summary>
        /// <param name="nodeAddress">SC-адрес узла</param>
        /// <param name="preffix">префикс для узла</param>
        /// <returns>уникальный идентификатор для узла</returns>
        public Identifier GenerateUniqueSysIdentifier(ScAddress nodeAddress, string preffix)
        {
            Identifier identifier         = Identifier.Invalid;
            Identifier probablyIdentifier = string.Format("{0}_{1}_{2}", preffix, UnixDateTime.FromDateTime(DateTime.Now).GetHashCode(), nodeAddress.GetHashCode());

            var content  = new LinkContent(probablyIdentifier.Value);
            var command  = new FindLinksCommand(content);
            var response = (FindLinksResponse)knowledgeBase.ExecuteCommand(command);

            if (response.Addresses.Count == 0)
            {
                identifier = probablyIdentifier;
            }
            return(identifier);
        }