Beispiel #1
0
        private static void Main(string[] args)
        {
            //Process command-line args
            processArgs(args);
            //Register minidump dumper only if the app isn't being debugged. No use filling up hard drives with s***e
            //Minidump is Windows-only, so we need a platform check here
            if (PlatformDetector.DetectPlatform() == Platform.Windows && !System.Diagnostics.Debugger.IsAttached)
            {
                MiniDump.Register("crashdump-" + Guid.NewGuid().ToString("N") + ".dmp",
                                  fullDump
                                      ? MiniDump.MINIDUMP_TYPE.MiniDumpWithFullMemory
                                      : MiniDump.MINIDUMP_TYPE.MiniDumpNormal);
            }
            var main = new EntryPoint();

            main._server = new SS14Server();
            LogManager.Log("Server -> Starting");

            if (main._server.Start())
            {
                LogManager.Log("Server -> Can not start server", LogLevel.Fatal);
                //Not like you'd see this, haha. Perhaps later for logging.
                Environment.Exit(0);
            }

            string strVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            LogManager.Log("Server Version " + strVersion + " -> Ready");

            main._server.MainLoop();
        }
Beispiel #2
0
        private FileStream WindowsCreateFile(string fileName, bool allowConcurrentWrite)
        {
            int fileShare = Win32FileNativeMethods.FILE_SHARE_READ;

            if (allowConcurrentWrite)
            {
                fileShare |= Win32FileNativeMethods.FILE_SHARE_WRITE;
            }

            if (this.CreateFileParameters.EnableFileDelete && PlatformDetector.GetCurrentRuntimeOS() != RuntimeOS.Windows)
            {
                fileShare |= Win32FileNativeMethods.FILE_SHARE_DELETE;
            }

            IntPtr handle = Win32FileNativeMethods.CreateFile(
                fileName,
                Win32FileNativeMethods.FileAccess.GenericWrite,
                fileShare,
                IntPtr.Zero,
                Win32FileNativeMethods.CreationDisposition.OpenAlways,
                this.CreateFileParameters.FileAttributes,
                IntPtr.Zero);

            if (handle.ToInt32() == -1)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            var safeHandle  = new Microsoft.Win32.SafeHandles.SafeFileHandle(handle, true);
            var returnValue = new FileStream(safeHandle, FileAccess.Write, this.CreateFileParameters.BufferSize);

            returnValue.Seek(0, SeekOrigin.End);
            return(returnValue);
        }
Beispiel #3
0
        private FileStream TryCreateFileStream(bool allowConcurrentWrite)
        {
            FileShare fileShare = FileShare.Read;

            if (allowConcurrentWrite)
            {
                fileShare = FileShare.ReadWrite;
            }

#if !NET_CF
            if (this.CreateFileParameters.EnableFileDelete && PlatformDetector.GetCurrentRuntimeOS() != RuntimeOS.Windows)
            {
                fileShare |= FileShare.Delete;
            }
#endif

#if !NET_CF && !SILVERLIGHT
            if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.WindowsNT) ||
                PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Windows))
            {
                return(this.WindowsCreateFile(this.FileName, allowConcurrentWrite));
            }
#endif

            return(new FileStream(
                       this.FileName,
                       FileMode.Append,
                       FileAccess.Write,
                       fileShare,
                       this.CreateFileParameters.BufferSize));
        }
Beispiel #4
0
        public void Android_GalaxyTab()
        {
            var userAgentSpan = UserAgents.Chrome_GalaxyTabS4.AsSpan();
            var actual        = PlatformDetector.GetPlatformAndOS(userAgentSpan);

            Assert.Equal(OperatingSystems.Android, actual.OS);
        }
