Example #1
0
 /// <summary>
 /// Creates an instance of the Woopsa server without using the Reflector. You
 /// will have to create the object hierarchy yourself, using WoopsaObjects
 /// or implementing IWoopsaContainer yourself.
 ///
 /// It will automatically create the required HTTP server
 /// on the specified port and will prefix woopsa verbs with the specified
 /// route prefix. It will also add all the necessary native extensions for
 /// Publish/Subscribe and Mutli-Requests.
 /// </summary>
 /// <param name="root">The root object that will be published via Woopsa.</param>
 /// <param name="port">The port on which to run the web server</param>
 /// <param name="routePrefix">
 /// The prefix to add to all routes for woopsa verbs. For example, specifying
 /// "myPrefix" will make the server available on http://server/myPrefix
 /// </param>
 /// <param name="threadPoolSize">
 /// The maximum number of threads to be created.
 /// CustomThreadPool.DefaultThreadPoolSize means use default operating system value.</param>
 /// <param name="priority">
 /// The priority of the server threads.
 /// </param>
 public WoopsaServer(IWoopsaContainer root, int port = DefaultPort, string routePrefix = DefaultServerPrefix,
                     int threadPoolSize = CustomThreadPool.DefaultThreadPoolSize, ThreadPriority priority = DefaultThreadPriority)
     : this(root, new WebServer(port, threadPoolSize, priority), routePrefix)
 {
     _isWebServerEmbedded = true;
     WebServer.Start();
 }
Example #2
0
 /// <summary>
 /// Creates an instance of the Woopsa server without using the Reflector. You
 /// will have to create the object hierarchy yourself, using WoopsaObjects
 /// or implementing IWoopsaContainer yourself.
 ///
 /// If you are already using a <see cref="WebServer"/> somewhere else,
 /// this constructor will simply add the woopsa routes to that server.
 /// This allows you to serve static content and the Woopsa protocol
 /// on the same network interface and on the same port.
 /// </summary>
 /// <param name="root">The root object that will be published via Woopsa.</param>
 /// <param name="server">The server on which Woopsa routes will be added</param>
 /// <param name="routePrefix">
 /// The prefix to add to all routes for woopsa verbs. For example, specifying
 /// "myPrefix" will make the server available on http://server/myPrefix
 /// </param>
 public WoopsaServer(IWoopsaContainer root, WebServer server, string routePrefix = DefaultServerPrefix)
 {
     _root        = root;
     WebServer    = server;
     _routePrefix = routePrefix;
     AddRoutes();
 }
Example #3
0
        public static IWoopsaElement ByNameOrNull(this IWoopsaContainer woopsaContainer, string name)
        {
            IWoopsaElement result;

            // For performance optimization, use directly the methods of classes WoopsaObject and WoopsaContainer
            // Complexity : O(1)
            if (woopsaContainer is WoopsaObject)
            {
                WoopsaObject woopsaObject = (WoopsaObject)woopsaContainer;
                result = woopsaObject.ByNameOrNull(name);
            }
            else if (woopsaContainer is WoopsaContainer)
            {
                WoopsaContainer container = (WoopsaContainer)woopsaContainer;
                result = container.ByNameOrNull(name);
            }
            else
            {
                // The code below can manage all the cases, but is used only for elements not
                // of type WoopsaContainer or WoopsaObject
                // Complexity : O(n)
                result = woopsaContainer.Items.ByNameOrNull(name);
                if (result == null && woopsaContainer is IWoopsaObject)
                {
                    IWoopsaObject woopsaObject = (IWoopsaObject)woopsaContainer;
                    result = woopsaObject.Properties.ByNameOrNull(name);
                    if (result == null)
                    {
                        woopsaObject.Methods.ByNameOrNull(name);
                    }
                }
            }
            return(result);
        }
Example #4
0
        public static IWoopsaElement ByPathOrNull(this IWoopsaContainer element, string path)
        {
            string workPath = WoopsaUtils.RemoveInitialSeparator(path);

            if (workPath == string.Empty)
            {
                return(element);
            }
            else
            {
                string[] pathElements = workPath.Split(WoopsaConst.WoopsaPathSeparator);

                IWoopsaElement result = element;
                foreach (var item in pathElements)
                {
                    if (result is IWoopsaContainer)
                    {
                        result = ((IWoopsaContainer)result).ByNameOrNull(item);
                    }
                    else
                    {
                        result = null;
                        break;
                    }
                }
                return(result);
            }
        }
Example #5
0
 /// <summary>
 /// Creates an instance of the Woopsa server without using the Reflector. You
 /// will have to create the object hierarchy yourself, using WoopsaObjects 
 /// or implementing IWoopsaContainer yourself.
 /// 
 /// If you are already using a <see cref="WebServer"/> somewhere else,
 /// this constructor will simply add the woopsa routes to that server.
 /// This allows you to serve static content and the Woopsa protocol
 /// on the same network interface and on the same port.
 /// </summary>
 /// <param name="root">The root object that will be published via Woopsa.</param>
 /// <param name="server">The server on which Woopsa routes will be added</param>
 /// <param name="routePrefix">
 /// The prefix to add to all routes for woopsa verbs. For example, specifying
 /// "myPrefix" will make the server available on http://server/myPrefix
 /// </param>
 public WoopsaServer(IWoopsaContainer root, WebServer server, string routePrefix = DefaultServerPrefix)
 {
     _root = root;
     WebServer = server;
     _routePrefix = routePrefix;
     AddRoutes();
 }
