コード例 #1
0
        public override object BeforeMethod(string method)
        {
            if (method == null)
            {
                return(null);
            }

            if (string.Equals(method, "logicalname", StringComparison.OrdinalIgnoreCase))
            {
                return(LogicalName);
            }

            Guid id;

            if (!Guid.TryParse(method, out id))
            {
                return(null);
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                try
                {
                    var entity = serviceContext.RetrieveSingle(new EntityReference(this.LogicalName, id), new ColumnSet(true));

                    EntityDrop entityDrop = (entity == null) ? null : new EntityDrop(this, entity);
                    return((entityDrop != null && entityDrop.Permissions.CanRead) ? entityDrop : null);
                }
                catch (FaultException <OrganizationServiceFault> )
                {
                    return(null);
                }
            }
        }
コード例 #2
0
        private string GetLayouts(Entity entityList)
        {
            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Getting Entity List For: {0}, entityId: {1}", entityList.LogicalName, entityList.Id));

            var viewConfigurations =
                GetEntityViews()
                .Select(
                    view =>
                    new ViewConfiguration(PortalViewContext.CreatePortalContext(),
                                          PortalViewContext.CreateServiceContext(), entityList, EntityLogicalName, PrimaryKeyName,
                                          view.Id, GridMetadataConfiguration, PortalViewContext.PortalName, LanguageCode,
                                          EnableEntityPermissions, "page", "filter", "query", "sort", "My", 20, "mf", null, null, null, null, null, view.DisplayName))
                .ToList();

            var layouts =
                viewConfigurations.Select(c =>
            {
                try
                {
                    return(new ViewLayout(c, null, PortalViewContext.PortalName, LanguageCode, false,
                                          (c.ItemActionLinks != null && c.ItemActionLinks.Any())));
                }
                catch (SavedQueryNotFoundException ex)
                {
                    ADXTrace.Instance.TraceWarning(TraceCategory.Application, ex.Message);
                    return(null);
                }
            }).Where(l => l != null);


            return(JsonConvert.SerializeObject(layouts));
        }
コード例 #3
0
        private EntityMetadata GetEntityMetadata()
        {
            var cacheKey = "liquid:entitymetadata:{0}".FormatWith(EntityReference.LogicalName);

            object cached;

            if (Html.ViewContext.TempData.TryGetValue(cacheKey, out cached) && cached is EntityMetadata)
            {
                return(cached as EntityMetadata);
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var response = (RetrieveEntityResponse)serviceContext.Execute(new RetrieveEntityRequest
                {
                    LogicalName   = LogicalName,
                    EntityFilters = EntityFilters.Entity | EntityFilters.Attributes | EntityFilters.Relationships
                });

                var entityMetadata = response.EntityMetadata;

                Html.ViewContext.TempData[cacheKey] = entityMetadata;

                return(entityMetadata);
            }
        }
コード例 #4
0
        private Entity GetEntity()
        {
            var cacheKey = "liquid:entity:{0}:{1}".FormatWith(EntityReference.LogicalName, EntityReference.Id);

            object cached;

            if (Html.ViewContext.TempData.TryGetValue(cacheKey, out cached) && cached is Entity)
            {
                return(cached as Entity);
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var response = (RetrieveResponse)serviceContext.Execute(new RetrieveRequest
                {
                    ColumnSet = new ColumnSet(true),
                    Target    = EntityReference
                });

                var entity = response.Entity;

                Html.ViewContext.TempData[cacheKey] = entity;

                return(entity);
            }
        }
コード例 #5
0
        public IEnumerable <TemplateFileInfo> GetTemplateFiles()
        {
            var website = PortalViewContext.Website.EntityReference;

            var fetch = new Fetch
            {
                Entity = new FetchEntity(EntityLogicalName, new[] { NameAttributeLogicalName })
                {
                    Filters = new []
                    {
                        new Filter
                        {
                            Type       = LogicalOperator.And,
                            Conditions = new []
                            {
                                new Condition("statecode", ConditionOperator.Equal, 0),
                                new Condition("adx_websiteid", ConditionOperator.Equal, website.Id)
                            }
                        }
                    },
                    Orders = new []
                    {
                        new Order(NameAttributeLogicalName, OrderType.Ascending),
                    }
                }
            };

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var response = (RetrieveMultipleResponse)serviceContext.Execute(fetch.ToRetrieveMultipleRequest());

                return(response.EntityCollection.Entities
                       .Select(e => new TemplateFileInfo(e.GetAttributeValue <string>(NameAttributeLogicalName))));
            }
        }
