private void buttonQuery1_Click(object sender, EventArgs e)
        {
            richTextBoxOutput.Text = string.Empty;
            long             resourceID  = Convert.ToInt64(textBoxTargetGID1.Text, 16);
            List <ModelCode> propertyIDs = new List <ModelCode>();

            foreach (object selectedItem in listBoxProperties1.SelectedItems)
            {
                propertyIDs.Add((ModelCode)selectedItem);
            }
            NetworkModelGDAProxy networkModelGDAProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");

            try
            {
                ResourceDescription resourceDescription = networkModelGDAProxy.GetValues(resourceID, propertyIDs);
                using (StringWriter stringWriter = new StringWriter())
                {
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Formatting = Formatting.Indented;
                        resourceDescription.ExportToXml(xmlTextWriter);
                    }
                    richTextBoxOutput.Text = stringWriter.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Get Values - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        public async Task <ResourceDescription> GetValues(long globalId)
        {
            string message = "Getting values method started.";

            Console.WriteLine(message);
            //CommonTrace.WriteTrace(CommonTrace.TraceError, message);

            XmlTextWriter       xmlWriter = null;
            ResourceDescription rd        = null;

            try
            {
                short            type       = ModelCodeHelper.ExtractTypeFromGlobalId(globalId);
                List <ModelCode> properties = modelResourcesDesc.GetAllPropertyIds((DMSType)type);

                networkModelGdaClient = NetworkModelGdaClient.CreateClient();
                rd = await networkModelGdaClient.GetValues(globalId, properties);

                xmlWriter            = new XmlTextWriter(Config.Instance.ResultDirecotry + "\\GetValues_Results.xml", Encoding.Unicode);
                xmlWriter.Formatting = Formatting.Indented;
                rd.ExportToXml(xmlWriter);
                xmlWriter.Flush();

                message = "Getting values method successfully finished.";
                Console.WriteLine(message);
                //CommonTrace.WriteTrace(CommonTrace.TraceError, message);
            }
            catch (Exception e)
            {
                message = string.Format("Getting values method for entered id = {0} failed.\n\t{1}", globalId, e.Message);
                Console.WriteLine(message);
                //CommonTrace.WriteTrace(CommonTrace.TraceError, message);
            }
            finally
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Close();
                }
            }

            return(rd);
        }
Esempio n. 3
0
        public List <List <string> > GetValuesAndPath(long globalId)
        {
            List <string> path     = new List <string>();
            List <string> strProps = new List <string>();
            string        message  = "Getting values method started.";

            Console.WriteLine(message);
            CommonTrace.WriteTrace(CommonTrace.TraceError, message);

            XmlTextWriter       xmlWriter = null;
            ResourceDescription rd        = null;

            try
            {
                short            type       = ModelCodeHelper.ExtractTypeFromGlobalId(globalId);
                List <ModelCode> properties = modelResourcesDesc.GetAllPropertyIds((DMSType)type);

                rd = GdaQueryProxy.GetValues(globalId, properties);

                foreach (Property prop in rd.Properties)
                {
                    switch (prop.Type)
                    {
                    case PropertyType.Bool:
                        strProps.Add(prop.Id.ToString() + "~" + prop.AsBool().ToString());
                        break;

                    case PropertyType.Int32:
                        strProps.Add(prop.Id.ToString() + "~" + prop.AsInt().ToString());
                        break;

                    case PropertyType.Int64:
                        if (prop.Id.ToString().Contains("DATE"))
                        {
                            strProps.Add(prop.Id.ToString() + "~" + new DateTime(prop.AsLong()).ToString());
                        }
                        else
                        {
                            strProps.Add(prop.Id.ToString() + "~" + prop.AsLong().ToString());
                        }
                        break;

                    case PropertyType.Float:
                        strProps.Add(prop.Id.ToString() + "~" + prop.AsFloat().ToString());
                        break;

                    case PropertyType.String:
                        strProps.Add(prop.Id.ToString() + "~" + prop.AsString().ToString());
                        break;

                    case PropertyType.Reference:
                        strProps.Add(prop.Id.ToString() + "~" + prop.AsReference().ToString());
                        break;

                    case PropertyType.Enum:
                        strProps.Add(prop.Id.ToString() + "~" + prop.AsEnum().ToString());
                        break;

                    case PropertyType.ReferenceVector:
                        string val = prop.Id.ToString() + "~";
                        foreach (var item in prop.AsLongs())
                        {
                            val += item.ToString() + "\n";
                        }
                        strProps.Add(val);
                        break;

                    default:
                        strProps.Add(prop.Id.ToString() + "~" + "Empty");
                        break;
                    }
                }

                xmlWriter = new XmlTextWriter(Config.Instance.ResultDirecotry + "\\GetValues_Results.xml", Encoding.Unicode);
                path.Add(Config.Instance.ResultDirecotry + "\\GetValues_Results.xml");
                xmlWriter.Formatting = Formatting.Indented;
                rd.ExportToXml(xmlWriter);
                xmlWriter.Flush();

                message = "Getting values method successfully finished.";
                Console.WriteLine(message);
                CommonTrace.WriteTrace(CommonTrace.TraceError, message);
            }
            catch (Exception e)
            {
                message = string.Format("Getting values method for entered id = {0} failed.\n\t{1}", globalId, e.Message);
                Console.WriteLine(message);
                CommonTrace.WriteTrace(CommonTrace.TraceError, message);
            }
            finally
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Close();
                }
            }
            List <List <string> > strRet = new List <List <string> >();

            strRet.Add(path);
            strRet.Add(strProps);
            return(strRet);
        }