Example #6
0
        public static IWoopsaElement ByName(this IWoopsaContainer woopsaContainer, string name)
        {
            IWoopsaElement result = ByNameOrNull(woopsaContainer, name);

            if (result != null)
            {
                return(result);
            }
            else
            {
                throw new WoopsaNotFoundException(string.Format("Woopsa element not found : {0}", name));
            }
        }
Example #7
0
        /// <summary>
        /// Finds the WoopsaElement specified by path, relative to a container
        /// </summary>
        /// <param name="element">The element in which to start the search</param>
        /// <param name="path">The path, specified relative to elemen</param>
        /// <returns>An IWoopsaElement if found, throws IWoopsaNotFoundException if not</returns>
        ///
        public static IWoopsaElement ByPath(this IWoopsaContainer element, string path)
        {
            IWoopsaElement result = ByPathOrNull(element, path);

            if (result != null)
            {
                return(result);
            }
            else
            {
                throw new WoopsaNotFoundException(string.Format("Woopsa element not found at path : {0}", path));
            }
        }
Example #8
0
        private static IWoopsaContainer GetContainerRoot(IWoopsaContainer element)
        {
            IWoopsaContainer result = element;

            if (result != null)
            {
                while (result.Owner != null)
                {
                    result = result.Owner;
                }
            }
            return(result);
        }
Example #9
0
        /// <summary>
        /// Gets the path of a WoopsaElement relative to a root
        /// </summary>
        /// <param name="element">The WoopsaElement to get the path for</param>
        /// <param name="root">The root WoopsaElement to consider as root. Must be in the element's Owner chain.</param>
        /// <returns></returns>
        public static string GetPath(this IWoopsaElement element, IWoopsaContainer root)
        {
            StringBuilder stringBuilder = new StringBuilder();

            BuildPath(stringBuilder, element, root);
            if (stringBuilder.Length == 0) //Special case when it's the root
            {
                return(WoopsaConst.WoopsaRootPath);
            }
            else
            {
                return(stringBuilder.ToString());
            }
        }
Example #10
0
 public static string SerializeMetadata(this IWoopsaContainer container, bool justName = false)
 {
     if (justName)
     {
         return(String.Format(StringFormat, JsonEscape(container.Name)));
     }
     if (container is IWoopsaObject)
     {
         return((container as IWoopsaObject).SerializeMetadata());
     }
     else
     {
         string items = container.Items.SerializeMetadata();
         return(String.Format(MetadataContainer, container.Name, items));
     }
 }
Example #11
0
 internal WoopsaUnboundClientObject(WoopsaClient client, WoopsaContainer container, string name, IWoopsaContainer root)
     : base(client, container, name, root)
 {
 }
Example #12
0
 internal WoopsaBaseClientObject(WoopsaClient client, WoopsaContainer container, string name, IWoopsaContainer root)
     : base(container, name)
 {
     Client = client;
     Root   = root ?? this;
 }
 internal WoopsaUnboundClientObject(WoopsaClient client, WoopsaContainer container, string name, IWoopsaContainer root)
     : base(client, container, name, root)
 {
 }
 internal WoopsaBaseClientObject(WoopsaClient client, WoopsaContainer container, string name, IWoopsaContainer root)
     : base(container, name)
 {
     Client = client;
     Root = root ?? this;
 }
Example #15
0
 private static void BuildPath(StringBuilder stringBuilder, IWoopsaElement element, IWoopsaContainer root)
 {
     if (element != null)
     {
         if (element == root)
         {
             stringBuilder.Append(WoopsaConst.WoopsaPathSeparator);
         }
         else
         {
             if (element.Owner != root)
             {
                 BuildPath(stringBuilder, element.Owner, root);
             }
             if (element.Owner != null) // it is not the root
             {
                 stringBuilder.Append(WoopsaConst.WoopsaPathSeparator);
                 stringBuilder.Append(element.Name);
             }
         }
     }
 }
Example #16
0
 /// <summary>
 /// Creates an instance of the Woopsa server without using the Reflector. You
 /// will have to create the object hierarchy yourself, using WoopsaObjects 
 /// or implementing IWoopsaContainer yourself.
 /// 
 /// It will automatically create the required HTTP server
 /// on the specified port and will prefix woopsa verbs with the specified 
 /// route prefix. It will also add all the necessary native extensions for 
 /// Publish/Subscribe and Mutli-Requests.
 /// </summary>
 /// <param name="root">The root object that will be published via Woopsa.</param>
 /// <param name="port">The port on which to run the web server</param>
 /// <param name="routePrefix">
 /// The prefix to add to all routes for woopsa verbs. For example, specifying
 /// "myPrefix" will make the server available on http://server/myPrefix
 /// </param>
 /// <param name="threadPoolSize">
 /// The maximum number of threads to be created. 
 /// CustomThreadPool.DefaultThreadPoolSize means use default operating system value.</param>
 /// <param name="priority">
 /// The priority of the server threads.
 /// </param>
 public WoopsaServer(IWoopsaContainer root, int port = DefaultPort, string routePrefix = DefaultServerPrefix,
     int threadPoolSize = CustomThreadPool.DefaultThreadPoolSize, ThreadPriority priority = DefaultThreadPriority)
     : this(root, new WebServer(port, threadPoolSize, priority), routePrefix)
 {
     _isWebServerEmbedded = true;
     WebServer.Start();
 }