コード例 #1
0
        private static DistributedContentStoreSettings CreateDistributedStoreSettings(
            DistributedCacheServiceArguments arguments,
            RedisContentLocationStoreConfiguration redisContentLocationStoreConfiguration)
        {
            var distributedSettings = arguments.Configuration.DistributedContentSettings;

            PinConfiguration pinConfiguration = new PinConfiguration();

            if (distributedSettings.IsPinBetterEnabled)
            {
                ApplyIfNotNull(distributedSettings.PinMinUnverifiedCount, v => pinConfiguration.PinMinUnverifiedCount = v);
                ApplyIfNotNull(distributedSettings.StartCopyWhenPinMinUnverifiedCountThreshold, v => pinConfiguration.StartCopyWhenPinMinUnverifiedCountThreshold = v);
                ApplyIfNotNull(distributedSettings.MaxIOOperations, v => pinConfiguration.MaxIOOperations = v);
            }

            var distributedContentStoreSettings = new DistributedContentStoreSettings()
            {
                TrustedHashFileSizeBoundary     = distributedSettings.TrustedHashFileSizeBoundary,
                ParallelHashingFileSizeBoundary = distributedSettings.ParallelHashingFileSizeBoundary,
                MaxConcurrentCopyOperations     = distributedSettings.MaxConcurrentCopyOperations,
                PinConfiguration                     = pinConfiguration,
                RetryIntervalForCopies               = distributedSettings.RetryIntervalForCopies,
                MaxRetryCount                        = distributedSettings.MaxRetryCount,
                TimeoutForProactiveCopies            = TimeSpan.FromMinutes(distributedSettings.TimeoutForProactiveCopiesMinutes),
                ProactiveCopyMode                    = (ProactiveCopyMode)Enum.Parse(typeof(ProactiveCopyMode), distributedSettings.ProactiveCopyMode),
                PushProactiveCopies                  = distributedSettings.PushProactiveCopies,
                ProactiveCopyOnPut                   = distributedSettings.ProactiveCopyOnPut,
                ProactiveCopyOnPin                   = distributedSettings.ProactiveCopyOnPin,
                ProactiveCopyUsePreferredLocations   = distributedSettings.ProactiveCopyUsePreferredLocations,
                MaxConcurrentProactiveCopyOperations = distributedSettings.MaxConcurrentProactiveCopyOperations,
                ProactiveCopyLocationsThreshold      = distributedSettings.ProactiveCopyLocationsThreshold,
                ProactiveCopyRejectOldContent        = distributedSettings.ProactiveCopyRejectOldContent,
                ReplicaCreditInMinutes               = distributedSettings.IsDistributedEvictionEnabled ? distributedSettings.ReplicaCreditInMinutes : null,
                EnableRepairHandling                 = distributedSettings.IsRepairHandlingEnabled,
                LocationStoreBatchSize               = distributedSettings.RedisBatchPageSize,
                RestrictedCopyReplicaCount           = distributedSettings.RestrictedCopyReplicaCount,
                CopyAttemptsWithRestrictedReplicas   = distributedSettings.CopyAttemptsWithRestrictedReplicas,
                AreBlobsSupported                    = redisContentLocationStoreConfiguration.AreBlobsSupported,
                MaxBlobSize = redisContentLocationStoreConfiguration.MaxBlobSize,
                DelayForProactiveReplication  = TimeSpan.FromSeconds(distributedSettings.ProactiveReplicationDelaySeconds),
                ProactiveReplicationCopyLimit = distributedSettings.ProactiveReplicationCopyLimit,
                EnableProactiveReplication    = distributedSettings.EnableProactiveReplication,
                TraceProactiveCopy            = distributedSettings.TraceProactiveCopy,
                ProactiveCopyGetBulkBatchSize = distributedSettings.ProactiveCopyGetBulkBatchSize,
                ProactiveCopyGetBulkInterval  = TimeSpan.FromSeconds(distributedSettings.ProactiveCopyGetBulkIntervalSeconds)
            };

            if (distributedSettings.EnableProactiveReplication && redisContentLocationStoreConfiguration.Checkpoint != null)
            {
                distributedContentStoreSettings.ProactiveReplicationInterval = redisContentLocationStoreConfiguration.Checkpoint.RestoreCheckpointInterval;
            }

            ApplyIfNotNull(distributedSettings.MaximumConcurrentPutAndPlaceFileOperations, v => distributedContentStoreSettings.MaximumConcurrentPutAndPlaceFileOperations = v);

            arguments.Overrides.Override(distributedContentStoreSettings);

            ConfigurationPrinter.TraceConfiguration(distributedContentStoreSettings, arguments.Logger);

            return(distributedContentStoreSettings);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            ILog log = LogManager.GetLogger("GPIO");

            log.Debug("Start");

            PinConfiguration output = ConnectorPin.P1Pin36.Output().Name("Output1");

            PinConfiguration[] outputs = new PinConfiguration[]
            {
                output
            };

            GpioConnection gpio = new GpioConnection(outputs);
            //gpio.Open();

            ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            Mcp3008SpiConnection spi = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            IInputAnalogPin inputPin = spi.In(Mcp3008Channel.Channel0);

            gpio.Open();
            ElectricPotential volts = ElectricPotential.FromVolts(0);

            while (!Console.KeyAvailable)
            {
                var v = referenceVoltage * (double)inputPin.Read().Relative;
                Console.WriteLine("{0} mV", v.Millivolts);
                if ((Math.Abs(v.Millivolts - volts.Millivolts) > 100))
                {
                    volts = ElectricPotential.FromMillivolts(v.Millivolts);
                    Console.WriteLine("Voltage ch0: {0}", volts.Millivolts.ToString());
                }
                gpio.Toggle("Output1");
                Thread.Sleep(2000);
            }
            gpio.Close();

            //bool bShutdown = false;
            //while(!bShutdown)
            //{

            //    gpio.Toggle(output);
            //    log.Debug("Toggle output");

            //    Thread.Sleep(5000);

            //}
        }
