コード例 #1
0
        public void Create()
        {
            var eventInfo = typeof(AppDomain).GetEvent("AssemblyResolve");
            var signature = EventSignature.Create(eventInfo);

            Assert.That(signature.EventHandlerType, Is.SameAs(typeof(ResolveEventHandler)));
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task <IEventLock?> LockEventForProcessingAsync(EthereumNetwork network,
                                                                    ContractAddress contractAddresses,
                                                                    EventSignature eventSignature,
                                                                    TransactionHash transactionHash,
                                                                    int eventIndex,
                                                                    BlockNumber blockNumber,
                                                                    GasLimit gasUsed,
                                                                    GasPrice gasPrice,
                                                                    EventRetrievalStrategy retrievalStrategy)
        {
            var param = new
            {
                Network         = network.Name,
                ContractAddress = contractAddresses,
                EventSignature  = eventSignature,
                TransactionHash = transactionHash,
                EventIndex      = eventIndex,
                MachineName     = this._machineName,
                BlockNumber     = (int)blockNumber.Value,
                GasUsed         = gasUsed,
                GasPrice        = gasPrice,
                Strategy        = retrievalStrategy.GetName()
            };

            return(await this._database.QuerySingleOrDefaultAsync <object, EventLockEntity>(storedProcedure : @"Ethereum.Event_Lock", param : param));
        }
コード例 #3
0
        public void Equals_True()
        {
            var signature1 = new EventSignature(typeof(Action));
            var signature2 = new EventSignature(typeof(Action));

            Assert.That(signature1.Equals(signature2), Is.True);
        }
コード例 #4
0
        public void GetHashCode_ForEqualObjects()
        {
            var signature1 = new EventSignature(typeof(Action));
            var signature2 = new EventSignature(typeof(Action));

            Assert.That(signature1.GetHashCode(), Is.EqualTo(signature2.GetHashCode()));
        }
コード例 #5
0
ファイル: StoryEvent.cs プロジェクト: fgeraci/CS195-Core
 public StoryEvent(
     EventSignature signature,
     EventID id,
     params uint[] parameters)
 {
     this.Signature = signature;
     this.Participants = parameters;
     this.ID = id;
 }
コード例 #6
0
        public void Equals_False()
        {
            var signature = new EventSignature(typeof(Action));

            Assert.That(signature.Equals(null), Is.False);

            var signatureWithDifferentEventHandlerType = new EventSignature(typeof(EventHandler));

            Assert.That(signature.Equals(signatureWithDifferentEventHandlerType), Is.False);
        }
コード例 #7
0
ファイル: StoryEvent.cs プロジェクト: fgeraci/CS195-Core
 public StoryEvent(StoryEvent other)
 {
     this.Signature = new EventSignature(other.Signature);
     this.Participants = new uint[other.Participants.Length];
     Array.Copy(
         other.Participants, 
         this.Participants, 
         other.Participants.Length);
     this.ID = other.ID;
 }
コード例 #8
0
ファイル: EventStub.cs プロジェクト: fgeraci/CS195-Core
 /// <summary>
 /// Private constructor, as TryGetEventStub should be used instead. 
 /// </summary>
 private EventStub(EventSignature mainSignature, List<EventSignature> signatures, EventID id)
 {
     this.MainSignature = this.Signature = mainSignature;
     this.allSignatures = signatures;
     AnalyzeSignatures(this.allSignatures);
     this.name = mainSignature.Name;
     this.name = Regex.Replace(this.name, "([a-z])([A-Z])", "$1 $2");
     this.name = Regex.Replace(this.name, "(\\(.*\\))", "");
     this.ID = id;
 }
コード例 #9
0
ファイル: StoryEvent.cs プロジェクト: fgeraci/CS195-Core
 public StoryEvent(
     EventSignature signature,
     EventID id,
     params SmartObject[] parameters)
 {
     this.Signature = signature;
     this.Participants = new uint[parameters.Length];
     for (int i = 0; i < parameters.Length; i++)
         this.Participants[i] = parameters[i].Id;
     this.ID = id;
 }
コード例 #10
0
        public void Equals_Object()
        {
            var signature = new EventSignature(typeof(Action));

            object otherSignatureAsObject = new EventSignature(typeof(Action));

            Assert.That(signature.Equals(otherSignatureAsObject), Is.True);

            Assert.That(signature.Equals((object)null), Is.False);

            object completelyUnrelatedObject = new object();

            Assert.That(signature.Equals(completelyUnrelatedObject), Is.False);
        }
        private async Task <bool> AttemptToResolveEventAsync <TEventHandler, TEvent, TEventOutput>(INetworkBlockHeader blockHeader, GameRoundId gameRoundId, CancellationToken cancellationToken)
            where TEventHandler : IEventHandler <TEventOutput> where TEvent : Event <TEventOutput>, new() where TEventOutput : EventOutput
        {
            TEvent evt = this._contractInfo.Event <TEvent>();

            EventSignature eventSignature = this._eventSignatureFactory.Create(evt);

            IReadOnlyList <TransactionHash> transactionHashes = await this._gameRoundDataManager.GetTransactionsAsync(gameRoundId : gameRoundId, functionName : evt.Name);

            IReadOnlyList <IPendingNetworkTransaction> transactions =
                await this._transactionLoader.GetTransactionsAsync(network : blockHeader.Network, transactionHashes : transactionHashes, cancellationToken : cancellationToken);

            IReadOnlyList <NetworkTransactionReceipt> receipts =
                await this._transactionLoader.GetTransactionReceiptsAsync(network : blockHeader.Network, transactionHashes : transactionHashes, cancellationToken : cancellationToken);

            bool handled = false;

            foreach (NetworkTransactionReceipt?receipt in receipts)
            {
                IPendingNetworkTransaction transaction = transactions.First(tx => tx.TransactionHash == receipt.TransactionHash);

                IReadOnlyList <TransactionEventLogEntry> logs = receipts.SelectMany(r => r.Logs?.Where(l => l.Topics[0]
                                                                                                       .ToEventSignature() == eventSignature) ?? Array.Empty <TransactionEventLogEntry>())
                                                                .ToArray();

                IEventDispatcher ed = new EventDispatcher <TEventHandler, TEvent, TEventOutput>(contractInfo: this._contractInfo,
                                                                                                eventSignature: eventSignature,
                                                                                                eventHandlerFactory: this._eventHandlerFactory,
                                                                                                eventDataManager: this._eventDataManager,
                                                                                                eventDecoder: this._eventDecoder,
                                                                                                confirmationsReadinessChecker: this._confirmationsReadinessChecker,
                                                                                                logger: this._logger);

                handled |= await ed.DispatchAsync(network : blockHeader.Network,
                                                  logs : logs,
                                                  networkBlockHeader : blockHeader,
                                                  latestBlockNumberOnNetwork : blockHeader.Number,
                                                  isFresh : false,
                                                  gasUsed : receipt.GasUsed,
                                                  gasPrice : transaction.GasPrice,
                                                  retrievalStrategy : EventRetrievalStrategy.RISKY);
            }

            return(handled);
        }
コード例 #12
0
        /// <summary>
        /// Converts a WinQual EventSignature into a StackHashEventSignature.
        /// </summary>
        /// <param name="eventSignature">WinQual Event signature to convert.</param>
        /// <returns>Converted event signature.</returns>
        public static StackHashEventSignature ConvertEventSignature(EventSignature eventSignature)
        {
            if (eventSignature == null)
            {
                throw new ArgumentNullException("eventSignature");
            }

            StackHashParameterCollection paramCollection = new StackHashParameterCollection();

            foreach (Parameter param in eventSignature.Parameters)
            {
                StackHashParameter stackHashParam = new StackHashParameter(param.Name, param.Value);
                paramCollection.Add(stackHashParam);
            }

            StackHashEventSignature stackHashEventSignature = new StackHashEventSignature(paramCollection);

            return(stackHashEventSignature);
        }
コード例 #13
0
ファイル: EventFactory.cs プロジェクト: re-motion/TypePipe
        public MutableEventInfo CreateEvent(
            MutableType declaringType,
            string name,
            Type handlerType,
            MethodAttributes accessorAttributes,
            Func <MethodBodyCreationContext, Expression> addBodyProvider,
            Func <MethodBodyCreationContext, Expression> removeBodyProvider,
            Func <MethodBodyCreationContext, Expression> raiseBodyProvider)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("handlerType", handlerType, typeof(Delegate));
            ArgumentUtility.CheckNotNull("addBodyProvider", addBodyProvider);
            ArgumentUtility.CheckNotNull("removeBodyProvider", removeBodyProvider);
            // Raise body provider may be null.

            MemberAttributesUtility.ValidateAttributes(
                "event accessor methods", MemberAttributesUtility.InvalidMethodAttributes, accessorAttributes, "accessorAttributes");

            var signature = new EventSignature(handlerType);

            if (declaringType.AddedEvents.Any(e => e.Name == name && EventSignature.Create(e).Equals(signature)))
            {
                throw new InvalidOperationException("Event with equal name and signature already exists.");
            }

            var attributes          = accessorAttributes | MethodAttributes.SpecialName;
            var addRemoveParameters = new[] { new ParameterDeclaration(handlerType, "handler") };

            var addMethod    = CreateAccessor(declaringType, "add_" + name, attributes, typeof(void), addRemoveParameters, addBodyProvider);
            var removeMethod = CreateAccessor(declaringType, "remove_" + name, attributes, typeof(void), addRemoveParameters, removeBodyProvider);

            MutableMethodInfo raiseMethod = null;

            if (raiseBodyProvider != null)
            {
                var invokeMethod    = GetInvokeMethod(handlerType);
                var raiseParameters = invokeMethod.GetParameters().Select(p => new ParameterDeclaration(p.ParameterType, p.Name, p.Attributes));
                raiseMethod = CreateAccessor(declaringType, "raise_" + name, attributes, invokeMethod.ReturnType, raiseParameters, raiseBodyProvider);
            }

            return(new MutableEventInfo(declaringType, name, EventAttributes.None, addMethod, removeMethod, raiseMethod));
        }
