コード例 #1
0
 public Registry With <TImplementation>() where TImplementation : IInterceptor <TService>
 {
     _implementationType     = typeof(TImplementation);
     _implementationFactory  = null;
     _implementationInstance = null;
     _registry.Add(Build());
     return(_registry);
 }
コード例 #2
0
 public Registry As(Type implementationType)
 {
     _implementationType     = implementationType;
     _implementationFactory  = null;
     _implementationInstance = null;
     _registry.Add(Build());
     return(_registry);
 }
コード例 #3
0
        public void Add_does_not_raise_an_exception_when_adding_the_same_registration_twice(Registry sut,
                                                                                            [Registration] IServiceRegistration registration)
        {
            // Act
            sut.Add(registration);

            // Assert
            Assert.That(() => sut.Add(registration), Throws.Nothing);
        }
コード例 #4
0
        public void Add_can_add_two_differently_named_registrations(Registry sut,
                                                                    [Registration(Name = "one")] IServiceRegistration registration1,
                                                                    [Registration(Name = "two")] IServiceRegistration registration2)
        {
            // Arrange
            sut.Add(registration1);

            // Act & assert
            Assert.That(() => sut.Add(registration2), Throws.Nothing);
        }
コード例 #5
0
        internal static void Run()
        {
            // http://ocw.mit.edu/courses/aeronautics-and-astronautics/16-410-principles-of-autonomy-and-decision-making-fall-2010/lecture-notes/MIT16_410F10_lec21.pdf

            var states = new Registry <IState>();
            var x1     = states.Add(new NamedState("x1"));
            var x2     = states.Add(new NamedState("x2"));
            var x3     = states.Add(new NamedState("x3"));

            var observations = new Registry <IObservation>();
            var o2           = observations.Add(new NamedObservation("o2"));
            var o3           = observations.Add(new NamedObservation("o3"));

            // test the HMM with a known graph
            {
                var initial = new InitialStateMatrix(states);
                initial.SetProbability(x1, 1);
                initial.SetProbability(x2, 0);
                initial.SetProbability(x3, 0);

                var transitions = new TransitionMatrix(states);
                transitions.SetTransition(x1, x1, 0);
                transitions.SetTransition(x1, x2, 0.5);
                transitions.SetTransition(x1, x3, 0.5);
                transitions.SetTransition(x2, x1, 0);
                transitions.SetTransition(x2, x2, 0.9);
                transitions.SetTransition(x2, x3, 0.1);
                transitions.SetTransition(x3, x1, 0);
                transitions.SetTransition(x3, x2, 0);
                transitions.SetTransition(x3, x3, 1);

                var emissions = new EmissionMatrix(states, observations);
                emissions.SetEmission(x1, o2, 0.5);
                emissions.SetEmission(x2, o2, 0.9);
                emissions.SetEmission(x3, o2, 0.1);

                emissions.SetEmission(x1, o3, 0.5);
                emissions.SetEmission(x2, o3, 0.1);
                emissions.SetEmission(x3, o3, 0.9);

                var hmm = new HiddenMarkovModel(states, initial, transitions, emissions);

                // expected output: 1, 3, 3, 3, 3, 3, 3, 3, 3
                hmm.ApplyViterbiAndPrint(new[] { o2, o3, o3, o2, o2, o2, o3, o2, o3 });

                // expected output: 1, 2, 2, 2, 2, 2, 2, 2
                hmm.ApplyViterbiAndPrint(new[] { o2, o3, o3, o2, o2, o2, o3, o2 });
            }
        }
コード例 #6
0
ファイル: TestRegistry.cs プロジェクト: cschladetsch/Pyro
        public void TestReferenceFields()
        {
            var        reg = new Registry();
            IRef <Foo> foo = reg.Add(new Foo());

            Assert.AreSame(foo.Class.Type, typeof(Foo));
        }
