Пример #1
0
        public async Task <bool> RenewResourceObserverLeaseAsync(string resourceUriString, string leaseKey,
                                                                 TimeSpan lifetime)
        {
            IPiSystem resource = GetPiSystem(resourceUriString);

            return(await resource.RenewObserverLeaseAsync(leaseKey, lifetime));
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <string> > > GetPiSystemSubscriptionList(string resourceUriString)
        {
            try
            {
                if (string.IsNullOrEmpty(resourceUriString))
                {
                    throw new ArgumentNullException("resourceUriString");
                }

                IPiSystem pisystem = graphManager.GetPiSystem(resourceUriString);

                if (pisystem == null)
                {
                    logger?.LogWarning($"Pi-system '{resourceUriString}' is null.");
                }
                else
                {
                    logger?.LogInformation($"Returned pi-system '{resourceUriString}'.");
                }

                IEnumerable <string> list = await pisystem.GetSubscriptionListAsync();

                return(StatusCode(200, list));
            }
            catch (Exception ex)
            {
                logger?.LogError(ex, $"Error getting subscriptions from pi-system.");
                return(StatusCode(500, ex.Message));
            }
        }
Пример #3
0
        /// <summary>
        /// Add an error observer to a resource.
        /// </summary>
        /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
        /// <param name="lifetime">The lifetime of the lease.</param>
        /// <param name="observer">Error observer to receive events.</param>
        /// <returns>A unique string for the lease key, whic is used to refresh the lease for the observer.</returns>
        public async Task <string> AddResourceObserverAsync(string resourceUriString, TimeSpan lifetime, ErrorObserver observer)
        {
            IErrorObserver objRef = await client.CreateObjectReference <IErrorObserver>(observer);

            IPiSystem resource = GetPiSystem(resourceUriString);

            return(await resource.AddObserverAsync(lifetime, objRef));
        }
Пример #4
0
        /// <summary>
        /// Adds or updates a resource's metadata.
        /// </summary>
        /// <param name="metadata">Metadata that describes the resource.</param>
        /// <returns></returns>
        public async Task UpsertPiSystemMetadataAsync(EventMetadata metadata)
        {
            Uri uri = new Uri(metadata.ResourceUriString);

            metadata.ResourceUriString = uri.ToCanonicalString(false);
            IPiSystem resource = GetPiSystem(metadata.ResourceUriString);
            await resource.UpsertMetadataAsync(metadata);
        }
Пример #5
0
        public async Task UnsubscribeAsync(string subscriptionUriString, string identity)
        {
            Uri       uri = new Uri(subscriptionUriString);
            string    resourceUriString = uri.ToCanonicalString(false, true);
            IPiSystem resource          = GetPiSystem(resourceUriString);

            await resource.UnsubscribeAsync(subscriptionUriString, identity);
        }
Пример #6
0
        /// <summary>
        /// Unsubscribes a subscription from a resource.
        /// </summary>
        /// <param name="subscriptionUriString">Unique URI for the subscription.</param>
        /// <returns></returns>
        public async Task UnsubscribeAsync(string subscriptionUriString)
        {
            //get the resource to unsubscribe
            Uri       uri = new Uri(subscriptionUriString);
            string    resourceUriString = uri.ToCanonicalString(false, true);
            IPiSystem resource          = GetPiSystem(resourceUriString);

            //unsubscribe from the resource
            await resource.UnsubscribeAsync(subscriptionUriString);
        }
Пример #7
0
        private async Task UnsubscribeFromResourceAsync()
        {
            //unsubscribe from resource
            string uriString = State.Metadata.SubscriptionUriString;
            Uri    uri       = new Uri(uriString);

            string    resourceUriString = uriString.Replace("/" + uri.Segments[uri.Segments.Length - 1], "");
            IPiSystem resource          = GrainFactory.GetGrain <IPiSystem>(resourceUriString);

            if (State.Metadata != null && !string.IsNullOrEmpty(State.Metadata.SubscriptionUriString))
            {
                await resource.UnsubscribeAsync(State.Metadata.SubscriptionUriString);
            }
        }
Пример #8
0
        public async Task <string> SubscribeAsync(string resourceUriString, SubscriptionMetadata metadata)
        {
            Uri    uri = new Uri(resourceUriString);
            string subscriptionUriString = uri.ToCanonicalString(true) + Guid.NewGuid();

            metadata.SubscriptionUriString = subscriptionUriString;

            ISubscription subscription = GetSubscription(subscriptionUriString);
            await subscription.UpsertMetadataAsync(metadata);

            IPiSystem resource = GetPiSystem(uri.ToCanonicalString(false));
            await resource.SubscribeAsync(subscription);

            return(subscriptionUriString);
        }
Пример #9
0
 private async void Sink_OnResponse(object sender, EventSinkResponseArgs e)
 {
     IPiSystem pisystem = GrainFactory.GetGrain <IPiSystem>(e.Message.ResourceUri);
     await pisystem.PublishAsync(e.Message);
 }
Пример #10
0
 /// <summary>
 /// Clears the resource; equivalent to deleting the resource.
 /// </summary>
 /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
 /// <returns></returns>
 public async Task ClearPiSystemAsync(string resourceUriString)
 {
     IPiSystem resource = GetPiSystem(resourceUriString);
     await resource.ClearAsync();
 }
Пример #11
0
 /// <summary>
 /// Removes an observer from a resource.
 /// </summary>
 /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
 /// <param name="leaseKey">Unqiue string of the observer's lease.</param>
 /// <returns></returns>
 public async Task RemoveResourceObserverAsync(string resourceUriString, string leaseKey)
 {
     IPiSystem resource = GetPiSystem(resourceUriString);
     await resource.RemoveObserverAsync(leaseKey);
 }
Пример #12
0
        /// <summary>
        /// Gets a list of subscription URIs subscribed to the resource.
        /// </summary>
        /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
        /// <returns>Array of subscription URIs subscribed to the resource.</returns>
        public async Task <IEnumerable <string> > GetPiSystemSubscriptionListAsync(string resourceUriString)
        {
            IPiSystem resource = GetPiSystem(resourceUriString);

            return(await resource.GetSubscriptionListAsync());
        }
Пример #13
0
 /// <summary>
 /// Publishes a message to a resources with indexes.
 /// </summary>
 /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
 /// <param name="message">Message to publishes.</param>
 /// <param name="indexes">Indexes used to filter subscriptions to subset.</param>
 /// <returns></returns>
 public async Task PublishAsync(string resourceUriString, EventMessage message, List <KeyValuePair <string, string> > indexes)
 {
     IPiSystem resource = GetPiSystem(resourceUriString);
     await resource.PublishAsync(message, indexes);
 }
Пример #14
0
 /// <summary>
 /// Publishes a message to a resource.
 /// </summary>
 /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
 /// <param name="message">Message to publish.</param>
 /// <returns></returns>
 public async Task PublishAsync(string resourceUriString, EventMessage message)
 {
     IPiSystem resource = GetPiSystem(resourceUriString);
     await resource.PublishAsync(message);
 }
Пример #15
0
        public async Task <CommunicationMetrics> GetPiSystemMetricsAsync(string resourceUriString)
        {
            IPiSystem resource = GetPiSystem(resourceUriString);

            return(await resource.GetMetricsAsync());
        }
Пример #16
0
        /// <summary>
        /// Get a resource's metadata.
        /// </summary>
        /// <param name="resourceUriString">Unique URI that identifies the resource.</param>
        /// <returns>Resource's metadata.</returns>
        public async Task <EventMetadata> GetPiSystemMetadataAsync(string resourceUriString)
        {
            IPiSystem resource = GetPiSystem(resourceUriString);

            return(await resource.GetMetadataAsync());
        }