コード例 #14
0
ファイル: EventStub.cs プロジェクト: fgeraci/CS195-Core
 /// <summary>
 /// Tries to create an EventStub for the given EventSignature. Returns whether it was successful.
 /// The EventStub returned as an out argument will be null if no EventStub can be generated, and the
 /// generated EventStub otherwise.
 /// Retarget indicates if the signature has a MergeAtAttribute, whether that link is followed or not.
 /// </summary>
 public static bool TryGetEventStub(EventSignature signature, out EventStub stub, 
     bool retarget = false, EventID id = null)
 {
     EventSignature chosen = signature;
     MergeAtAttribute[] mergeAt = chosen.GetAttributes<MergeAtAttribute>();
     if (mergeAt.Length != 0)
     {
         if (!retarget)
         {
             stub = null;
             return false;
         }
         var target = EventLibrary.Instance.GetSignaturesOfType(mergeAt[0].Target);
         if (target.Count() != 0)
         {
             chosen = target.First();
         }
     }
     MergeAttribute[] merge = chosen.GetAttributes<MergeAttribute>();
     IEnumerable<EventSignature> allSigs = new EventSignature[] { chosen };
     if (merge.Length != 0)
     {
         for (int i = 0; i < merge[0].Types.Length; i++)
         {
             allSigs = allSigs.Union(EventLibrary.Instance.GetSignaturesOfType(merge[0].Types[i]));
         }
     }
     try
     {
         if (id == null)
         {
             stub = new EventStub(chosen, new List<EventSignature>(allSigs));
         }
         else
         {
             stub = new EventStub(chosen, new List<EventSignature>(allSigs), id);
         }
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
         Debug.Log(e.StackTrace);
         stub = null;
         return false;
     }
     return true;
 }