コード例 #7
0
        public virtual void RedoProtection(Mobile from, BaseJewel item)
        {
            if (m_Registry.ContainsKey(from))
            {
                new RedoProtectionTimer(from, this).Start();
            }
            else if (from.BeginAction(typeof(DefensiveSpell)))
            {
                double value = (int)(from.Skills[SkillName.EvalInt].Value + from.Skills[SkillName.Meditation].Value + from.Skills[SkillName.Inscribe].Value);
                value /= 4;

                if (value < 0)
                {
                    value = 0;
                }
                else if (value > 75)
                {
                    value = 75.0;
                }

                Registry.Add(from, value);
                new ProtectionTimer(from, this).Start();

                from.FixedParticles(0x375A, 9, 20, 5016, EffectLayer.Waist);
                from.PlaySound(0x1ED);
                --m_Uses;
            }
            else
            {
                new RedoProtectionTimer(from, this).Start();
            }
        }
コード例 #8
0
        public override void OnHit(Mobile attacker, Mobile defender, int damage)
        {
            if (Registry.Contains(defender) || !this.Validate(attacker) || !this.CheckMana(attacker, true))
            {
                return;
            }

            ClearCurrentAbility(attacker);

            attacker.SendLocalizedMessage(1063358); // You deliver a talon strike!
            defender.SendLocalizedMessage(1063359); // Your attacker delivers a talon strike!

            defender.FixedParticles(0x373A, 1, 17, 0x26BC, 0x662, 0, EffectLayer.Waist);

            Timer t = new InternalTimer(defender, (int)(10.0 * (attacker.Skills[SkillName.Ninjitsu].Value - 50.0) / 70.0 + 5), attacker);       //5 - 15 damage

            BuffInfo.AddBuff(defender, new BuffInfo(BuffIcon.TalonStrike, 1028856, 1151309, TimeSpan.FromSeconds(5.0), defender, "40"));

            t.Start();

            Registry.Add(defender, t);

            if (attacker is BaseCreature)
            {
                PetTrainingHelper.OnWeaponAbilityUsed((BaseCreature)attacker, SkillName.Ninjitsu);
            }
        }
コード例 #9
0
ファイル: Feint.cs プロジェクト: zerodowned/last-wish
        public override void OnHit(Mobile attacker, Mobile defender, int damage)
        {
            if (!Validate(attacker) || !CheckMana(attacker, true))
            {
                return;
            }

            if (Registry.Contains(defender))
            {
                FeintTimer existingtimer = (FeintTimer)Registry[defender];
                existingtimer.Stop();
                Registry.Remove(defender);
            }

            ClearCurrentAbility(attacker);

            attacker.SendLocalizedMessage(1063360);               // You baffle your target with a feint!
            defender.SendLocalizedMessage(1063361);               // You were deceived by an attacker's feint!

            attacker.FixedParticles(0x3728, 1, 13, 0x7F3, 0x962, 0, EffectLayer.Waist);

            Timer t = new FeintTimer(defender, (int)(20.0 + 3.0 * (Math.Max(attacker.Skills[SkillName.Ninjitsu].Value, attacker.Skills[SkillName.Bushido].Value) - 50.0) / 7.0));                       //20-50 % decrease

            t.Start();
            Registry.Add(defender, t);
        }
