void ParseDestinationName() { // _destinationPath may contain a path routing through embedded documents. var segments = _destinationPath.Split(Separator); Debug.Assert(segments.Length > 0); var currentElementsObject = Elements; // Target dictionaries to create for the path: Create a row of TargetDictionaries as we step through the segments. for (var i = 0; i < segments.Length - 1; i++) { var segment = segments[i]; var target = segment == ParentString ? TargetDictionary.CreateTargetParent() : TargetDictionary.CreateTargetChild(segment); currentElementsObject.SetObject(Keys.T, target); currentElementsObject = target.Elements; } // The destination is the last segment of the path. It has to be saved in the embedded GoTo-Action's Elements. var destination = segments[segments.Length - 1]; Elements.SetString(Keys.D, destination); }
bool Handle(TemplateTypeParameter p, ISemantic arg) { // if no argument given, try to handle default arguments if (arg == null) { return(TryAssignDefaultType(p)); } // If no spezialization given, assign argument immediately if (p.Specialization == null) { return(Set(p, arg, 0)); } bool handleResult = HandleDecl(null, p.Specialization, arg); if (!handleResult) { return(false); } // Apply the entire argument to parameter p if there hasn't been no explicit association yet TemplateParameterSymbol tps; if (!TargetDictionary.TryGetValue(p, out tps) || tps == null) { TargetDictionary[p] = new TemplateParameterSymbol(p, arg); } return(true); }
/// <summary> /// This is overridden to create a target dictionary that utilizes an ESENT database for persistence /// </summary> /// <param name="configuration">The configuration element for the target dictionary</param> /// <returns>A simple dictionary if no <c>cachePath</c> attribute is found or an ESENT backed target /// dictionary if the attribute is found.</returns> public override TargetDictionary CreateTargetDictionary(XPathNavigator configuration) { TargetDictionary td = null; string cachePath = configuration.GetAttribute("cachePath", String.Empty); // If no database path is specified, use the simple target dictionary (i.e. project references) if (String.IsNullOrWhiteSpace(cachePath)) { td = base.CreateTargetDictionary(configuration); } else { try { td = new ESentTargetDictionary(this, configuration); } catch (Exception ex) { this.WriteMessage(MessageLevel.Error, BuildComponentUtilities.GetExceptionMessage(ex)); } } return(td); }
public static TargetDictionary CreateTargetParent() { var target = new TargetDictionary(); target.Elements.SetName(Keys.R, "/P"); return(target); }
public static TargetDictionary CreateTargetChild(string name) { var target = new TargetDictionary(); target.Elements.SetName(Keys.R, "/C"); target.Elements.SetString(Keys.N, name); return(target); }
public void StartService() { if (ServiceStarted) { return; } ServiceStarted = true; MDNS.Start(); SD.ServiceInstanceDiscovered += (s, e) => MDNS.SendQuery(e.ServiceInstanceName, type: DnsType.SRV); MDNS.AnswerReceived += (s, e) => { var servers = e.Message.Answers.OfType <SRVRecord>(); foreach (var server in servers) { var target = server.Target.ToString(); var name = string.Join(".", server.Name.Labels.TakeLast(3)); lock (_dictLock) { if (TargetDictionary.ContainsKey(target)) { if (!TargetDictionary[target].Contains(name)) { TargetDictionary[target].Add(name); } } else { TargetDictionary.Add(target, new HashSet <string> { name }); } } Logger.LogInformation($"Receive service record: {name} = {target}"); MDNS.SendQuery(server.Target, type: DnsType.A); } var addresses = e.Message.Answers.OfType <AddressRecord>(); foreach (var address in addresses) { if (!DomainNameDictionary.TryAdd(address.Name.ToString(), address.Address)) { DomainNameDictionary[address.Name.ToString()] = address.Address; } Logger.LogInformation($"Receive address record: {address.Name} = {address.Address}"); if (TargetDictionary.ContainsKey(address.Name.ToString())) { TargetDictionary[address.Name.ToString()] .Where(t => EventDictionary.ContainsKey(t)) .Foreach(t => EventDictionary[t].Invoke(this, new IPAddressEventArgs(address.Address))); } } }; Logger.LogInformation("Service discovery started"); }
/// <summary> /// This is overridden to create a target dictionary that utilizes an SQL database for persistence /// </summary> /// <param name="configuration">The configuration element for the target dictionary</param> /// <returns>A simple dictionary if no <c>connectionString</c> attribute is found or a SQL backed target /// dictionary if the attribute is found.</returns> public override TargetDictionary CreateTargetDictionary(XPathNavigator configuration) { TargetDictionary td = null; string connectionString, groupId, attrValue; int frameworkCacheSize, projectCacheSize; bool cacheProject, isProjectData; if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var parent = configuration.Clone(); parent.MoveToParent(); var cache = parent.SelectSingleNode("sqlCache"); connectionString = cache.GetAttribute("connectionString", String.Empty); attrValue = cache.GetAttribute("frameworkLocalCacheSize", String.Empty); frameworkCacheSize = Convert.ToInt32(attrValue, CultureInfo.InvariantCulture); attrValue = cache.GetAttribute("projectLocalCacheSize", String.Empty); projectCacheSize = Convert.ToInt32(attrValue, CultureInfo.InvariantCulture); attrValue = cache.GetAttribute("cacheProject", String.Empty); cacheProject = Convert.ToBoolean(attrValue, CultureInfo.InvariantCulture); groupId = configuration.GetAttribute("groupId", String.Empty); isProjectData = groupId.StartsWith("Project_", StringComparison.OrdinalIgnoreCase); // If no connection is specified or if it is project data and we aren't caching it, use the simple // target dictionary. if (String.IsNullOrWhiteSpace(connectionString) || (isProjectData && !cacheProject)) { td = base.CreateTargetDictionary(configuration); } else { try { td = new SqlTargetDictionary(this, configuration, connectionString, groupId, isProjectData ? projectCacheSize : frameworkCacheSize, isProjectData); } catch (Exception ex) { this.WriteMessage(MessageLevel.Error, BuildComponentUtilities.GetExceptionMessage(ex)); } } return(td); }
/// <summary> /// This is used to create a <see cref="TargetDictionary"/> used to store reference link targets /// </summary> /// <param name="configuration">The configuration element for the target dictionary</param> /// <returns>A default <see cref="InMemoryTargetDictionary"/> instance containing the reference link /// targets</returns> /// <remarks>This can be overridden in derived classes to provide persistent caches with backing stores /// other than the default <see cref="Dictionary{TKey, TValue}"/></remarks>. public virtual TargetDictionary CreateTargetDictionary(XPathNavigator configuration) { TargetDictionary d = null; try { d = new InMemoryTargetDictionary(this, configuration); } catch (Exception ex) { this.WriteMessage(MessageLevel.Error, BuildComponentUtilities.GetExceptionMessage(ex)); } return(d); }
/// <summary> /// Unpostpone target in the case when it didn't successfuly consume a message. /// </summary> public void UnpostponeTargetNotConsumed(ITargetBlock <T> targetBlock) { Target target; if (!TargetDictionary.TryGetValue(targetBlock, out target)) { return; } unpostponedTargets.Enqueue(Tuple.Create(target, new DataflowMessageHeader())); target.Postponed.Value = false; target.Reserved.Value = false; }
/// <summary> /// Unpostpones the given target. /// </summary> /// <param name="targetBlock">Target to unpostpone.</param> /// <param name="messageConsumed">Did the target consume an item?</param> public void UnpostponeTarget(ITargetBlock <T> targetBlock, bool messageConsumed) { Target target; if (!TargetDictionary.TryGetValue(targetBlock, out target)) { return; } if (messageConsumed) { target.MessageSent(); } unpostponedTargets.Enqueue(target); target.Postponed.Value = false; }
bool Handle(TemplateTypeParameter p, ISemantic arg) { // if no argument given, try to handle default arguments if (arg == null) { if (p.Default == null) { return(false); } else { IStatement stmt = null; ctxt.PushNewScope(DResolver.SearchBlockAt(ctxt.ScopedBlock.NodeRoot as IBlockNode, p.Default.Location, out stmt)); ctxt.ScopedStatement = stmt; var defaultTypeRes = TypeDeclarationResolver.Resolve(p.Default, ctxt); bool b = false; if (defaultTypeRes != null) { b = Set(p, defaultTypeRes.First()); } ctxt.Pop(); return(b); } } // If no spezialization given, assign argument immediately if (p.Specialization == null) { return(Set(p, arg)); } bool handleResult = HandleDecl(p, p.Specialization, arg); if (!handleResult) { return(false); } // Apply the entire argument to parameter p if there hasn't been no explicit association yet if (!TargetDictionary.ContainsKey(p.Name) || TargetDictionary[p.Name] == null) { TargetDictionary[p.Name] = new TemplateParameterSymbol(p, arg); } return(true); }
private static T GetDef <T>(Dictionary <int, T> TargetDictionary, string assetUrl, int ID) where T : ScriptableObject { if (TargetDictionary == null) { TargetDictionary = new Dictionary <int, T>(); } if (TargetDictionary.ContainsKey(ID)) { return(TargetDictionary[ID]); } else { var res = Resources.Load <T>(Path.Combine(assetUrl, ID.ToString())); if (res == null) { Debug.LogError("the res is null:" + assetUrl + " :" + ID); return(null); } TargetDictionary.Add(ID, GameObject.Instantiate <T>(res)); return(TargetDictionary[ID]); } }