コード例 #15
0
ファイル: EventStub.cs プロジェクト: fgeraci/CS195-Core
 /// <summary>
 /// Private constructor, as TryGetEventStub should be used instead.
 /// </summary>
 private EventStub(EventSignature mainSignature, List<EventSignature> signatures)
     :this(mainSignature, signatures, new EventID())
 {
 }
コード例 #16
0
ファイル: StoryEvent.cs プロジェクト: fgeraci/CS195-Core
 public StoryEvent(
     EventSignature signature,
     params uint[] parameters)
     :this(signature, new EventID(), parameters)
 {
 }
コード例 #17
0
 public SchedulerEventArguments(EventSignature signature, float probability, bool isSelected)
 {
     this.Signature = signature;
     this.Probability = probability.ToString();
     this.IsSelected = isSelected;
 }
コード例 #18
0
        public new void ToString()
        {
            var signature = new EventSignature(typeof(EventHandler));

            Assert.That(signature.ToString(), Is.EqualTo("System.EventHandler"));
        }
コード例 #19
0
 public SchedulableEvent(EventSignature signature, float probability)
 {
     this.Signature = signature;
     this.Probability = probability;
 }
コード例 #20
0
 public DelegateDescriptor(EventSignature signature)
 {
     this.signature = signature;
 }
