Exemplo n.º 1
0
        private void MiCreateClass_Click(object sender, EventArgs e)
        {
            WorkAsyncInfo wai = new WorkAsyncInfo
            {
                Message = "Building class...",
                Work    = (worker, args) =>
                {
                    args.Result = EntityTools.CreateEntityClass(Service, worker, dgvMain.SelectedRows[0].Cells[0].Value.ToString());
                },
                ProgressChanged  = ProgressChanged,
                PostWorkCallBack = NewResultsAvailable,
                AsyncArgument    = null,
                MessageHeight    = 150,
                MessageWidth     = 340
            };

            WorkAsync(wai);
        }
Exemplo n.º 2
0
        private void MiAnalyzeEntity_Click(object sender, EventArgs e)
        {
            string entityLogicalName = dgvMain.SelectedRows[0].Cells[0].Value.ToString();

            WorkAsyncInfo wai = new WorkAsyncInfo
            {
                Message = "Analyzing Entity " + entityLogicalName,
                Work    = (worker, args) =>
                {
                    args.Result = EntityTools.AnalyzeEntity(Service, worker, entityLogicalName);
                },
                ProgressChanged  = ProgressChanged,
                PostWorkCallBack = NewResultsAvailable,
                AsyncArgument    = null,
                MessageHeight    = 150,
                MessageWidth     = 340,
            };

            WorkAsync(wai);
        }
