public override void Execute(VisitContext context) { var i = 0; var length = Length != null ? Length.Next() : 1; for (;;) { var action = Actions.Sample(); if (action != null) { action.Parent = this; action.Execute(context); } if (++i >= length) break; } if (Successor != null) { var succ = Successor.Sample(); if (succ != null) { succ.Parent = this; succ.Execute(context); } } }
public override void Execute(VisitContext context) { var i = 0; foreach (var action in GetActions(context)) { //Console.Out.WriteLine(i++ + ":"); action.Parent = this; action.Execute(context); } }
private void VisitNodeAndChildren(ModelMetadata metadata, VisitContext visitContext) { Contract.Requires(metadata != null); Contract.Requires(visitContext != null); // Do not traverse the model if caching must be ignored if (metadata.IgnoreCaching) { return; } object model; try { model = metadata.Model; } catch { // Retrieving the model failed - typically caused by a property getter throwing // Being unable to retrieve a property is not an error - many properties can only be retrieved if certain conditions are met // For example, Uri.AbsoluteUri throws for relative URIs but it shouldn't be considered a validation error return; } // Optimization: we don't need to recursively traverse the graph for null and primitive types if (model == null || TypeHelper.IsSimpleType(model.GetType())) { ShallowVisit(metadata, visitContext); return; } // Check to avoid infinite recursion. This can happen with cycles in an object graph. if (visitContext.Visited.Contains(model)) { return; } visitContext.Visited.Add(model); // Visit the children first - depth-first traversal IEnumerable enumerableModel = model as IEnumerable; if (enumerableModel == null) { this.VisitProperties(metadata, visitContext); } else { this.VisitElements(enumerableModel, visitContext); } ShallowVisit(metadata, visitContext); // Pop the object so that it can be visited again in a different path visitContext.Visited.Remove(model); }
public override void Convert(VisitContext visitContext) { var wc = visitContext.WebClient; if (wc != null) { wc.DownloadString(ConversionUrl); } //visitContext.Visit.Pages.Add(new VisitPage //{ // Url = GetUrl(visitContext.Visit), // Duration = TimeSpan.FromSeconds(0.1) //}); }
public override void Execute(VisitContext context) { var i = 0; var length = Length != null ? Math.Round(Length.Next()) : int.MaxValue; foreach (var action in Actions) { action.Parent = this; action.Execute(context); if (++i >= length) { break; } } }
public override void Execute(VisitContext context) { base.Execute(context); var url = new StringBuilder(Url); var search = Url.Contains("?"); foreach (var p in QueryStringParameters) { url.Append(search ? "&" : "?"); url.Append(p.Key).Append("=").Append(p.Value()); search = true; } Execute(context, url.ToString()); }
public override void Execute(VisitContext context) { var action = Actions.Sample(); if (action != null) { action.Parent = this; action.Execute(context); if (Successor != null) { var succ = Successor.Sample(); if (succ != null) { succ.Parent = this; succ.Execute(context); } } } }
IEnumerable<VisitAction> GetActions(VisitContext context) { yield return SymposiumData.Pages["Experience"].Action; if (_random.NextDouble() < _bounceRate) yield break; yield return SymposiumData.Pages["Adverts"].Action; var midPages = _random.Next(0, 4); for (var i = 0; i < midPages; i++) { yield return _midPages.Sample(); } if (_random.NextDouble() < _conversionRate) { yield return SymposiumData.Pages["Register"].Action; if (_random.NextDouble() < 0.8) { yield return SymposiumData.Pages["Ticket Purchase"].Action; } } }
/// <summary> /// Flatten the <paramref name="model"/>. /// Properties are stored into a dictionary. /// Property name is used as key. Properties in a submodel are separated with a period. /// <see cref="Enumerable"/> properties are keyed with square brackets. /// </summary> /// <example> /// <list type="bullet"> /// <item>Property1</item> /// <item>Property2</item> /// <item>Property3.SubProperty1</item> /// <item>Property3.SubProperty2</item> /// <item>Property4[0].Item</item> /// <item>Property4[1].Item</item> /// <item>...</item> /// </list> /// </example> /// <param name="model">The model to be flattened.</param> /// <param name="type">The <see cref="Type"/> to use for flattening.</param> /// <param name="metadataProvider">The <see cref="ModelMetadataProvider"/> used to provide the model metadata.</param> /// <param name="keyPrefix">The <see cref="string"/> to append to the key for any validation errors.</param> /// <returns>The <see cref="ModelDictionary"/>.</returns> public ModelDictionary Flatten(object model, Type type, ModelMetadataProvider metadataProvider, string keyPrefix) { if (type == null) { throw Error.ArgumentNull("type"); } if (metadataProvider == null) { throw Error.ArgumentNull("metadataProvider"); } ModelMetadata metadata = metadataProvider.GetMetadataForType(() => model, type); VisitContext visitContext = new VisitContext { MetadataProvider = metadataProvider, RootPrefix = keyPrefix }; this.VisitNodeAndChildren(metadata, visitContext); return visitContext.FlatCommand; }
protected void Execute(VisitContext context, string url) { var wc = context.WebClient; if (wc != null) { //System.Console.Out.WriteLine(url); try { context.LastResponse = wc.DownloadString(url); } catch (WebException wex) { var r = wex.Response as HttpWebResponse; if (r == null || r.StatusCode != HttpStatusCode.NotFound) { throw; } } } context.ConvertGoals(); }
public Clock(VisitContext context) { Context = context; }
public VisitDetailViewComponent(EntityRef visitRef) { _context = visitRef == null ? null : new VisitContext(visitRef); }
public override bool BeginList <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { return(BeginList(container, (IListProperty)context.Property)); }
public override void EndCollection <TContainer, TValue>(TContainer container, VisitContext <IList <TValue> > context) { DoEndCollection(ref container, context); }
public override void EndList <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { EndList(container, (IListProperty)context.Property); }
private bool ShowContainerFoldoutIfNecessary <TContainer, TValue>(string displayName, VisitContext <TValue> context) where TContainer : IPropertyContainer where TValue : IPropertyContainer { var t = typeof(TValue); if (typeof(IPropertyContainer).IsAssignableFrom(t)) { // @TODO: dont rely on string comparison if (displayName == typeof(Entity).Name) { // special treatment for Entities to allow clickable behavior // @TODO improve the visitcontext environment for better type coersion RenderEntityView(new VisitContext <IPropertyContainer> { Property = context.Property, Value = context.Value, Index = context.Index, } ); return(false); } if (!IsEmptyComponentDataType(Property, context.Index, context.Value?.PropertyBag)) { ComponentState state; if (!_states.ContainsKey(_currentPath.ToString())) { _states[_currentPath.ToString()] = new ComponentState(); } state = _states[_currentPath.ToString()]; state.Showing = EditorGUILayout.Foldout( state.Showing, new GUIContent(displayName, displayName), new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold } ); return(state.Showing); } EditorGUILayout.LabelField(displayName, new GUIStyle(EditorStyles.boldLabel) { fontStyle = FontStyle.Bold }); return(false); } return(true); }
private static IEnumerable<IEnumerable<CompositionError>> CalculatePaths(CompositionException exception) { List<IEnumerable<CompositionError>> paths = new List<IEnumerable<CompositionError>>(); VisitContext context = new VisitContext(); context.Path = new Stack<CompositionError>(); context.LeafVisitor = path => { // Take a snapshot of the path paths.Add(path.Copy()); }; VisitCompositionException(exception, context); return paths; }
// Visits a single node (not including children) private static void ShallowVisit(ModelMetadata metadata, VisitContext visitContext) { Contract.Requires(metadata != null); Contract.Requires(visitContext != null); Contract.Requires(visitContext.KeyBuilders != null); string key = visitContext.RootPrefix; foreach (IKeyBuilder keyBuilder in visitContext.KeyBuilders.Reverse()) { key = keyBuilder.AppendTo(key); } if (!metadata.IsComplexType) { visitContext.FlatCommand.Add(key, metadata.Model); } }
public bool CustomUIVisit <TContainer>(ref TContainer container, ref VisitContext <bool> context) where TContainer : IPropertyContainer { return(DoField(ref container, ref context, (label, val) => EditorGUILayout.Toggle(label, val))); }
public bool CustomUIVisit <TContainer>(ref TContainer container, ref VisitContext <Font> context) where TContainer : IPropertyContainer { return(DoField(ref container, ref context, (label, val) => (Font)EditorGUILayout.ObjectField(label, val, typeof(Font), false))); }
public bool CustomUIVisit <TContainer>(ref TContainer container, ref VisitContext <byte> context) where TContainer : IPropertyContainer { return(DoField(ref container, ref context, (label, val) => (byte)Mathf.Clamp(EditorGUILayout.IntField(label, val), byte.MinValue, byte.MaxValue))); }
public override void Visit <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { Visit(context.Property); }
public override void EndContainer <TContainer, TValue>(TContainer container, VisitContext <TValue> context) { EndContainer(context.Property); }
private void VisitProperties(ModelMetadata metadata, VisitContext visitContext) { Contract.Requires(metadata != null); Contract.Requires(visitContext != null); PropertyScope propertyScope = new PropertyScope(); visitContext.KeyBuilders.Push(propertyScope); foreach (ModelMetadata childMetadata in metadata.Properties) { propertyScope.PropertyName = childMetadata.PropertyName; this.VisitNodeAndChildren(childMetadata, visitContext); } visitContext.KeyBuilders.Pop(); }
public override bool BeginCollection <TContainer, TValue>(TContainer container, VisitContext <IList <TValue> > context) { return(DoBeginCollection(ref container, context)); }
private void VisitElements(IEnumerable model, VisitContext visitContext) { Contract.Requires(model != null); Contract.Requires(visitContext != null); Type elementType = this.GetElementType(model.GetType()); ModelMetadata elementMetadata = visitContext.MetadataProvider.GetMetadataForType(null, elementType); ElementScope elementScope = new ElementScope { Index = 0 }; visitContext.KeyBuilders.Push(elementScope); foreach (object element in model) { elementMetadata.Model = element; this.VisitNodeAndChildren(elementMetadata, visitContext); elementScope.Index++; } visitContext.KeyBuilders.Pop(); }
public override bool BeginContainer <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { return(DoBeginContainer(ref container, context)); }
private static void VisitError(CompositionError error, VisitContext context) { context.Path.Push(error); if (error.Exception == null) { // This error is a root cause, so write // out the stack from this point context.LeafVisitor(context.Path); } else { VisitException(error.Exception, context); } context.Path.Pop(); }
public override bool BeginContainer <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { return(BeginContainer(context.Property, context.Index)); }
public override void EndContainer <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { DoEndContainer(ref container, context); }
public override void Visit <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { }
public override void Execute(VisitContext context) { var random = Randomness.Random; var page = StartPage(); //System.Console.Out.WriteLine("Random walk"); var wc = context.WebClient; if (wc != null) { if (_map == null) { _map = XDocument.Load(MapUrl).Root; } //wc.Headers.Add("X-Colossus-Map", _map == null ? "true" : "false"); page.Parent = this; page.Execute(context); //wc.Headers.Remove("X-Colossus-Map"); //var map = _map ?? XDocument.Parse(wc.ResponseHeaders["X-Colossus-Map"]).Root; var current = _map; var length = Math.Round(Length.Next()); for (var i = 0; i < length; i++) { var parent = current.Parent; var children = current.Elements("Item").ToArray(); var siblings = current.Parent == null ? new XElement[0] : current.Parent.Elements("Item").Where(e => e != current).ToArray(); if (parent == null && children.Length == 0 && siblings.Length == 0) break; var direction = 0; resample: var x = random.NextDouble(); if (x < 0.1 && parent != null) { current = parent; direction = -1; } //If we just jumped one step up, don't descent again too often else if (x < (direction == -1 ? 0.2 : 0.5) && children.Length > 0) { current = children[random.Next(0, children.Length)]; direction = 1; } else if (siblings.Length > 0) { current = siblings[random.Next(0, siblings.Length)]; direction = 0; } else { goto resample; } new PageAction((string)current.Attribute("HRef")) { Parent = this }.Execute(context); } } //System.Console.Out.WriteLine(""); //var i = 0; //while (page != null && i++ <= length) //{ // page.Execute(context); // page = null; // if (context.LastResponse != null) // { // var doc = new HtmlDocument(); // doc.LoadHtml(context.LastResponse); // if (doc.DocumentNode != null) // { // var links = doc.DocumentNode.SelectNodes("//a"); // if (links != null) // { // var goodLinks = links.Where(l => l.GetAttributeValue("href", "") != "").ToArray(); // var link = goodLinks[random.Next(0, goodLinks.Length)].GetAttributeValue("href", ""); // var urlBuilder = new UriBuilder(BaseUrl); // urlBuilder.Path = link; // page = new PageAction // { // Parent = this, // Url = urlBuilder.Uri.ToString() // }; // } // } // } //} }
public virtual void Convert(VisitContext visitContext) { }
private static void VisitCompositionException(CompositionException exception, VisitContext context) { foreach (CompositionError error in exception.Errors) { VisitError(error, context); } if (exception.InnerException != null) { VisitException(exception.InnerException, context); } }
public override bool ExcludeVisit <TContainer, TValue>(ref TContainer container, VisitContext <TValue> context) { var customHandler = this as ICustomUIVisit <TValue>; if (customHandler == null) { return(false); } var previous = context.Value; if (false == customHandler.CustomUIVisit(ref container, ref context)) { // early exit - no need to setvalue return(true); } var next = context.Value; var property = context.Property; var isReadOnly = IsReadOnly(property); if (ValuesAreDifferent(previous, next) && !isReadOnly && !property.IsReadOnly) { var typedProperty = (IStructProperty <TContainer, TValue>)property; typedProperty.SetValue(ref container, next); PushChange(container, property); } return(true); }
private static void VisitCompositionException(CompositionException exception, VisitContext context) { foreach (CompositionError error in exception.Errors) { VisitError(error, context); } if (exception.InnerException != null) { VisitException(exception.InnerException, context); } }
public VisitRepository(VisitContext orderContext) : base(orderContext) { }
private static void VisitException(Exception exception, VisitContext context) { CompositionException composition = exception as CompositionException; if (composition != null) { VisitCompositionException(composition, context); } else { VisitError(new CompositionError(exception.Message, exception.InnerException), context); } }
public NamespaceDeclarationVisitor(VisitContext context) : base(context) { }