コード例 #3
0
 /// <nodoc />
 public DistributedContentStore(
     byte[] localMachineLocation,
     Func <NagleQueue <ContentHash>, DistributedEvictionSettings, ContentStoreSettings, TrimBulkAsync, IContentStore> innerContentStoreFunc,
     IContentLocationStoreFactory contentLocationStoreFactory,
     IFileExistenceChecker <T> fileExistenceChecker,
     IFileCopier <T> fileCopier,
     IPathTransformer <T> pathTransform,
     ICopyRequester copyRequester,
     ReadOnlyDistributedContentSession <T> .ContentAvailabilityGuarantee contentAvailabilityGuarantee,
     AbsolutePath tempFolderForCopies,
     IAbsFileSystem fileSystem,
     int locationStoreBatchSize,
     IReadOnlyList <TimeSpan> retryIntervalForCopies = null,
     PinConfiguration pinConfiguration = null,
     int?replicaCreditInMinutes        = null,
     IClock clock = null,
     bool enableRepairHandling                 = false,
     TimeSpan?contentHashBumpTime              = null,
     bool useTrustedHash                       = false,
     int trustedHashFileSizeBoundary           = -1,
     long parallelHashingFileSizeBoundary      = -1,
     int maxConcurrentCopyOperations           = 512,
     ContentStoreSettings contentStoreSettings = null,
     bool enableProactiveCopy                  = false)
     : this(
         localMachineLocation,
         innerContentStoreFunc,
         contentLocationStoreFactory,
         fileExistenceChecker,
         fileCopier,
         pathTransform,
         copyRequester,
         contentAvailabilityGuarantee,
         tempFolderForCopies,
         fileSystem,
         locationStoreBatchSize,
         new DistributedContentStoreSettings()
 {
     UseTrustedHash = useTrustedHash,
     TrustedHashFileSizeBoundary = trustedHashFileSizeBoundary,
     ParallelHashingFileSizeBoundary = parallelHashingFileSizeBoundary,
     MaxConcurrentCopyOperations = maxConcurrentCopyOperations,
     RetryIntervalForCopies = retryIntervalForCopies,
     PinConfiguration = pinConfiguration,
     EnableProactiveCopy = enableProactiveCopy
 },
         replicaCreditInMinutes,
         clock,
         enableRepairHandling,
         contentHashBumpTime,
         contentStoreSettings)
 {
     // This constructor is used from tests,
     // so we need to complete _postInitializationCompletion when startup is done.
     _setPostInitializationCompletionAfterStartup = true;
 }
コード例 #4
0
 private void ChangePortState(PinConfiguration pinConfiguration, PortStates portState)
 {
     switch (pinConfiguration.PortType)
     {
     case PortTypes.Switch:
     case PortTypes.Pulse:
         var outputPin = _outputPins.First(p => p.PinId == pinConfiguration.PinId);
         ChangePortState(outputPin, portState);
         break;
     }
 }
コード例 #5
0
        public GPIOSolenoid(int id, string name, string address)
        {
            log     = LogManager.GetLogger("Device");
            Id      = id;
            Name    = name;
            Address = address;

            pin = GPIOService.GetGPIOPin(Address);

            pinConfig = pin.Output().Name(name);
            GPIOService.Gpio.Add(pinConfig);
        }
コード例 #6
0
        //setup the event handler for changes - using Raspberry.IO.GeneralPurpose library
        public GpioInputPin(int pinNumber, String name)
            : base(pinNumber, name)
        {
            var gpioPin = GpioController.IntToConnectorPin(pinNumber);

            _pin = gpioPin.Input()
                   .Name(gpioPin.ToString())
                   .OnStatusChanged(b =>
            {
                InputChanged(b);
            });

            Log.LogMessage("GpioInputPin CTOR() " + name + " on " + gpioPin);
        }
コード例 #7
0
        public async Task ProativeCopyDistributedTest()
        {
            // Use the same context in two sessions when checking for file existence
            var loggingContext = new Context(Logger);

            var contentHashes = new List <ContentHash>();

            int machineCount = 3;

            ConfigureWithOneMaster();

            // We need pin better to be triggered.
            PinConfiguration = new PinConfiguration();

            await RunTestAsync(
                loggingContext,
                machineCount,
                async context =>
            {
                var masterStore     = context.GetMaster();
                var defaultFileSize = (Config.MaxSizeQuota.Hard / 4) + 1;

                var sessions = context.EnumerateWorkersIndices().Select(i => context.GetDistributedSession(i)).ToArray();

                // Insert random file #1 into worker #1
                var putResult1 = await sessions[0].PutRandomAsync(context, HashType.Vso0, false, defaultFileSize, Token).ShouldBeSuccess();
                var hash1      = putResult1.ContentHash;

                var getBulkResult1 = await masterStore.GetBulkAsync(context, hash1, GetBulkOrigin.Global).ShouldBeSuccess();

                // LocationStore knew no machines, so copying should not be possible. However, next time it will know location 1.
                getBulkResult1.ContentHashesInfo[0].Locations.Count.Should().Be(1);

                // Insert random file #2 into worker #2
                var putResult2 = await sessions[0].PutRandomAsync(context, HashType.Vso0, false, defaultFileSize, Token).ShouldBeSuccess();
                var hash2      = putResult2.ContentHash;

                await Task.Delay(TimeSpan.FromSeconds(1));     // Wait for proactive copy to finish in the background.

                var getBulkResult2 = await masterStore.GetBulkAsync(context, hash2, GetBulkOrigin.Global).ShouldBeSuccess();

                // Should have proactively copied to worker #1
                getBulkResult2.ContentHashesInfo[0].Locations.Count.Should().Be(2);
            },
                implicitPin : ImplicitPin.None);
        }
コード例 #8
0
 public GPIOAlarm(int id, string name, string address)
 {
     Id        = id;
     Name      = name;
     Address   = address;
     pin       = GPIOService.GetGPIOPin(Address);
     pinConfig = pin.Input().Name(Name).OnStatusChanged(b =>
     {
         State = b ? true : false;
         //Console.WriteLine("Alarm {0} {1}", Name, b ? "on" : "off");
         AlarmStatusChangedEventArgs e = new AlarmStatusChangedEventArgs();
         e.Value = b;
         OnStatusChanged(e);
     });
     Id = id;
     GPIOService.Gpio.Add(pinConfig);
 }
コード例 #9
0
ファイル: MotorDriver.cs プロジェクト: manf88/ACHIM
        public void Initialize()
        {
            if (Pin1 == Pin2)
            {
                throw new NullReferenceException("Set the Pins before calling Initialize()");
            }

            _pinConfig1 = Pin1.Output();
            _pinConfig2 = Pin2.Output();

            _settings = new GpioConnectionSettings()
            {
                Driver = new GpioConnectionDriver()
            };
            _connection = new GpioConnection(_settings);
            _connection.Add(_pinConfig1);
            _connection.Add(_pinConfig2);
        }
