private void ButtonGetValues_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedGID == null)
            {
                return;
            }

            List <ModelCode> selectedProperties = new List <ModelCode>();

            foreach (var child in Properties.Children)
            {
                if (child is CheckBox checkBox)
                {
                    if (checkBox.IsChecked.Value)
                    {
                        foreach (KeyValuePair <ModelCode, string> keyValuePair in propertiesDesc)
                        {
                            if (keyValuePair.Value.Equals(checkBox.Content))
                            {
                                selectedProperties.Add(keyValuePair.Key);
                            }
                        }
                    }
                }
            }
            ResourceDescription rd = null;

            try
            {
                rd = tgda.GetValues(SelectedGID.GID, selectedProperties);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "GetValues", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (rd != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Returned entity" + Environment.NewLine + Environment.NewLine);
                sb.Append($"Entity with gid: 0x{rd.Id:X16}" + Environment.NewLine);

                foreach (Property property in rd.Properties)
                {
                    switch (property.Type)
                    {
                    case PropertyType.Int64:
                        StringAppender.AppendLong(sb, property);
                        break;

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

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

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

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

                    default:
                        sb.Append($"{property.Id}: {property.PropertyValue.LongValue}{Environment.NewLine}");
                        break;
                    }
                }

                Values.Document.Blocks.Clear();
                Values.AppendText(sb.ToString());
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            ModelResourcesDesc resDesc = new ModelResourcesDesc();

            try
            {
                // Set NMSTestInterfaceClient console layout
                Console.SetWindowPosition(0, 0);
                Console.SetBufferSize(250, 1000);
                Console.SetWindowSize((int)(Console.LargestWindowWidth * 0.7), (int)(Console.LargestWindowHeight * 0.8));
                Console.Title = "Network Model Service Test Client";
            }
            catch (Exception ex)
            {
                string errPositionMessage = string.Format("Error: Could not set Network Model Service Test Client's window size and position. {0}", ex.Message);
                Console.WriteLine(errPositionMessage);
                CommonTrace.WriteTrace(CommonTrace.TraceError, errPositionMessage);
            }

            string message = string.Format("Network Model Service Test Client is up and running...");

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

            message = string.Format("Result directory: {0}", Config.Instance.ResultDirecotry);
            Console.WriteLine(message);
            CommonTrace.WriteTrace(CommonTrace.TraceInfo, message);


            try
            {
                TestGda tgda = new TestGda();


                string str = string.Empty;
                do
                {
                    PrintMenu();
                    str = Console.ReadLine();

                    if (str == "1")
                    {
                        try
                        {
                            tgda.GetValues(InputGlobalId());
                        }
                        catch (Exception ex)
                        {
                            message = string.Format("GetValues failed. {0}", ex.Message);
                            Console.WriteLine(message);
                            CommonTrace.WriteTrace(CommonTrace.TraceError, message);
                        }
                    }
                    else if (str == "2")
                    {
                        try
                        {
                            tgda.GetExtentValues(InputModelCode());
                        }
                        catch (Exception ex)
                        {
                            message = string.Format("GetExtentValues failed. {0}", ex.Message);
                            Console.WriteLine(message);
                            CommonTrace.WriteTrace(CommonTrace.TraceError, message);
                        }
                    }
                    else if (str == "3")
                    {
                        try
                        {
                            tgda.GetRelatedValues(InputGlobalId(), InputAssociation());
                        }
                        catch (Exception ex)
                        {
                            message = string.Format("GetRelatedValues failed. {0}", ex.Message);
                            Console.WriteLine(message);
                            CommonTrace.WriteTrace(CommonTrace.TraceError, message);
                        }
                    }
                    else if (str == "4")
                    {
                        try
                        {
                            tgda.TestApplyDeltaInsert();
                        }
                        catch (Exception ex)
                        {
                            message = string.Format("Test ApplyUpdate: Insert - Update - Delte failed. {0}", ex.Message);
                            Console.WriteLine(message);
                            CommonTrace.WriteTrace(CommonTrace.TraceError, message);
                        }
                    }
                    else if (str != "q")
                    {
                        PrintUnknownOption();
                    }

                    Console.WriteLine();
                }while (str != "q");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                CommonTrace.WriteTrace(CommonTrace.TraceError, ex.Message);
            }

            message = "Network Model Service Test Client stopped.";
            Console.WriteLine(message);
            CommonTrace.WriteTrace(CommonTrace.TraceError, message);
        }
        private void ButtonGetRelatedValues_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedProperty == null)
            {
                return;
            }

            List <ModelCode> selectedProperties = new List <ModelCode>();

            foreach (var child in PropertiesInRelated.Children)
            {
                CheckBox checkBox;
                if (child is CheckBox && (child as CheckBox).IsChecked.Value)
                {
                    checkBox = child as CheckBox;
                    foreach (KeyValuePair <ModelCode, string> keyValuePair in propertiesDesc)
                    {
                        if (keyValuePair.Value.Equals(checkBox.Content))
                        {
                            selectedProperties.Add(keyValuePair.Key);
                        }
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Returned entities" + Environment.NewLine + Environment.NewLine);

            ////////////////////////////////////////////
            List <long>         gidReferences = new List <long>();
            ResourceDescription rd            = tgda.GetValues(SelectedGID.GID, new List <ModelCode>()
            {
                SelectedProperty.Property
            });

            if (rd != null)
            {
                Property prop = rd.GetProperty(SelectedProperty.Property);

                if ((short)(unchecked ((long)SelectedProperty.Property & (long)ModelCodeMask.MASK_ATTRIBUTE_TYPE)) == (short)PropertyType.Reference)
                {
                    gidReferences.Add(prop.AsReference());
                }
                else if ((short)(unchecked ((long)SelectedProperty.Property & (long)ModelCodeMask.MASK_ATTRIBUTE_TYPE)) == (short)PropertyType.ReferenceVector)
                {
                    gidReferences.AddRange(prop.AsReferences());
                }
            }

            HashSet <DMSType> referencedDmsTypes = new HashSet <DMSType>();

            if (gidReferences.Count > 0)
            {
                foreach (long gidReference in gidReferences)
                {
                    DMSType dmsType = (DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(gidReference);
                    if (!referencedDmsTypes.Contains(dmsType))
                    {
                        referencedDmsTypes.Add(dmsType);
                    }
                }
            }
            ////////////////////////////////////////////////////////

            try
            {
                if (SelectedDmsType != null)
                {
                    Association association = new Association(SelectedProperty.Property, modelResourcesDesc.GetModelCodeFromType(SelectedDmsType.DmsType));
                    List <long> gids        = tgda.GetRelatedValues(SelectedGID.GID, selectedProperties, association, sb);
                }
                else
                {
                    /////////////////////////////////////////////////////////////
                    HashSet <ModelCode> referencedDmsTypesProperties      = new HashSet <ModelCode>(modelResourcesDesc.GetAllPropertyIds(referencedDmsTypes.First()));
                    List <ModelCode>    toBeRemovedFormSelectedProperties = new List <ModelCode>();
                    foreach (ModelCode property in selectedProperties)
                    {
                        if (!referencedDmsTypesProperties.Contains(property))
                        {
                            toBeRemovedFormSelectedProperties.Add(property);
                        }
                    }

                    foreach (ModelCode property in toBeRemovedFormSelectedProperties)
                    {
                        selectedProperties.Remove(property);
                    }

                    foreach (var child in PropertiesInRelated.Children)
                    {
                        CheckBox checkBox;
                        if (child is CheckBox && (child as CheckBox).IsChecked.Value)
                        {
                            checkBox = child as CheckBox;
                            foreach (KeyValuePair <ModelCode, string> keyValuePair in propertiesDesc)
                            {
                                if (keyValuePair.Value.Equals(checkBox.Content) && toBeRemovedFormSelectedProperties.Contains(keyValuePair.Key))
                                {
                                    checkBox.IsChecked = false;
                                }
                            }
                        }
                    }

                    CheckAllBtn.IsEnabled = true;
                    /////////////////////////////////////////////////////////////

                    Association association = new Association(SelectedProperty.Property, 0x0000000000000000);
                    List <long> gids        = tgda.GetRelatedValues(SelectedGID.GID, selectedProperties, association, sb);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "GetRelatedValues", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            RelatedValues.Document.Blocks.Clear();
            RelatedValues.AppendText(sb.ToString());
        }