Ejemplo n.º 1
0
        /// <summary>
        /// Create the cdm message processor
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="encoder"></param>
        /// <param name="logger"></param>
        public CdmMessageProcessor(IStorageAdapter storage, IRecordEncoder encoder,
                                   ILogger logger)
        {
            _logger               = logger ?? throw new ArgumentNullException(nameof(logger));
            _encoder              = encoder ?? throw new ArgumentNullException(nameof(encoder));
            _storage              = storage ?? throw new ArgumentNullException(nameof(storage));
            _lock                 = new SemaphoreSlim(1, 1);
            _samplesCacheSize     = 0;
            _cacheUploadTriggered = false;
            _samplesCache         = new Dictionary <string, List <MonitoredItemMessageModel> >();
            _dataSetsCache        = new Dictionary <string, List <DataSetMessageModel> >();
            _cdmCorpus            = new CdmCorpusDefinition();
            var cdmLogger = _logger.ForContext(typeof(CdmStatusLevel));

            _cdmCorpus.SetEventCallback(new EventCallback {
                Invoke = (level, msg) => LogCdm(cdmLogger, level, msg)
            });
            _cdmCorpus.Storage.Mount("adls", _storage.Adapter);
            var gitAdapter = new GithubAdapter();

            _cdmCorpus.Storage.Mount("cdm", gitAdapter);
            _cdmCorpus.Storage.DefaultNamespace = "adls";
            _cdmCorpus.AppId     = "Azure Industrial IoT";
            _manifestResolved    = null;
            _cacheUploadInterval = TimeSpan.FromSeconds(20);
            _cacheUploadTimer    = new Timer(CacheTimer_ElapsedAsync, null,
                                             _cacheUploadInterval, Timeout.InfiniteTimeSpan);
        }
        // NOTE: The Github adapter is on the deprecation path, in favor of using a remote adapter. It is currently
        // used for testing purposes and its functionality can be similarly achieved by using a remote adapter.
        // The Github adapter currently points to the public standards schema documents on the CDM repo (on master) and
        // is not configurable to point to a different repo.
        static void ConfigureGithubAdapter()
        {
            // Default values for the optional parameters used by the Github adapter.
            string timeout         = "2000";
            string maximumTimeout  = "10000";
            string numberOfRetries = "2";

            // Ask the user if optional parameters should be configured, or if defaults should just be used.
            if (ConfigureOptionalParameters("GithubAdapter"))
            {
                // Configure optional parameters.
                timeout         = GetOptionalParameterValueFromUser("timeout", "GithubAdapter", timeout /* this is just to show what the value should look like. */);
                maximumTimeout  = GetOptionalParameterValueFromUser("maximum timeout", "GithubAdapter", maximumTimeout);
                numberOfRetries = GetOptionalParameterValueFromUser("number of retries", "GithubAdapter", numberOfRetries);
            }

            // Create a Github adapter with the parameter values given by the user.
            var adapter = new GithubAdapter()
            {
                Timeout         = TimeSpan.FromMilliseconds(int.Parse(timeout)),
                MaximumTimeout  = TimeSpan.FromMilliseconds(int.Parse(maximumTimeout)),
                NumberOfRetries = int.Parse(numberOfRetries)
                                  // WaitTimeCallback is another optional parameter and can also be configured here.
            };

            // List the newly configured adapter's properties.
            Console.WriteLine("\nGithubAdapter configured. Properties of this GithubAdapter are:");
            Console.WriteLine("  Timeout: " + adapter.Timeout.Value.TotalMilliseconds);
            Console.WriteLine("  MaximumTimeout: " + adapter.MaximumTimeout.Value.TotalMilliseconds);
            Console.WriteLine("  NumberOfRetries: " + adapter.NumberOfRetries);
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        public async Task WhenFindingLatestRelease_OneReleaseIsReturned()
        {
            var adapter = new GithubAdapter();
            var release = await adapter.FindLatestReleaseAsync(CancellationToken.None);

            Assert.IsNotNull(release);
            Assert.IsTrue(release.TagVersion.Major >= 1);
        }
Ejemplo n.º 4
0
        public void should_object_contain_sha_key()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();

            // assert
            references.First().Object.Sha.Should().NotBeEmpty();
        }
