/// <summary> /// Initializes a new instance of the <see cref="Timeline<T>"/> class. /// </summary> public TimeEngine() { for (int timesliceIndex = 0; timesliceIndex < _timeslices.Length; timesliceIndex++) { _timeslices[timesliceIndex] = new Timeslice(); } }
/// <summary> /// Start a site host /// </summary> /// <param name="rootAssemblyPath">Path to the assembly that contains a configuration point</param> /// <param name="majorVersion">Major version of site being hosted</param> /// <param name="versionName">Name of version</param> public SiteHost(string rootAssemblyPath, int majorVersion, string versionName) { MajorVersion = majorVersion; VersionName = versionName; TargetPath = rootAssemblyPath; SuccessHistory = new Timeslice(); FailureHistory = new Timeslice(); Trace.TraceInformation("Starting up site v" + MajorVersion + " at " + TargetPath); // Find paths if (!File.Exists(rootAssemblyPath)) { throw new Exception("Root assembly path not accessible"); } var binPath = Path.GetDirectoryName(rootAssemblyPath); var outerDirectory = Path.GetDirectoryName(binPath); if (outerDirectory == null) { throw new Exception("Could not guess outer hosting directory"); } // Try to edit child's Web.Config file for Azure hosting requirements. We also turn on debug information, so we can capture it for logging. var webConfigPath = Path.Combine(outerDirectory, "web.config"); if (File.Exists(webConfigPath)) { try { EditForHosting(webConfigPath, binPath); } catch (Exception ex) { LastError = ex; Trace.TraceWarning("Failed to edit web.config: " + ex); } } else { Trace.TraceWarning("Expected to see web config at '" + webConfigPath + "', but it was missing"); } // Chuck a copy of Huygens into the hosted site's bin directory. // This is required for hosting //if (!File.Exists(binPath + @"\Huygens.dll")) // File.Copy(exePath + @".\Huygens.dll", binPath + @"\Huygens.dll", true); // try dropping in bin directly. Trace.TraceInformation("Loading and creating server at " + TargetPath); // Start the host HostedSite = new DirectServer(outerDirectory); Trace.TraceInformation("Warming server at " + TargetPath); WarmAndTest(); Trace.TraceInformation("New version ready: v" + MajorVersion + " at " + TargetPath); }
private static TagContent RenderGraph(Timeslice success, Timeslice failure) { var height = 240; var width = 320; var doc = SvgHeader(width, height, out var root); var good = success.View().Values.ToArray(); var bad = failure.View().Values.ToArray(); var allMax = Math.Max(1, Math.Max(good.Max(), bad.Max())); DrawLines(good, allMax, height, width, root, "good"); DrawLines(bad, allMax, height, width, root, "bad"); return(doc); }
/// <summary> /// Evaluates the frame. /// </summary> /// <param name="mSecond">The m second.</param> public void EvaluateFrame(ulong time) { //System.Console.WriteLine("Timeline: EvaluateFrame {" + time.ToString() + "}"); _isRebuildList = true; _isRebuildLink = true; ulong listFractionTime; ulong linkFractionTime; int listFractionTimeIndex = 0; int linkFractionTimeIndex = 0; bool isFirstLoop = true; while (true) { //+ check for escape if (time <= 0) { return; } //+ new timelice Timeslice timeslice = _timeslices[_timesliceIndex]; Dictionary <ulong, List <TElement> > list = timeslice.List; Dictionary <ulong, LinkHead> link = timeslice.Link; listFractionTime = FillWorkingFractionArray <List <TElement> >(list, ref _listWorkingFractionArray, TimePrecision.ListWorkingFractionSize, ref listFractionTimeIndex, ref _listMaxWorkingFraction); linkFractionTime = FillWorkingFractionArray <LinkHead>(link, ref _linkWorkingFractionArray, TimePrecision.LinkWorkingFractionSize, ref linkFractionTimeIndex, ref _linkMaxWorkingFraction); //+ process time-slices ulong fractionTime = System.Math.Min(listFractionTime, linkFractionTime); if (isFirstLoop == true) { isFirstLoop = false; time += fractionTime; } ulong lastFractionTime = 0; while (fractionTime < ulong.MaxValue) { //+ advance time-slice + check for escape time -= (fractionTime - lastFractionTime); if (time <= 0) { return; } //+ evaluate time #region Evalutate Time if (listFractionTime == fractionTime) { List <TElement> objectList = list[listFractionTime]; int objectIndex; int objectListCount = objectList.Count; for (objectIndex = 0; objectIndex <= (objectListCount - 5); objectIndex += 5) { _threadPool.Add(objectList.GetRange(objectIndex, 5)); } if (objectIndex != objectListCount) { _threadPool.Add(objectList.GetRange(objectIndex, objectListCount - objectIndex)); } //+ next list.Remove(listFractionTime); listFractionTime = (listFractionTimeIndex > 0 ? _listWorkingFractionArray[--listFractionTimeIndex] : ulong.MaxValue); } if (linkFractionTime == fractionTime) { LinkBase nextItem; LinkHead head = link[linkFractionTime]; LinkBase item = head.Chain; int itemCount = head.Count; int itemIndex; for (itemIndex = 0; itemIndex <= (itemCount - 5); itemIndex += 5) { LinkBase item0 = item; nextItem = item0.NextLink; item0.NextLink = null; //+ paranoia LinkBase item1 = nextItem; nextItem = item1.NextLink; item1.NextLink = null; //+ paranoia LinkBase item2 = nextItem; nextItem = item2.NextLink; item2.NextLink = null; //+ paranoia LinkBase item3 = nextItem; nextItem = item3.NextLink; item3.NextLink = null; //+ paranoia LinkBase item4 = nextItem; nextItem = item4.NextLink; item4.NextLink = null; //+ paranoia item = nextItem; _threadPool.Add(new LinkBase[] { item0, item1, item2, item3, item4 }); } if (itemIndex != itemCount) { itemCount -= itemIndex; LinkBase[] itemArray = new LinkBase[itemCount]; itemIndex = 0; //for (; itemIndex < itemCount; /*item != null;*/ item = nextItem) //for (; item != null; item = nextItem) for (; itemIndex < itemCount; item = nextItem) { nextItem = item.NextLink; item.NextLink = null; //+ paranoia itemArray[itemIndex++] = item; } _threadPool.Add(itemArray); } //+ next link.Remove(linkFractionTime); linkFractionTime = (linkFractionTimeIndex > 0 ? _linkWorkingFractionArray[--linkFractionTimeIndex] : ulong.MaxValue); } #endregion Evalutate Time _threadPool.Join(); //System.Console.WriteLine("Timeslice: " + time.ToString()); //+ process state-change #region Process State-Change ContextChange nextContext; //for (Context context = m_contextChangeLink; context != null; context = nextContext) //{ // nextContext = context.NextContext; // context.NextContext = null; //+ paranoia // context.Execute(); //} ContextChange context = _contextChangeLink; int contextCount = _contextChangeLinkCount; int contextIndex; for (contextIndex = 0; contextIndex <= (contextCount - 5); contextIndex += 5) { ContextChange context0 = context; nextContext = context0.NextContextChange; context0.NextContextChange = null; //+ paranoia ContextChange context1 = nextContext; nextContext = context1.NextContextChange; context1.NextContextChange = null; //+ paranoia ContextChange context2 = nextContext; nextContext = context2.NextContextChange; context2.NextContextChange = null; //+ paranoia ContextChange context3 = nextContext; nextContext = context3.NextContextChange; context3.NextContextChange = null; //+ paranoia ContextChange context4 = nextContext; nextContext = context4.NextContextChange; context4.NextContextChange = null; //+ paranoia context = nextContext; _threadPool.Add(new ContextChange[] { context0, context1, context2, context3, context4 }); } if (contextIndex != contextCount) { contextCount -= contextIndex; ContextChange[] contextArray = new ContextChange[contextCount]; contextIndex = 0; //for (; contextIndex < itemCount; /*context != null;*/ context = nextContext) //for (; context != null; context = nextContext) for (; contextIndex < contextCount; context = nextContext) { nextContext = context.NextContextChange; context.NextContextChange = null; //+ paranoia contextArray[contextIndex++] = context; } _threadPool.Add(contextArray); } //+ clear _contextChangeLink = null; _contextChangeLinkCount = 0; #endregion Process State-Change //+ if ((_isRebuildList == true) || (_listMaxWorkingFraction == fractionTime)) { _isRebuildList = false; listFractionTime = FillWorkingFractionArray <List <TElement> >(list, ref _listWorkingFractionArray, TimePrecision.ListWorkingFractionSize, ref listFractionTimeIndex, ref _listMaxWorkingFraction); } if ((_isRebuildLink == true) || (_linkMaxWorkingFraction == fractionTime)) { _isRebuildLink = false; linkFractionTime = FillWorkingFractionArray <LinkHead>(link, ref _linkWorkingFractionArray, TimePrecision.LinkWorkingFractionSize, ref linkFractionTimeIndex, ref _linkMaxWorkingFraction); } lastFractionTime = fractionTime; fractionTime = System.Math.Min(listFractionTime, linkFractionTime); _threadPool.Join(); } //+ advance time _isRebuildList = true; _isRebuildLink = true; time -= (TimePrecision.TimeScaler - lastFractionTime); _timesliceIndex++; if (_timesliceIndex >= TimesliceArraySize) { _timesliceIndex = 0; //System.Console.WriteLine("Timeline: ccycle"); //+ dehibernate #region Dehibernate for (LinkedListNode <Hibernate> hibernateNode = _hibernateList.First; hibernateNode != null; hibernateNode = hibernateNode.Next) { Hibernate hibernate = hibernateNode.Value; ulong newTime = (hibernate.Time -= TimesliceArrayTime); if (newTime < TimesliceArrayTime) { if (newTime < 0) { throw new System.InvalidOperationException(); //+ paranoia } //+ remove node _hibernateList.Remove(hibernateNode); //+ add to timeline System.Console.WriteLine("Timeline: Dehibernate {" + newTime.ToString() + "}"); Add(hibernate.Object, newTime); } else { hibernateNode.Value = hibernate; } } LinkBase lastObject = _hibernateLink; for (LinkBase @object = _hibernateLink; @object != null; @object = @object.NextLink) { ulong newTime = (@object.HibernateTime -= TimesliceArrayTime); if (newTime < TimesliceArrayTime) { if (newTime < 0) { throw new System.InvalidOperationException(); //+ paranoia } //+ remove node //lastObject = (m_hibernateLink != @object ? (lastObject.NextTimeLink = @object.NextTimeLink) : (m_hibernateLink = @object.NextTimeLink)); lastObject = (lastObject.NextLink = @object.NextLink); @object.NextLink = null; //+ paranoia //+ add to timeline System.Console.WriteLine("Timeline: Dehibernate {" + newTime.ToString() + "}"); Add(@object, newTime); } else { lastObject = @object; } } } #endregion Dehibernate } }