コード例 #10
0
        static void Main(string[] args)
        {
            const ConnectorPin led1Pin   = ConnectorPin.P1Pin26;
            const ConnectorPin led2Pin   = ConnectorPin.P1Pin24;
            const ConnectorPin led3Pin   = ConnectorPin.P1Pin22;
            const ConnectorPin led4Pin   = ConnectorPin.P1Pin15;
            const ConnectorPin led5Pin   = ConnectorPin.P1Pin13;
            const ConnectorPin led6Pin   = ConnectorPin.P1Pin11;
            const ConnectorPin buttonPin = ConnectorPin.P1Pin03;

            Console.WriteLine("Chaser Sample: Sample a LED chaser with a switch to change behavior");
            Console.WriteLine();
            Console.WriteLine("\tLed 1: {0}", led1Pin);
            Console.WriteLine("\tLed 2: {0}", led2Pin);
            Console.WriteLine("\tLed 3: {0}", led3Pin);
            Console.WriteLine("\tLed 4: {0}", led4Pin);
            Console.WriteLine("\tLed 5: {0}", led5Pin);
            Console.WriteLine("\tLed 6: {0}", led6Pin);
            Console.WriteLine("\tSwitch: {0}", buttonPin);
            Console.WriteLine();

            var driver = args.GetDriver();

            // Declare outputs (leds)
            var leds = new PinConfiguration[]
            {
                led1Pin.Output().Name("Led1").Enable(),
                led2Pin.Output().Name("Led2"),
                led3Pin.Output().Name("Led3").Enable(),
                led4Pin.Output().Name("Led4"),
                led5Pin.Output().Name("Led5").Enable(),
                led6Pin.Output().Name("Led6")
            };

            // Assign a behavior to the leds
            var behavior = new ChaserBehavior(leds)
            {
                Loop      = args.GetLoop(),
                RoundTrip = args.GetRoundTrip(),
                Width     = args.GetWidth(),
                Interval  = TimeSpan.FromMilliseconds(args.GetSpeed())
            };

            // Alternate behaviors...

            /*
             * var random = new Random();
             * var behavior = new PatternBehavior(leds, Enumerable.Range(0, 5).Select(i => random.Next(511)))
             *                 {
             *                     Loop = Helpers.GetLoop(args),
             *                     RoundTrip = Helpers.GetRoundTrip(args),
             *                     Interval = Helpers.GetSpeed(args)
             *                 };*/

            /*
             * var behavior = new BlinkBehavior(leds)
             *                 {
             *                     Count = args.GetWidth(),
             *                     Interval = args.GetSpeed()
             *                 };*/

            // Declare input (switchButton) interacting with the leds behavior
            var switchButton = buttonPin.Input()
                               .Name("Switch")
                               .Revert()
                               .Switch()
                               .Enable()
                               .OnStatusChanged(b =>
            {
                behavior.RoundTrip = !behavior.RoundTrip;
                Console.WriteLine("Button switched {0}", b ? "on" : "off");
            });

            // Create connection
            var settings = new GpioConnectionSettings {
                Driver = driver
            };

            using (var connection = new GpioConnection(settings, leds))
            {
                Console.WriteLine("Using {0}, frequency {1:0.##}hz", settings.Driver.GetType().Name, 1000.0 / args.GetSpeed());

                Thread.Sleep(1000);

                connection.Add(switchButton);
                connection.Start(behavior); // Starting the behavior automatically registers the pins to the connection, if needed.

                Console.ReadKey(true);

                connection.Stop(behavior);
            }
        }