Beispiel #5
0
        /// <summary>
        /// Scans the specified assembly for types marked with <see cref="ConditionMethodsAttribute" /> and adds
        /// them to the factory. Optionally it prepends the specified text to layout renderer names to avoid
        /// naming collisions.
        /// </summary>
        /// <param name="theAssembly">The assembly to be scanned for layout renderers.</param>
        /// <param name="prefix">The prefix to be prepended to layout renderer names.</param>
        public static void AddConditionMethodsFromAssembly(Assembly theAssembly, string prefix)
        {
            try
            {
                InternalLogger.Debug("AddLogEventConditionsFromAssembly('{0}')", theAssembly.FullName);
                foreach (Type t in theAssembly.GetTypes())
                {
                    if (t.IsDefined(typeof(ConditionMethodsAttribute), false))
                    {
                        if (PlatformDetector.IsSupportedOnCurrentRuntime(t))
                        {
                            foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Static))
                            {
                                ConditionMethodAttribute[] malist = (ConditionMethodAttribute[])mi.GetCustomAttributes(typeof(ConditionMethodAttribute), false);

                                foreach (ConditionMethodAttribute ma in malist)
                                {
                                    if (PlatformDetector.IsSupportedOnCurrentRuntime(mi))
                                    {
                                        AddConditionMethod(ma.Name, mi);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InternalLogger.Error("Failed to add LogEventConditions from '" + theAssembly.FullName + "': {0}", ex);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Scans the specified assembly for types marked with <see cref="TargetAttribute" /> and adds
 /// them to the factory. Optionally it prepends the specified text to the target names to avoid
 /// naming collisions.
 /// </summary>
 /// <param name="theAssembly">The assembly to be scanned for targets.</param>
 /// <param name="prefix">The prefix to be prepended to target names.</param>
 public static void AddTargetsFromAssembly(Assembly theAssembly, string prefix)
 {
     try
     {
         InternalLogger.Debug("AddTargetsFromAssembly('{0}')", theAssembly.FullName);
         foreach (Type t in theAssembly.GetTypes())
         {
             TargetAttribute[] attributes = (TargetAttribute[])t.GetCustomAttributes(typeof(TargetAttribute), false);
             if (attributes != null)
             {
                 foreach (TargetAttribute attr in attributes)
                 {
                     if (PlatformDetector.IsSupportedOnCurrentRuntime(t))
                     {
                         AddTarget(prefix + attr.Name, t);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         InternalLogger.Error("Failed to add targets from '" + theAssembly.FullName + "': {0}", ex);
     }
 }
Beispiel #7
0
        public void Macintosh()
        {
            var userAgentSpan = UserAgents.Chrome_OSX.AsSpan();
            var actual        = PlatformDetector.GetPlatformAndOS(userAgentSpan);

            Assert.Equal(Platforms.Macintosh, actual.Platform);
            Assert.Equal(OperatingSystems.MacOSX, actual.OS);
        }
Beispiel #8
0
        public void iPad()
        {
            var userAgentSpan = UserAgents.Chrome_IPad.AsSpan();
            var actual        = PlatformDetector.GetPlatformAndOS(userAgentSpan);

            Assert.Equal(Platforms.iPad, actual.Platform);
            Assert.Equal(OperatingSystems.IOS, actual.OS);
        }
Beispiel #9
0
        public void Linux_Pixel3()
        {
            var userAgentSpan = UserAgents.Chrome_Pixel3.AsSpan();
            var actual        = PlatformDetector.GetPlatformAndOS(userAgentSpan);

            //Assert.Equal(Platforms.Pixel3, actual.Platform);
            Assert.Equal(OperatingSystems.Android, actual.OS);
        }
 public string GetConfigEditorPath()
 {
     if (PlatformDetector.IsWindows() && StringExt.IsNullOrWhiteSpace(_userData.ConfigEditorPath) == false && Path.Combine(Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.System)), "NOTEPAD.EXE").ToUpperInvariant() == _userData.ConfigEditorPath.ToUpperInvariant())
     {
         return(Path.GetFileName(_userData.ConfigEditorPath).ToLowerInvariant());
     }
     return(_userData.ConfigEditorPath);
 }
Beispiel #11
0
 public static void FreeUsbResources()
 {
     // Free usb resources
     if (PlatformDetector.RunningPlatform() == PlatformDetector.Platform.Linux)
     {
         UsbDevice.Exit();
     }
 }
Beispiel #12
0
        public void Windows10_Win64()
        {
            var userAgentSpan = UserAgents.Chrome_Windows.AsSpan();
            var actual        = PlatformDetector.GetPlatformAndOS(userAgentSpan);

            Assert.Equal(Platforms.Windows10, actual.Platform);
            Assert.Equal(OperatingSystems.Windows, actual.OS);
        }
Beispiel #13
0
        static HidSelector()
        {
            if (Instance != null)
            {
                return;
            }

            switch (PlatformDetector.RunningPlatform())
            {
            case PlatformDetector.Platform.Linux:
                Instance = new Libusb.LibusbHidManager();
                break;

            case PlatformDetector.Platform.Mac:
                Instance = new MacOS.MacHidManager();
                break;

            case PlatformDetector.Platform.Windows:
                Instance = new Windows.WinHidManager();
                break;
            }

            var readyEvent = new ManualResetEvent(false);

            ManagerThread = new Thread(Instance.RunImpl);
            ManagerThread.IsBackground = true;
            ManagerThread.Start(readyEvent);
            readyEvent.WaitOne();

            /*
             * foreach (var hidManager in new HidManager[]
             * {
             * new Windows.WinHidManager(),
             * //new Linux.LinuxHidManager(), //Disabled, because BlinkStick does not use this
             * new MacOS.MacHidManager(),
             * new Libusb.LibusbHidManager(),
             * new Unsupported.UnsupportedHidManager()
             * })
             * {
             * if (hidManager.IsSupported)
             * {
             * var readyEvent = new ManualResetEvent(false);
             *
             * Instance = hidManager;
             * ManagerThread = new Thread(Instance.RunImpl);
             * ManagerThread.IsBackground = true;
             * ManagerThread.Start(readyEvent);
             * readyEvent.WaitOne();
             *
             * break;
             * }
             * }
             */
        }
Beispiel #14
0
        protected Browser(ReadOnlySpan <char> userAgent, string version)
        {
            var platform = PlatformDetector.GetPlatformAndOS(userAgent);

            this.platform = platform.Platform;
            this.OS       = platform.OS;

            this.DeviceType = GetDeviceType(platform);

            this.Version = version;
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Boondocks bootstrap starting...");

            try
            {
                var platformDetector = new PlatformDetector();

                IPathFactory pathFactory = platformDetector.CreatePathFactory();

                var deviceConfigurationProvider = new DeviceConfigurationProvider(pathFactory);

                if (deviceConfigurationProvider.Exists())
                {
                    //Get the device configuration
                    var deviceConfiguration = deviceConfigurationProvider.GetDeviceConfiguration();

                    //Create the container
                    using (var container = ContainerFactory.Create(pathFactory, deviceConfiguration, new BootstrapModule()))
                    {
                        //Get the agent host
                        var host = container.Resolve <BootstrapHost>();

                        var cancellationTokenSource = new CancellationTokenSource();

                        //We shall cancel on the keypress
                        Console.CancelKeyPress += (sender, eventArgs) => cancellationTokenSource.Cancel();

                        try
                        {
                            //Run the host
                            host.RunAsync(cancellationTokenSource.Token).GetAwaiter().GetResult();
                        }
                        catch (TaskCanceledException)
                        {
                        }
                    }
                }
                else
                {
                    //There is no sense is attempting to run without a configuration.
                    SleepForever("Unable to find device configuration.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An exception occurred: {ex.Message}");
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine("Bootstrap exiting.");
            }
        }
 public MainLoopTimer()
 {
     if (PlatformDetector.DetectPlatform() == Platform.Windows)
     {
         mainLoopTimer = new TimerQueue();
     }
     else
     {
         mainLoopTimer = new TimerMainLoopTimer();
     }
 }
    void OnTriggerEnter(Collider other)
    {
        //Try to find a PlatformDetector on the touching object:
        PlatformDetector detector = other.GetComponent <PlatformDetector>();

        //If there is a detector,
        if (detector != null)
        {
            //Set this Transform as its 'platform' variable:
            detector.platform = transform;
        }
    }
    void OnTriggerExit(Collider other)
    {
        //Try to find a PlatformDetector on the touching object:
        PlatformDetector detector = other.GetComponent <PlatformDetector>();

        //If there is a detector,
        if (detector != null)
        {
            //Null out its 'platform' variable:
            detector.platform = null;
        }
    }
Beispiel #19
0
        /// <summary>
        /// Initializes file logging by creating data structures that
        /// enable efficient multi-file logging.
        /// </summary>
        protected override void InitializeTarget()
        {
            base.InitializeTarget();

            if (!this.KeepFileOpen)
            {
                this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
            }
            else
            {
                if (this.ArchiveAboveSize != -1 || this.ArchiveEvery != FileArchivePeriod.None)
                {
                    if (this.NetworkWrites)
                    {
                        this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
                    }
                    else if (this.ConcurrentWrites)
                    {
#if NET_CF || SILVERLIGHT
                        this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
#elif MONO
                        //
                        // mono on Windows uses mutexes, on Unix - special appender
                        //
                        if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix))
                        {
                            this.appenderFactory = UnixMultiProcessFileAppender.TheFactory;
                        }
                        else
                        {
                            this.appenderFactory = MutexMultiProcessFileAppender.TheFactory;
                        }
#else
                        this.appenderFactory = MutexMultiProcessFileAppender.TheFactory;
#endif
                    }
                    else
                    {
                        this.appenderFactory = CountingSingleProcessFileAppender.TheFactory;
                    }
                }
                else
                {
                    if (this.NetworkWrites)
                    {
                        this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
                    }
                    else if (this.ConcurrentWrites)
                    {
#if NET_CF || SILVERLIGHT
                        this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
#elif MONO
                        //
                        // mono on Windows uses mutexes, on Unix - special appender
                        //
                        if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix))
                        {
                            this.appenderFactory = UnixMultiProcessFileAppender.TheFactory;
                        }
                        else
                        {
                            this.appenderFactory = MutexMultiProcessFileAppender.TheFactory;
                        }
#else
                        this.appenderFactory = MutexMultiProcessFileAppender.TheFactory;
#endif
                    }
                    else
                    {
                        this.appenderFactory = SingleProcessFileAppender.TheFactory;
                    }
                }
            }

            this.recentAppenders = new BaseFileAppender[this.OpenFileCacheSize];

            if ((this.OpenFileCacheSize > 0 || this.EnableFileDelete) && this.OpenFileCacheTimeout > 0)
            {
                this.autoClosingTimer = new Timer(
                    this.AutoClosingTimerCallback,
                    null,
                    this.OpenFileCacheTimeout * 1000,
                    this.OpenFileCacheTimeout * 1000);
            }

            // Console.Error.WriteLine("Name: {0} Factory: {1}", this.Name, this.appenderFactory.GetType().FullName);
        }
Beispiel #20
0
        /// <summary>
        /// Initializes file logging by creating data structures that
        /// enable efficient multi-file logging.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            if (!KeepFileOpen)
            {
                _appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
            }
            else
            {
                if (_archiveAboveSize != -1 || _archiveEvery != ArchiveEveryMode.None)
                {
                    if (NetworkWrites)
                    {
                        _appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
                    }
                    else if (ConcurrentWrites)
                    {
#if NETCF
                        _appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
#elif MONO
                        //
                        // mono on Windows uses mutexes, on Unix - special appender
                        //
                        if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix))
                        {
                            _appenderFactory = UnixMultiProcessFileAppender.TheFactory;
                        }
                        else
                        {
                            _appenderFactory = MutexMultiProcessFileAppender.TheFactory;
                        }
#else
                        _appenderFactory = MutexMultiProcessFileAppender.TheFactory;
#endif
                    }
                    else
                    {
                        _appenderFactory = CountingSingleProcessFileAppender.TheFactory;
                    }
                }
                else
                {
                    if (NetworkWrites)
                    {
                        _appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
                    }
                    else if (ConcurrentWrites)
                    {
#if NETCF
                        _appenderFactory = RetryingMultiProcessFileAppender.TheFactory;
#elif MONO
                        //
                        // mono on Windows uses mutexes, on Unix - special appender
                        //
                        if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix))
                        {
                            _appenderFactory = UnixMultiProcessFileAppender.TheFactory;
                        }
                        else
                        {
                            _appenderFactory = MutexMultiProcessFileAppender.TheFactory;
                        }
#else
                        _appenderFactory = MutexMultiProcessFileAppender.TheFactory;
#endif
                    }
                    else
                    {
                        _appenderFactory = SingleProcessFileAppender.TheFactory;
                    }
                }
            }

            _recentAppenders = new BaseFileAppender[OpenFileCacheSize];

            if ((OpenFileCacheSize > 0 || EnableFileDelete) && OpenFileCacheTimeout > 0)
            {
                _autoClosingTimer = new Timer(new TimerCallback(this.AutoClosingTimerCallback), null, OpenFileCacheTimeout * 1000, OpenFileCacheTimeout * 1000);
            }

            // Console.Error.WriteLine("Name: {0} Factory: {1}", this.Name, _appenderFactory.GetType().FullName);
        }