Exemplo n.º 1
0
        /// <summary>
        /// Due to some performance issues with version of EBO prior to 2.0, we will limit the amount of points that can be consumed out of EBO versions
        /// prior to 2.0 to 100. No limit for point count in version 2.0 and above.
        /// </summary>
        private bool EvaluatePerformanceImpact(List <Signal> signals)
        {
            try
            {
                // We save this right away so we can execute this setup processor from the value push processor if it is not running
                Cache.AddOrUpdateItem(this.ConfigurationId, "SetupProcessorConfigurationId", this.CacheTenantId, 0);
                var response   = ManagedEwsClient.GetWebServiceInformation(EboEwsSettings);
                var eboVersion = new Version(response.GetWebServiceInformationSystem.Version);
                if (eboVersion.Major > 1)
                {
                    _signalsToUse = signals;
                }
                else
                {
                    if (signals.Count > 100)
                    {
                        Prompts.Add(new Prompt
                        {
                            Severity = PromptSeverity.MayContinue,
                            Message  = $"Due to performance concerns, only 100 points out of {signals.Count} can be consumed when using EBO versions prior to 2.0. Please update your EBO to version 2.0 or greater to get the full functionality of the EBO IoT Edge Smart Connector Extension."
                        });
                    }

                    _signalsToUse = signals.Take(100).ToList();
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogError(LogCategory.Processor, this.Name, ex.ToString());
                return(false);
            }
        }
Exemplo n.º 2
0
        private async Task <bool> ReadExistingSubscriptions(List <Signal> signals)
        {
            Logger.LogTrace(LogCategory.Processor, this.Name, $"Reading existing subscriptions..");

            var activeSubscriptions          = Cache.RetrieveItem($"ActiveSubscriptions", () => new List <string>(), CacheTenantId, 0) as List <string>;
            var activeSubscriptionsToIterate = activeSubscriptions.ToList();

            foreach (var sub in activeSubscriptionsToIterate)
            {
                if (IsCancellationRequested)
                {
                    return(false);
                }
                var subscription = Cache.RetrieveItem($"ActiveSubscriptions#{sub}", CacheTenantId);
                Logger.LogDebug(LogCategory.Processor, $"Reading existing subscription: {sub}");
                try
                {
                    CheckCancellationToken();

                    var si = new SubscriptionReader
                    {
                        Address  = EboEwsSettings.Address,
                        UserName = EboEwsSettings.UserName,
                        Password = EboEwsSettings.Password,
                        SubscriptionEventType = EwsSubscriptionEventTypeEnum.ValueItemChanged,
                        SubscriptionId        = sub
                    };
                    var results = si.ReadData();
                    // Attempt to update the values by reading the subscription, if this fails return all Prompts
                    if (!await UpdateValues(si, results))
                    {
                        if (!si.IsResubscribeRequired)
                        {
                            return(false);
                        }
                        activeSubscriptions.Remove(sub);
                        Cache.DeleteItem($"ActiveSubscriptions#{sub}", CacheTenantId);
                    }

                    // It's possible that the subscription id has changed if it failed to be renewed/ updated... reset it here
                    if (si.SubsciptionChanged)
                    {
                        Logger.LogDebug(LogCategory.Processor, $"Subscription Id {sub} has changed to {si.SubscriptionId}, updating cache values to represent this");
                        activeSubscriptions.Remove(sub);
                        activeSubscriptions.Add(si.SubscriptionId);
                        Cache.DeleteItem($"ActiveSubscriptions#{sub}", CacheTenantId);
                        Cache.AddOrUpdateItem(subscription, $"ActiveSubscriptions#{si.SubscriptionId}", CacheTenantId, 0);
                    }
                }

                catch (Exception)
                {
                    activeSubscriptions.Remove(sub);
                    Cache.DeleteItem($"ActiveSubscriptions#{sub}", CacheTenantId);
                }
            }

            // Save any changes to cache
            Cache.AddOrUpdateItem(activeSubscriptions, $"ActiveSubscriptions", CacheTenantId, 0);
            return(true);
        }
Exemplo n.º 3
0
        private async Task <bool> SubscribeAndReadNew(List <Signal> signals)
        {
            Logger.LogTrace(LogCategory.Processor, this.Name, $"Creating and reading new subscriptions..");
            var activeSubscriptions = Cache.RetrieveItem($"ActiveSubscriptions", () => new List <string>(), CacheTenantId, 0) as List <string>;

            var subscribedIds = new List <string>();

            foreach (var subscription in activeSubscriptions)
            {
                var itemsToAdd = Cache.RetrieveItem <List <string> >($"ActiveSubscriptions#{subscription}", null, CacheTenantId);
                if (itemsToAdd != null)
                {
                    subscribedIds.AddRange(itemsToAdd);
                }
            }

            var unsubscribedIds = signals.Select(a => a.EwsId).Where(a => !subscribedIds.Contains(a)).ToList();

            Logger.LogDebug(LogCategory.Processor, this.Name, $"Found {unsubscribedIds.Count} points that are not currently subscribed to.");
            Logger.LogTrace(LogCategory.Processor, this.Name, $"Unsubscribed Point Ids: {unsubscribedIds.ToJSON()}");

            while (unsubscribedIds.Any())
            {
                if (IsCancellationRequested)
                {
                    return(false);
                }
                try
                {
                    var idsToSubscribeTo = unsubscribedIds.Take(MaxItemsPerSubscription).ToList();
                    CheckCancellationToken();
                    var si = new SubscriptionReader
                    {
                        Address  = EboEwsSettings.Address,
                        UserName = EboEwsSettings.UserName,
                        Password = EboEwsSettings.Password,
                        SubscriptionEventType = EwsSubscriptionEventTypeEnum.ValueItemChanged,
                        Ids = idsToSubscribeTo
                    };

                    // Attempt to update the values by reading the subscription, if this fails return all false as this could go on forever.
                    var results = si.ReadData();
                    // If all the ids we subscribed to failed, just continue on.. nothing to see here..
                    if (si.FailedSubscribedItems.Count == idsToSubscribeTo.Count)
                    {
                        return(true);
                    }
                    if (!await UpdateValues(si, results, true))
                    {
                        return(false);
                    }

                    Cache.AddOrUpdateItem(si.SubscribedItems, $"ActiveSubscriptions#{si.SubscriptionId}", CacheTenantId, 0);
                    unsubscribedIds = unsubscribedIds.Skip(MaxItemsPerSubscription).ToList();

                    activeSubscriptions.Add(si.SubscriptionId);
                    Cache.AddOrUpdateItem(activeSubscriptions, $"ActiveSubscriptions", CacheTenantId, 0);

                    // Add any prompts generated from reader to the list of prompts
                    Prompts.AddRange(si.ReadData().Prompts);

                    if (si.FailedSubscribedItems.Any())
                    {
                        Logger.LogInfo(LogCategory.Processor, this.Name, $"Some items failed to be subscribed to: {si.FailedSubscribedItems.ToJSON()}");
                    }
                }

                catch (Exception ex)
                {
                    Prompts.Add(ex.ToPrompt());
                    break;
                }
            }

            return(true);

            // TODO: How to handle subscriptions to value items that keep failing?
        }