Esempio n. 4
0
        public List <List <string> > GetRelatedValuesAndPath(long sourceGlobalId, Association association)
        {
            string        message  = "Getting related values method started.";
            List <string> path     = new List <string>();
            List <string> strProps = new List <string>();

            Console.WriteLine(message);
            CommonTrace.WriteTrace(CommonTrace.TraceError, message);

            List <long> resultIds = new List <long>();


            XmlTextWriter xmlWriter         = null;
            int           numberOfResources = 2;

            try
            {
                List <ModelCode> properties = new List <ModelCode>();
                properties.Add(ModelCode.IDOBJ_ALIASNAME);
                properties.Add(ModelCode.IDOBJ_MRID);
                properties.Add(ModelCode.IDOBJ_NAME);

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

                xmlWriter = new XmlTextWriter(Config.Instance.ResultDirecotry + "\\GetRelatedValues_Results.xml", Encoding.Unicode);
                path.Add(Config.Instance.ResultDirecotry + "\\GetRelatedValues_Results.xml");
                xmlWriter.Formatting = Formatting.Indented;

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

                    for (int i = 0; i < rds.Count; i++)
                    {
                        resultIds.Add(rds[i].Id);
                        properties.Clear();
                        properties = modelResourcesDesc.GetAllPropertyIds((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rds[i].Id));
                        ResourceDescription rd = GdaQueryProxy.GetValues(rds[i].Id, properties);
                        rd.ExportToXml(xmlWriter);
                        foreach (Property prop in rd.Properties)
                        {
                            switch (prop.Type)
                            {
                            case PropertyType.Bool:
                                strProps.Add(prop.Id.ToString() + "~" + prop.AsBool().ToString());
                                break;

                            case PropertyType.Int32:
                                strProps.Add(prop.Id.ToString() + "~" + prop.AsInt().ToString());
                                break;

                            case PropertyType.Int64:
                                if (prop.Id.ToString().Contains("DATE"))
                                {
                                    strProps.Add(prop.Id.ToString() + "~" + new DateTime(prop.AsLong()).ToString());
                                }
                                else
                                {
                                    strProps.Add(prop.Id.ToString() + "~" + prop.AsLong().ToString());
                                }
                                break;

                            case PropertyType.Float:
                                strProps.Add(prop.Id.ToString() + "~" + prop.AsFloat().ToString());
                                break;

                            case PropertyType.String:
                                strProps.Add(prop.Id.ToString() + "~" + prop.AsString().ToString());
                                break;

                            case PropertyType.Reference:
                                strProps.Add(prop.Id.ToString() + "~" + prop.AsReference().ToString());
                                break;

                            case PropertyType.Enum:
                                strProps.Add(prop.Id.ToString() + "~" + prop.AsEnum().ToString());
                                break;

                            case PropertyType.ReferenceVector:
                                string val = prop.Id.ToString() + "~";
                                foreach (var item in prop.AsLongs())
                                {
                                    val += item.ToString() + "\n";
                                }
                                strProps.Add(val);
                                break;

                            default:
                                strProps.Add(prop.Id.ToString() + "~" + "Empty");
                                break;
                            }
                        }
                        xmlWriter.Flush();
                    }

                    resourcesLeft = GdaQueryProxy.IteratorResourcesLeft(iteratorId);
                }

                GdaQueryProxy.IteratorClose(iteratorId);

                message = "Getting related values method successfully finished.";
                Console.WriteLine(message);
                CommonTrace.WriteTrace(CommonTrace.TraceError, 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);
                Console.WriteLine(message);
                CommonTrace.WriteTrace(CommonTrace.TraceError, message);
            }
            finally
            {
                if (xmlWriter != null)
                {
                    xmlWriter.Close();
                }
            }

            List <List <string> > strRet = new List <List <string> >();

            strRet.Add(path);
            strRet.Add(strProps);
            return(strRet);
        }