コード例 #11
0
        public IContentStore CreateContentStore(
            AbsolutePath localCacheRoot,
            NagleQueue <ContentHash> evictionAnnouncer              = null,
            ProactiveReplicationArgs replicationSettings            = null,
            DistributedEvictionSettings distributedEvictionSettings = null,
            bool checkLocalFiles        = true,
            TrimBulkAsync trimBulkAsync = null)
        {
            var redisContentLocationStoreConfiguration = new RedisContentLocationStoreConfiguration
            {
                RedisBatchPageSize    = _distributedSettings.RedisBatchPageSize,
                BlobExpiryTimeMinutes = _distributedSettings.BlobExpiryTimeMinutes,
                MaxBlobCapacity       = _distributedSettings.MaxBlobCapacity,
                MaxBlobSize           = _distributedSettings.MaxBlobSize,
                EvictionWindowSize    = _distributedSettings.EvictionWindowSize
            };

            ApplyIfNotNull(_distributedSettings.ReplicaCreditInMinutes, v => redisContentLocationStoreConfiguration.ContentLifetime = TimeSpan.FromMinutes(v));
            ApplyIfNotNull(_distributedSettings.MachineRisk, v => redisContentLocationStoreConfiguration.MachineRisk = v);
            ApplyIfNotNull(_distributedSettings.LocationEntryExpiryMinutes, v => redisContentLocationStoreConfiguration.LocationEntryExpiry = TimeSpan.FromMinutes(v));
            ApplyIfNotNull(_distributedSettings.MachineExpiryMinutes, v => redisContentLocationStoreConfiguration.MachineExpiry             = TimeSpan.FromMinutes(v));

            redisContentLocationStoreConfiguration.ReputationTrackerConfiguration.Enabled = _distributedSettings.IsMachineReputationEnabled;

            if (_distributedSettings.IsContentLocationDatabaseEnabled)
            {
                var dbConfig = new RocksDbContentLocationDatabaseConfiguration(localCacheRoot / "LocationDb")
                {
                    StoreClusterState = _distributedSettings.StoreClusterStateInDatabase
                };

                redisContentLocationStoreConfiguration.Database = dbConfig;
                if (_distributedSettings.ContentLocationDatabaseGcIntervalMinutes != null)
                {
                    dbConfig.LocalDatabaseGarbageCollectionInterval = TimeSpan.FromMinutes(_distributedSettings.ContentLocationDatabaseGcIntervalMinutes.Value);
                }

                ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseCacheEnabled, v => dbConfig.CacheEnabled = v);
                ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseFlushDegreeOfParallelism, v => dbConfig.FlushDegreeOfParallelism         = v);
                ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseFlushSingleTransaction, v => dbConfig.FlushSingleTransaction             = v);
                ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseFlushPreservePercentInMemory, v => dbConfig.FlushPreservePercentInMemory = v);
                ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseCacheMaximumUpdatesPerFlush, v => dbConfig.CacheMaximumUpdatesPerFlush   = v);
                ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseCacheFlushingMaximumInterval, v => dbConfig.CacheFlushingMaximumInterval = v);

                ApplySecretSettingsForLlsAsync(redisContentLocationStoreConfiguration, localCacheRoot).GetAwaiter().GetResult();
            }

            if (_distributedSettings.IsRedisGarbageCollectionEnabled)
            {
                redisContentLocationStoreConfiguration.GarbageCollectionConfiguration = new RedisGarbageCollectionConfiguration()
                {
                    MaximumEntryLastAccessTime = TimeSpan.FromMinutes(30)
                };
            }
            else
            {
                redisContentLocationStoreConfiguration.GarbageCollectionConfiguration = null;
            }

            var localMachineLocation = _arguments.PathTransformer.GetLocalMachineLocation(localCacheRoot);
            var contentHashBumpTime  = TimeSpan.FromMinutes(_distributedSettings.ContentHashBumpTimeMinutes);

            // RedisContentSecretName and RedisMachineLocationsSecretName can be null. HostConnectionStringProvider won't fail in this case.
            IConnectionStringProvider contentConnectionStringProvider          = TryCreateRedisConnectionStringProvider(_redisContentSecretNames.RedisContentSecretName);
            IConnectionStringProvider machineLocationsConnectionStringProvider = TryCreateRedisConnectionStringProvider(_redisContentSecretNames.RedisMachineLocationsSecretName);

            var redisContentLocationStoreFactory = new RedisContentLocationStoreFactory(
                contentConnectionStringProvider,
                machineLocationsConnectionStringProvider,
                SystemClock.Instance,
                contentHashBumpTime,
                _keySpace,
                localMachineLocation,
                configuration: redisContentLocationStoreConfiguration
                );

            ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee contentAvailabilityGuarantee;
            if (string.IsNullOrEmpty(_distributedSettings.ContentAvailabilityGuarantee))
            {
                contentAvailabilityGuarantee =
                    ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee
                    .FileRecordsExist;
            }
            else if (!Enum.TryParse(_distributedSettings.ContentAvailabilityGuarantee, true, out contentAvailabilityGuarantee))
            {
                throw new ArgumentException($"Unable to parse {nameof(_distributedSettings.ContentAvailabilityGuarantee)}: [{_distributedSettings.ContentAvailabilityGuarantee}]");
            }

            PinConfiguration pinConfiguration = null;

            if (_distributedSettings.IsPinBetterEnabled)
            {
                pinConfiguration = new PinConfiguration();
                if (_distributedSettings.PinRisk.HasValue)
                {
                    pinConfiguration.PinRisk = _distributedSettings.PinRisk.Value;
                }
                if (_distributedSettings.MachineRisk.HasValue)
                {
                    pinConfiguration.MachineRisk = _distributedSettings.MachineRisk.Value;
                }
                if (_distributedSettings.FileRisk.HasValue)
                {
                    pinConfiguration.FileRisk = _distributedSettings.FileRisk.Value;
                }
                if (_distributedSettings.MaxIOOperations.HasValue)
                {
                    pinConfiguration.MaxIOOperations = _distributedSettings.MaxIOOperations.Value;
                }
                pinConfiguration.UsePinCache = _distributedSettings.IsPinCachingEnabled;
                if (_distributedSettings.PinCacheReplicaCreditRetentionMinutes.HasValue)
                {
                    pinConfiguration.PinCacheReplicaCreditRetentionMinutes = _distributedSettings.PinCacheReplicaCreditRetentionMinutes.Value;
                }
                if (_distributedSettings.PinCacheReplicaCreditRetentionDecay.HasValue)
                {
                    pinConfiguration.PinCacheReplicaCreditRetentionDecay = _distributedSettings.PinCacheReplicaCreditRetentionDecay.Value;
                }
            }

            var lazyTouchContentHashBumpTime = _distributedSettings.IsTouchEnabled ? (TimeSpan?)contentHashBumpTime : null;

            if (redisContentLocationStoreConfiguration.ReadMode == ContentLocationMode.LocalLocationStore)
            {
                // LocalLocationStore has its own internal notion of lazy touch/registration. We disable the lazy touch in distributed content store
                // because it can conflict with behavior of the local location store.
                lazyTouchContentHashBumpTime = null;
            }

            var contentStoreSettings = FromDistributedSettings(_distributedSettings);

            ConfigurationModel configurationModel = null;

            if (_arguments.Configuration.LocalCasSettings.CacheSettingsByCacheName.TryGetValue(_arguments.Configuration.LocalCasSettings.CasClientSettings.DefaultCacheName, out var namedCacheSettings))
            {
                configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(namedCacheSettings.CacheSizeQuotaString)));
            }

            _logger.Debug("Creating a distributed content store for Autopilot");
            var contentStore =
                new DistributedContentStore <AbsolutePath>(
                    localMachineLocation,
                    (announcer, evictionSettings, checkLocal, trimBulk) =>
                    ContentStoreFactory.CreateContentStore(_fileSystem, localCacheRoot, announcer, distributedEvictionSettings: evictionSettings,
                                                           contentStoreSettings: contentStoreSettings, trimBulkAsync: trimBulk, configurationModel: configurationModel),
                    redisContentLocationStoreFactory,
                    _arguments.Copier,
                    _arguments.Copier,
                    _arguments.PathTransformer,
                    contentAvailabilityGuarantee,
                    localCacheRoot,
                    _fileSystem,
                    _distributedSettings.RedisBatchPageSize,
                    new DistributedContentStoreSettings()
            {
                UseTrustedHash                  = _distributedSettings.UseTrustedHash,
                CleanRandomFilesAtRoot          = _distributedSettings.CleanRandomFilesAtRoot,
                TrustedHashFileSizeBoundary     = _distributedSettings.TrustedHashFileSizeBoundary,
                ParallelHashingFileSizeBoundary = _distributedSettings.ParallelHashingFileSizeBoundary,
                MaxConcurrentCopyOperations     = _distributedSettings.MaxConcurrentCopyOperations,
                PinConfiguration                = pinConfiguration,
                EmptyFileHashShortcutEnabled    = _distributedSettings.EmptyFileHashShortcutEnabled,
                RetryIntervalForCopies          = _distributedSettings.RetryIntervalForCopies,
            },
                    replicaCreditInMinutes: _distributedSettings.IsDistributedEvictionEnabled?_distributedSettings.ReplicaCreditInMinutes: null,
                    enableRepairHandling: _distributedSettings.IsRepairHandlingEnabled,
                    contentHashBumpTime: lazyTouchContentHashBumpTime,
                    contentStoreSettings: contentStoreSettings);

            _logger.Debug("Created Distributed content store.");
            return(contentStore);
        }
