示例#1
0
        private void bGetRelValues_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tbGid.Text))
            {
                MessageBox.Show("Enter valid GID first", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (Combo.SelectedItem == null)
            {
                MessageBox.Show("Please choose reference for all fields", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if (ComboType.SelectedItem == null)
            {
                MessageBox.Show("Reference type must be selected first. If there is nothing to select from, try loading references fist", "Warning", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
                return;
            }

            //gid
            var gid = InputGlobalId(tbGid.Text);

            if (gid == -1)
            {
                return;
            }

            //za popunjavanje propertija
            var props = new List <ModelCode>();

            foreach (var item in _item3)
            {
                if (!item.IsChecked)
                {
                    continue;
                }
                var myStatus = (ModelCode)Enum.Parse(typeof(ModelCode), item.Name, true);
                props.Add(myStatus);
            }

            var asc = new Association();

            try
            {
                //asocijacija

                Enum.TryParse(Combo.SelectedItem.ToString(), true, out ModelCode mc);
                asc.PropertyId = mc;
                Enum.TryParse(ComboType.SelectedItem.ToString(), true, out mc);
                asc.Type = mc;
            }
            catch (Exception)
            {
                MessageBox.Show("Incorrect field selection for reference or reference type", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }


            var gda = new TestGda();

            if (gda.GetRelatedValues(gid, props, asc) != null)
            {
                var path = Directory.GetCurrentDirectory();
                path            = Path.GetFullPath(Path.Combine(path, @"..\..\..\Results\GetRelatedValues_Results.xml"));
                TextBoxRel.Text = string.Empty;
                TextBoxRel.Text = File.Exists(path) ? File.ReadAllText(path) : "File does not exists";
            }
            else
            {
                MessageBox.Show("Unkown error in GetRelatedValues");
            }
        }
示例#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());
        }