コード例 #21
0
ファイル: EventFactory.cs プロジェクト: re-motion/TypePipe
        public MutableEventInfo CreateEvent(
            MutableType declaringType,
            string name,
            EventAttributes attributes,
            MutableMethodInfo addMethod,
            MutableMethodInfo removeMethod,
            MutableMethodInfo raiseMethod)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("addMethod", addMethod);
            ArgumentUtility.CheckNotNull("removeMethod", removeMethod);
            // Raise method may be null.

            MemberAttributesUtility.ValidateAttributes("events", MemberAttributesUtility.InvalidEventAttributes, attributes, "attributes");

            if (addMethod.IsStatic != removeMethod.IsStatic || (raiseMethod != null && raiseMethod.IsStatic != addMethod.IsStatic))
            {
                throw new ArgumentException("Accessor methods must be all either static or non-static.", "addMethod");
            }

            if (!ReferenceEquals(addMethod.DeclaringType, declaringType))
            {
                throw new ArgumentException("Add method is not declared on the current type.", "addMethod");
            }
            if (!ReferenceEquals(removeMethod.DeclaringType, declaringType))
            {
                throw new ArgumentException("Remove method is not declared on the current type.", "removeMethod");
            }
            if (raiseMethod != null && !ReferenceEquals(raiseMethod.DeclaringType, declaringType))
            {
                throw new ArgumentException("Raise method is not declared on the current type.", "raiseMethod");
            }

            if (addMethod.ReturnType != typeof(void))
            {
                throw new ArgumentException("Add method must have return type void.", "addMethod");
            }
            if (removeMethod.ReturnType != typeof(void))
            {
                throw new ArgumentException("Remove method must have return type void.", "removeMethod");
            }

            var addMethodParameterTypes    = addMethod.GetParameters().Select(p => p.ParameterType).ToList();
            var removeMethodParameterTypes = removeMethod.GetParameters().Select(p => p.ParameterType).ToList();

            if (addMethodParameterTypes.Count != 1 || !addMethodParameterTypes[0].IsSubclassOf(typeof(Delegate)))
            {
                throw new ArgumentException("Add method must have a single parameter that is assignable to 'System.Delegate'.", "addMethod");
            }
            if (removeMethodParameterTypes.Count != 1 || !removeMethodParameterTypes[0].IsSubclassOf(typeof(Delegate)))
            {
                throw new ArgumentException("Remove method must have a single parameter that is assignable to 'System.Delegate'.", "removeMethod");
            }

            if (addMethodParameterTypes.Single() != removeMethodParameterTypes.Single())
            {
                throw new ArgumentException("The type of the handler parameter is different for the add and remove method.", "removeMethod");
            }

            var handlerType  = addMethodParameterTypes.Single();
            var invokeMethod = GetInvokeMethod(handlerType);

            if (raiseMethod != null && !MethodSignature.AreEqual(raiseMethod, invokeMethod))
            {
                throw new ArgumentException("The signature of the raise method does not match the handler type.", "raiseMethod");
            }

            var signature = new EventSignature(handlerType);

            if (declaringType.AddedEvents.Any(e => e.Name == name && EventSignature.Create(e).Equals(signature)))
            {
                throw new InvalidOperationException("Event with equal name and signature already exists.");
            }

            return(new MutableEventInfo(declaringType, name, attributes, addMethod, removeMethod, raiseMethod));
        }
コード例 #22
0
ファイル: StoryEvent.cs プロジェクト: fgeraci/CS195-Core
 public StoryEvent(
     EventSignature signature,
     params SmartObject[] parameters)
     :this(signature, new EventID(), parameters)
 {
 }