コード例 #12
0
        public async Task PinCacheTests()
        {
            var startTime          = TestClock.UtcNow;
            var pinCacheTimeToLive = TimeSpan.FromMinutes(30);

            PinConfiguration = new PinConfiguration()
            {
                // Low risk and high risk tolerance for machine or file loss to prevent pin better from kicking in
                MachineRisk = 0.0000001,
                FileRisk    = 0.0000001,
                PinRisk     = 0.9999,
                PinCacheReplicaCreditRetentionMinutes = (int)pinCacheTimeToLive.TotalMinutes,
                UsePinCache = true
            };

            ContentAvailabilityGuarantee = ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee.FileRecordsExist;

            await RunTestAsync(
                new Context(Logger),
                3,
                async context =>
            {
                var sessions = context.Sessions;
                var session0 = context.GetDistributedSession(0);

                var redisStore0 = (RedisContentLocationStore)session0.ContentLocationStore;

                // Insert random file in session 0
                var putResult0 = await sessions[0].PutRandomAsync(context, ContentHashType, false, ContentByteCount, Token).ShouldBeSuccess();

                // Pinning the file on another machine should succeed
                await sessions[1].PinAsync(context, putResult0.ContentHash, Token).ShouldBeSuccess();

                // Remove the location from backing content location store so that in the absence of pin caching the
                // result of pin should be false.
                var getBulkResult = await redisStore0.GetBulkAsync(context, new[] { putResult0.ContentHash }, Token, UrgencyHint.Nominal).ShouldBeSuccess();
                Assert.True(getBulkResult.ContentHashesInfo[0].Locations.Count == 1);

                await redisStore0.TrimBulkAsync(
                    context,
                    getBulkResult.ContentHashesInfo.Select(c => new ContentHashAndLocations(c.ContentHash)).ToList(),
                    Token,
                    UrgencyHint.Nominal).ShouldBeSuccess();

                // Verify no locations for the content
                var postTrimGetBulkResult = await redisStore0.GetBulkAsync(context, new[] { putResult0.ContentHash }, Token, UrgencyHint.Nominal).ShouldBeSuccess();
                Assert.True((postTrimGetBulkResult.ContentHashesInfo[0].Locations?.Count ?? 0) == 0);

                // Simulate calling pin within pin cache TTL
                TestClock.UtcNow = startTime + TimeSpan.FromMinutes(pinCacheTimeToLive.TotalMinutes * .99);

                // Now try to pin/pin bulk again (within pin cache TTL)
                await sessions[1].PinAsync(context.Context, putResult0.ContentHash, Token).ShouldBeSuccess();

                var pinBulkResult1withinTtl = await sessions[1].PinAsync(context.Context, new[] { putResult0.ContentHash }, Token);
                Assert.True((await pinBulkResult1withinTtl.Single()).Item.Succeeded);

                // Simulate calling pin within pin cache TTL
                TestClock.UtcNow = startTime + TimeSpan.FromMinutes(pinCacheTimeToLive.TotalMinutes * 1.01);

                var pinResult1afterTtl = await sessions[1].PinAsync(context.Context, putResult0.ContentHash, Token);
                Assert.False(pinResult1afterTtl.Succeeded);

                var pinBulkResult1afterTtl = await sessions[1].PinAsync(context.Context, new[] { putResult0.ContentHash }, Token);
                Assert.False((await pinBulkResult1afterTtl.Single()).Item.Succeeded);
            });
        }