コード例 #10
0
        static INIFiles()
        {
            Registry <int, MockINIInnerStruct> regstr = new Registry <int, MockINIInnerStruct>();

            regstr.Add(1, new MockINIInnerStruct(1, 2, 0, 0));
            regstr.Add(2, new MockINIInnerStruct(0, 0, 3, 4));
            regstr.Add(3, new MockINIInnerStruct(1, 0, 3, 0));
            regstr.Add(4, new MockINIInnerStruct(1, 0, 0, 4));
            ReadSubSectionRegistrySource = new object[]
            {
                new object[] { "TestSubSectionRegistryStruct", new MockINISubSectionRegistryStruct()
                               {
                                   INNER = regstr
                               } }
            };
        }
        /// <summary>
        /// Registers the type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TV">The type of the V.</typeparam>
        /// <param name="abstraction">The abstraction.</param>
        /// <param name="concrete">The concrete.</param>
        /// <param name="createInstance">if set to <c>true</c> [create instance].</param>
        /// <param name="ctorArgs">The ctor args.</param>
        /// <param name="isPrejittingEnabled">if set to <c>true</c> [is prejitting enabled].</param>
        /// <exception cref="TypeMismatchException"></exception>
        public void RegisterType <T, TV>(T abstraction, TV concrete, bool createInstance = false, object[] ctorArgs = null, bool isPrejittingEnabled = true)
        {
            var newRegistration = new TypeInformation()
            {
                Abstraction = typeof(T), Concrete = typeof(TV), Name = typeof(T).Name
            };

            if (newRegistration.Concrete.IsImplemented(newRegistration.Abstraction))
            {
                if (!IsRegisteredAlready(newRegistration))
                {
                    if (isPrejittingEnabled)
                    {
                        PreJitMethods(newRegistration.Concrete);
                    }

                    lock (Registry) {
                        Registry.Add(newRegistration, createInstance ? newRegistration.Concrete.DynamicallyCreateInstance(ctorArgs) : null);
                    }
                }
            }
            else
            {
                throw new TypeMismatchException(string.Format(Consts.ConcreteClassDoesntImplementInterface,
                                                              new object[] { newRegistration.Concrete.Name, newRegistration.Abstraction.Name }));
            }
        }
        /// <summary>
        /// Registers the type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="concreteObj">The concrete object.</param>
        public void RegisterType <T>(object concreteObj)
        {
            var abstraction = typeof(T);

            if (concreteObj == null)
            {
                throw new NullReferenceException(Consts.NullParametersException);
            }

            if (!(concreteObj is T))
            {
                throw new TypeMismatchException(string.Format(Consts.ConcreteClassDoesntImplementInterface,
                                                              new object[] { concreteObj.GetType().Name, abstraction.Name }));
            }

            var found = Registry.Keys.FirstOrDefault(x => string.Equals(x.Abstraction.Name, abstraction.Name, StringComparison.OrdinalIgnoreCase));

            if (found == null)
            {
                Registry.Add(new TypeInformation()
                {
                    Abstraction = abstraction, Name = abstraction.Name
                }, concreteObj);
            }
        }
コード例 #13
0
        public void Create(string name, long personalNumber)
        {
            var id     = _db.GetUniqueId();
            var member = new Member(name, personalNumber, id);

            _db.Add(member);
        }
コード例 #14
0
ファイル: Rule.cs プロジェクト: Modetor/ModernCreator.V2
 /*\ Register FAQ
  * >>> Last night. i've implemented such a beautifull feature called 'Registry'
  * >>> Q.1 : What is Registry ?
  * >>> A.1 : It's a modern way to store data in server(in RAM) while it retain dynamic binding, it also works much better than servers' 'cookies'.
  * >>>
  * >>> Q.2 : Does it cost any overhead or extra memory allocations ?
  * >>> A.2 : Overhead ? No. Memory allocations depends on what data it stores!
  \*/
 public void Register(string key, dynamic obj)
 {
     if (!Registry.ContainsKey(key))
     {
         Registry.Add(key, obj);
     }
 }