コード例 #6
0
        private EntityListViewDrop[] GetViews()
        {
            if (ViewMetadataConfiguration == null)
            {
                return((Entity.GetAttributeValue <string>("adx_view") ?? string.Empty).Split(',').Select(e =>
                {
                    Guid parsed;
                    return Guid.TryParse(e.Trim(), out parsed) ? new Guid?(parsed) : null;
                }).Where(e => e.HasValue).Select(e =>
                {
                    try
                    {
                        return new EntityView(PortalViewContext.CreateServiceContext(), e.Value, LanguageCode);
                    }
                    catch
                    {
                        return null;
                    }
                }).Where(e => e != null).Select(e => new EntityListViewDrop(this, e)).ToArray());
            }

            return
                (ViewMetadataConfiguration.Views.Select(e =>
            {
                try
                {
                    return new EntityView(PortalViewContext.CreateServiceContext(), e.ViewId, LanguageCode,
                                          e.DisplayName != null ? Localization.GetLocalizedString(e.DisplayName, LanguageCode) : null);
                }
                catch
                {
                    return null;
                }
            }).Where(e => e != null).Select(e => new EntityListViewDrop(this, e)).ToArray());
        }
コード例 #7
0
        private bool TryAssert(CrmEntityRight right)
        {
            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var attachedEntity = serviceContext.MergeClone(Entity);

                return(PortalViewContext.CreateCrmEntitySecurityProvider().TryAssert(serviceContext, attachedEntity, right));
            }
        }
コード例 #8
0
        private string[] GetRoleKeysForUser()
        {
            var userRoles = _roles.Value;

            if (!userRoles.Any())
            {
                return(new string[] { });
            }

            var serviceContext = PortalViewContext.CreateServiceContext();

            var entityMetadata = serviceContext.GetEntityMetadata("adx_webrole", EntityFilters.Attributes);

            // Must check if new attribute exists to maintain compatability with previous schema versions and prevent runtime
            // exceptions when portal code updates are pushed to web apps where new solutions have not yet been applied.
            if (entityMetadata == null || entityMetadata.Attributes == null ||
                !entityMetadata.Attributes.Select(a => a.LogicalName).Contains("adx_key"))
            {
                return(new string[] { });
            }

            var fetch = new Fetch
            {
                Entity = new FetchEntity("adx_webrole")
                {
                    Attributes = new List <FetchAttribute> {
                        new FetchAttribute("adx_key"), new FetchAttribute("adx_name")
                    },
                    Filters = new List <Filter>
                    {
                        new Filter
                        {
                            Type    = LogicalOperator.And,
                            Filters = new List <Filter>
                            {
                                new Filter
                                {
                                    Type       = LogicalOperator.Or,
                                    Conditions = userRoles.Select(role => new Condition("adx_name", ConditionOperator.Equal, role)).ToList()
                                }
                            }
                        }
                    }
                }
            };

            var response = (RetrieveMultipleResponse)serviceContext.Execute(fetch.ToRetrieveMultipleRequest());

            if (response == null || !response.EntityCollection.Entities.Any())
            {
                return(new string[] { });
            }

            var keys = response.EntityCollection.Entities.Where(e => e.Attributes.Contains("adx_key")).Select(e => e.Attributes["adx_key"].ToString()).ToArray();

            return(keys);
        }
コード例 #9
0
        private EntityDrop GetRelatedEntity(Relationship relationship)
        {
            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var clone = serviceContext.MergeClone(Entity);

                var entity = serviceContext.RetrieveRelatedEntity(clone, relationship);

                return(this.CreateEntityDropWithPermission(entity));
            }
        }