コード例 #13
0
        private static DistributedContentStoreSettings CreateDistributedStoreSettings(
            DistributedCacheServiceArguments arguments,
            RedisContentLocationStoreConfiguration redisContentLocationStoreConfiguration)
        {
            var distributedSettings = arguments.Configuration.DistributedContentSettings;

            ContentAvailabilityGuarantee contentAvailabilityGuarantee;

            if (string.IsNullOrEmpty(distributedSettings.ContentAvailabilityGuarantee))
            {
                contentAvailabilityGuarantee = ContentAvailabilityGuarantee.FileRecordsExist;
            }
            else if (!Enum.TryParse(distributedSettings.ContentAvailabilityGuarantee, true, out contentAvailabilityGuarantee))
            {
                throw new ArgumentException($"Unable to parse {nameof(distributedSettings.ContentAvailabilityGuarantee)}: [{distributedSettings.ContentAvailabilityGuarantee}]");
            }

            PinConfiguration pinConfiguration = null;

            if (distributedSettings.IsPinBetterEnabled)
            {
                pinConfiguration = new PinConfiguration();
                ApplyIfNotNull(distributedSettings.PinRisk, v => pinConfiguration.PinRisk = v);
                ApplyIfNotNull(distributedSettings.PinMinUnverifiedCount, v => pinConfiguration.PinMinUnverifiedCount = v);
                ApplyIfNotNull(distributedSettings.MachineRisk, v => pinConfiguration.MachineRisk         = v);
                ApplyIfNotNull(distributedSettings.FileRisk, v => pinConfiguration.FileRisk               = v);
                ApplyIfNotNull(distributedSettings.MaxIOOperations, v => pinConfiguration.MaxIOOperations = v);

                pinConfiguration.IsPinCachingEnabled = distributedSettings.IsPinCachingEnabled;

                ApplyIfNotNull(distributedSettings.PinCacheReplicaCreditRetentionMinutes, v => pinConfiguration.PinCachePerReplicaRetentionCreditMinutes = v);
                ApplyIfNotNull(distributedSettings.PinCacheReplicaCreditRetentionDecay, v => pinConfiguration.PinCacheReplicaCreditRetentionFactor       = v);
            }

            var contentHashBumpTime          = TimeSpan.FromMinutes(distributedSettings.ContentHashBumpTimeMinutes);
            var lazyTouchContentHashBumpTime = distributedSettings.IsTouchEnabled ? (TimeSpan?)contentHashBumpTime : null;

            if (redisContentLocationStoreConfiguration.ReadMode == ContentLocationMode.LocalLocationStore)
            {
                // LocalLocationStore has its own internal notion of lazy touch/registration. We disable the lazy touch in distributed content store
                // because it can conflict with behavior of the local location store.
                lazyTouchContentHashBumpTime = null;
            }

            var distributedContentStoreSettings = new DistributedContentStoreSettings()
            {
                TrustedHashFileSizeBoundary     = distributedSettings.TrustedHashFileSizeBoundary,
                ParallelHashingFileSizeBoundary = distributedSettings.ParallelHashingFileSizeBoundary,
                MaxConcurrentCopyOperations     = distributedSettings.MaxConcurrentCopyOperations,
                PinConfiguration                      = pinConfiguration,
                RetryIntervalForCopies                = distributedSettings.RetryIntervalForCopies,
                MaxRetryCount                         = distributedSettings.MaxRetryCount,
                TimeoutForProactiveCopies             = TimeSpan.FromMinutes(distributedSettings.TimeoutForProactiveCopiesMinutes),
                ProactiveCopyMode                     = (ProactiveCopyMode)Enum.Parse(typeof(ProactiveCopyMode), distributedSettings.ProactiveCopyMode),
                PushProactiveCopies                   = distributedSettings.PushProactiveCopies,
                ProactiveCopyOnPut                    = distributedSettings.ProactiveCopyOnPut,
                ProactiveCopyOnPin                    = distributedSettings.ProactiveCopyOnPin,
                ProactiveCopyUsePreferredLocations    = distributedSettings.ProactiveCopyUsePreferredLocations,
                MaxConcurrentProactiveCopyOperations  = distributedSettings.MaxConcurrentProactiveCopyOperations,
                ProactiveCopyLocationsThreshold       = distributedSettings.ProactiveCopyLocationsThreshold,
                ProactiveCopyRejectOldContent         = distributedSettings.ProactiveCopyRejectOldContent,
                ReplicaCreditInMinutes                = distributedSettings.IsDistributedEvictionEnabled ? distributedSettings.ReplicaCreditInMinutes : null,
                EnableRepairHandling                  = distributedSettings.IsRepairHandlingEnabled,
                ContentHashBumpTime                   = lazyTouchContentHashBumpTime,
                LocationStoreBatchSize                = distributedSettings.RedisBatchPageSize,
                ContentAvailabilityGuarantee          = contentAvailabilityGuarantee,
                PrioritizeDesignatedLocationsOnCopies = distributedSettings.PrioritizeDesignatedLocationsOnCopies,
                RestrictedCopyReplicaCount            = distributedSettings.RestrictedCopyReplicaCount,
                CopyAttemptsWithRestrictedReplicas    = distributedSettings.CopyAttemptsWithRestrictedReplicas,
                AreBlobsSupported                     = redisContentLocationStoreConfiguration.AreBlobsSupported,
                MaxBlobSize = redisContentLocationStoreConfiguration.MaxBlobSize,
                DelayForProactiveReplication  = TimeSpan.FromSeconds(distributedSettings.ProactiveReplicationDelaySeconds),
                ProactiveReplicationCopyLimit = distributedSettings.ProactiveReplicationCopyLimit,
                EnableProactiveReplication    = distributedSettings.EnableProactiveReplication,
                TraceProactiveCopy            = distributedSettings.TraceProactiveCopy,
            };

            if (distributedSettings.EnableProactiveReplication && redisContentLocationStoreConfiguration.Checkpoint != null)
            {
                distributedContentStoreSettings.ProactiveReplicationInterval = redisContentLocationStoreConfiguration.Checkpoint.RestoreCheckpointInterval;
            }

            ApplyIfNotNull(distributedSettings.MaximumConcurrentPutAndPlaceFileOperations, v => distributedContentStoreSettings.MaximumConcurrentPutAndPlaceFileOperations = v);

            arguments.Overrides.Override(distributedContentStoreSettings);

            ConfigurationPrinter.TraceConfiguration(distributedContentStoreSettings, arguments.Logger);

            return(distributedContentStoreSettings);
        }
コード例 #14
0
        //const ConnectorPin Station12OutputPin = ConnectorPin.P1Pin36;

        static void Main(string[] args)
        {
            // Declare outputs (leds)
            var leds = new PinConfiguration[]
            {
                Station1OutputPin.Output().Name("Led1").Enable(),
                Station2OutputPin.Output().Name("Led2"),
                Station3OutputPin.Output().Name("Led3").Enable(),
                Station4OutputPin.Output().Name("Led4"),
                Station5OutputPin.Output().Name("Led5").Enable(),
                Station6OutputPin.Output().Name("Led6"),
                Station7OutputPin.Output().Name("Led7").Enable(),
                Station8OutputPin.Output().Name("Led8"),
                Station9OutputPin.Output().Name("Led9").Enable(),
                Station10OutputPin.Output().Name("Led10"),
                Station11OutputPin.Output().Name("Led11").Enable(),
                //Station12OutputPin.Output().Name("Led12")
            };

            Console.WriteLine("Chaser Sample: Sample a LED chaser with a switch to change behavior");
            Console.WriteLine();
            Console.WriteLine("\tLed 1: {0}", Station1OutputPin);
            Console.WriteLine("\tLed 2: {0}", Station2OutputPin);
            Console.WriteLine("\tLed 3: {0}", Station3OutputPin);
            Console.WriteLine("\tLed 4: {0}", Station4OutputPin);
            Console.WriteLine("\tLed 5: {0}", Station5OutputPin);
            Console.WriteLine("\tLed 6: {0}", Station6OutputPin);
            Console.WriteLine("\tSwitch: {0}", PushButtonInputPin);
            Console.WriteLine();

            // Assign a behavior to the leds
            int period   = 250;
            var behavior = new ChaserBehavior(leds)
            {
                Loop      = true,                             // args.GetLoop(),
                RoundTrip = true,                             // args.GetRoundTrip(),
                Width     = 12,                               // args.GetWidth(),
                Interval  = TimeSpan.FromMilliseconds(period) //TimeSpan.FromMilliseconds(args.GetSpeed())
            };
            var switchButton = LowPressureFaultInputPin.Input()
                               //.Name("Switch")
                               //.Revert()
                               //.Switch()
                               //.Enable()
                               .OnStatusChanged(b =>
            {
                behavior.RoundTrip = !behavior.RoundTrip;
                Console.WriteLine("Button switched {0}", b ? "on" : "off");
            });

            // Create connection
            var settings = new GpioConnectionSettings();// { Driver = driver };

            using (var connection = new GpioConnection(settings, leds))
            {
                Console.WriteLine("Using {0}, frequency {1:0.##}hz", settings.Driver.GetType().Name, 1000.0 / period);

                Thread.Sleep(1000);

                connection.Add(switchButton);
                connection.Start(behavior); // Starting the behavior automatically registers the pins to the connection, if needed.

                Console.ReadKey(true);

                connection.Stop(behavior);
            }
        }
