Esempio n. 1
0
        private string GetAtom(ODataOperation operation)
        {
            StringBuilder sb = new StringBuilder();

            if (operation is ODataAction)
            {
                sb.Append("<action");
            }
            else if (operation is ODataFunction)
            {
                sb.Append("<function");
            }
            else
            {
                throw new ArgumentException();
            }

            sb.Append(" metadata=\"");
            sb.Append(TestUriUtils.ToEscapedUriString(operation.Metadata));
            sb.Append("\" title=\"");
            sb.Append(operation.Title);
            sb.Append("\" target=\"");
            sb.Append(operation.Target.OriginalString);
            sb.Append("\" xmlns=\"");
            sb.Append(TestAtomConstants.ODataMetadataNamespace);
            sb.Append("\" />");
            return(sb.ToString());
        }
        private static void CreateResultTemplates(
            string baseUri,
            string workspaceName,
            IEnumerable <CollectionInfo> collections,
            IEnumerable <SingletonInfo> singletons,
            out string xmlResultTemplate,
            out string[] jsonLightResultTemplate)
        {
            Debug.Assert(baseUri != null, "baseUri != null");

            List <string> xmlLines       = new List <string>();
            List <string> jsonLightLines = new List <string>();

            xmlLines.Add(@"<service xml:base=""" + baseUri + @""" xmlns=""http://www.w3.org/2007/app"" xmlns:atom=""http://www.w3.org/2005/Atom"">");
            xmlLines.Add(@"$(Indent)<serviceDocument>");
            jsonLightLines.Add("{");
            jsonLightLines.Add(@"$(Indent)""" + JsonLightConstants.ODataContextAnnotationName + @""":""" + TestUriUtils.ToEscapedUriString(JsonLightConstants.DefaultMetadataDocumentUri) + @""",""value"":[");

            if (workspaceName == null)
            {
                workspaceName = TestAtomConstants.AtomWorkspaceDefaultTitle;
            }
            xmlLines.Add(@"$(Indent)$(Indent)<atom:title type='text'>" + workspaceName + "</atom:title>");

            StringBuilder jsonLightBuilder = new StringBuilder();

            if (collections != null)
            {
                foreach (var collection in collections)
                {
                    xmlLines.Add(@"$(Indent)$(Indent)<collection href=""" + collection.Url + @""">");

                    if (collection.Name != null || collection.TitleAnnotation != null)
                    {
                        string titleValue = collection.TitleAnnotation ?? collection.Name;

                        xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title type='text'>" + titleValue + @"</atom:title>");
                    }
                    else
                    {
                        xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title />");
                    }

                    xmlLines.Add(@"$(Indent)$(Indent)</collection>");

                    if (jsonLightBuilder.Length > 0)
                    {
                        jsonLightBuilder.Append(",");
                    }

                    jsonLightBuilder.Append("{");
                    jsonLightBuilder.Append("$(NL)");
                    jsonLightBuilder.Append(@"$(Indent)$(Indent)$(Indent)""name"":""" + collection.Name + "\",");
                    jsonLightBuilder.Append(@"""url"":""" + collection.Url + "\"");
                    jsonLightBuilder.Append(@"$(NL)");
                    jsonLightBuilder.Append("$(Indent)$(Indent)}");
                }

                jsonLightLines.Add("$(Indent)$(Indent)" + jsonLightBuilder.ToString());
            }
            else
            {
                jsonLightLines.Add("$(Indent)$(Indent)");
            }

            if (singletons != null)
            {
                foreach (var singleton in singletons)
                {
                    xmlLines.Add(@"$(Indent)$(Indent)<singleton href=""" + singleton.Url + @""">");

                    if (singleton.Name != null || singleton.TitleAnnotation != null)
                    {
                        string titleValue = singleton.TitleAnnotation ?? singleton.Name;

                        xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title type='text'>" + titleValue + @"</atom:title>");
                    }
                    else
                    {
                        xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title />");
                    }

                    xmlLines.Add(@"$(Indent)$(Indent)</collection>");

                    if (jsonLightBuilder.Length > 0)
                    {
                        jsonLightBuilder.Append(",");
                    }

                    jsonLightBuilder.Append("{");
                    jsonLightBuilder.Append("$(NL)");
                    jsonLightBuilder.Append(@"$(Indent)$(Indent)$(Indent)""name"":""" + singleton.Name + "\",");
                    jsonLightBuilder.Append(@"""url"":""" + singleton.Url + "\"");
                    jsonLightBuilder.Append(@"$(NL)");
                    jsonLightBuilder.Append("$(Indent)$(Indent)}");
                }

                jsonLightLines.Add("$(Indent)$(Indent)" + jsonLightBuilder.ToString());
            }
            else
            {
                jsonLightLines.Add("$(Indent)$(Indent)");
            }

            xmlLines.Add(@"$(Indent)</serviceDocument>");
            xmlLines.Add(@"</service>");
            jsonLightLines.Add("$(Indent)]");
            jsonLightLines.Add("}");

            xmlResultTemplate       = string.Join("$(NL)", xmlLines);
            jsonLightResultTemplate = jsonLightLines.ToArray();
        }