Example #1
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                // Get options
                var options = ConstructionOptions?.Invoke(this);

                // Prepare the line numbers callback
                LineNumbersLambda = options.LineNumbersLambda;
                if (LineNumbersLambda != null)
                {
                    options.LineNumbers       = "function";
                    options.LineNumbersLambda = null;
                }

                // Create the editor
                await MonacoEditorBase.Create(Id, options, jsObjectRef);
            }

            await base.OnAfterRenderAsync(firstRender);
        }
		public SystemInfoNodeProvider(IFileSystemManager manager, ConstructionOptions options)
			: this(manager, options.Scheme.IsNullOrEmpty() ? "systeminfo" : options.Scheme)
		{
			var root = (ImaginaryDirectory)this.ImaginaryFileSystem.RootDirectory;
						
			var systemClockDirectory = (ImaginaryDirectory)root.ResolveDirectory("SystemClock").Create();
			ImaginaryDirectory environmentVariablesDirectory = new EnvironmentVariablesDirectory(this.ImaginaryFileSystem, root.Address.ResolveAddress("EnvironmentVariables"));

			root.Add(systemClockDirectory);
			root.Add(environmentVariablesDirectory);
			
			var dateTimeFile = new ImaginaryMemoryFile
			(
				this.ImaginaryFileSystem,
				systemClockDirectory.Address.ResolveAddress("./CurrentDateTime"),
				delegate
				{
					return Encoding.ASCII.GetBytes(DateTime.Now.ToUniversalTime().ToString(DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString) + Environment.NewLine);
				},
				PredicateUtils<ImaginaryMemoryFile>.AlwaysTrue
			);

			dateTimeFile.Changed += delegate
			{
				string s;
				TimeSpan timeSpan;
				DateTime dateTime;

				s = Encoding.ASCII.GetString(dateTimeFile.RawNonDynamicValue);

				s = s.Trim(c => Char.IsWhiteSpace(c) || c == '\r' || c == '\n' || c == '\t');

				if (TimeSpan.TryParse(s, out timeSpan))
				{
					dateTime = DateTime.Now;

					dateTime += timeSpan;
				}
				else
				{
					try
					{
						dateTime = DateTime.ParseExact(s, DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString, CultureInfo.InvariantCulture);

						dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
						dateTime = dateTime.ToLocalTime();
					}
					catch (FormatException e)
					{
						Console.Error.WriteLine(e);

						return;
					}
				}

				EnvironmentUtils.SetSystemTime(dateTime);
			};

			systemClockDirectory.Add(dateTimeFile);

			var utcDateTimeFile = new ImaginaryMemoryFile
			(
				this.ImaginaryFileSystem,
				systemClockDirectory.Address.ResolveAddress("./CurrentUtcDateTime"),
				delegate
				{
					return Encoding.ASCII.GetBytes(DateTime.Now.ToUniversalTime().ToString(DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString) + "\n");
				},
				PredicateUtils<ImaginaryMemoryFile>.AlwaysTrue
			);

			utcDateTimeFile.Changed += delegate
			{
				TimeSpan timeSpan;
				DateTime dateTime;

				var s = Encoding.ASCII.GetString(utcDateTimeFile.RawNonDynamicValue);

				s = s.Trim(c => Char.IsWhiteSpace(c) || c == '\r' || c == '\n' || c == '\t');

				if (TimeSpan.TryParse(s, out timeSpan))
				{
					dateTime = DateTime.Now;

					dateTime += timeSpan;
				}
				else
				{
					try
					{
						dateTime = DateTime.ParseExact(s, DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString, CultureInfo.InvariantCulture);

						dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
					}
					catch (FormatException e)
					{
						Console.Error.WriteLine(e);

						return;
					}
				}

				EnvironmentUtils.SetSystemTime(dateTime);
			};

			systemClockDirectory.Add(utcDateTimeFile);
			
			var localDateTimeFile = new ImaginaryMemoryFile
			(
				this.ImaginaryFileSystem,
				systemClockDirectory.Address.ResolveAddress("./CurrentLocalDateTime"),
				delegate
				{
					return Encoding.ASCII.GetBytes(DateTime.Now.ToString(DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString) + Environment.NewLine);
				},
				PredicateUtils<ImaginaryMemoryFile>.AlwaysTrue
			);

			localDateTimeFile.Changed += delegate
			{
				TimeSpan timeSpan;
				DateTime dateTime;

				var s = Encoding.ASCII.GetString(localDateTimeFile.RawNonDynamicValue);

				s = s.Trim(c => Char.IsWhiteSpace(c) || c == '\r' || c == '\n' || c == '\t');

				if (TimeSpan.TryParse(s, out timeSpan))
				{
					dateTime = DateTime.Now;

					dateTime += timeSpan;
				}
				else
				{
					try
					{
						dateTime = DateTime.ParseExact(s, DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString, CultureInfo.InvariantCulture);

						dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
					}
					catch (FormatException e)
					{
						Console.Error.WriteLine(e);

						return;
					}
				}

				EnvironmentUtils.SetSystemTime(dateTime);
			};

			systemClockDirectory.Add(localDateTimeFile);
		}
        public SystemInfoNodeProvider(IFileSystemManager manager, ConstructionOptions options)
            : this(manager, options.Scheme.IsNullOrEmpty() ? "systeminfo" : options.Scheme)
        {
            var root = (ImaginaryDirectory)this.ImaginaryFileSystem.RootDirectory;

            var systemClockDirectory = (ImaginaryDirectory)root.ResolveDirectory("SystemClock").Create();
            ImaginaryDirectory environmentVariablesDirectory = new EnvironmentVariablesDirectory(this.ImaginaryFileSystem, root.Address.ResolveAddress("EnvironmentVariables"));

            root.Add(systemClockDirectory);
            root.Add(environmentVariablesDirectory);

            var dateTimeFile = new ImaginaryMemoryFile
                               (
                this.ImaginaryFileSystem,
                systemClockDirectory.Address.ResolveAddress("./CurrentDateTime"),
                delegate
            {
                return(Encoding.ASCII.GetBytes(DateTime.Now.ToUniversalTime().ToString(DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString) + Environment.NewLine));
            },
                PredicateUtils <ImaginaryMemoryFile> .AlwaysTrue
                               );

            dateTimeFile.Changed += delegate
            {
                string   s;
                TimeSpan timeSpan;
                DateTime dateTime;

                s = Encoding.ASCII.GetString(dateTimeFile.RawNonDynamicValue);

                s = s.Trim(c => Char.IsWhiteSpace(c) || c == '\r' || c == '\n' || c == '\t');

                if (TimeSpan.TryParse(s, out timeSpan))
                {
                    dateTime = DateTime.Now;

                    dateTime += timeSpan;
                }
                else
                {
                    try
                    {
                        dateTime = DateTime.ParseExact(s, DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString, CultureInfo.InvariantCulture);

                        dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
                        dateTime = dateTime.ToLocalTime();
                    }
                    catch (FormatException e)
                    {
                        Console.Error.WriteLine(e);

                        return;
                    }
                }

                EnvironmentUtils.SetSystemTime(dateTime);
            };

            systemClockDirectory.Add(dateTimeFile);

            var utcDateTimeFile = new ImaginaryMemoryFile
                                  (
                this.ImaginaryFileSystem,
                systemClockDirectory.Address.ResolveAddress("./CurrentUtcDateTime"),
                delegate
            {
                return(Encoding.ASCII.GetBytes(DateTime.Now.ToUniversalTime().ToString(DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString) + "\n"));
            },
                PredicateUtils <ImaginaryMemoryFile> .AlwaysTrue
                                  );

            utcDateTimeFile.Changed += delegate
            {
                TimeSpan timeSpan;
                DateTime dateTime;

                var s = Encoding.ASCII.GetString(utcDateTimeFile.RawNonDynamicValue);

                s = s.Trim(c => Char.IsWhiteSpace(c) || c == '\r' || c == '\n' || c == '\t');

                if (TimeSpan.TryParse(s, out timeSpan))
                {
                    dateTime = DateTime.Now;

                    dateTime += timeSpan;
                }
                else
                {
                    try
                    {
                        dateTime = DateTime.ParseExact(s, DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString, CultureInfo.InvariantCulture);

                        dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
                    }
                    catch (FormatException e)
                    {
                        Console.Error.WriteLine(e);

                        return;
                    }
                }

                EnvironmentUtils.SetSystemTime(dateTime);
            };

            systemClockDirectory.Add(utcDateTimeFile);

            var localDateTimeFile = new ImaginaryMemoryFile
                                    (
                this.ImaginaryFileSystem,
                systemClockDirectory.Address.ResolveAddress("./CurrentLocalDateTime"),
                delegate
            {
                return(Encoding.ASCII.GetBytes(DateTime.Now.ToString(DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString) + Environment.NewLine));
            },
                PredicateUtils <ImaginaryMemoryFile> .AlwaysTrue
                                    );

            localDateTimeFile.Changed += delegate
            {
                TimeSpan timeSpan;
                DateTime dateTime;

                var s = Encoding.ASCII.GetString(localDateTimeFile.RawNonDynamicValue);

                s = s.Trim(c => Char.IsWhiteSpace(c) || c == '\r' || c == '\n' || c == '\t');

                if (TimeSpan.TryParse(s, out timeSpan))
                {
                    dateTime = DateTime.Now;

                    dateTime += timeSpan;
                }
                else
                {
                    try
                    {
                        dateTime = DateTime.ParseExact(s, DateTimeFormats.SortableUtcDateTimeFormatWithFractionSecondsString, CultureInfo.InvariantCulture);

                        dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
                    }
                    catch (FormatException e)
                    {
                        Console.Error.WriteLine(e);

                        return;
                    }
                }

                EnvironmentUtils.SetSystemTime(dateTime);
            };

            systemClockDirectory.Add(localDateTimeFile);
        }
		public MyComputerNodeProvider(IFileSystemManager manager, ConstructionOptions options)
			: this(manager, options.Scheme.IsNullOrEmpty() ? "mycomputer" : options.Scheme)
		{
		}
 public MyComputerNodeProvider(IFileSystemManager manager, ConstructionOptions options)
     : this(manager, options.Scheme.IsNullOrEmpty() ? "mycomputer" : options.Scheme)
 {
 }