コード例 #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("GPIOTestHarness");
            bool Station1OutputState = false;
            bool Station2OutputState = false;
            bool Station3OutputState = false;
            bool Station4OutputState = false;

            //var Output1 = Station1OutputPin.Output();
            //var Output2 = Station2OutputPin.Output();
            //var Output3 = Station3OutputPin.Output();
            //var Output4 = Station4OutputPin.Output();
            var pins = new PinConfiguration[]
            {
                Station1OutputPin.Output().Name("Output1"),
                Station2OutputPin.Output().Name("Output2"),
                Station3OutputPin.Output().Name("Output3"),
                Station4OutputPin.Output().Name("Output4")
            };
            //var settings = new GpioConnectionSettings();
            var connection = new GpioConnection(pins);

            var Input1 = LowPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowPressureFaultInput {0}", b ? "on" : "off");
                if (Station1OutputState != b)
                {
                    connection.Toggle("Output1"); Station1OutputState = b;
                }
            });

            connection.Add(Input1);
            var Input2 = HighPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("HighPressureFaultInput {0}", b ? "on" : "off");
                if (Station2OutputState != b)
                {
                    connection.Toggle("Output2"); Station2OutputState = b;
                }
            });

            connection.Add(Input2);
            var Input3 = LowWellFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowWellFaultInput {0}", b ? "on" : "off");
                if (Station3OutputState != b)
                {
                    connection.Toggle("Output3"); Station3OutputState = b;
                }
            });

            connection.Add(Input3);
            var Input4 = OverloadFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("OverloadFaultInput {0}", b ? "on" : "off");
                if (Station4OutputState != b)
                {
                    connection.Toggle("Output4"); Station4OutputState = b;
                }
            });

            connection.Add(Input4);

            ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            Mcp3008SpiConnection spi = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            IInputAnalogPin inputPin = spi.In(Mcp3008Channel.Channel0);

            connection.Open();
            ElectricPotential volts = ElectricPotential.FromVolts(0);

            while (!Console.KeyAvailable)
            {
                var v = referenceVoltage * (double)inputPin.Read().Relative;
                if ((Math.Abs(v.Millivolts - volts.Millivolts) > 100))
                {
                    volts = ElectricPotential.FromMillivolts(v.Millivolts);
                    Console.WriteLine("Voltage ch0: {0}", volts.Millivolts.ToString());
                }
            }
            connection.Close();
        }
コード例 #16
0
 private static void ConnectionGlobalPinAdd(PinConfiguration pc)
 {
     //if (CommonHelper.IsBoard)
     _gpioConnectionGlobalPin.Add(pc);
 }