コード例 #15
0
 /// <summary>
 ///
 /// </summary>
 public CoreWindowRendererModule()
 {
     Registry.Add(new TplWRFactoryRegisterer <FalagardButton>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardDefault>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardEditbox>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardFrameWindow>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardItemEntry>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardListHeader>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardListHeaderSegment>());
     //Registry.Add(new TplWRFactoryRegisterer<FalagardListbox>()); // TODO: remove this
     Registry.Add(new TplWRFactoryRegisterer <FalagardListView>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardMenubar>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardMenuItem>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardMultiColumnList>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardMultiLineEditbox>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardPopupMenu>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardProgressBar>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardScrollablePane>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardScrollbar>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardSlider>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardStatic>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardStaticImage>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardStaticText>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardTabButton>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardTabControl>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardTitlebar>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardToggleButton>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardTooltip>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardItemListbox>());
     Registry.Add(new TplWRFactoryRegisterer <FalagardTree>()); // TODO: remove this
     // TODO: Registry.Add(new TplWRFactoryRegisterer<FalagardTreeView>());
 }
コード例 #16
0
ファイル: DualWield.cs プロジェクト: Pumpk1ns/RunZHA
        public override void OnHit(Mobile attacker, Mobile defender, int damage)
        {
            if (!Validate(attacker) || !CheckMana(attacker, true))
            {
                return;
            }

            if (Registry.Contains(attacker))
            {
                DualWieldTimer existingtimer = (DualWieldTimer)Registry[attacker];
                existingtimer.Stop();
                Registry.Remove(attacker);
            }

            ClearCurrentAbility(attacker);

            attacker.SendLocalizedMessage(1063362);               // You dually wield for increased speed!

            attacker.FixedParticles(0x3779, 1, 15, 0x7F6, 0x3E8, 3, EffectLayer.LeftHand);

            Timer t = new DualWieldTimer(attacker, (int)(20.0 + 3.0 * (attacker.Skills[SkillName.Magery].Value - 50.0) / 7.0));                 //20-50 % increase

            t.Start();
            Registry.Add(attacker, t);
        }
コード例 #17
0
ファイル: DualWield.cs プロジェクト: techy2493/ServUO
        public override void OnHit(Mobile attacker, Mobile defender, int damage)
        {
            if (!this.Validate(attacker) || !this.CheckMana(attacker, true))
            {
                return;
            }

            if (Registry.Contains(attacker))
            {
                DualWieldTimer existingtimer = (DualWieldTimer)Registry[attacker];
                existingtimer.Stop();
                Registry.Remove(attacker);
            }

            ClearCurrentAbility(attacker);

            attacker.SendLocalizedMessage(1063362); // You dually wield for increased speed!

            attacker.FixedParticles(0x3779, 1, 15, 0x7F6, 0x3E8, 3, EffectLayer.LeftHand);

            Timer t = new DualWieldTimer(attacker, (int)(20.0 + 3.0 * (attacker.Skills[SkillName.Ninjitsu].Value - 50.0) / 7.0));       //20-50 % increase

            BuffInfo.AddBuff(defender, new BuffInfo(BuffIcon.DualWield, 1151294, 1151293, TimeSpan.FromSeconds(6.0), attacker, damage));

            t.Start();
            Registry.Add(attacker, t);
        }
