/// <summary> /// Scans current domain included previously unloaded assemblies for IRegister implementations. /// Assemblies in common will be called first, followed by any others. /// Calling assembly will be last /// </summary> /// <param name="callingAssembly"> /// Used to determine which IRegister implementors should be run last. /// Useful when you need to override some previous registrations /// </param> /// <returns>An autofac IContainer</returns> public static IContainer GetContainerInstance(Assembly callingAssembly) { DiagnosticsContract.Ensures(DiagnosticsContract.Result <IContainer>() != null); var containerBuilder = new ContainerBuilder(); var assemblies = AssemblyHelper.AssembliesOrdered("Disty.Common", callingAssembly.FullName); var types = TypeHelper.FindTypesThatExtend <IRegister>(assemblies); foreach (var type in types) { Trace.WriteLine("Executing IRegister.Register method within type " + type); try { ((IRegister)Activator.CreateInstance(type)).Register(containerBuilder); } catch (Exception exception) { Trace.WriteLine(string.Format("Failed to register {0}: {1}", type, exception.Message)); } } var container = containerBuilder.Build(); return(container); }
internal TraceLoggingTypeInfo( Type dataType, string name, EventLevel level, EventOpcode opcode, EventKeywords keywords, EventTags tags) { if (dataType == null) { throw new ArgumentNullException("dataType"); } if (name == null) { throw new ArgumentNullException("eventName"); } Contract.EndContractBlock(); Statics.CheckName(name); this.name = name; this.keywords = keywords; this.level = level; this.opcode = opcode; this.tags = tags; this.dataType = dataType; this.propertyValueFactory = PropertyValue.GetFactory(dataType); }
public EqualityComparerCompatibleComparerDecorator(IComparer <T> comparer, IEqualityComparer <T> equalityComparer) { Contract.Requires <ArgumentNullException>(!ReferenceEquals(comparer, null)); Contract.Requires <ArgumentNullException>(!ReferenceEquals(equalityComparer, null)); this.comparer = comparer; this.equalityComparer = equalityComparer; }
private static void ExportDot(IList <string> tokenNames, List <RuleBinding> rules, HashSet <State> reachableStates, Dictionary <int, RuleBinding> stateRules, string path) { Contract.Requires(rules != null); Contract.Requires(reachableStates != null); Contract.Requires(stateRules != null); StringBuilder builder = new StringBuilder(); builder.AppendLine("digraph G {"); foreach (var rule in rules) { builder.AppendLine(string.Format("subgraph rule_{0} {{", rule.Name)); foreach (var state in reachableStates.Where(i => stateRules[i.Id] == rule)) { builder.AppendLine(string.Format("state_{0}[label=\"{1}\"]", state.Id, GetStateLabel(state))); } builder.AppendLine(string.Format("label = \"{0}\"", rule.Name)); builder.AppendLine("}"); } foreach (var state in reachableStates) { // now define the transitions foreach (var transition in state.OutgoingTransitions) { builder.AppendLine(string.Format("state_{0} -> state_{1}[label=\"{2}\"]", transition.SourceState.Id, transition.TargetState.Id, GetTransitionLabel(transition, tokenNames))); } } builder.AppendLine("}"); System.IO.File.WriteAllText(path, builder.ToString()); }
public void Consume() { if (_source.La(1) != '\\') { _source.Consume(); _range = Math.Max(_range, _source.Index); _slashCount = 0; return; } // make sure the next character has been processed this.La(1); if (_escapeListIndex >= _escapeIndexes.Count || _escapeIndexes[_escapeListIndex] != Index) { _source.Consume(); _slashCount++; } else { for (int i = 0; i < 6; i++) { _source.Consume(); } _escapeListIndex++; _slashCount = 0; } Contract.Assert(_range >= Index); }
public static IEnumerable <IBinaryTreeNode> TraverseSubtree(this IBinaryTreeNode partialroot, TraverseOrder order = TraverseOrder.InOrder) { Contract.Requires <ArgumentNullException>(partialroot != null); Contract.Ensures(Contract.Result <IEnumerable <IBinaryTreeNode> >() != null); return(partialroot.TraverseSubtree <object>(null, null, null, order).Select(res => res.Item1)); }
public void InsertRange(int index, IEnumerable <TData> collection) { Contract.Requires <ArgumentOutOfRangeException>(index >= 0 && index <= Count); var itor = collection.GetEnumerator(); var node = Find(ref index); node.Split(index, _new); var next = node.Next; while (itor.MoveNext()) { if (node.Count >= node.Capacity) { node.Next = new UnrolledLinkedListNode <TData>(blocksize); node = node.Next; next.Previous = node; } node.Insert(node.Count, itor.Current, _new); // Append to last node Count++; } Version++; }
private TraceLoggingEventTypes( EventTags tags, string defaultName, TraceLoggingTypeInfo[] typeInfos) { if (defaultName == null) { throw new ArgumentNullException("defaultName"); } Contract.EndContractBlock(); this.typeInfos = typeInfos; this.name = defaultName; this.tags = tags; this.level = Statics.DefaultLevel; var collector = new TraceLoggingMetadataCollector(); foreach (var typeInfo in typeInfos) { this.level = Statics.Combine((int)typeInfo.Level, this.level); this.opcode = Statics.Combine((int)typeInfo.Opcode, this.opcode); this.keywords |= typeInfo.Keywords; typeInfo.WriteMetadata(collector, null, EventFieldFormat.Default); } this.typeMetadata = collector.GetMetadata(); this.scratchSize = collector.ScratchSize; this.dataCount = collector.DataCount; this.pinCount = collector.PinCount; }
internal EventPayload(List <string> payloadNames, List <object> payloadValues) { Contract.Assert(payloadNames.Count == payloadValues.Count); m_names = payloadNames; m_values = payloadValues; }
public int IndexOf(T item) { Contract.Ensures(Contract.Result <int>() >= -1); Contract.Ensures(Contract.Result <int>() < Count); return(this.IndexOf <T>(item)); }
public override bool Add(Request item) { if (item == null) { throw new ArgumentNullException(nameof(item), "the request is null"); } if (item.Itens.IsNullOrEmpty()) { throw new ArgumentException("Every request need items"); } if (string.IsNullOrWhiteSpace(item.UserId)) { throw new InvalidOperationException("The request does not have an associated user"); } Contract.EndContractBlock(); foreach (var requestItem in item.Itens) { requestItem.Request = item; requestItem.RequestId = item.Id; } return(base.Add(item)); }
internal static int IndexOf <T>(this IEnumerable <T> list, T item) { Contract.Requires <ArgumentNullException>(list != null); var itor = list.GetEnumerator(); int count = 0; if (ReferenceEquals(item, null)) { while (itor.MoveNext()) { if (ReferenceEquals(itor.Current, null)) { return(count); } count++; } } else { var comparer = EqualityComparer <T> .Default; while (itor.MoveNext()) { if (comparer.Equals(itor.Current, item)) { return(count); } count++; } } return(-1); }
public static int GetDegree(this IBinaryTreeNode node) { Contract.Requires <ArgumentNullException>(node != null); Contract.Ensures(Contract.Result <int>() >= 0 && Contract.Result <int>() <= 2); if (SentinelEx.NotEqualNull(node.LeftChild)) { if (SentinelEx.NotEqualNull(node.RightChild)) { return(2); } else { return(1); } } else if (SentinelEx.NotEqualNull(node.RightChild)) { return(1); } else { return(0); } }
public Antlr4BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IOutputWindowService outputWindowService) : base(textBuffer, taskScheduler, textDocumentFactoryService, outputWindowService) { Contract.Requires(textBuffer != null); Contract.Requires(taskScheduler != null); Contract.Requires(textDocumentFactoryService != null); Contract.Requires(outputWindowService != null); if (!_initialized) { try { #if false // have to create an instance of the tool to make sure the error manager gets initialized new AntlrTool(); #endif } catch (Exception e) { if (ErrorHandler.IsCriticalException(e)) { throw; } } _initialized = true; } }
public void PrintTo(TextWriter textOut) { Contract.Requires <ArgumentNullException>(textOut != null); if (Count == 0) { textOut.WriteLine("Null Unrolled Linked List"); } var node = head; node.PrintTo(textOut); while (node.Next != head) { node = node.Next; textOut.Write("->"); node.PrintTo(textOut); } #if DEBUG textOut.Write($", hot at [{_hotindex}]:"); _hotnode?.PrintTo(textOut); #endif }
public virtual int LastIndexOf(TData item) { Contract.Ensures(Contract.Result <int>() >= -1); Contract.Ensures(Contract.Result <int>() < Count); return(EnumerateIndexOf(item, true)); }
/// <summary> /// Initializes a new instance of the EventSourceActivity class that /// is attached to the specified parent activity. /// The activity is created in the Initialized state. Call Start() to /// write the activity's Start event. /// </summary> /// <param name="parentActivity"> /// The parent activity. Activity events will be written /// to the event source attached to this activity. /// </param> /// <param name="startStopOptions"> /// The options to use for the start and stop events of the activity. /// Note that the Opcode property will be ignored. /// </param> internal EventSourceActivity(EventSourceActivity parentActivity, EventSourceOptions startStopOptions) { Contract.Requires <ArgumentNullException>(parentActivity != null, nameof(parentActivity)); _eventSource = parentActivity.EventSource; _startStopOptions = startStopOptions; _parentId = parentActivity.Id; }
public static void BindRule(RuleBinding ruleBinding, Nfa body) { Contract.Requires <ArgumentNullException>(ruleBinding != null, "ruleBinding"); Contract.Requires <ArgumentNullException>(body != null, "body"); ruleBinding.StartState.AddTransition(new EpsilonTransition(body.StartState)); body.EndState.AddTransition(new EpsilonTransition(ruleBinding.EndState)); }
public Nfa(State startState, State endState) { Contract.Requires <ArgumentNullException>(startState != null, "startState"); Contract.Requires <ArgumentNullException>(endState != null, "endState"); StartState = startState; EndState = endState; }
protected EditorFactoryRegistrationAttribute(Type factoryType, short nameResourceID) { Contract.Requires <ArgumentNullException>(factoryType != null, "factoryType"); _factoryType = factoryType; _nameResourceID = nameResourceID; _trustLevel = __VSEDITORTRUSTLEVEL.ETL_NeverTrusted; }
public JavaQuickInfoSource(ITextBuffer textBuffer, JavaQuickInfoSourceProvider provider) { Contract.Requires <ArgumentNullException>(textBuffer != null, "textBuffer"); Contract.Requires <ArgumentNullException>(provider != null, "provider"); _textBuffer = textBuffer; _provider = provider; }
private void BeginUpdateQuickInfoContent(IQuickInfoSession session, SnapshotPoint triggerPoint) { Contract.Requires(session != null); Action updateAction = () => UpdateQuickInfoContent(session, triggerPoint); Task.Factory.StartNew(updateAction, CancellationToken.None, TaskCreationOptions.None, Provider.PriorityIntelliSenseTaskScheduler).HandleNonCriticalExceptions(); }
public ProvideLinkedEditorFactoryAttribute(Type factoryType, Type linkedFactoryType, short nameResourceID) : base(factoryType, nameResourceID) { Contract.Requires(factoryType != null); Contract.Requires <ArgumentNullException>(linkedFactoryType != null, "linkedFactoryType"); _linkedFactoryType = linkedFactoryType; }
/// <summary> /// Writes an event associated with this activity. /// May only be called when the activity is in the Started state. /// </summary> /// <param name="eventName"> /// The name to use for the event. Must not be null. /// </param> /// <param name="options"> /// The options to use for the event. /// </param> internal void Write(string eventName, EventSourceOptions options) { Contract.Requires <ArgumentNullException>(eventName != null, nameof(eventName)); var data = EmptyStruct.Instance; Write(eventName, ref options, ref data); }
public void Reverse(int index, int count) { Contract.Requires <ArgumentOutOfRangeException>(index >= 0); Contract.Requires <ArgumentOutOfRangeException>(count >= 0); Contract.Requires <ArgumentOutOfRangeException>(index + count <= Count); throw new NotImplementedException(); }
public static IEnumerable <IMultiwayTreeNode> TraverseSubtree(this IMultiwayTreeNode partialroot, TraverseOrder order = TraverseOrder.LevelOrder) { Contract.Requires <ArgumentNullException>(partialroot != null); Contract.Requires <NotSupportedException>(order != TraverseOrder.InOrder, "多叉树不支持中序遍历"); Contract.Ensures(Contract.Result <IEnumerable <IMultiwayTreeNode> >() != null); return(partialroot.TraverseSubtree <object>(null, null, order).Select(res => res.Item1)); }
/// <summary> /// Writes a Stop event with the specified name. Sets the activity /// to the Stopped state. /// May only be called when the activity is in the Started state. /// </summary> /// <param name="eventName"> /// The name to use for the event. Must not be null. /// </param> internal void Stop(string eventName) { Contract.Requires <ArgumentNullException>(eventName != null, nameof(eventName)); var data = EmptyStruct.Instance; Stop(eventName, ref data); }
public Antlr4BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IOutputWindowService outputWindowService) : base(textBuffer, taskScheduler, textDocumentFactoryService, outputWindowService) { Contract.Requires(textBuffer != null); Contract.Requires(taskScheduler != null); Contract.Requires(textDocumentFactoryService != null); Contract.Requires(outputWindowService != null); }
/// <summary> /// Initializes a new instance of the EventSourceActivity class that /// is attached to the specified event source. The new activity will /// be attached to the parent activity as specified by /// parentActivityId. /// The activity is created in the Initialized state. Call Start() to /// write the activity's Start event. /// </summary> /// <param name="eventSource"> /// The event source to which the activity events should be written. /// </param> /// <param name="startStopOptions"> /// The options to use for the start and stop events of the activity. /// Note that the Opcode property will be ignored. /// </param> /// <param name="parentActivityId"> /// The id of the parent activity to which this new activity /// should be attached. /// </param> internal EventSourceActivity(EventSource eventSource, EventSourceOptions startStopOptions, Guid parentActivityId) { Contract.Requires <ArgumentNullException>(eventSource != null, nameof(eventSource)); _eventSource = eventSource; _startStopOptions = startStopOptions; _parentId = parentActivityId; }
public ProvideDebuggerExceptionKindAttribute(string debugEngineGuid, string exceptionKind) { Contract.Requires <ArgumentNullException>(debugEngineGuid != null, "debugEngineGuid"); Contract.Requires <ArgumentNullException>(exceptionKind != null, "exceptionKind"); _debugEngine = Guid.Parse(debugEngineGuid); _exceptionKind = exceptionKind; }