Example #1
0
        // Added the loadFailSafe optimization
        public void Load(bool loadImages, bool loadFailSafe = true)
        {
            var request = new GetContentRequest1(new appId(), new getContentRequest())
            {
                getContentRequest =
                {
                    contentIdentifier = ContentIdentifier,
                    locale =_locale,
                    version =_collection + "." + _version
                }
            };

            var documents = new List<requestedDocument>
                                {
                                    new requestedDocument {type = documentTypes.common, selector = Selectors.Mtps.LINKS},
                                    new requestedDocument {type = documentTypes.primary,  selector = Selectors.Mtps.TOC},
                                    new requestedDocument {type = documentTypes.common, selector = Selectors.Mtps.SEARCH},
                                    new requestedDocument {type = documentTypes.feature,  selector = Selectors.Mtps.ANNOTATIONS}
                                };

            if (loadFailSafe)
                documents.Add(new requestedDocument { type = documentTypes.primary, selector = Selectors.Mtps.FAILSAFE });

            request.getContentRequest.requestedDocuments = documents.ToArray();

            var client = new ContentServicePortTypeClient(WcfService.SERVICE_NAME);
            //client.GetContent()  appIdValue = new appId { value = Application };

            GetContentResponse1 response;
            try
            {
                response = client.GetContent(request);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debugger.Break();
                return;
            }

            if (validateAsFilename.Match(response.getContentResponse.contentId).Success)
            {
                ContentId = response.getContentResponse.contentId;
            }
            else
            {
                throw (new BadContentIdException("ContentId contains illegal characters: [" + ContentId + "]"));
            }

            NumImages = response.getContentResponse.imageDocuments.Length;

            foreach (var commonDoc in response.getContentResponse.commonDocuments)
            {
                if (commonDoc.Any == null) continue;

                if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.SEARCH.ToLowerInvariant())
                {
                    Metadata = commonDoc.Any[0].OuterXml;
                }
                else if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.LINKS.ToLowerInvariant())
                {
                    Links = commonDoc.Any[0].OuterXml;
                }
            }

            foreach (primary primaryDoc in response.getContentResponse.primaryDocuments)
            {
                if (primaryDoc.Any == null) continue;

                if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.FAILSAFE.ToLowerInvariant())
                {
                    Xml = primaryDoc.Any.OuterXml;
                }
                else if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.TOC.ToLowerInvariant())
                {
                    Toc = primaryDoc.Any.OuterXml;
                }
            }

            foreach (feature featureDoc in response.getContentResponse.featureDocuments)
            {
                if (featureDoc.Any == null) continue;

                if (featureDoc.featureFormat.ToLowerInvariant() == Selectors.Mtps.ANNOTATIONS.ToLowerInvariant())
                {
                    Annotations = featureDoc.Any[0].OuterXml;
                }

            }

            // If we get no meta/search or wiki data, plug in NOP data because
            // we can't LoadXml an empty string nor pass null navigators to
            // the transform.
            if (string.IsNullOrEmpty(Metadata))
                Metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />";

            if (string.IsNullOrEmpty(Annotations))
                Annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />";

            if (loadImages)
            {
                var imageDocs = new requestedDocument[response.getContentResponse.imageDocuments.Length];

                // Now that we know their names, we run a request with each image.
                for (int i = 0; i < response.getContentResponse.imageDocuments.Length; i++)
                {
                    imageDocs[i] = new requestedDocument
                                       {
                                           type = documentTypes.image,
                                           selector = response.getContentResponse.imageDocuments[i].name + "." + response.getContentResponse.imageDocuments[i].imageFormat
                                       };
                }

                request.getContentRequest.requestedDocuments = imageDocs;

                response = client.GetContent(request);

                foreach (image imageDoc in response.getContentResponse.imageDocuments)
                {
                    var imageFilename = imageDoc.name + "." + imageDoc.imageFormat;

                    if (validateAsFilename.Match(imageFilename).Success)
                    {
                        Images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value));
                    }
                    else
                    {
                        throw (new BadImageNameExeception("Image filename contains illegal characters: [" + imageFilename + "]"));
                    }
                }
            }
        }