コード例 #18
0
        private void LoadConfiguration()
        {
            if (!_fileReader.FileExists(REPOSITORY_CONFIGURATION_FILE))
            {
                throw CreateConfigurationNotFoundException(REPOSITORY_CONFIGURATION_FILE);
            }

            var lines = _fileReader.ReadAllLines(REPOSITORY_CONFIGURATION_FILE);

            foreach (var line in lines)
            {
                if (!line.StartsWith("//"))
                {
                    var directory = line.Trim();

                    if (_directoryReader.DirectoryExists(directory))
                    {
                        Registry.Add(new Repository(directory));
                    }
                    else
                    {
                        throw CreateDirectoryNotFoundException(directory);
                    }
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Transforms the <paramref name="compilation"/> given the other criteria.
        /// </summary>
        /// <typeparam name="TTransformation"></typeparam>
        /// <param name="compilation">A compilation.</param>
        /// <param name="progress">Reporting progress.</param>
        /// <param name="cancellationToken">For asynchronous purposes.</param>
        /// <param name="transformation">A Transformation.</param>
        /// <param name="sourceFilePath">An optional Source File Path.</param>
        /// <param name="configure">Configures the <paramref name="transformation"/>. Should return the same.</param>
        private void TransformCompiledCode <TTransformation>(CSharpCompilation compilation, IProgress <Diagnostic> progress, CancellationToken cancellationToken
                                                             , TTransformation transformation, string sourceFilePath = DefaultSourceFilePath, ConfigureTransformationCallback <TTransformation> configure = null)
            where TTransformation : TransformationBase
        {
            Requires.NotNull(compilation, nameof(compilation));
            Requires.NotNull(progress, nameof(progress));
            Requires.NotNull(transformation, nameof(transformation));

            var descriptor = Create(sourceFilePath);

            var generatedCompilationUnits = (configure?.Invoke(transformation) ?? transformation)
                                            .TransformAsync(compilation, progress, cancellationToken).Result.ToArray();

            // TODO: TBD: will probably need some sort of OnException handlers for case specific Exception responses...
            foreach (var generatedCompilationUnit in generatedCompilationUnits)
            {
                // TODO: TBD: this is the core of the code generated assets...
                var generatedSyntaxTree = generatedCompilationUnit.SyntaxTree;
                var genText             = generatedSyntaxTree.GetText(cancellationToken);
                // TODO: TBD: instead of keeping a loose Id here, could potentially map the CUS's to a Uuid-keyed dictionary.
                var genId = Guid.NewGuid();

                var actualRetries = 3;

                try
                {
                    /* This is ordinarily auto-created by environmental tooling. However, depending
                     * on when our CG tooling `sees´ the event, the paths may not entirely exist yet. */

                    // TODO: TBD: may need the full path?
                    var outputPath = Registry.MakeRelativeSourcePath(genId);

                    // Create/Truncate should be sufficient.
                    using (var s = File.Open(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        using (var sw = new StreamWriter(s))
                        {
                            sw.Write(genText);
                        }
                    }

                    descriptor.GeneratedAssetKeys.Add(genId);
                }
                // ReSharper disable once IdentifierTypo
                catch (IOException ioex) when(ioex.HResult == HrProcessCannotAccessFile && ShouldRetry(ref actualRetries))
                {
                    // ReSharper disable once MethodSupportsCancellation
                    Delay(FromMilliseconds(200d)).Wait(cancellationToken);
                }
                catch (Exception ex)
                {
                    ReportError(progress, CodeGenerationErrorCode, ex);
                    FileFailures.Add(ex);
                    break;
                }
            }

            // TODO: TBD: potentially refactor this to more generic methods...
            Registry.Add(descriptor);
        }
コード例 #20
0
 public void AddEventEntry(IEventEntry entry)
 {
     if (_CanAddEntry(entry))
     {
         Registry.Add(entry.EventTag, entry.Broadcaster);
     }
 }
コード例 #21
0
        public virtual void Register(Type gameType, Type apiType)
        {
            if (apiType == null || gameType == null)
            {
                return;
            }
            if (!typeof(MyObjectBuilder_Base).IsAssignableFrom(gameType))
            {
                return;
            }
            if (!typeof(BaseObject).IsAssignableFrom(apiType))
            {
                return;
            }
            if (Registry.ContainsKey(apiType))
            {
                return;
            }
            if (Registry.ContainsValue(gameType))
            {
                return;
            }

            Registry.Add(gameType, apiType);
        }
コード例 #22
0
 public void Install(Registry registry)
 {
     foreach (TStatData statData in statDataArr)
     {
         TStat stat = (TStat)System.Activator.CreateInstance(typeof(TStat), new object[] { (TStatData)statData, registry });
         registry.Add <TStat>(stat);
     }
 }
コード例 #23
0
        private void Initialise()
        {
            IRegistry reg = new Registry();

            reg.Add(RegistryResolver, new RegistryResolver(reg));

            ParameterRegistry.Add(ValueIdentifier, reg);
        }
コード例 #24
0
        public void add(Particle particle, ParticleForceGenerator fg)
        {
            ParticleForceRegistration registration = new ParticleForceRegistration();

            registration.particle = particle;
            registration.fg       = fg;
            registrations.Add(registration);
        }
コード例 #25
0
        public void GetAll_can_return_multiple_matching_registrations(Registry sut,
                                                                      [Registration(Name = "one")] IServiceRegistration registration1,
                                                                      [Registration(Name = "two")] IServiceRegistration registration2,
                                                                      [Registration(Name = "three")] IServiceRegistration registration3)
        {
            // Arrange
            sut.Add(registration1);
            sut.Add(registration2);
            sut.Add(registration3);

            var expected = new [] { registration1, registration2, registration3 };

            // Act
            var result = sut.GetAll(typeof(ISampleService));

            // Assert
            Assert.That(result, Is.EquivalentTo(expected));
        }
コード例 #26
0
    public static void RegisterBlocks()
    {
        _registry = new Registry <Block>();

        _blockAir = new BlockAir();
        _registry.Add("air", _blockAir);
        _registry.Add("dirt", new BlockSolid("block_dirt", "b1"));
        _registry.Add("grass", new BlockSolid("block_dirt", "b2"));
        _registry.Add("stone", new BlockSolid("block_stone", "b3"));
        _registry.Add("mossy_stone", new BlockSolid("block_stone", "b4"));
        _registry.Add("sand", new BlockSolid("block_sand", "b5"));
        _registry.Add("sandstone", new BlockSolid("block_sandstone", "b6"));
        _registry.Add("wood", new BlockSolid("block_wood", "b7"));
        _registry.Add("bedrock", new BlockSolid(null, "b26"));
    }
コード例 #27
0
ファイル: TestRegistry.cs プロジェクト: cschladetsch/Pyro
        public void TestValues()
        {
            var reg = new Registry();
            var num = reg.Add(42);

            Assert.IsNotNull(num);
            Assert.IsNotNull(num.Value);

            Assert.AreEqual(num.Value, 42);

            IConstRefBase cref = num;

            Assert.AreEqual(cref.Get <int>(), 42);

            var str = reg.Add("");

            str.Value = "Foo";
            Assert.AreEqual(str.Value, "Foo");
        }
コード例 #28
0
        public ScriptEditForm()
        {
            InitializeComponent();
            Context = new ContextBase();

            ofd.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            sfd.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            UpdateTitle();
            UpdateStats();

            HighlightAssoc.Add(NoHighlighter.Instance, langNoneToolStripMenuItem);
            HighlightAssoc.Add(INIHighlighter.Instance, langINIToolStripMenuItem);
            HighlightAssoc.Add(ScriptHighlighter.Instance, langScriptToolStripMenuItem);

            foreach (string s in Context.ValFuncRef)
            {
                lboxFunctions.Items.Add(s);
            }
        }
コード例 #29
0
        private void AddConvention()
        {
            var descriptor = new ConventionServiceDescriptor(
                _predicates.ToPredicate(),
                _typeFinderBuilder.ToTypeFinder(),
                _lifecycle,
                _lifetime,
                _precondition);

            _registry.Add(descriptor);
        }
コード例 #30
0
        void AddEntry(Service service)
        {
            var entry = new Entry()
            {
                Id                 = new Guid(service.Id),
                Name               = service.Name,
                Quantity           = 1,
                CurrentMarkupPrice = Math.Round(service.TotalCost(), 2),
                TaxPercentage      = Math.Round(service.TaxPercentage, 3)
            };

            Entries.Add(entry);
            _registry.Add(new KeyValuePair <Guid, Entry>(entry.Id, entry));
            _entryDictionary.Add(service, entry);

            bool collectionsInSync = Entries.Count == _registry.Count &&
                                     Entries.Count == _entryDictionary.Count;

            Debug.Assert(collectionsInSync);
        }