public PeekResult Peek(PeekParameters parameters)
        {
            try
            {
                if (parameters == null)
                {
                    throw new ArgumentNullException("parameters");
                }

                if (string.IsNullOrWhiteSpace(parameters.ItemUri))
                {
                    throw new ArgumentException(Resources.MissingItemUri);
                }

                if (Client.IsExistingObject(parameters.ItemUri))
                {
                    var readOptions = new ReadOptions { LoadFlags = LoadFlags.Expanded | LoadFlags.WebDavUrls };
                    var item = Client.Read(parameters.ItemUri, readOptions);

                    switch (GetItemType(item.Id))
                    {
                        case ItemType.Category:
                            return CategoryResult.From((CategoryData)item, Client, CurrentUserId);
                        case ItemType.Component:
                            return ComponentResult.From((ComponentData)item, CurrentUserId);
                        case ItemType.ComponentTemplate:
                            return ComponentTemplateResult.From((ComponentTemplateData)item, Client, CurrentUserId);
                        case ItemType.Folder:
                            return FolderResult.From((FolderData)item, CurrentUserId);
                        case ItemType.Group:
                            return GroupResult.From((GroupData)item);
                        case ItemType.Keyword:
                            return KeywordResult.From((KeywordData)item, CurrentUserId);
                        case ItemType.MultimediaType:
                            return MultimediaTypeResult.From((MultimediaTypeData)item);
                        case ItemType.Page:
                            return PageResult.From((PageData)item, Client, CurrentUserId);
                        case ItemType.PageTemplate:
                            return PageTemplateResult.From((PageTemplateData)item, Client, CurrentUserId);
                        case ItemType.Publication:
                            return PublicationResult.From((PublicationData)item, CurrentUserId);
                        case ItemType.PublicationTarget:
                            return PublicationTargetResult.From((PublicationTargetData)item);
                        case ItemType.Schema:
                            return SchemaResult.From((SchemaData)item, CurrentUserId);
                        case ItemType.StructureGroup:
                            return StructureGroupResult.From((StructureGroupData)item, CurrentUserId);
                        case ItemType.TargetGroup:
                            return TargetGroupResult.From((TargetGroupData)item, CurrentUserId);
                        case ItemType.TargetType:
                            return TargetTypeResult.From((TargetTypeData)item);
                        case ItemType.TemplateBuildingBlock:
                            return TemplateBuildingBlockResult.From((TemplateBuildingBlockData)item, Client, CurrentUserId);
                        case ItemType.User:
                            return UserResult.From((UserData)item, Client);
                        case ItemType.VirtualFolder:
                            return VirtualFolderResult.From((VirtualFolderData)item, CurrentUserId);
                    }
                }

                return new EmptyResult();
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Beispiel #2
0
        public PeekResult Peek(PeekParameters parameters)
        {
            try
            {
                if (parameters == null)
                {
                    throw new ArgumentNullException("parameters");
                }

                if (string.IsNullOrWhiteSpace(parameters.ItemUri))
                {
                    throw new ArgumentException(Resources.MissingItemUri);
                }

                if (Client.IsExistingObject(parameters.ItemUri))
                {
                    var readOptions = new ReadOptions {
                        LoadFlags = LoadFlags.Expanded | LoadFlags.WebDavUrls
                    };
                    var item = Client.Read(parameters.ItemUri, readOptions);

                    switch (GetItemType(item.Id))
                    {
                    case ItemType.Category:
                        return(CategoryResult.From((CategoryData)item, Client, CurrentUserId));

                    case ItemType.Component:
                        return(ComponentResult.From((ComponentData)item, CurrentUserId));

                    case ItemType.ComponentTemplate:
                        return(ComponentTemplateResult.From((ComponentTemplateData)item, Client, CurrentUserId));

                    case ItemType.Folder:
                        return(FolderResult.From((FolderData)item, CurrentUserId));

                    case ItemType.Group:
                        return(GroupResult.From((GroupData)item));

                    case ItemType.Keyword:
                        return(KeywordResult.From((KeywordData)item, CurrentUserId));

                    case ItemType.MultimediaType:
                        return(MultimediaTypeResult.From((MultimediaTypeData)item));

                    case ItemType.Page:
                        return(PageResult.From((PageData)item, Client, CurrentUserId));

                    case ItemType.PageTemplate:
                        return(PageTemplateResult.From((PageTemplateData)item, Client, CurrentUserId));

                    case ItemType.Publication:
                        return(PublicationResult.From((PublicationData)item, CurrentUserId));

                    case ItemType.PublicationTarget:
                        return(PublicationTargetResult.From((PublicationTargetData)item));

                    case ItemType.Schema:
                        return(SchemaResult.From((SchemaData)item, CurrentUserId));

                    case ItemType.StructureGroup:
                        return(StructureGroupResult.From((StructureGroupData)item, CurrentUserId));

                    case ItemType.TargetGroup:
                        return(TargetGroupResult.From((TargetGroupData)item, CurrentUserId));

                    case ItemType.TargetType:
                        return(TargetTypeResult.From((TargetTypeData)item));

                    case ItemType.TemplateBuildingBlock:
                        return(TemplateBuildingBlockResult.From((TemplateBuildingBlockData)item, Client, CurrentUserId));

                    case ItemType.User:
                        return(UserResult.From((UserData)item, Client));

                    case ItemType.VirtualFolder:
                        return(VirtualFolderResult.From((VirtualFolderData)item, CurrentUserId));
                    }
                }

                return(new EmptyResult());
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }