Exemple #1
0
        }         // proc WriteXml

        public static void WriteXml(this IDEContext context, XDocument value, string contentType = MimeTypes.Text.Xml)
        {
            using (var tw = context.GetOutputTextWriter(contentType, context.Server.Encoding, -1))
                value.Save(tw);
        }         // proc WriteXml
Exemple #2
0
        }         // proc WriteListFetchList

        #endregion

        void IDEListService.WriteList(IDEContext r, IDEListController controller, int startAt, int count)
        {
            var sendTypeDefinition = String.Compare(r.GetProperty("desc", Boolean.FalseString), Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0;

            // Suche den passenden Descriptor
            var descriptor = controller.Descriptor;

            if (descriptor == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest, String.Format("Liste '{0}' besitzt kein Format.", controller.Id));
            }

            controller.OnBeforeList();

            // Rückgabe
            using (var tw = r.GetOutputTextWriter(MimeTypes.Text.Xml))
                using (var xml = XmlWriter.Create(tw, GetSettings(tw)))
                {
                    xml.WriteStartDocument();
                    xml.WriteStartElement("list");

                    // Sollen die Strukturinformationen übertragen werdem
                    if (sendTypeDefinition)
                    {
                        xml.WriteStartElement("typedef");
                        descriptor.WriteType(new DEListTypeWriter(xml));
                        xml.WriteEndElement();
                    }

                    // Gib die Daten aus
                    using (controller.EnterReadLock())
                    {
                        var list = controller.List;

                        // Prüfe auf Indexierte Listen
                        var  useInterface     = ListEnumeratorType.Enumerable;
                        Type useInterfaceType = null;
                        foreach (var ii in list.GetType().GetTypeInfo().ImplementedInterfaces)
                        {
                            if (ii.IsGenericType)
                            {
                                Type genericType = ii.GetGenericTypeDefinition();
                                if (genericType == typeof(IList <>))
                                {
                                    if (useInterface < ListEnumeratorType.ListTyped)
                                    {
                                        useInterface     = ListEnumeratorType.ListTyped;
                                        useInterfaceType = ii;
                                    }
                                }
                                else if (genericType == typeof(IReadOnlyList <>))
                                {
                                    if (useInterface < ListEnumeratorType.ReadOnlyList)
                                    {
                                        useInterface     = ListEnumeratorType.ReadOnlyList;
                                        useInterfaceType = ii;
                                    }
                                }
                                else if (genericType == typeof(IDERangeEnumerable2 <>))
                                {
                                    if (useInterface < ListEnumeratorType.RangeEnumerator)
                                    {
                                        useInterface     = ListEnumeratorType.RangeEnumerator;
                                        useInterfaceType = ii;
                                    }
                                }
                            }
                            else if (ii == typeof(System.Collections.IList))
                            {
                                if (useInterface < ListEnumeratorType.ListUntyped)
                                {
                                    useInterface = ListEnumeratorType.ListUntyped;
                                }
                            }
                        }

                        // Gib die entsprechende Liste aus
                        xml.WriteStartElement("items");
                        switch (useInterface)
                        {
                        case ListEnumeratorType.Enumerable:
                            var enumerator = list.GetEnumerator();
                            try
                            {
                                WriteListFetchEnum(xml, descriptor, enumerator, startAt, count);
                            }
                            finally
                            {
                                var tmp = enumerator as IDisposable;
                                if (tmp != null)
                                {
                                    tmp.Dispose();
                                }
                            }
                            break;

                        case ListEnumeratorType.ReadOnlyList:
                        case ListEnumeratorType.ListTyped:
                        case ListEnumeratorType.RangeEnumerator:
                            WriteListFetchTyped(useInterfaceType, r, xml, descriptor, list, startAt, count);
                            break;


                        case ListEnumeratorType.ListUntyped:
                            WriteListFetchList(xml, descriptor, (IList)list, startAt, count);
                            break;

                        default:
                            throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError, String.Format("Liste '{0}' nicht aufzählbar.", controller.Id));
                        }
                        xml.WriteEndElement();
                    }

                    xml.WriteEndElement();
                    xml.WriteEndDocument();
                }
        }         // proc IDEListService.WriteList
Exemple #3
0
 public void OpenText(string sContentType, Encoding encoding = null)
 {
     PrepareOutput();
     textOutput = context.GetOutputTextWriter(contentType, encoding);
 }         // proc OpenText