コード例 #10
0
        private EntityNoteDrop[] GetNotes()
        {
            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var filter = new FilterExpression(LogicalOperator.And);

                filter.AddCondition("objecttypecode", ConditionOperator.Equal, EntityReference.LogicalName);
                filter.AddCondition("objectid", ConditionOperator.Equal, EntityReference.Id);

                var query = new QueryExpression("annotation")
                {
                    // When we get notes, we want to get most attributes, but NOT documentbody, to avoid having
                    // to load large file contents. We want people to use the handler URL on the note drop if
                    // possible. If not, the note drop can lazy-load the documentbody attribute if requested.
                    ColumnSet = new ColumnSet(new[]
                    {
                        "annotationid",
                        "createdby",
                        "createdon",
                        "createdonbehalfby",
                        "filename",
                        "filesize",
                        "isdocument",
                        "langid",
                        "mimetype",
                        "modifiedby",
                        "modifiedon",
                        "modifiedonbehalfby",
                        "notetext",
                        "objectid",
                        "objecttypecode",
                        "ownerid",
                        "owningbusinessunit",
                        "owningteam",
                        "owninguser",
                        "stepid",
                        "subject",
                        "versionnumber"
                    }),
                    Criteria = filter
                };

                query.AddOrder("createdon", OrderType.Ascending);

                var response = (RetrieveMultipleResponse)serviceContext.Execute(new RetrieveMultipleRequest
                {
                    Query = query
                });

                return(response.EntityCollection.Entities
                       .Select(e => new EntityNoteDrop(this, e)).ToArray());
            }
        }
コード例 #11
0
        private string GetDocumentBody()
        {
            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var response = (RetrieveResponse)serviceContext.Execute(new RetrieveRequest
                {
                    Target    = EntityReference,
                    ColumnSet = new ColumnSet("documentbody")
                });

                return(response.Entity.GetAttributeValue <string>("documentbody"));
            }
        }
コード例 #12
0
        private EntityDrop[] GetRelatedEntities(Relationship relationship)
        {
            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var clone = serviceContext.MergeClone(Entity);

                var drops = serviceContext.RetrieveRelatedEntities(clone, relationship).Entities
                            .Select(e => this.CreateEntityDropWithPermission(e))
                            .ToArray();

                return(drops);
            }
        }
コード例 #13
0
        private EntityCollectionDrop GetResults()
        {
            if (_permissionRightResult != null && !(_permissionRightResult.GlobalPermissionGranted || _permissionRightResult.PermissionGranted))
            {
                return(new EntityCollectionDrop(this, new EntityCollection()));
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var response = (RetrieveMultipleResponse)serviceContext.Execute(_fetch.Value.ToRetrieveMultipleRequest());

                return(new EntityCollectionDrop(this, response.EntityCollection));
            }
        }
コード例 #14
0
        private string GetUrl()
        {
            if (FullEntity == null)
            {
                return(null);
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var clone = serviceContext.MergeClone(FullEntity);

                return(PortalViewContext.UrlProvider.GetUrl(serviceContext, clone));
            }
        }
コード例 #15
0
 private string GetLabel()
 {
     try
     {
         using (var serviceContext = PortalViewContext.CreateServiceContext())
         {
             return(_languageCode != null && _languageCode.Value != 0
                                         ? serviceContext.GetOptionSetValueLabel(_entityLogicalName, _attributeLogicalName, _value.Value, _languageCode.Value)
                                         : serviceContext.GetOptionSetValueLabel(_entityLogicalName, _attributeLogicalName, _value.Value));
         }
     }
     catch
     {
         return(null);
     }
 }
コード例 #16
0
        public bool TryReadTemplateFile(string templateName, out string template)
        {
            var website = PortalViewContext.Website.EntityReference;

            var fetch = new Fetch
            {
                PageSize = 1,
                Entity   = new FetchEntity(EntityLogicalName, new[] { SourceAttributeLogicalName })
                {
                    Filters = new []
                    {
                        new Filter
                        {
                            Type       = LogicalOperator.And,
                            Conditions = new []
                            {
                                new Condition("statecode", ConditionOperator.Equal, 0),
                                new Condition("adx_websiteid", ConditionOperator.Equal, website.Id),
                                new Condition(NameAttributeLogicalName, ConditionOperator.Equal, templateName)
                            }
                        }
                    }
                }
            };

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var response = (RetrieveMultipleResponse)serviceContext.Execute(fetch.ToRetrieveMultipleRequest());
                var entity   = response.EntityCollection.Entities.FirstOrDefault();

                if (entity == null)
                {
                    template = null;

                    return(false);
                }

                template = entity.GetAttributeValue <string>(SourceAttributeLogicalName) ?? string.Empty;

                return(true);
            }
        }
