Ejemplo n.º 1
0
 public static void DecodeWoopsaLink(this IWoopsaValue value, out string woopsaServerUrl, out string woopsaItemPath)
 {
     if (value.Type == WoopsaValueType.WoopsaLink)
     {
         string[] parts = value.AsText.Split(WoopsaConst.WoopsaLinkSeparator);
         if (parts.Length == 1)
         {
             woopsaServerUrl = null;
             woopsaItemPath  = WoopsaUtils.RemoveInitialSeparator(parts[0]);
         }
         else if (parts.Length == 2)
         {
             woopsaServerUrl = parts[0];
             woopsaItemPath  = WoopsaUtils.RemoveInitialSeparator(parts[1]);
         }
         else
         {
             throw new WoopsaException(string.Format("Badly formed WoopsaLink {0} ", value.AsText));
         }
     }
     else
     {
         throw new WoopsaException(string.Format("Cannot decode WoopsaValue of type {0} as a WoopsaLink", value.Type));
     }
 }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
 protected BaseWoopsaSubscriptionServiceSubscription(
     WoopsaSubscriptionChannel channel,
     WoopsaContainer root,
     int subscriptionId, string propertyPath,
     TimeSpan monitorInterval, TimeSpan publishInterval)
 {
     Channel             = channel;
     Root                = root;
     SubscriptionId      = subscriptionId;
     MonitorInterval     = monitorInterval;
     PublishInterval     = publishInterval;
     PropertyPath        = propertyPath;
     IncrementalObjectId = WoopsaUtils.NextIncrementalObjectId();
     _lock               = new object();
     _notifications      = new List <IWoopsaNotification>();
     if (monitorInterval == WoopsaSubscriptionServiceConst.MonitorIntervalLastPublishedValueOnly &&
         publishInterval == WoopsaSubscriptionServiceConst.PublishIntervalOnce)
     {
         DoPublish();
     }
     else if (publishInterval > TimeSpan.FromMilliseconds(0))
     {
         _publishTimer           = channel.ServiceImplementation.TimerScheduler.AllocateTimer(publishInterval);
         _publishTimer.Elapsed  += _publishTimer_Elapsed;
         _publishTimer.IsEnabled = true;
     }
     else
     {
         throw new WoopsaException("A publish interval of 0 with a non-zero monitor interval is not allowed");
     }
 }
Ejemplo n.º 4
0
 public WoopsaClientSubscription Subscribe(string relativePath,
                                           EventHandler <WoopsaNotificationEventArgs> propertyChangedHandler,
                                           TimeSpan monitorInterval, TimeSpan publishInterval)
 {
     return(Client.SubscriptionChannel.Subscribe(
                WoopsaUtils.CombinePath(this.GetPath(), relativePath),
                relativePath,
                (sender, e) => propertyChangedHandler?.Invoke(this, e),
                monitorInterval,
                publishInterval
                ));
 }
Ejemplo n.º 5
0
 public static string FormatRelativeWoopsaLink(string woopsaItemPath)
 {
     return(WoopsaUtils.RemoveInitialSeparator(woopsaItemPath));
 }