예제 #1
0
        public static ServiceDocument ToServiceDocument(IEnumerable<string> userStreams, 
                                                        IEnumerable<string> systemStreams,
                                                        IPEndPoint httpEndPoint)
        {
            if (userStreams == null || systemStreams == null || httpEndPoint == null)
                return null;

            var document = new ServiceDocument();

            var userWorkspace = new WorkspaceElement();
            userWorkspace.SetTitle("User event streams");

            var systemWorkspace = new WorkspaceElement();
            systemWorkspace.SetTitle("System event streams");

            foreach (var userStream in userStreams)
            {
                var collection = new CollectionElement();

                collection.SetTitle(userStream);
                collection.SetUri(httpEndPoint.ToHttpUrl("/streams/{0}", userStream));

                collection.AddAcceptType(ContentType.Xml);
                collection.AddAcceptType(ContentType.Atom);
                collection.AddAcceptType(ContentType.Json);
                collection.AddAcceptType(ContentType.AtomJson);

                userWorkspace.AddCollection(collection);
            }

            foreach (var systemStream in systemStreams)
            {
                var collection = new CollectionElement();

                collection.SetTitle(systemStream);
                collection.SetUri(httpEndPoint.ToHttpUrl("/streams/{0}", systemStream));

                collection.AddAcceptType(ContentType.Xml);
                collection.AddAcceptType(ContentType.Atom);
                collection.AddAcceptType(ContentType.Json);
                collection.AddAcceptType(ContentType.AtomJson);

                systemWorkspace.AddCollection(collection);
            }

            document.AddWorkspace(userWorkspace);
            document.AddWorkspace(systemWorkspace);

            return document;
        }
예제 #2
0
        public static ServiceDocument ToServiceDocument(IEnumerable<string> userStreams, IEnumerable<string> systemStreams, string userHostName)
        {
            if (userStreams == null || systemStreams == null || userHostName == null)
                return null;

            var document = new ServiceDocument();

            var userWorkspace = new WorkspaceElement();
            userWorkspace.SetTitle("User event streams");

            var systemWorkspace = new WorkspaceElement();
            systemWorkspace.SetTitle("System event streams");

            foreach (var userStream in userStreams)
            {
                var collection = new CollectionElement();

                collection.SetTitle(userStream);
                collection.SetUri(HostName.Combine(userHostName, "/streams/{0}", Uri.EscapeDataString(userStream)));

                collection.AddAcceptType(ContentType.Xml);
                collection.AddAcceptType(ContentType.Atom);
                collection.AddAcceptType(ContentType.Json);
                collection.AddAcceptType(ContentType.AtomJson);

                userWorkspace.AddCollection(collection);
            }

            foreach (var systemStream in systemStreams)
            {
                var collection = new CollectionElement();

                collection.SetTitle(systemStream);
                collection.SetUri(HostName.Combine(userHostName, "/streams/{0}", Uri.EscapeDataString(systemStream)));

                collection.AddAcceptType(ContentType.Xml);
                collection.AddAcceptType(ContentType.Atom);
                collection.AddAcceptType(ContentType.Json);
                collection.AddAcceptType(ContentType.AtomJson);

                systemWorkspace.AddCollection(collection);
            }

            document.AddWorkspace(userWorkspace);
            document.AddWorkspace(systemWorkspace);

            return document;
        }
예제 #3
0
        public void have_at_least_one_workspace()
        {
            var writer = XmlWriter.Create(new MemoryStream());
            var doc = new ServiceDocument();

            Assert.Throws<AtomSpecificationViolationException>(() => doc.WriteXml(writer));
            writer.Close();
        }