Example #2
0
        // Added the loadFailSafe optimization
        public void Load(bool loadImages, bool loadFailSafe = true)
        {
            var request = new GetContentRequest1(new appId(), new getContentRequest())
            {
                getContentRequest =
                {
                    contentIdentifier = ContentIdentifier,
                    locale            = _locale,
                    version           = _collection + "." + _version
                }
            };


            var documents = new List <requestedDocument>
            {
                new requestedDocument {
                    type = documentTypes.common, selector = Selectors.Mtps.LINKS
                },
                new requestedDocument {
                    type = documentTypes.primary, selector = Selectors.Mtps.TOC
                },
                new requestedDocument {
                    type = documentTypes.common, selector = Selectors.Mtps.SEARCH
                },
                new requestedDocument {
                    type = documentTypes.feature, selector = Selectors.Mtps.ANNOTATIONS
                }
            };


            if (loadFailSafe)
            {
                documents.Add(new requestedDocument {
                    type = documentTypes.primary, selector = Selectors.Mtps.FAILSAFE
                });
            }

            request.getContentRequest.requestedDocuments = documents.ToArray();

            var client = new ContentServicePortTypeClient(WcfService.SERVICE_NAME);
            //client.GetContent()  appIdValue = new appId { value = Application };

            GetContentResponse1 response;

            try
            {
                response = client.GetContent(request);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debugger.Break();
                return;
            }

            if (validateAsFilename.Match(response.getContentResponse.contentId).Success)
            {
                ContentId = response.getContentResponse.contentId;
            }
            else
            {
                throw (new BadContentIdException("ContentId contains illegal characters: [" + ContentId + "]"));
            }

            NumImages = response.getContentResponse.imageDocuments.Length;


            foreach (var commonDoc in response.getContentResponse.commonDocuments)
            {
                if (commonDoc.Any == null)
                {
                    continue;
                }

                if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.SEARCH.ToLowerInvariant())
                {
                    Metadata = commonDoc.Any[0].OuterXml;
                }
                else if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.LINKS.ToLowerInvariant())
                {
                    Links = commonDoc.Any[0].OuterXml;
                }
            }

            foreach (primary primaryDoc in response.getContentResponse.primaryDocuments)
            {
                if (primaryDoc.Any == null)
                {
                    continue;
                }

                if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.FAILSAFE.ToLowerInvariant())
                {
                    Xml = primaryDoc.Any.OuterXml;
                }
                else if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.TOC.ToLowerInvariant())
                {
                    Toc = primaryDoc.Any.OuterXml;
                }
            }


            foreach (feature featureDoc in response.getContentResponse.featureDocuments)
            {
                if (featureDoc.Any == null)
                {
                    continue;
                }

                if (featureDoc.featureFormat.ToLowerInvariant() == Selectors.Mtps.ANNOTATIONS.ToLowerInvariant())
                {
                    Annotations = featureDoc.Any[0].OuterXml;
                }
            }

            // If we get no meta/search or wiki data, plug in NOP data because
            // we can't LoadXml an empty string nor pass null navigators to
            // the transform.
            if (string.IsNullOrEmpty(Metadata))
            {
                Metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />";
            }

            if (string.IsNullOrEmpty(Annotations))
            {
                Annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />";
            }


            if (loadImages)
            {
                var imageDocs = new requestedDocument[response.getContentResponse.imageDocuments.Length];

                // Now that we know their names, we run a request with each image.
                for (int i = 0; i < response.getContentResponse.imageDocuments.Length; i++)
                {
                    imageDocs[i] = new requestedDocument
                    {
                        type     = documentTypes.image,
                        selector = response.getContentResponse.imageDocuments[i].name + "." + response.getContentResponse.imageDocuments[i].imageFormat
                    };
                }

                request.getContentRequest.requestedDocuments = imageDocs;


                response = client.GetContent(request);

                foreach (image imageDoc in response.getContentResponse.imageDocuments)
                {
                    var imageFilename = imageDoc.name + "." + imageDoc.imageFormat;

                    if (validateAsFilename.Match(imageFilename).Success)
                    {
                        Images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value));
                    }
                    else
                    {
                        throw (new BadImageNameExeception("Image filename contains illegal characters: [" + imageFilename + "]"));
                    }
                }
            }
        }
