Exemple #1
0
        protected virtual void AddEntityAssocationSetServiceReferenceForWebLinkSet(IEditableCrmEntityControl control, Entity entity, Relationship relationship, Control container)
        {
            var serviceBaseUri = string.IsNullOrEmpty(control.CmsServiceBaseUri) ? PortalCrmConfigurationManager.GetCmsServiceBaseUri(PortalName) : control.CmsServiceBaseUri;
            var context        = PortalCrmConfigurationManager.GetServiceContext(PortalName);

            var serviceUri = context.GetType().GetCrmEntitySetDataServiceUri("adx_weblink", serviceBaseUri, "adx_weblinksetid", entity.Id);

            AddServiceReference(control, serviceUri, "xrm-entity-{0}-ref".FormatWith(relationship.ToSchemaName("_")), container);
        }
Exemple #2
0
        public virtual void AddEntityMetadata(string portalName, IEditableCrmEntityControl control, Control container, Entity entity)
        {
            if (control == null || container == null || entity == null)
            {
                return;
            }

            if (entity.LogicalName == "adx_weblinkset")
            {
                // Output the service reference for the web link set itself.
                AddEntityServiceReference(control, entity, entity.GetAttributeValue <string>("adx_name"), container);

                // Output the service reference for the child web links of the set.
                AddEntityAssocationSetServiceReferenceForWebLinkSet(control, entity, "adx_weblinkset_weblink".ToRelationship(), container);
                AddEntityAssocationSetServiceReference(portalName, control, entity, "adx_weblinkset_weblink".ToRelationship(), container, "xrm-entity-{0}-update-ref");
                AddEntitySetSchemaMap(control, "adx_weblink", container);

                // Output the service reference and schema map for site web pages (required to create new web links).
                AddEntitySetServiceReference(control, "adx_webpage", container);
                AddEntitySetSchemaMap(control, "adx_webpage", container);

                string weblinkDeleteUriTemplate;

                if (TryGetCrmEntityDeleteDataServiceUriTemplate(control, "adx_weblink", out weblinkDeleteUriTemplate))
                {
                    AddServiceReference(control, weblinkDeleteUriTemplate, "xrm-uri-template xrm-entity-adx_weblink-delete-ref", container);
                }

                return;
            }

            string serviceUri;

            if (!TryGetDataServiceEntityUri(control, entity, out serviceUri))
            {
                return;
            }

            // Add the service reference to the bound entity.
            container.Controls.Add(new HyperLink {
                CssClass = "xrm-entity-ref", NavigateUrl = VirtualPathUtility.ToAbsolute(serviceUri), Text = string.Empty
            });

            string entityUrlServiceUri;

            // Add the service reference for getting the URL of the bound entity.
            if (TryGetCrmEntityUrlDataServiceUri(control, entity, out entityUrlServiceUri))
            {
                AddServiceReference(control, entityUrlServiceUri, "xrm-entity-url-ref", container, "GetEntityUrl");
            }

            var crmEntityName = entity.LogicalName;

            AddEntitySetSchemaMap(control, crmEntityName, container);

            // If the entity is "deletable", add a service reference for soft-delete of the entity.
            if (DeletableEntityNames.Contains(crmEntityName))
            {
                string deleteServiceUri;

                if (TryGetCrmEntityDeleteDataServiceUri(control, entity, out deleteServiceUri))
                {
                    AddServiceReference(control, deleteServiceUri, "xrm-entity-delete-ref", container);
                }
            }

            if (FileAttachmentEntityNames.Contains(crmEntityName))
            {
                string fileAttachmentServiceUri;

                if (TryGetCrmEntityFileAttachmentDataServiceUri(control, entity, out fileAttachmentServiceUri))
                {
                    AddServiceReference(control, fileAttachmentServiceUri, "xrm-entity-attachment-ref", container);
                }
            }

            // Add the service references on which the creation of various entities are dependent.
            foreach (var dependencyEntityName in DependencyEntityNames)
            {
                AddEntitySetServiceReference(control, dependencyEntityName, container);
                AddEntitySetSchemaMap(control, dependencyEntityName, container);
            }

            // Add the service reference URI Templates for the notes associated with given entity types.
            foreach (var fileAttachmentEntity in FileAttachmentEntityNames)
            {
                string uriTemplate;

                if (TryGetCrmEntityFileAttachmentDataServiceUriTemplate(control, fileAttachmentEntity, out uriTemplate))
                {
                    AddServiceReference(control, uriTemplate, "xrm-uri-template xrm-entity-{0}-attachment-ref".FormatWith(fileAttachmentEntity), container);
                }
            }

            // Add the service reference URI Templates for getting URLs for specific entity types.
            foreach (var urlEntityName in UrlEntityNames)
            {
                string uriTemplate;

                if (TryGetCrmEntityUrlDataServiceUriTemplate(control, urlEntityName, out uriTemplate))
                {
                    AddServiceReference(control, uriTemplate, "xrm-uri-template xrm-entity-{0}-url-ref".FormatWith(urlEntityName), container, "GetEntityUrl");
                }
            }

            IEnumerable <Relationship> childAssociations;

            if (ChildAssociationsByEntityName.TryGetValue(crmEntityName, out childAssociations))
            {
                foreach (var childAssociation in childAssociations)
                {
                    AddEntityAssocationSetServiceReference(portalName, control, entity, childAssociation, container);
                }
            }

            Relationship parentalRelationship;

            // Output the URL path of parent entity to the DOM (mostly to be read if the entity is deleted--the user
            // will then be redirected to the parent).
            if (_parentalRelationshipsByEntityName.TryGetValue(crmEntityName, out parentalRelationship))
            {
                var context = PortalCrmConfigurationManager.GetServiceContext(PortalName);
                entity = context.MergeClone(entity);

                var parent = entity.GetRelatedEntity(context, parentalRelationship);

                var dependencyProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName);

                if (dependencyProvider == null)
                {
                    throw new InvalidOperationException("Unable to create {0} for current portal configuration.".FormatWith(typeof(IDependencyProvider).FullName));
                }

                var urlProvider = dependencyProvider.GetDependency <IEntityUrlProvider>();

                if (urlProvider == null)
                {
                    throw new InvalidOperationException("Unable to create {0} for current portal configuration.".FormatWith(typeof(IEntityUrlProvider).FullName));
                }

                var parentPath = urlProvider.GetApplicationPath(context, parent ?? entity);

                if (parentPath != null)
                {
                    AddServiceReference(control, parentPath.AbsolutePath, "xrm-entity-parent-url-ref", container);
                }
            }

            // Output the sitemarkers of the current web page into the DOM.
            if (crmEntityName == "adx_webpage")
            {
                var context = PortalCrmConfigurationManager.GetServiceContext(PortalName);
                entity = context.MergeClone(entity);

                foreach (var siteMarker in entity.GetRelatedEntities(context, "adx_webpage_sitemarker"))
                {
                    var siteMarkerRef = new HtmlGenericControl("span");

                    siteMarkerRef.Attributes["class"] = "xrm-entity-adx_webpage_sitemarker";
                    siteMarkerRef.Attributes["title"] = siteMarker.GetAttributeValue <string>("adx_name");

                    container.Controls.Add(siteMarkerRef);
                }

                AddEntitySetSchemaMap(control, "adx_webfile", container);
            }
        }