コード例 #17
0
        public virtual string GetEditable(Context context, string key, EditableOptions options)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var attachedEntity   = serviceContext.MergeClone(Entity.Attributes.ContainsKey(key) ? Entity : FullEntity);
                var portalViewEntity = PortalViewContext.GetEntity(serviceContext, attachedEntity);

                IHtmlString html = null;

                context.Stack(() =>
                {
                    html = Html.AttributeInternal(
                        portalViewEntity.GetAttribute(key),
                        options.Type ?? "html",
                        options.Title,
                        options.Escape.GetValueOrDefault(false),
                        options.Tag ?? "div",
                        options.CssClass,
                        options.Liquid.GetValueOrDefault(true),
                        context,
                        options.Default);
                });

                return(html == null ? null : html.ToString());
            }
        }
コード例 #18
0
        private EntityPermissionsDrop GetPermissions()
        {
            if (!AdxstudioCrmConfigurationManager.GetCrmSection().ContentMap.Enabled)
            {
                return(null);
            }

            if (FullEntity == null)
            {
                return(null);
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                var clone = serviceContext.MergeClone(FullEntity);

                var permissionResult = new CrmEntityPermissionProvider(PortalViewContext.PortalName)
                                       .TryAssert(serviceContext, clone);

                return(permissionResult == null
                                        ? null
                                        : new EntityPermissionsDrop(permissionResult));
            }
        }
コード例 #19
0
        public override object BeforeMethod(string method)
        {
            if (method == null)
            {
                return(null);
            }

            using (var serviceContext = PortalViewContext.CreateServiceContext())
            {
                try
                {
                    Entity location;

                    Guid id;

                    if (!Guid.TryParse(method, out id))
                    {
                        return(null);
                    }

                    if (!string.IsNullOrWhiteSpace(_folderName))
                    {
                        // Get documents based on provided folder name.

                        var entity = new Entity(LogicalName)
                        {
                            Id = id
                        };

                        location = GetDocumentLocation(serviceContext, entity, _folderName);
                    }
                    else
                    {
                        // Get documents based on "primary attribute_id" folder.

                        var metadata = serviceContext.GetEntityMetadata(LogicalName, EntityFilters.Attributes);

                        location = GetDocumentLocation(serviceContext, metadata, id);
                    }

                    if (location == null)
                    {
                        return(null);
                    }

                    var crmEntityPermissionProvider = new CrmEntityPermissionProvider();

                    if (!crmEntityPermissionProvider.TryAssert(serviceContext, CrmEntityPermissionRight.Read, location))
                    {
                        ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Permission Denied. You do not have the appropriate Entity Permissions to Read document locations.");

                        return(null);
                    }

                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Read SharePoint Document Location Permission Granted.");

                    var spConnection = new SharePointConnection("SharePoint");

                    var factory = new ClientFactory();

                    using (var client = factory.CreateClientContext(spConnection))
                    {
                        // retrieve the SharePoint list and folder names for the document location
                        string listName, folderName;

                        serviceContext.GetDocumentLocationListAndFolder(location, out listName, out folderName);

                        var folder = client.AddOrGetExistingFolder(listName, folderName);

                        var fileCollection = folder.Files;
                        client.Load(folder.Files);
                        client.ExecuteQuery();

                        var files = fileCollection.ToArray().OrderBy(file => file.Name);

                        if (!files.Any())
                        {
                            return(null);
                        }

                        return(files.Select(file => new SharePointDocumentDrop(this, file, location)));
                    }
                }
                catch (FaultException <OrganizationServiceFault> )
                {
                    return(null);
                }
            }
        }