Example #3
0
        // Added the loadFailSafe optimization
        public void Load(bool loadImages, bool loadFailSafe)
        {
            getContentRequest request = new getContentRequest();

            request.contentIdentifier = contentIdentifier;
            request.locale            = locale;
            request.version           = collection + "." + version;

            List <requestedDocument> documents = new List <requestedDocument>();


            requestedDocument document = new requestedDocument();

            document.selector = "Mtps.Links";
            document.type     = documentTypes.common;
            documents.Add(document);

            document          = new requestedDocument();
            document.type     = documentTypes.primary;
            document.selector = "Mtps.Toc";
            documents.Add(document);

            document          = new requestedDocument();
            document.type     = documentTypes.common;
            document.selector = "Mtps.Search";
            documents.Add(document);

            document          = new requestedDocument();
            document.type     = documentTypes.feature;
            document.selector = "Mtps.Annotations";
            documents.Add(document);

            if (loadFailSafe == true)
            {
                document          = new requestedDocument();
                document.type     = documentTypes.primary;
                document.selector = "Mtps.Failsafe";
                documents.Add(document);
            }

            request.requestedDocuments = documents.ToArray();

            ContentService proxy = new ContentService();

            proxy.appIdValue       = new appId();
            proxy.appIdValue.value = application;

            getContentResponse response;

            try
            {
                response = proxy.GetContent(request);
            }
            catch
            {
                return;
            }

            if (validateAsFilename.Match(response.contentId).Success == true)
            {
                contentId = response.contentId;
            }
            else
            {
                throw (new BadContentIdException("ContentId contains illegal characters: [" + contentId + "]"));
            }

            numImages = response.imageDocuments.Length;


            foreach (common commonDoc in response.commonDocuments)
            {
                if (commonDoc.Any != null)
                {
                    switch (commonDoc.commonFormat.ToLower())
                    {
                    case "mtps.search":
                        metadata = commonDoc.Any[0].OuterXml;
                        break;

                    case "mtps.links":
                        links = commonDoc.Any[0].OuterXml;
                        break;
                    }
                }
            }

            foreach (primary primaryDoc in response.primaryDocuments)
            {
                if (primaryDoc.Any != null)
                {
                    switch (primaryDoc.primaryFormat.ToLower())
                    {
                    case "mtps.failsafe":
                        xml = primaryDoc.Any.OuterXml;
                        break;

                    case "mtps.toc":
                        toc = primaryDoc.Any.OuterXml;
                        break;
                    }
                }
            }


            foreach (feature featureDoc in response.featureDocuments)
            {
                if (featureDoc.Any != null)
                {
                    if (featureDoc.featureFormat.ToLower() == "mtps.annotations")
                    {
                        annotations = featureDoc.Any[0].OuterXml;
                    }
                }
            }

            // If we get no meta/search or wiki data, plug in NOP data because
            // we can't LoadXml an empty string nor pass null navigators to
            // the transform.
            if (string.IsNullOrEmpty(metadata) == true)
            {
                metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />";
            }
            if (string.IsNullOrEmpty(annotations) == true)
            {
                annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />";
            }


            if (loadImages == true)
            {
                requestedDocument[] imageDocs = new requestedDocument[response.imageDocuments.Length];

                // Now that we know their names, we run a request with each image.
                for (int i = 0; i < response.imageDocuments.Length; i++)
                {
                    imageDocs[i]          = new requestedDocument();
                    imageDocs[i].type     = documentTypes.image;
                    imageDocs[i].selector = response.imageDocuments[i].name + "." +
                                            response.imageDocuments[i].imageFormat;
                }

                request.requestedDocuments = imageDocs;
                response = proxy.GetContent(request);

                foreach (image imageDoc in response.imageDocuments)
                {
                    string imageFilename = imageDoc.name + "." + imageDoc.imageFormat;
                    if (validateAsFilename.Match(imageFilename).Success == true)
                    {
                        images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value));
                    }
                    else
                    {
                        throw (new BadImageNameExeception(
                                   "Image filename contains illegal characters: [" + imageFilename + "]"));
                    }
                }
            }
        }