Beispiel #1
0
        private static string GetStringProperty(DtoAttributesGroup group, string name)
        {
            name = name.ToLowerInvariant();
            Object value;

            group.TryGetValue(name, out value);
            if (value is string)
            {
                return(value.ToString());
            }
            else if (value is DtoAttributDefinition)
            {
                DtoAttributDefinition definition = value as DtoAttributDefinition;
                if (definition != null && definition.Value is string)
                {
                    return(definition.Value as string);
                }
            }
            return(null);
        }
Beispiel #2
0
        public static string DtoAttributDefinitionToString(DtoAttributDefinition definition, List <PropertyInfo> dtoAttributDefinitionProperties)
        {
            string result = "";

            StringBuilder stringBuilder = new StringBuilder();

            if (definition != null)
            {
                stringBuilder.AppendLine("DtoAttributDefinition:");
                stringBuilder.AppendLine("");
                for (int i = 0; i < dtoAttributDefinitionProperties.Count; i++)
                {
                    PropertyInfo propertyInfo  = dtoAttributDefinitionProperties[i];
                    object       propertyValue = propertyInfo.GetValue(definition);
                    if (propertyValue != null)
                    {
                        string output = "";
                        if (propertyInfo.Name != "Value")
                        {
                            output = string.Format("{0} : {1}", propertyInfo.Name, propertyValue.ToString());
                        }
                        else
                        {
                            if (definition.EnumDefinition == null)
                            {
                                output = string.Format("{0} : {1}", propertyInfo.Name, propertyValue.ToString());
                            }
                            else
                            {
                                output = string.Format("{0} : {1}", propertyInfo.Name, GetEnumDefinitionValue(definition));
                            }
                        }

                        stringBuilder.AppendLine(output);
                    }
                }
            }

            result = stringBuilder.ToString();
            return(result);
        }
