public AssertTokenizer(Tests/*!*/ tests) { _log = new LoggingErrorSink(); _tests = tests; _context = tests.Context; DefaultEncoding = RubyEncoding.UTF8; Compatibility = tests.Context.RubyOptions.Compatibility; }
/// <summary> /// Updates the varz structure with uptime, cpu, memory usage .... /// </summary> private void UpdateVarz() { TimeSpan span = DateTime.Now - RubyCompatibility.DateTimeFromRubyString((string)this.discover["start"]); this.Varz["uptime"] = string.Format(CultureInfo.InvariantCulture, "{0}d:{1}h:{2}m:{3}s", span.Days, span.Hours, span.Minutes, span.Seconds); float cpu = ((float)Process.GetCurrentProcess().TotalProcessorTime.Ticks / span.Ticks) * 100; // trim it to one decimal precision cpu = float.Parse(cpu.ToString("F1", CultureInfo.CurrentCulture), CultureInfo.CurrentCulture); this.Varz["cpu"] = cpu; this.Varz["mem"] = Process.GetCurrentProcess().WorkingSet64 / 1024; // extra uhuru information this.Varz["cpu_time"] = Process.GetCurrentProcess().TotalProcessorTime; // this is the cpu percentage for the time span between the Nextvalue calls; this.Varz["system_cpu"] = this.CpuPerformance.NextValue(); this.Varz["system_cpu_ticks"] = this.CpuPerformance.RawValue; // todo: add memory usage here // consider: // PerformanceCounter ramCounter; // ramCounter = new PerformanceCounter("Memory", "Available MBytes"); // ramCounter.NextValue(); this.Varz["system_mem"] = null; }
public RubyOptions(IDictionary <string, object> /*!*/ options) : base(options) { _arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection; _argumentEncoding = GetOption(options, "ArgumentEncoding", RubyEncoding.Default); _compatibility = GetCompatibility(options, "Compatibility", RubyCompatibility.Default); _mainFile = GetOption(options, "MainFile", (string)null); _verbosity = GetOption(options, "Verbosity", 1); _debugVariable = GetOption(options, "DebugVariable", false); _enableTracing = GetOption(options, "EnableTracing", false); _savePath = GetOption(options, "SavePath", (string)null); _loadFromDisk = GetOption(options, "LoadFromDisk", false); _profile = GetOption(options, "Profile", false); _noAssemblyResolveHook = GetOption(options, "NoAssemblyResolveHook", false); _requirePaths = GetStringCollectionOption(options, "RequiredPaths", ';', ','); _hasSearchPaths = GetOption <object>(options, "SearchPaths", null) != null; if (_compatibility < RubyCompatibility.Ruby19) { _kcode = GetKCoding(options, "KCode", null); _libraryPaths = GetStringCollectionOption(options, "LibraryPaths", ';', ',') ?? new ReadOnlyCollection <string>(new[] { "." }); } else { _libraryPaths = GetStringCollectionOption(options, "LibraryPaths19", ';', ',') ?? new ReadOnlyCollection <string>(new[] { "." }); } }
/// <summary> /// Runs this the VCAP component. This method is non-blocking. /// </summary> public virtual void Run() { this.Discover = new Dictionary <string, object>() { { "type", this.ComponentType }, { "index", this.Index }, { "uuid", this.UUID }, { "host", string.Format(CultureInfo.InvariantCulture, "{0}:{1}", this.Host, this.Port) }, { "credentials", this.Authentication }, { "start", RubyCompatibility.DateTimeToRubyString(this.StartedAt = DateTime.Now) } }; // Listen for discovery requests VCAPReactor.OnComponentDiscover += delegate(string msg, string reply, string subject) { this.UpdateDiscoverUptime(); VCAPReactor.SendReply(reply, JsonConvertibleObject.SerializeToJson(this.Discover)); }; VCAPReactor.Start(); // Varz is customizable this.Varz = new Dictionary <string, object>(); foreach (string key in this.Discover.Keys) { this.Varz[key] = this.Discover[key]; } this.Varz["num_cores"] = Environment.ProcessorCount; // todo: change this to a more accurate method // consider: // PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time"); // upTime.NextValue(); // TimeSpan ts2 = TimeSpan.FromSeconds(upTime.NextValue()); // Console.WriteLine("{0}d {1}h {2}m {3}s", ts2.Days, ts2.Hours, ts2.Minutes, ts2.Seconds); this.Varz["system_start"] = RubyCompatibility.DateTimeToRubyString(DateTime.Now.AddMilliseconds(-Environment.TickCount)); this.CpuPerformance = new PerformanceCounter(); this.CpuPerformance.CategoryName = "Processor Information"; this.CpuPerformance.CounterName = "% Processor Time"; this.CpuPerformance.InstanceName = "_Total"; this.CpuPerformance.NextValue(); this.Healthz = "ok\n"; this.StartHttpServer(); // Also announce ourselves on startup.. VCAPReactor.SendVCAPComponentAnnounce(JsonConvertibleObject.SerializeToJson(this.Discover)); }
public RubyOptions(IDictionary <string, object> /*!*/ options) : base(options) { _arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection; _mainFile = GetOption(options, "MainFile", (string)null); _verbosity = GetOption(options, "Verbosity", 1); _enableTracing = GetOption(options, "EnableTracing", false); _savePath = GetOption(options, "SavePath", (string)null); _loadFromDisk = GetOption(options, "LoadFromDisk", false); _profile = GetOption(options, "Profile", false); _libraryPaths = GetStringCollectionOption(options, "LibraryPaths", ';', ',') ?? new ReadOnlyCollection <string>(new[] { "." }); _hasSearchPaths = GetOption <object>(options, "SearchPaths", null) != null; _compatibility = GetCompatibility(options, "Compatibility", RubyCompatibility.Default); }
public List <RubyHash> CalculateDeployments() { List <RubyHash> deployments = new List <RubyHash>(); foreach (string d in AllDeployments()) { string deploymentDateTime = new DirectoryInfo(d).Name; DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDateTime); deployments.Add(new RubyHash() { { "id", deploymentMetadata.Id }, { "ref", deploymentMetadata.GitRef }, { "sha1", deploymentMetadata.GitSha }, { "force_clean_build", deploymentMetadata.ForceCleanBuild }, { "hot_deploy", deploymentMetadata.HotDeploy }, { "created_at", RubyCompatibility.DateTimeToEpochSeconds(DateTime.Parse(deploymentDateTime)) }, { "activations", deploymentMetadata.Activations } }); } return(deployments); }
private static RubyCompatibility GetCompatibility(IDictionary<string, object>/*!*/ options, string/*!*/ name, RubyCompatibility defaultValue) { object value; if (options != null && options.TryGetValue(name, out value)) { if (value is RubyCompatibility) { return (RubyCompatibility)value; } string str = value as string; if (str != null) { switch (str) { case "1.8": return RubyCompatibility.Ruby186; case "1.9": return RubyCompatibility.Ruby19; case "2.0": return RubyCompatibility.Ruby20; } } return (RubyCompatibility)Convert.ChangeType(value, typeof(RubyCompatibility), Thread.CurrentThread.CurrentCulture); } return defaultValue; }
public RubyOptions(IDictionary<string, object>/*!*/ options) : base(options) { _arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection; _argumentEncoding = GetOption(options, "ArgumentEncoding", RubyEncoding.Default); _compatibility = GetCompatibility(options, "Compatibility", RubyCompatibility.Default); _mainFile = GetOption(options, "MainFile", (string)null); _verbosity = GetOption(options, "Verbosity", 1); _debugVariable = GetOption(options, "DebugVariable", false); _enableTracing = GetOption(options, "EnableTracing", false); _savePath = GetOption(options, "SavePath", (string)null); _loadFromDisk = GetOption(options, "LoadFromDisk", false); _profile = GetOption(options, "Profile", false); _noAssemblyResolveHook = GetOption(options, "NoAssemblyResolveHook", false); _requirePaths = GetStringCollectionOption(options, "RequiredPaths", ';', ','); _hasSearchPaths = GetOption<object>(options, "SearchPaths", null) != null; if (_compatibility < RubyCompatibility.Ruby19) { _kcode = GetKCoding(options, "KCode", null); _libraryPaths = GetStringCollectionOption(options, "LibraryPaths", ';', ',') ?? new ReadOnlyCollection<string>(new[] { "." }); } else { _libraryPaths = GetStringCollectionOption(options, "LibraryPaths19", ';', ',') ?? new ReadOnlyCollection<string>(new[] { "." }); } }
public void Test_RubyCompatibility() { int epochValue = RubyCompatibility.DateTimeToEpochSeconds(new DateTime(1970, 1, 1)); Assert.AreEqual(0, epochValue); }
// copies relevant options from runtime options: public RubyCompilerOptions(RubyOptions/*!*/ runtimeOptions) { Compatibility = runtimeOptions.Compatibility; }
public Tokenizer(bool verbatim, ErrorSink/*!*/ errorSink) { ContractUtils.RequiresNotNull(errorSink, "errorSink"); _bigIntParser = new BignumParser(); _errorSink = errorSink; _sourceUnit = null; _parser = null; _verbatim = verbatim; _compatibility = RubyCompatibility.Default; // _buffer = null; _initialLocation = SourceLocation.Invalid; _tokenSpan = SourceSpan.Invalid; _tokenValue = new TokenValue(); _bufferPos = 0; // TODO: _input = null; }
public RubyOptions(IDictionary<string, object>/*!*/ options) : base(options) { _arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection; _mainFile = GetOption(options, "MainFile", (string)null); _verbosity = GetOption(options, "Verbosity", 1); _enableTracing = GetOption(options, "EnableTracing", false); _savePath = GetOption(options, "SavePath", (string)null); _loadFromDisk = GetOption(options, "LoadFromDisk", false); _profile = GetOption(options, "Profile", false); _noAssemblyResolveHook = GetOption(options, "NoAssemblyResolveHook", false); _libraryPaths = GetStringCollectionOption(options, "LibraryPaths", ';', ',') ?? new ReadOnlyCollection<string>(new[] { "." }); _hasSearchPaths = GetOption<object>(options, "SearchPaths", null) != null; _compatibility = GetCompatibility(options, "Compatibility", RubyCompatibility.Default); _DefaultExceptionDetail = this.ExceptionDetail; #if !SILVERLIGHT if (_compatibility == RubyCompatibility.Ruby18) { _kcode = GetKCoding(options, "KCode", null); } #endif #if DEBUG _UseThreadAbortForSyncRaise = GetOption(options, "UseThreadAbortForSyncRaise", false); _CompileRegexps = GetOption(options, "CompileRegexps", false); #endif }
public static bool CheckUrlAge(string url) { Uri uri = new Uri(url); int urlAge = int.Parse(HttpUtility.ParseQueryString(uri.Query)["timestamp"]) - RubyCompatibility.DateTimeToEpochSeconds(DateTime.Now); if (urlAge > 60 * 60) { return(false); } return(true); }
// copies relevant options from runtime options: public RubyCompilerOptions(RubyOptions /*!*/ runtimeOptions) { Compatibility = runtimeOptions.Compatibility; }
public RubyOptions(IDictionary<string, object>/*!*/ options) : base(options) { _arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection; _mainFile = GetOption(options, "MainFile", (string)null); _verbosity = GetOption(options, "Verbosity", 1); _enableTracing = GetOption(options, "EnableTracing", false); _savePath = GetOption(options, "SavePath", (string)null); _loadFromDisk = GetOption(options, "LoadFromDisk", false); _profile = GetOption(options, "Profile", false); _libraryPaths = GetStringCollectionOption(options, "LibraryPaths", ';', ',') ?? new ReadOnlyCollection<string>(new[] { "." }); _hasSearchPaths = GetOption<object>(options, "SearchPaths", null) != null; _compatibility = GetCompatibility(options, "Compatibility", RubyCompatibility.Default); #if DEBUG _UseThreadAbortForSyncRaise = GetOption(options, "UseThreadAbortForSyncRaise", false); #endif }
/// <summary> /// Updates the discovery uptime. /// </summary> private void UpdateDiscoverUptime() { TimeSpan span = DateTime.Now - RubyCompatibility.DateTimeFromRubyString((string)this.discover["start"]); this.discover["uptime"] = string.Format(CultureInfo.InvariantCulture, "{0}d:{1}h:{2}m:{3}s", span.Days, span.Hours, span.Minutes, span.Seconds); }
/// <summary> /// Registers a component using the specified options. /// </summary> /// <param name="options">The options for the component.</param> public void Register(Dictionary <string, object> options) { if (options == null) { throw new ArgumentNullException("options"); } this.Varz = new Dictionary <string, object>(); string uuid = Guid.NewGuid().ToString("N"); object type = options["type"]; object index = options.ContainsKey("index") ? options["index"] : null; if (index != null) { uuid = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", index, uuid); } string host = options["host"].ToString(); int port = options.ContainsKey("statusPort") ? (int)options["statusPort"] : 0; if (port < 1) { port = NetworkInterface.GrabEphemeralPort(); } Reactor nats = (Reactor)options["nats"]; //// string[] auth = new string[] //// { //// options.ContainsKey("user") ? options["user"].ToString() : string.Empty, //// options.ContainsKey("password") ? options["password"].ToString() : string.Empty //// }; string[] auth = new string[] { Credentials.GenerateCredential(32), Credentials.GenerateCredential(32) }; // Discover message limited this.discover = new Dictionary <string, object>() { { "type", type }, { "index", index }, { "uuid", uuid }, { "host", string.Format(CultureInfo.InvariantCulture, "{0}:{1}", host, port) }, { "credentials", auth }, { "start", RubyCompatibility.DateTimeToRubyString(DateTime.Now) } }; // Varz is customizable this.Varz = new Dictionary <string, object>(); foreach (string key in this.discover.Keys) { this.Varz[key] = this.discover[key]; } this.Varz["num_cores"] = Environment.ProcessorCount; // todo: change this to a more accurate method // consider: // PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time"); // upTime.NextValue(); // TimeSpan ts2 = TimeSpan.FromSeconds(upTime.NextValue()); // Console.WriteLine("{0}d {1}h {2}m {3}s", ts2.Days, ts2.Hours, ts2.Minutes, ts2.Seconds); this.Varz["system_start"] = RubyCompatibility.DateTimeToRubyString(DateTime.Now.AddMilliseconds(-Environment.TickCount)); this.CpuPerformance = new PerformanceCounter(); this.CpuPerformance.CategoryName = "Processor Information"; this.CpuPerformance.CounterName = "% Processor Time"; this.CpuPerformance.InstanceName = "_Total"; this.CpuPerformance.NextValue(); this.Healthz = "ok\n"; this.StartHttpServer(host, port, auth); // Listen for discovery requests nats.Subscribe( "vcap.component.discover", delegate(string msg, string reply, string subject) { this.UpdateDiscoverUptime(); nats.Publish(reply, null, JsonConvertibleObject.SerializeToJson(this.discover)); }); // Also announce ourselves on startup.. nats.Publish("vcap.component.announce", null, msg: JsonConvertibleObject.SerializeToJson(this.discover)); }
internal static Encoding /*!*/ GetDefaultHostEncoding(RubyCompatibility compatibility) { return((compatibility >= RubyCompatibility.Ruby19) ? Encoding.UTF8 : BinaryEncoding.Instance); }
private static RubyCompatibility GetCompatibility(IDictionary <string, object> /*!*/ options, string /*!*/ name, RubyCompatibility defaultValue) { object value; if (options != null && options.TryGetValue(name, out value)) { if (value is RubyCompatibility) { return((RubyCompatibility)value); } string str = value as string; if (str != null) { switch (str) { case "1.8": return(RubyCompatibility.Ruby18); case "1.9": return(RubyCompatibility.Ruby19); case "2.0": return(RubyCompatibility.Ruby20); } } return((RubyCompatibility)Convert.ChangeType(value, typeof(RubyCompatibility), Thread.CurrentThread.CurrentCulture)); } return(defaultValue); }
internal static Encoding/*!*/ GetDefaultHostEncoding(RubyCompatibility compatibility) { return (compatibility >= RubyCompatibility.Ruby19) ? Encoding.UTF8 : BinaryEncoding.Instance; }