Exemplo n.º 1
0
        /// <summary>
        /// Search elements
        /// Important: Search only works within the right containerID
        /// </summary>
        /// <param name="containerId"></param>
        /// <param name="searchCriteria"></param>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task <ServiceActionReturnMessage> Search(string containerId, string searchCriteria, int start, int limit = 10)
        {
            try
            {
                if (ServiceActions.TryGetValue("SEARCH", out ServiceAction action))
                {
                    List <IElement> elements = new List <IElement>();

                    //bool found = false;
                    action.ClearArgumentsValue();
                    action.SetArgumentValue("ContainerID", containerId);
                    action.SetArgumentValue("SearchCriteria", string.Format("dc:title contains \"{0}\"", searchCriteria));
                    action.SetArgumentValue("Filter", "*");
                    action.SetArgumentValue("StartingIndex", start.ToString());
                    action.SetArgumentValue("RequestedCount", limit.ToString());
                    action.SetArgumentValue("SortCriteria", "");
                    ServiceActionReturnMessage message = await action.InvokeAsync(ServiceTypesString.CONTENTDIRECTORY, serviceControls.Select(c => c).Where(c => c.ServiceType == ServiceTypes.CONTENTDIRECTORY).FirstOrDefault().URI);

                    if (message.ActionStatus == ActionStatus.Okay)
                    {
                        string   result         = action.GetArgumentValue("Result");
                        DIDLLite didlliteResult = result.Deserialize <DIDLLite>();

                        if (string.IsNullOrEmpty(result) || didlliteResult == null)
                        {
                            return(null);
                        }

                        foreach (DIDLContainer container in didlliteResult.Containers)
                        {
                            switch (container.Title)
                            {
                            case "Zones":
                            case "Renderers":
                            case "Search":
                                break;

                            default:
                                IElement element = Prism.Unity.Windows.PrismUnityApplication.Current.Container.Resolve <ElementContainer>(new ResolverOverride[]
                                {
                                    new ParameterOverride("didl", container)
                                });
                                elements.Add(element);

                                break;
                            }
                        }
                        foreach (DIDLItem item in didlliteResult.Items)
                        {
                            IElement element = Prism.Unity.Windows.PrismUnityApplication.Current.Container.Resolve <ElementItem>(new ResolverOverride[]
                            {
                                new ParameterOverride("didl", item)
                            });
                            elements.Add(element);
                        }

                        message.ReturnValue = elements;
                        return(message);
                    }
                    else
                    {
                        return(message);
                    }
                }
                else
                {
                    return(new ServiceActionReturnMessage()
                    {
                        ActionStatus = ActionStatus.Error, ActionMessage = string.Format("Action not available: Browse")
                    });
                }
            }
            catch (Exception exception)
            {
                return(new ServiceActionReturnMessage()
                {
                    ActionStatus = ActionStatus.Error, ActionMessage = exception.Message
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// BrowseMetaData
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <ServiceActionReturnMessage> BrowseMetaData(string Id)
        {
            try
            {
                if (ServiceActions.TryGetValue("BROWSE", out ServiceAction action))
                {
                    ElementBase element = null;

                    action.ClearArgumentsValue();
                    action.SetArgumentValue("ObjectID", Id);
                    action.SetArgumentValue("BrowseFlag", "BrowseMetadata");
                    action.SetArgumentValue("Filter", "*");
                    action.SetArgumentValue("StartingIndex", "0");
                    action.SetArgumentValue("RequestedCount", "0");
                    action.SetArgumentValue("SortCriteria", "");
                    ServiceActionReturnMessage message = await action.InvokeAsync(ServiceTypesString.CONTENTDIRECTORY, serviceControls.Select(c => c).Where(c => c.ServiceType == ServiceTypes.CONTENTDIRECTORY).FirstOrDefault().URI);

                    if (message.ActionStatus == ActionStatus.Okay)
                    {
                        string   result         = action.GetArgumentValue("Result");
                        DIDLLite didlliteResult = result.Deserialize <DIDLLite>();

                        if (string.IsNullOrEmpty(result) || didlliteResult == null)
                        {
                            return(new ServiceActionReturnMessage()
                            {
                                ActionStatus = ActionStatus.Error, ActionMessage = string.Format("Parsing error DIDLLite-string")
                            });
                        }

                        foreach (DIDLContainer container in didlliteResult.Containers)
                        {
                            switch (container.Title)
                            {
                            case "Zones":
                            case "Renderers":
                            case "Search":
                                break;

                            default:
                                //element = PrismUnityApplication.Current.Container.Resolve<ElementContainer>(new ResolverOverride[]
                                //    {
                                //       new ParameterOverride("didl", container)
                                //    });
                                element = PrismUnityApplication.Current.Container.Resolve <ElementBase>("DIDLContainer",
                                                                                                        new DependencyOverride(typeof(IEventAggregator), eventAggregator),
                                                                                                        new DependencyOverride(typeof(ICachingService), cachingService),
                                                                                                        new DependencyOverride(typeof(DIDLContainer), container));

                                break;
                            }
                        }
                        foreach (DIDLItem item in didlliteResult.Items)
                        {
                            //element = PrismUnityApplication.Current.Container.Resolve<ElementItem>(new ResolverOverride[]
                            //            {
                            //               new ParameterOverride("didl", item)
                            //            });
                            element = PrismUnityApplication.Current.Container.Resolve <ElementBase>("DIDLItem",
                                                                                                    new DependencyOverride(typeof(IEventAggregator), eventAggregator),
                                                                                                    new DependencyOverride(typeof(ICachingService), cachingService),
                                                                                                    new DependencyOverride(typeof(DIDLItem), item));
                        }

                        message.ReturnValue = element;
                        return(message);
                    }
                    else
                    {
                        return(message);
                    }
                }
                else
                {
                    return(new ServiceActionReturnMessage()
                    {
                        ActionStatus = ActionStatus.Error, ActionMessage = string.Format("Action not available: Browse")
                    });
                }
            }
            catch (Exception exception)
            {
                throw new Exception();
                return(new ServiceActionReturnMessage()
                {
                    ActionStatus = ActionStatus.Error, ActionMessage = exception.Message
                });
            }
        }