Ejemplo n.º 5
0
        public void should_be_at_least_one_reference()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();

            // assert
            references.Count.Should().BeGreaterOrEqualTo(1);
        }
Ejemplo n.º 6
0
        public void should_contain_at_least_one_item_in_tree()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();
            var tree       = adapter.GetTrees(references.First().Object.Sha);

            // assert
            tree.Tree.Count.Should().BeGreaterOrEqualTo(1);
        }
Ejemplo n.º 7
0
        public void should_trees_contain_tree()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();
            var tree       = adapter.GetTrees(references.First().Object.Sha);

            // assert
            tree.Tree.Should().NotBeNull();
        }
Ejemplo n.º 8
0
        public void should_blob_contain_content_field()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();
            var trees      = adapter.GetTrees(references.First().Object.Sha);
            var blob       = adapter.GetBlob(trees.Tree.First().Sha);

            // assert
            blob.Content.Should().NotBeEmpty();
        }
Ejemplo n.º 9
0
        public void should_contain_ref_and_object_and_url_fields()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();

            // assert
            references.First().Ref.Should().NotBeEmpty();
            references.First().Url.Should().NotBeEmpty();
            references.First().Object.Should().NotBeNull();
        }
Ejemplo n.º 10
0
        public void should_tree_contain_path_and_url_and_sha()
        {
            // arrange
            var adapter = new GithubAdapter("alexanderbeletsky", "blog.beletsky.net");

            // act
            var references = adapter.GetAllReferences();
            var tree       = adapter.GetTrees(references.First().Object.Sha);

            // assert
            tree.Tree.First().Path.Should().NotBeEmpty();
            tree.Tree.First().Url.Should().NotBeEmpty();
            tree.Tree.First().Sha.Should().NotBeEmpty();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create the cdm message processor
        /// </summary>
        /// <param name="config"></param>
        /// <param name="logger"></param>
        /// <param name="storage"></param>
        public CdmMessageProcessor(ICdmClientConfig config,
                                   ILogger logger, IAdlsStorage storage)
        {
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
            _config  = config ?? throw new ArgumentNullException(nameof(config));
            _storage = storage ?? throw new ArgumentNullException(nameof(storage));

            _lock                 = new SemaphoreSlim(1, 1);
            _samplesCacheSize     = 0;
            _cacheUploadTimer     = new Timer(CacheTimer_ElapesedAsync);
            _cacheUploadTriggered = false;
            _cacheUploadInterval  = TimeSpan.FromSeconds(20);
            _samplesCache         = new Dictionary <string, List <MonitoredItemSampleModel> >();
            _dataSetsCache        = new Dictionary <string, List <DataSetMessageModel> >();

            _cdmCorpus = new CdmCorpusDefinition();
            _cdmCorpus.SetEventCallback(new EventCallback {
                Invoke = (level, msg) => {
                    switch (level)
                    {
                    case CdmStatusLevel.Error:
                        _logger.Error("CDM message: {0}", msg);
                        break;

                    case CdmStatusLevel.Warning:
                        _logger.Warning("CDM message: {0}", msg);
                        break;

                    case CdmStatusLevel.Progress:
                        _logger.Verbose("CDM message: {0}", msg);
                        break;

                    case CdmStatusLevel.Info:
                        _logger.Debug("CDM message: {0}", msg);
                        break;
                    }
                }
            });

            _adapter = new ADLSAdapter($"{config.ADLSg2HostName}",
                                       $"/{config.ADLSg2ContainerName}/{config.RootFolder}", config.TenantId, config.AppId, config.AppSecret);
            _cdmCorpus.Storage.Mount("adls", _adapter);
            var gitAdapter = new GithubAdapter();

            _cdmCorpus.Storage.Mount("cdm", gitAdapter);
            _cdmCorpus.Storage.DefaultNamespace = "adls";
        }
Ejemplo n.º 12
0
 public UpdateService(IServiceProvider serviceProvider)
 {
     this.githubAdapter = serviceProvider.GetService <GithubAdapter>();
     this.taskDialog    = serviceProvider.GetService <ITaskDialog>();
 }
Ejemplo n.º 13
0
 public UpdateService(IServiceProvider serviceProvider)
 {
     this.githubAdapter = serviceProvider.GetService <GithubAdapter>();
 }