コード例 #17
0
        public IContentStore CreateContentStore(AbsolutePath localCacheRoot)
        {
            var redisContentLocationStoreFactory = CreateRedisCacheFactory(localCacheRoot, out var redisContentLocationStoreConfiguration);

            var localMachineLocation = _arguments.PathTransformer.GetLocalMachineLocation(localCacheRoot);

            ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee contentAvailabilityGuarantee;
            if (string.IsNullOrEmpty(_distributedSettings.ContentAvailabilityGuarantee))
            {
                contentAvailabilityGuarantee =
                    ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee
                    .FileRecordsExist;
            }
            else if (!Enum.TryParse(_distributedSettings.ContentAvailabilityGuarantee, true, out contentAvailabilityGuarantee))
            {
                throw new ArgumentException($"Unable to parse {nameof(_distributedSettings.ContentAvailabilityGuarantee)}: [{_distributedSettings.ContentAvailabilityGuarantee}]");
            }

            PinConfiguration pinConfiguration = null;

            if (_distributedSettings.IsPinBetterEnabled)
            {
                pinConfiguration = new PinConfiguration();
                if (_distributedSettings.PinRisk.HasValue)
                {
                    pinConfiguration.PinRisk = _distributedSettings.PinRisk.Value;
                }
                if (_distributedSettings.MachineRisk.HasValue)
                {
                    pinConfiguration.MachineRisk = _distributedSettings.MachineRisk.Value;
                }
                if (_distributedSettings.FileRisk.HasValue)
                {
                    pinConfiguration.FileRisk = _distributedSettings.FileRisk.Value;
                }
                if (_distributedSettings.MaxIOOperations.HasValue)
                {
                    pinConfiguration.MaxIOOperations = _distributedSettings.MaxIOOperations.Value;
                }

                pinConfiguration.UsePinCache = _distributedSettings.IsPinCachingEnabled;

                if (_distributedSettings.PinCacheReplicaCreditRetentionMinutes.HasValue)
                {
                    pinConfiguration.PinCacheReplicaCreditRetentionMinutes = _distributedSettings.PinCacheReplicaCreditRetentionMinutes.Value;
                }
                if (_distributedSettings.PinCacheReplicaCreditRetentionDecay.HasValue)
                {
                    pinConfiguration.PinCacheReplicaCreditRetentionDecay = _distributedSettings.PinCacheReplicaCreditRetentionDecay.Value;
                }
            }

            var contentHashBumpTime          = TimeSpan.FromMinutes(_distributedSettings.ContentHashBumpTimeMinutes);
            var lazyTouchContentHashBumpTime = _distributedSettings.IsTouchEnabled ? (TimeSpan?)contentHashBumpTime : null;

            if (redisContentLocationStoreConfiguration.ReadMode == ContentLocationMode.LocalLocationStore)
            {
                // LocalLocationStore has its own internal notion of lazy touch/registration. We disable the lazy touch in distributed content store
                // because it can conflict with behavior of the local location store.
                lazyTouchContentHashBumpTime = null;
            }

            var contentStoreSettings = FromDistributedSettings(_distributedSettings);

            ConfigurationModel configurationModel = null;

            if (_arguments.Configuration.LocalCasSettings.CacheSettingsByCacheName.TryGetValue(_arguments.Configuration.LocalCasSettings.CasClientSettings.DefaultCacheName, out var namedCacheSettings))
            {
                configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(namedCacheSettings.CacheSizeQuotaString)));
            }

            var bandwidthCheckedCopier = new BandwidthCheckedCopier(_arguments.Copier, BandwidthChecker.Configuration.FromDistributedContentSettings(_distributedSettings), _logger);

            _logger.Debug("Creating a distributed content store for Autopilot");
            var contentStore =
                new DistributedContentStore <AbsolutePath>(
                    localMachineLocation,
                    (announcer, evictionSettings, checkLocal, trimBulk) =>
                    ContentStoreFactory.CreateContentStore(_fileSystem, localCacheRoot, announcer, distributedEvictionSettings: evictionSettings,
                                                           contentStoreSettings: contentStoreSettings, trimBulkAsync: trimBulk, configurationModel: configurationModel),
                    redisContentLocationStoreFactory,
                    _arguments.Copier,
                    bandwidthCheckedCopier,
                    _arguments.PathTransformer,
                    _arguments.CopyRequester,
                    contentAvailabilityGuarantee,
                    localCacheRoot,
                    _fileSystem,
                    _distributedSettings.RedisBatchPageSize,
                    new DistributedContentStoreSettings()
            {
                UseTrustedHash                  = _distributedSettings.UseTrustedHash,
                CleanRandomFilesAtRoot          = _distributedSettings.CleanRandomFilesAtRoot,
                TrustedHashFileSizeBoundary     = _distributedSettings.TrustedHashFileSizeBoundary,
                ParallelHashingFileSizeBoundary = _distributedSettings.ParallelHashingFileSizeBoundary,
                MaxConcurrentCopyOperations     = _distributedSettings.MaxConcurrentCopyOperations,
                PinConfiguration                = pinConfiguration,
                EmptyFileHashShortcutEnabled    = _distributedSettings.EmptyFileHashShortcutEnabled,
                RetryIntervalForCopies          = _distributedSettings.RetryIntervalForCopies,
                MaxRetryCount                        = _distributedSettings.MaxRetryCount,
                TimeoutForProactiveCopies            = TimeSpan.FromMinutes(_distributedSettings.TimeoutForProactiveCopiesMinutes),
                ProactiveCopyMode                    = (ProactiveCopyMode)Enum.Parse(typeof(ProactiveCopyMode), _distributedSettings.ProactiveCopyMode),
                MaxConcurrentProactiveCopyOperations = _distributedSettings.MaxConcurrentProactiveCopyOperations,
                ProactiveCopyLocationsThreshold      = _distributedSettings.ProactiveCopyLocationsThreshold,
                MaximumConcurrentPutFileOperations   = _distributedSettings.MaximumConcurrentPutFileOperations,
            },
                    replicaCreditInMinutes: _distributedSettings.IsDistributedEvictionEnabled?_distributedSettings.ReplicaCreditInMinutes: null,
                    enableRepairHandling: _distributedSettings.IsRepairHandlingEnabled,
                    contentHashBumpTime: lazyTouchContentHashBumpTime,
                    contentStoreSettings: contentStoreSettings);

            _logger.Debug("Created Distributed content store.");
            return(contentStore);
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: red-man/raspberry-sharp-io
        static void Main(string[] args)
        {
            try
            {
                var driver    = args.GetDriver();
                var mainboard = Board.Current;

                if (!mainboard.IsRaspberryPi)
                {
                    Console.WriteLine("'{0}' is not a valid processor for a Raspberry Pi.", mainboard.Processor);
                    return;
                }

                // Declare outputs (leds)
                var leds = new PinConfiguration[]
                {
                    ConnectorPin.P1Pin26.Output().Name("Led1").Enable(),
                    ConnectorPin.P1Pin24.Output().Name("Led2"),
                    ConnectorPin.P1Pin22.Output().Name("Led3").Enable(),
                    ConnectorPin.P1Pin15.Output().Name("Led4"),
                    ConnectorPin.P1Pin13.Output().Name("Led5").Enable(),
                    ConnectorPin.P1Pin11.Output().Name("Led6")
                };

                // Assign a behavior to the leds
                var behavior = new ChaserBehavior(leds)
                {
                    Loop      = args.GetLoop(),
                    RoundTrip = args.GetRoundTrip(),
                    Width     = args.GetWidth(),
                    Interval  = args.GetSpeed()
                };

                // Alternate behaviors...

                /*
                 * var random = new Random();
                 * var behavior = new PatternBehavior(leds, Enumerable.Range(0, 5).Select(i => random.Next(511)))
                 *                 {
                 *                     Loop = Helpers.GetLoop(args),
                 *                     RoundTrip = Helpers.GetRoundTrip(args),
                 *                     Interval = Helpers.GetSpeed(args)
                 *                 };*/

                /*
                 * var behavior = new BlinkBehavior(leds)
                 *                 {
                 *                     Count = args.GetWidth(),
                 *                     Interval = args.GetSpeed()
                 *                 };*/

                // Declare input (switchButton) interacting with the leds behavior
                var switchButton = ConnectorPin.P1Pin03.Input()
                                   .Name("Switch")
                                   .Revert()
                                   .Switch()
                                   .Enable()
                                   .OnStatusChanged(b =>
                {
                    behavior.RoundTrip = !behavior.RoundTrip;
                    Console.WriteLine("Button switched {0}", b ? "on" : "off");
                });

                // Create connection
                Console.WriteLine("Running on Raspberry firmware rev{0}, board rev{1}, processor {2}", mainboard.Firmware, mainboard.Revision, mainboard.Processor);

                var settings = new GpioConnectionSettings {
                    Driver = driver
                };

                using (var connection = new GpioConnection(settings, leds))
                {
                    Console.WriteLine("Using {0}, frequency {1:0.##}hz", settings.Driver.GetType().Name, 1000.0 / args.GetSpeed());

                    Thread.Sleep(1000);

                    connection.Add(switchButton);
                    connection.Start(behavior); // Starting the behavior automatically registers the pins to the connection, if needed.

                    Console.ReadKey(true);

                    connection.Stop(behavior);
                }
            }
            catch (Exception ex)
            {
                var currentException = ex;
                while (currentException != null)
                {
                    Console.WriteLine("{0}: {1}", currentException.GetType().Name, currentException.Message);
                    currentException = currentException.InnerException;
                }
            }
        }