Exemplo n.º 3
0
        internal static Result GetEntityResult(IOrganizationService service, Dictionary <string, string> cache, string entityLogicalName, BackgroundWorker worker)
        {
            Result retVal = new Result();

            retVal.DataType = Result.ResultType.Entity;
            retVal.Key      = entityLogicalName;

            RetrieveEntityRequest request = new RetrieveEntityRequest()
            {
                EntityFilters         = EntityFilters.Attributes | EntityFilters.Relationships,
                RetrieveAsIfPublished = true,
                LogicalName           = entityLogicalName
            };
            RetrieveEntityResponse response = (RetrieveEntityResponse)service.Execute(request);

            #region attributes
            retVal.Header            = "Entity " + entityLogicalName;
            retVal.EntityLogicalName = entityLogicalName;

            retVal.FromCache = cache.ContainsKey(entityLogicalName);
            if (retVal.FromCache)
            {
                EntityTools.LoadFromCache(retVal, cache[entityLogicalName]);
                retVal.Data.Tables[0].DefaultView.Sort = "Key ASC";
            }
            else
            {
                retVal.Data = new DataSet();
                DataTable Data = new DataTable(entityLogicalName);
                retVal.Data.Tables.Add(Data);
                Data.Columns.AddRange(
                    new DataColumn[] {
                    new DataColumn("Key", typeof(string)),
                    new DataColumn("Logical Name", typeof(string)),
                    new DataColumn("Display Name", typeof(string)),
                    new DataColumn("Required", typeof(string)),
                    new DataColumn("Data Type", typeof(string)),
                    new DataColumn("Metadata", typeof(string))
                });
                Data.PrimaryKey = new DataColumn[] { Data.Columns["Key"] };



                int pos = 1;
                int max = response.EntityMetadata.Attributes.Count();

                string primaryKey = entityLogicalName + "id";
                foreach (AttributeMetadata am in response.EntityMetadata.Attributes)
                {
                    if (am.DisplayName.LocalizedLabels.Count > 0)
                    {
                        DataRow newDR = Data.NewRow();
                        newDR["Key"]          = am.LogicalName;
                        newDR["Display Name"] = am.DisplayName.LocalizedLabels[0].Label;
                        newDR["Logical Name"] = am.LogicalName;
                        newDR["Data Type"]    = am.AttributeType.ToString();
                        switch (am.RequiredLevel.Value)
                        {
                        case AttributeRequiredLevel.None: newDR["Required"] = string.Empty; break;

                        case AttributeRequiredLevel.SystemRequired: newDR["Required"] = "Req'd"; break;

                        case AttributeRequiredLevel.ApplicationRequired: newDR["Required"] = "Req'd"; break;

                        case AttributeRequiredLevel.Recommended: newDR["Required"] = string.Empty; break;

                        //case AttributeRequiredLevel.Recommended: newDR["Required"] = "Rec'd"; break;
                        default:
                            break;
                        }
                        switch (am.AttributeType.ToString())
                        {
                        case "Lookup":
                            RetrieveAttributeRequest rar = new RetrieveAttributeRequest()
                            {
                                EntityLogicalName     = entityLogicalName,
                                LogicalName           = am.LogicalName,
                                RetrieveAsIfPublished = true
                            };
                            RetrieveAttributeResponse rarr = (RetrieveAttributeResponse)service.Execute(rar);
                            newDR["Metadata"] = string.Join(", ", ((LookupAttributeMetadata)rarr.AttributeMetadata).Targets);
                            break;

                        case "Picklist":
                            RetrieveAttributeRequest rarpl = new RetrieveAttributeRequest()
                            {
                                EntityLogicalName     = entityLogicalName,
                                LogicalName           = am.LogicalName,
                                RetrieveAsIfPublished = true
                            };
                            RetrieveAttributeResponse rarplr = (RetrieveAttributeResponse)service.Execute(rarpl);
                            newDR["Metadata"] = ((PicklistAttributeMetadata)rarplr.AttributeMetadata).OptionSet.Name;
                            break;

                        default:
                            newDR["Metadata"] = string.Empty;
                            break;
                        }
                        Data.Rows.Add(newDR);

                        worker.ReportProgress((int)(100 * ((double)pos++ / (double)max)));
                    }
                    Data.DefaultView.Sort = "Key ASC";
                }

                if (cache.ContainsKey(entityLogicalName))
                {
                    cache.Remove(entityLogicalName);
                }
                cache[entityLogicalName] = DSToSerial(retVal.Data);
            }
            #endregion

            #region relationships
            DataTable relationships = new DataTable("Relationships");
            retVal.Data.Tables.Add(relationships);
            relationships.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("key", typeof(string)),
                new DataColumn("Type", typeof(string)),
                new DataColumn("From Attribute", typeof(string)),
                new DataColumn("To Entity", typeof(string)),
                new DataColumn("To Attribute", typeof(string)),
            });

            DataRow ndr;
            foreach (OneToManyRelationshipMetadata x in response.EntityMetadata.OneToManyRelationships)
            {
                ndr                   = relationships.NewRow();
                ndr["key"]            = x.SchemaName;
                ndr["Type"]           = "M:1";
                ndr["From Attribute"] = x.ReferencedAttribute;
                ndr["To Entity"]      = x.ReferencingEntity;
                ndr["To Attribute"]   = x.ReferencingAttribute;
                relationships.Rows.Add(ndr);
            }
            foreach (OneToManyRelationshipMetadata x in response.EntityMetadata.ManyToOneRelationships)
            {
                ndr                   = relationships.NewRow();
                ndr["key"]            = x.SchemaName;
                ndr["Type"]           = "1:M";
                ndr["From Attribute"] = x.ReferencingAttribute;
                ndr["To Entity"]      = x.ReferencedEntity;
                ndr["To Attribute"]   = x.ReferencedAttribute;
                relationships.Rows.Add(ndr);
            }
            foreach (ManyToManyRelationshipMetadata x in response.EntityMetadata.ManyToManyRelationships)
            {
                ndr                   = relationships.NewRow();
                ndr["key"]            = x.SchemaName;
                ndr["Type"]           = "M:M";
                ndr["From Attribute"] = null;
                ndr["To Entity"]      = x.Entity1LogicalName == entityLogicalName ? x.Entity2LogicalName : x.Entity1LogicalName;
                ndr["To Attribute"]   = null;
                relationships.Rows.Add(ndr);
            }

            #endregion

            return(retVal);
        }