コード例 #1
0
ファイル: WoopsaExtensions.cs プロジェクト: mullerch/Woopsa
        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);
        }
コード例 #2
0
 /// <summary>
 /// Creates an instance of the Woopsa server adding multiRequestHandler and SubscriptionService
 ///
 /// 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>
 public WoopsaServer(WoopsaObject root, int port = DefaultPort, string routePrefix = DefaultServerPrefix) :
     this((IWoopsaContainer)root, port, routePrefix)
 {
     new WoopsaMultiRequestHandler(root, this);
     _subscriptionService = new WoopsaSubscriptionService(this, root);
     _subscriptionService.CanReconnectSubscriptionToNewObject += OnCanWatch;
 }
コード例 #3
0
ファイル: WoopsaObject.cs プロジェクト: mullerch/Woopsa
 public WoopsaMethod(WoopsaObject container, string name, WoopsaValueType returnType, IEnumerable <WoopsaMethodArgumentInfo> argumentInfos, WoopsaMethodInvoke methodInvoke)
     : base(container, name)
 {
     ReturnType    = returnType;
     ArgumentInfos = argumentInfos;
     _methodInvoke = methodInvoke;
     if (container != null)
     {
         container.Add(this);
     }
 }
コード例 #4
0
        public WoopsaMultiRequestHandler(WoopsaObject root, WoopsaServer server)
        {
            _server = server;

            new WoopsaMethod(root,
                             WoopsaMultiRequestConst.WoopsaMultiRequestMethodName,
                             WoopsaValueType.JsonData,
                             new List <WoopsaMethodArgumentInfo> {
                new WoopsaMethodArgumentInfo(WoopsaMultiRequestConst.WoopsaMultiRequestArgumentName, WoopsaValueType.JsonData)
            },
                             (s) => (HandleCall(s.ElementAt(0)))
                             );
        }
コード例 #5
0
 public WoopsaProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, WoopsaPropertySet set)
     : base(container, name)
 {
     Type       = type;
     _get       = get;
     IsReadOnly = set == null;
     if (!IsReadOnly)
     {
         _set = set;
     }
     if (container != null)
     {
         container.Add(this);
     }
 }
コード例 #6
0
 public WoopsaProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get)
     : this(container, name, type, get, null)
 {
 }