public async Task <List <ResourceDescription> > GetRelatedValues(long source, List <ModelCode> propIds, Association association)
        {
            int iteratorId;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "GetRelatedValues() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    iteratorId = gdaQueryProxy.GetRelatedValues(source, propIds, association);
                }
                catch (Exception e)
                {
                    string message = $"Failed to get related values for element with GID {source}.";
                    Logger.LogError(message, e);
                    throw e;
                }
            }

            return(await ProcessIterator(iteratorId));
        }
        private void buttonQuery3_Click(object sender, EventArgs e)
        {
            richTextBoxOutput.Text = string.Empty;
            long        source      = Convert.ToInt64(textBoxSourceGID3.Text, 16);
            Association association = new Association();

            ModelCodeHelper.GetModelCodeFromString(comboBoxSourceReference3.SelectedItem.ToString(), out ModelCode propertyID);
            association.PropertyId = propertyID;
            if (comboBoxTargetType3.SelectedItem.ToString() == "ANY")
            {
                association.Type = 0;
            }
            else
            {
                ModelCodeHelper.GetModelCodeFromString(comboBoxTargetType3.SelectedItem.ToString(), out ModelCode type);
                association.Type = type;
            }
            List <ModelCode> propertyIDs = new List <ModelCode>();

            foreach (object selectedItem in listBoxProperties3.SelectedItems)
            {
                ModelCodeHelper.GetModelCodeFromString(selectedItem.ToString(), out ModelCode modelCode);
                propertyIDs.Add(modelCode);
            }
            try
            {
                NetworkModelGDAProxy networkModelGDAProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
                int iteratorID    = networkModelGDAProxy.GetRelatedValues(source, propertyIDs, association);
                int resourcesLeft = networkModelGDAProxy.IteratorResourcesLeft(iteratorID);
                List <ResourceDescription> resourceDescriptions = null;
                using (StringWriter stringWriter = new StringWriter())
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Formatting = Formatting.Indented;
                        while (resourcesLeft > 0)
                        {
                            resourceDescriptions = networkModelGDAProxy.IteratorNext(numberOfResources, iteratorID);
                            foreach (ResourceDescription resourceDescription in resourceDescriptions)
                            {
                                resourceDescription.ExportToXml(xmlTextWriter);
                                stringWriter.Write(stringWriter.NewLine);
                            }
                            resourcesLeft = networkModelGDAProxy.IteratorResourcesLeft(iteratorID);
                        }
                        richTextBoxOutput.Text = stringWriter.ToString();
                    }
                networkModelGDAProxy.IteratorClose(iteratorID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Get Related Values - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        public List <long> GetRelatedValues(long sourceGlobalId, List <ModelCode> properties, Association association, StringBuilder sb)
        {
            string message = "Getting related values method started.";

            Logger.LogInfo(message);

            int           iteratorId        = 0;
            int           resourcesLeft     = 0;
            int           numberOfResources = 500;
            List <long>   resultIds         = new List <long>();
            StringBuilder tempSb            = new StringBuilder();

            try
            {
                using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    if (gdaQueryProxy == null)
                    {
                        string errMsg = "NetworkModelGDAProxy is null.";
                        Logger.LogWarn(errMsg);
                        throw new NullReferenceException(errMsg);
                    }

                    iteratorId    = gdaQueryProxy.GetRelatedValues(sourceGlobalId, properties, association);
                    resourcesLeft = gdaQueryProxy.IteratorResourcesLeft(iteratorId);

                    while (resourcesLeft > 0)
                    {
                        List <ResourceDescription> rds = gdaQueryProxy.IteratorNext(numberOfResources, iteratorId);

                        for (int i = 0; i < rds.Count; i++)
                        {
                            if (rds[i] != null)
                            {
                                tempSb.Append($"Entity with gid: 0x{rds[i].Id:X16}" + Environment.NewLine);

                                foreach (Property property in rds[i].Properties)
                                {
                                    switch (property.Type)
                                    {
                                    case PropertyType.Int64:
                                        StringAppender.AppendLong(tempSb, property);
                                        break;

                                    case PropertyType.Float:
                                        StringAppender.AppendFloat(tempSb, property);
                                        break;

                                    case PropertyType.String:
                                        StringAppender.AppendString(tempSb, property);
                                        break;

                                    case PropertyType.Reference:
                                        StringAppender.AppendReference(tempSb, property);
                                        break;

                                    case PropertyType.ReferenceVector:
                                        StringAppender.AppendReferenceVector(tempSb, property);
                                        break;

                                    default:
                                        tempSb.Append($"{property.Id}: {property.PropertyValue.LongValue}{Environment.NewLine}");
                                        break;
                                    }
                                }
                            }
                            resultIds.Add(rds[i].Id);
                        }
                        resourcesLeft = gdaQueryProxy.IteratorResourcesLeft(iteratorId);
                    }
                    gdaQueryProxy.IteratorClose(iteratorId);

                    message = "Getting related values method successfully finished.";
                    Logger.LogInfo(message);
                }
            }
            catch (Exception e)
            {
                message = string.Format("Getting related values method  failed for sourceGlobalId = {0} and association (propertyId = {1}, type = {2}). Reason: {3}", sourceGlobalId, association.PropertyId, association.Type, e.Message);
                Logger.LogError(message);
            }

            if (sb != null)
            {
                sb.Append(tempSb.ToString());
            }

            return(resultIds);
        }