Beispiel #3
0
        public static object GetEnumDefinitionValue(DtoAttributDefinition dtoAttributDefinition)
        {
            object result = null;

            JObject jObject = dtoAttributDefinition.EnumDefinition as JObject;

            if (jObject != null)
            {
                Dictionary <object, string> jObjectAttributes = JsonConvert.DeserializeObject(jObject.ToString(), typeof(Dictionary <object, string>)) as Dictionary <object, string>;
                if (jObjectAttributes != null)
                {
                    if (dtoAttributDefinition.Value != null)
                    {
                        object value = dtoAttributDefinition.Value;
                        Type   type  = value.GetType();

                        if (type == typeof(Int32) || type == typeof(Int64))
                        {
                            value = value.ToString();

                            if (jObjectAttributes.ContainsKey(value))
                            {
                                result = jObjectAttributes[value];
                            }
                        }
                        else if (type == typeof(bool))
                        {
                            bool boolValue = (bool)value;

                            result = jObjectAttributes.Values.FirstOrDefault(v => boolValue.ToString().ToUpper() == v.ToUpper());
                        }
                        else if (type == typeof(string))
                        {
                            if (dtoAttributDefinition.DataType == typeof(string))
                            {
                                result = value;
                            }
                            else if (dtoAttributDefinition.DataType == typeof(Guid))
                            {
                                string stringValue = value as string;
                                Guid   guid;
                                if (Guid.TryParse(stringValue, out guid))
                                {
                                    if (jObjectAttributes.ContainsKey(stringValue))
                                    {
                                        result = jObjectAttributes[stringValue];
                                    }
                                }
                            }
                        }
                        else if (type == typeof(Guid))
                        {
                            result = value;
                        }
                        else
                        {
#if DEBUG
                            Trace.WriteLine("GetEnumDefinitionValue - Unexpected branch");
#endif
                        }
                    }
                }
            }
            else
            {
                JArray jArray = dtoAttributDefinition.EnumDefinition as JArray;
                if (jArray != null)
                {
                    List <string> jArrayAttributes = JsonConvert.DeserializeObject(jArray.ToString(), typeof(List <string>)) as List <string>;
                    result = dtoAttributDefinition.Value;
                }
            }

            if (result == null)
            {
                result = "";
            }

            return(result);
        }
        /// <summary>
        /// Fill the TreeView.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetObjects_Click(object sender, RoutedEventArgs e)
        {
            if (!HasAllowedFlags())
            {
                return;
            }

            AttributeTreeView.Items.Clear();

            List <DtObject> items = null;

            ProgressWindow.Text = "Get properties.";
            ProgressWindow.Show();

            try
            {
                items = _integrationBase.ApiCore.DtObjects.GetObjects(_integrationBase.CurrentProject.Id, SelectedItem,
                                                                      AttributeDefinitionIsChecked, PsetCheckBoxIsChecked, InternalValuesCheckBoxIsChecked);
            }
            finally
            {
                ProgressWindow.Hide();
            }

            if (items != null && items.Count > 0)
            {
                DtObject     dtObject         = items.FirstOrDefault();
                TreeViewItem rootTreeViewItem = new TreeViewItem {
                    Header = dtObject.GetType().Name
                };
                rootTreeViewItem.Header = dtObject.GetType().Name;

                AttributeTreeView.Items.Add(rootTreeViewItem);

                TreeViewItem groupTreeViewItem;
                TreeViewItem attributeTreeViewItem;

                foreach (KeyValuePair <string, DtoAttributesGroup> kvpGroup in dtObject.AttributeGroups)
                {
                    groupTreeViewItem = new TreeViewItem();

                    if (dtObject.LocalizedAttributeGroups != null && dtObject.LocalizedAttributeGroups.ContainsKey(kvpGroup.Key))
                    {
                        groupTreeViewItem.Header = dtObject.LocalizedAttributeGroups[kvpGroup.Key];
                    }
                    else
                    {
                        groupTreeViewItem.Header = kvpGroup.Key;
                    }

                    rootTreeViewItem.Items.Add(groupTreeViewItem);

                    foreach (KeyValuePair <string, object> kvpAttribute in kvpGroup.Value)
                    {
                        // Can not set in TreeView.ItemTemplate.
                        attributeTreeViewItem = new TreeViewItem {
                            FontSize = 13
                        };

                        string header          = null;
                        string value           = "";
                        string definitionValue = "";

                        DtoAttributDefinition dtoAttributDefinition = null;

                        if (!AttributeDefinitionIsChecked)
                        {
                            if (kvpAttribute.Value != null)
                            {
                                value = kvpAttribute.Value.ToString();
                            }
                            header = string.Format("{0} : {1}", kvpAttribute.Key, value);
                        }
                        else
                        {
                            if (kvpAttribute.Value != null)
                            {
                                JObject jObject = kvpAttribute.Value as JObject;
                                if (jObject != null)
                                {
                                    dtoAttributDefinition = jObject.ToObject <DtoAttributDefinition>();
                                    if (dtoAttributDefinition != null && dtoAttributDefinition.EnumDefinition == null)
                                    {
                                        if (dtoAttributDefinition.Value != null)
                                        {
                                            value = dtoAttributDefinition.Value.ToString();
                                        }
                                    }
                                    else
                                    {
                                        value = ExtensionsClass.GetEnumDefinitionValue(dtoAttributDefinition) as string;
                                    }

                                    definitionValue = ExtensionsClass.DtoAttributDefinitionToString(dtoAttributDefinition, _dtoAttributDefinitionProperties);

                                    header = string.Format("{0} : {1}", dtoAttributDefinition.Name, value);
                                }
                            }
                        }

                        attributeTreeViewItem.Header = header;

                        if (!string.IsNullOrEmpty(definitionValue))
                        {
                            attributeTreeViewItem.ToolTip = definitionValue;
                        }

                        if ((dtoAttributDefinition != null && dtoAttributDefinition.IsInternal != true) || dtoAttributDefinition == null)
                        {
                            groupTreeViewItem.Items.Add(attributeTreeViewItem);
                        }
                    }
                }

                ExtensionsClass.ExpandTreeViewItem(rootTreeViewItem);
                AttributeTreeView.InvalidateVisual();

                ScrollViewer scrollViewer = ExtensionsClass.GetTypeObject(AttributeTreeView, typeof(ScrollViewer)) as ScrollViewer;
                if (scrollViewer != null)
                {
                    scrollViewer.ScrollToHome();
                }

                HasTreeViewItems = rootTreeViewItem.Items.Count > 0;
            }
            else
            {
                MessageBoxHelper.ShowInformation("No objects available.", _parentWindow);
            }
        }