private void LoadScripts(EntityMetadata emd)
        {
            var qba = new QueryByAttribute("systemform");

            qba.Attributes.Add("objecttypecode");
            // ReSharper disable once PossibleInvalidOperationException
            qba.Values.Add(emd.ObjectTypeCode.Value);
            qba.ColumnSet = new ColumnSet(true);

            foreach (var form in service.RetrieveMultiple(qba).Entities)
            {
                var doc = new XmlDocument();
                doc.LoadXml(form["formxml"].ToString());

                foreach (XmlNode eventNode in doc.SelectNodes("//event"))
                {
                    string eventName = eventNode.Attributes["name"].Value;

                    foreach (XmlNode handlerNode in eventNode.SelectNodes("Handlers/Handler"))
                    {
                        var script = new Script();
                        script.EntityLogicalName    = emd.LogicalName;
                        script.EntityName           = emd.DisplayName.UserLocalizedLabel.Label;
                        script.ScriptLocation       = handlerNode.Attributes["libraryName"].Value;
                        script.MethodCalled         = handlerNode.Attributes["functionName"].Value;
                        script.IsActive             = handlerNode.Attributes["enabled"].Value == "true";
                        script.PassExecutionContext = handlerNode.Attributes["passExecutionContext"]?.Value == "true";
                        script.Event     = eventName;
                        script.Arguments = handlerNode.Attributes["parameters"] != null ? handlerNode.Attributes["parameters"].Value : "";
                        script.Type      = "Form event";

                        if (eventName == "onchange")
                        {
                            var amd = emd.Attributes.FirstOrDefault(x => eventNode.Attributes != null && x.LogicalName == eventNode.Attributes["attribute"].Value);

                            if (amd != null)
                            {
                                var displayName = amd.DisplayName != null && amd.DisplayName.UserLocalizedLabel != null
                                    ? amd.DisplayName.UserLocalizedLabel.Label
                                    : "(" + amd.LogicalName + ")";

                                script.Attribute            = displayName;
                                script.AttributeLogicalName = amd.LogicalName;
                            }
                            else if (eventNode.Attributes["control"] == null)
                            {
                                script.Attribute            = eventNode.Attributes["attribute"].Value;
                                script.AttributeLogicalName = eventNode.Attributes["attribute"].Value;
                                script.HasProblem           = true;
                            }
                            else
                            {
                                XmlNode node             = doc.SelectSingleNode("//control[@id='" + eventNode.Attributes["control"].Value + "']");
                                XmlNode targetEntityNode = node.SelectSingleNode("parameters/TargetEntityType");

                                amd = emds.First(e => e.LogicalName == targetEntityNode.InnerText).Attributes.First(x => x.LogicalName == eventNode.Attributes["attribute"].Value);
                                var displayName = amd.DisplayName != null && amd.DisplayName.UserLocalizedLabel != null
                                   ? amd.DisplayName.UserLocalizedLabel.Label
                                   : "(" + amd.LogicalName + ")";

                                script.Attribute            = displayName;
                                script.AttributeLogicalName = amd.LogicalName;
                            }

                            if (eventNode.Attributes["control"] != null)
                            {
                                var control = eventNode.Attributes["control"].Value;

                                XmlNode node = doc.SelectSingleNode("//control[@id='" + control + "']");

                                var labelNode = node.ParentNode.SelectSingleNode("labels/label[@languagecode='" + userLcid + "']");
                                if (labelNode == null)
                                {
                                    labelNode = node.ParentNode.SelectSingleNode("labels/label");
                                }

                                var label = labelNode.Attributes["description"].Value;

                                script.Type                 = "Subgrid event";
                                script.Attribute            = string.Format("{0} / {1}", label, script.Attribute);
                                script.AttributeLogicalName = string.Format("{0} / {1}", control, script.AttributeLogicalName);
                            }
                        }
                        else if (eventName == "onrecordselect")
                        {
                            var control = eventNode.Attributes["control"].Value;

                            XmlNode node  = doc.SelectSingleNode("//control[@id='" + control + "']");
                            var     label = node.ParentNode.SelectSingleNode("labels/label[@languagecode='1036']").Attributes[
                                "description"].Value;

                            script.Type                 = "Subgrid event";
                            script.Attribute            = label;
                            script.AttributeLogicalName = control;
                        }
                        else if (eventName == "onsave")
                        {
                            if (eventNode.Attributes["control"] != null)
                            {
                                var control = eventNode.Attributes["control"].Value;

                                XmlNode node  = doc.SelectSingleNode("//control[@id='" + control + "']");
                                var     label = node.ParentNode.SelectSingleNode("labels/label[@languagecode='1036']").Attributes[
                                    "description"].Value;

                                script.Type                 = "Subgrid event";
                                script.Attribute            = label;
                                script.AttributeLogicalName = control;
                            }
                        }
                        else
                        {
                            script.Attribute            = "";
                            script.AttributeLogicalName = "";
                        }
                        script.Name = form["name"].ToString();

                        Scripts.Add(script);
                    }
                }

                foreach (XmlNode libraryNode in doc.SelectNodes("//Library"))
                {
                    var script = new Script();
                    script.EntityLogicalName    = emd.LogicalName;
                    script.EntityName           = emd.DisplayName.UserLocalizedLabel.Label;
                    script.ScriptLocation       = libraryNode.Attributes["name"].Value;
                    script.MethodCalled         = string.Empty;
                    script.Event                = string.Empty;
                    script.Attribute            = string.Empty;
                    script.AttributeLogicalName = string.Empty;
                    script.Name = form["name"].ToString();
                    script.Type = "Form Library";

                    Scripts.Add(script);
                }
            }
        }
