public PluginInfo(Type type, PluginSetConstructionInfo constructionInfo, IPluginInfoProvider pluginInfoProvider) { if (type.IsAbstract) { throw Errors.PluginIsAbstract(type); } if (type.IsNotPublic) { throw Errors.PluginIsNonPublic(type); } Type = type; Ancestors = ImmutableArray.Create( type.GetAllBaseTypes().Select(t => (TypeRef)t).ToArray()); Interfaces = ImmutableArray.Create( type.GetInterfaces().Select(t => (TypeRef)t).ToArray()); CastableTo = ImmutableHashSet.Create( Ancestors.AddRange(Interfaces).Add(type).ToArray()); Capabilities = pluginInfoProvider.GetCapabilities(type); Dependencies = pluginInfoProvider.GetDependencies(type); var allAssemblyRefs = constructionInfo.AllAssemblyRefs[type.Assembly]; AllDependencies = constructionInfo.Plugins .Where(p => p != type && ( allAssemblyRefs.Contains(p.Assembly) || CastableTo.Contains(p))) .Select(t => (TypeRef)t) .Concat(Dependencies) .ToImmutableHashSet(); }
public virtual string ToString(Func <IHierarchical <T>, string> formatter, bool convertToSingleLine = false) { var sbr = new StringBuilder(); sbr.AppendLine(convertToSingleLine ? formatter(this).Replace("\r", @"\r").Replace("\n", @"\n") : formatter(this)); var sb = new StringBuilder(); foreach (var node in Descendants) { sb.Append(convertToSingleLine ? formatter(node).Replace("\r", @"\r").Replace("\n", @"\n") : formatter(node)); sb.Insert(0, node == node.Parent.Children.Last() ? "└─" : "├─"); for (int i = 0; i < node.Ancestors.Count() - (Ancestors?.Count() ?? 0) - 1; i++) { sb.Insert(0, node.Ancestors.ElementAt(i) == node.Ancestors.ElementAt(i + 1).Children.Last() ? " " : "│ "); } sbr.AppendLine(sb.ToString()); sb.Clear(); } return(sbr.ToString()); }
protected override void RequestLoad(DesignService service, DesignBuffer buffer) { var document = new DilxDocument(); document.Read(buffer.LoadData()); Ancestors ancestors; IHost host; XDocument ancestor = null; if (document.Ancestors.Count >= 1) { ancestors = document.Ancestors; ancestor = MergeAncestors(ancestors); var merge = XDocument.Load(new StringReader(document.Content)); var current = new XDocument(); current.Add(new XElement(ancestor.Root)); Inheritance.Merge(current, merge); host = HostFromDocumentData(current, GetDocumentExpression(buffer)); } else { host = HostFromDocumentData(document.Content, GetDocumentExpression(buffer)); ancestors = null; } SetDesignHost(host, true); UpdateReadOnly(ancestor); _ancestors = ancestors; }
private IDetailBlockStart FindBlockStart(Func <IDetailBlockStart, bool> predicate) { // As a possibly premature optimization, check the parent container first as // semantically correct nesting will have it there var container = this.Parent as IRDomContainer; if (container != null) { var fromParent = container.GetMembers() .OfType <IDetailBlockStart>() .Where(predicate) .FirstOrDefault(); if (fromParent != null) { return(fromParent); } } var rootOrBase = Ancestors.Last(); // Root var descendants = rootOrBase.Descendants .OfType <IDetailBlockStart>() .Where(predicate) .FirstOrDefault(); if (descendants != null) { return(descendants); } throw new InvalidOperationException("Matching end region not found"); }
private void AssertNodeEquals(SyntaxNode node, IEnumerable <SyntaxNode> ancestors, string expected, string actual) { if (string.Equals(expected, actual)) { // YAY!!! everything is great. return; } if (expected == null) { var message = "The node is missing from baseline."; throw new SyntaxNodeBaselineException(node, Ancestors.ToArray(), expected, actual, message); } int charsVerified = 0; AssertNestingEqual(node, ancestors, expected, actual, ref charsVerified); AssertNameEqual(node, ancestors, expected, actual, ref charsVerified); AssertDelimiter(node, expected, actual, true, ref charsVerified); AssertLocationEqual(node, ancestors, expected, actual, ref charsVerified); AssertDelimiter(node, expected, actual, false, ref charsVerified); AssertContentEqual(node, ancestors, expected, actual, ref charsVerified); throw new InvalidOperationException("We can't figure out HOW these two things are different. This is a bug."); }
public new void New(IHost host) { CheckHostsDocument(host); InternalNew(host, false); _ancestors = new Ancestors(); _ancestors.Add(host.Document); UpdateReadOnly(MergeAncestors(_ancestors)); }
private PropertyDefinition SelectPropertyCore(QualifiedName qn) { return(propertyLookup.FindProperty(GetDefinition(), this.ComponentType, qn, Ancestors.Select(t => t.GetDefinition()) )); }
public Zipper Right() => right == null ? null : new Zipper( right.Value, right.Left, right.Right, new Stack <Zipper>(Ancestors.Reverse().Append(new ZipperRight(value, left, right, Ancestors))) );
/// <summary> Initializes the designer from a list of ancestor document expressions. </summary> /// <param name="ancestors"> List of ancestor document expressions. Must be non-empty. </param> public void New(Ancestors ancestors) { XDocument ancestor = MergeAncestors(ancestors); InternalNew(HostFromDocumentData(ancestor, String.Empty), true); UpdateReadOnly(ancestor); _ancestors = ancestors; }
private void RemoveFromAncestorArray(string currentKeyName) { if (Ancestors.ContainsKey( currentKeyName)) { Ancestors .Remove(currentKeyName); } }
private IType GetTypeFromReferenced() { var root = Ancestors.OfType <RDomRoot>().FirstOrDefault(); if (root != null) { return(root.FindByMetadataName(MetadataName)); } return(null); }
public override void New() { var ancestors = new Ancestors(); var documentExpression = new DocumentExpression(); documentExpression.Type = DocumentType.Document; documentExpression.DocumentArgs.OperatorName = ".Frontend.Form"; ancestors.Add(DocumentExpressionForm.Execute(documentExpression)); New(ancestors); }
private void OnObservedPropertyChanged() { DisposeAndClearAncestors(); var ancestor = InitAncestor(); if (ancestor != null) { Ancestors.Add(ancestor); } OnChanged(PathItem); }
private string GetAncestorValue(string ancestorKeyName) { string sAncestorDelimitedString = string.Empty; if (Ancestors.ContainsKey( ancestorKeyName)) { Ancestors.TryGetValue( ancestorKeyName, out sAncestorDelimitedString); } return(sAncestorDelimitedString); }
protected override void BeginVisitNode(AphidExpression expression) { if (IsMember(expression)) { _object = Ancestors.Peek().ToObject(); _member = expression.ToBinaryOperator(); _currentPath.Push(_member.LeftOperand); } else if (IsArray(expression)) { _array = expression.ToArray(); } }
//shared with observationbuilder (move to calculatorhelpers) private void AddToAncestorArray(string key, string value) { if (Ancestors.ContainsKey(key)) { //replace it Ancestors[key] = value; } else { //add it Ancestors.Add(key, value); } }
public CollectionChangeSubscriber(object effectiveObject, CollectionPathItem <T> pathItem, Action <PathItemBase <T> > onChanged) : base(effectiveObject, pathItem, onChanged) { var notifyCollectionChange = effectiveObject as INotifyCollectionChanged; if (notifyCollectionChange != null) { SubscribeToCollectionChange(notifyCollectionChange); } foreach (var ancestor in InitAncestors(EffectiveObject)) { Ancestors.Add(ancestor); } }
private async Task <bool> StreamAndSaveObservation(ContentURI docToCalcURI, IDictionary <string, string> fileOrFolderPaths, bool hasInitialColumnDictionary) { bool bHasObservation = false; string sId = string.Empty; string sFileToAnalyze = string.Empty; int i = 0; WriteColumnNameRow(); foreach (KeyValuePair <string, string> kvp in fileOrFolderPaths) { sId = kvp.Key; sFileToAnalyze = kvp.Value; if (await Helpers.FileStorageIO.URIAbsoluteExists( docToCalcURI, sFileToAnalyze)) { FileToAnalyzeReader = await Helpers.FileStorageIO.GetXmlReaderAsync(docToCalcURI, sFileToAnalyze); if (FileToAnalyzeReader != null) { using (FileToAnalyzeReader) { FileToAnalyzeReader.MoveToContent(); Ancestors.Clear(); AddObservations(docToCalcURI, hasInitialColumnDictionary); } } if (docToCalcURI.ErrorMessage != string.Empty) { //fix all errors before running an analysis break; } i++; } } if (docToCalcURI.ErrorMessage == string.Empty) { if (hasInitialColumnDictionary) { //save the observations file TextFile.Flush(); bHasObservation = true; } } return(bHasObservation); }
public static XmlDocument MergeAncestors(XmlDocument ADocument, Ancestors AAncestors, HttpContext AContext) { // Process any ancestors foreach (string LAncestor in AAncestors) { if (ADocument == null) { ADocument = ReadAncestor(LAncestor, AContext); } else { ADocument = Inheritance.Merge(ADocument, ReadAncestor(LAncestor, AContext)); } } return(ADocument); }
public PropertyChangeSubscriber(object effectiveObject, PropertyPathItem <T> pathItem, Action <PathItemBase <T> > onChanged) : base(effectiveObject, pathItem, onChanged) { var notifyPropertyChange = effectiveObject as INotifyPropertyChanged; if (notifyPropertyChange != null) { Subscribe(notifyPropertyChange); } var ancestor = InitAncestor(); if (ancestor != null) { Ancestors.Add(ancestor); } }
public override void Open(IHost host) { CheckHostsDocument(host); DocumentDesignBuffer buffer = BufferFromHost(host); Service.ValidateBuffer(buffer); var document = new DilxDocument(); document.Read(buffer.LoadData()); XDocument mergedAncestors = MergeAncestors(document.Ancestors); // do this first in case of errors SetDesignHost(host, false); Service.SetBuffer(buffer); Service.SetModified(false); _ancestors = document.Ancestors; UpdateReadOnly(mergedAncestors); }
public static void Main() { Ancestors.Show(new Manager().GetType()); Manager m = new Manager(); Employee e = new Employee(); Type t1 = typeof(Manager); Type t2 = typeof(Employee); RuntimeTypeHandle rtth = t1.TypeHandle; Type tt = Type.GetTypeFromHandle(rtth); Console.WriteLine(t1.IsSubclassOf(t2)); Console.WriteLine(t2.IsSubclassOf(t1)); Console.WriteLine(t2.IsAssignableFrom(t1)); }
public BinTree ToTree() { var tree = new BinTree(value, left, right); Zipper parent; while (Ancestors.TryPop(out parent)) { if (parent is ZipperLeft zl) { tree = new BinTree(zl.value, tree, zl.right); } else if (parent is ZipperRight zr) { tree = new BinTree(zr.value, zr.left, tree); } } return(tree); }
private XDocument MergeAncestors(Ancestors ancestors) { XDocument document = null; // Process any ancestors foreach (string ancestor in ancestors) { if (document == null) { document = LoadDocument(ancestor); } else { Inheritance.Merge(document, LoadDocument(ancestor)); } } return(document); }
private IDetailBlockStart FindBlockStart(Func <IDetailBlockStart, bool> predicate) { var parentContainers = Ancestors.OfType <IContainer>(); foreach (var container in parentContainers) { // TODO: I'm pretty sure you just need predicate, not the extra lambda, but want to complete testing before I check. var ret = container.GetMembers() .OfType <IDetailBlockStart>() .Where(x => predicate(x)) .SingleOrDefault(); if (ret != null) { return(ret); } } throw new InvalidOperationException("Matching start region not found"); }
public PluginInfo(Type type, PluginSetConstructionInfo constructionInfo) { Type = type; Ancestors = ImmutableArray.Create( type.GetAllBaseTypes().Select(t => (TypeRef)t).ToArray()); Interfaces = ImmutableArray.Create( type.GetInterfaces().Select(t => (TypeRef)t).ToArray()); CastableTo = ImmutableHashSet.Create( Ancestors.AddRange(Interfaces).Add(type).ToArray()); Capabilities = ImmutableDictionary <string, object> .Empty; Dependencies = ImmutableHashSet <TypeRef> .Empty; object?tmpPlugin = null; try { tmpPlugin = constructionInfo.PluginFactory.Create(type); } catch (Exception) { // There might be plugins we can't construct -- mainly, // b/c their constructors aren't written properly to support // temporary plugin factory. // All we can do here is to ignore this exception & assume // these plugins can't provide capabilities and dependencies. } if (tmpPlugin is IHasCapabilities hc) { Capabilities = hc.Capabilities; } if (tmpPlugin is IHasDependencies hd) { Dependencies = hd.Dependencies.Select(t => (TypeRef)t).ToImmutableHashSet(); } var allAssemblyRefs = constructionInfo.AllAssemblyRefs[type.Assembly]; AllDependencies = constructionInfo.Plugins .Where(p => p != type && ( allAssemblyRefs.Contains(p.Assembly) || CastableTo.Contains(p))) .Select(t => (TypeRef)t) .Concat(Dependencies) .ToImmutableHashSet(); }
protected override void Visit(AphidExpression expression) { //if (_filename != null && expression.Filename == null) //{ // expression.Filename = _filename; //} if (expression.Index == -1 && Ancestors.Count > 1) { var a = Ancestors.ToArray()[1]; if (a.Index == -1) { return; } //var a = Ancestors.FirstOrDefault(x => x.Index != -1); if (a != null) { expression.Index = a.Index; expression.Length = a.Length; } else if (expression is IParentNode parent) { var children = parent.GetChildren(); if (children.Any()) { expression.Index = children.First().Index; expression.Length = children .Where(x => x != null) .GroupBy(x => x.Index) .Select(x => x.OrderByDescending(y => y.Length).First()) .Sum(x => x.Length); } } } //expression.Code = _code; }
public Zipper Up() { Zipper parent; if (!Ancestors.TryPop(out parent)) { return(null); } var tree = new BinTree(value, left, right); if (parent is ZipperLeft zl) { zl.SetLeft(tree); } else if (parent is ZipperRight zr) { zr.SetRight(tree); } return(parent); }
private void UpdateAncestors(NotifyCollectionChangedEventArgs eventArgs) { switch (eventArgs.Action) { case NotifyCollectionChangedAction.Add: CheckIndexValid(eventArgs.NewStartingIndex, "NewStartingIndex", NotifyCollectionChangedAction.Add); Ancestors.Insert(eventArgs.NewStartingIndex, CreateSubscriberForCollectionItem(eventArgs.NewItems.Cast <object>().Single())); return; case NotifyCollectionChangedAction.Remove: CheckIndexValid(eventArgs.OldStartingIndex, "OldStartingIndex", NotifyCollectionChangedAction.Remove); Ancestors[eventArgs.OldStartingIndex].Dispose(); Ancestors.RemoveAt(eventArgs.OldStartingIndex); return; case NotifyCollectionChangedAction.Replace: CheckIndexValid(eventArgs.OldStartingIndex, "OldStartingIndex", NotifyCollectionChangedAction.Replace); Ancestors[eventArgs.OldStartingIndex].Dispose(); Ancestors[eventArgs.OldStartingIndex] = CreateSubscriberForCollectionItem(eventArgs.NewItems.Cast <object>().Single()); return; case NotifyCollectionChangedAction.Move: CheckIndexValid(eventArgs.OldStartingIndex, "OldStartingIndex", NotifyCollectionChangedAction.Move); CheckIndexValid(eventArgs.NewStartingIndex, "NewStartingIndex", NotifyCollectionChangedAction.Move); var movingAncestor = Ancestors[eventArgs.OldStartingIndex]; Ancestors.RemoveAt(eventArgs.OldStartingIndex); Ancestors.Insert(eventArgs.NewStartingIndex, movingAncestor); return; case NotifyCollectionChangedAction.Reset: DisposeAndClearAncestors(); foreach (var ancestor in InitAncestors(EffectiveObject)) { Ancestors.Add(ancestor); } return; default: throw new ArgumentException(string.Format("Unknown eventArgs.Action enum action: {0}", eventArgs.Action), "eventArgs"); } }
public RootObjectSubscriber(object effectiveObject, PathItemBase <T> pathItem, Action <PathItemBase <T> > onChanged) : base(effectiveObject, pathItem, onChanged) { Ancestors.Add(CreateSubscriber(effectiveObject, pathItem.Ancestor, onChanged)); }