예제 #2
0
        public void LoadFls()
        {
            WorkAsync("Loading Field Security profiles...",
                      (w, e) =>
            {
                var flsManager = new FlsManager(Service);
                profiles       = flsManager.LoadSecureProfiles();

                w.ReportProgress(0, "Loading Secured fields...");
                fields = flsManager.LoadSecureFields();

                var dico = new Dictionary <string, List <string> >();

                foreach (var field in fields)
                {
                    if (!dico.ContainsKey(field.Entity))
                    {
                        dico.Add(field.Entity, new List <string>());
                    }

                    if (!dico[field.Entity].Contains(field.Attribute))
                    {
                        dico[field.Entity].Add(field.Attribute);
                    }
                }

                metadata = MetadataHelper.LoadMetadata(dico, Service);
            },
                      e =>
            {
                var fieldsList   = new List <ListViewItem>();
                var profilesList = new List <ListViewItem>();

                foreach (var field in fields)
                {
                    var entityDislayName =
                        metadata.First(m => m.LogicalName == field.Entity).DisplayName.UserLocalizedLabel.Label;
                    var attributeDisplayName =
                        metadata.First(m => m.LogicalName == field.Entity)
                        .Attributes.First(a => a.LogicalName == field.Attribute)
                        .DisplayName.UserLocalizedLabel.Label;

                    var item = new ListViewItem(attributeDisplayName);
                    item.SubItems.Add(field.Attribute);
                    item.SubItems.Add(entityDislayName);
                    item.SubItems.Add(field.Entity);
                    item.SubItems.Add(string.Empty);
                    item.SubItems.Add(string.Empty);
                    item.SubItems.Add(string.Empty);
                    fieldsList.Add(item);
                }

                foreach (var profile in profiles)
                {
                    var item = new ListViewItem(profile.GetAttributeValue <string>("name"))
                    {
                        Tag = profile
                    };
                    profilesList.Add(item);
                }

                lvFlsRoles.Items.Clear();
                LvSecuredAttributes.Items.Clear();

                lvFlsRoles.Items.AddRange(profilesList.ToArray());
                LvSecuredAttributes.Items.AddRange(fieldsList.ToArray());
            },
                      e => SetWorkingMessage(e.UserState.ToString()));
        }