コード例 #1
0
        /// <summary>
        ///     运行需要守护的进程
        /// </summary>
        public virtual void Run()
        {
            var config = GetConfig();

            if (CheckConfig(config))
            {
                WindowsCore.CreateProcess(config.InstallPath);
            }
        }
コード例 #2
0
ファイル: NeoVM.cs プロジェクト: osmirnov/neo-hypervm
        /// <summary>
        /// Try Load library
        /// </summary>
        /// <param name="libraryName">Library name (Default=NeoVM)</param>
        /// <param name="error">Error</param>
        /// <returns>Return true if is loaded</returns>
        public static bool TryLoadLibrary(string libraryName, out string error)
        {
            if (IsLoaded)
            {
                error = "Already loaded";
                return(false);
            }

            if (string.IsNullOrEmpty(libraryName))
            {
                libraryName = DefaultLibraryName;
            }

            // Detect OS

            CrossPlatformLibrary core;

            switch (Environment.OSVersion.Platform)
            {
            default: core = null; break;

            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
            {
                core = new WindowsCore();
                break;
            }

            case PlatformID.Unix:
            case (PlatformID)128:
            case PlatformID.MacOSX:
            {
                // OSX detection workaround
                if (File.Exists(@"/System/Library/CoreServices/SystemVersion.plist"))
                {
                    core = new MacCore();
                    break;
                }
                core = new LinuxCore();
                break;
            }
            }

            // Check core
            if (core == null)
            {
                error = "Native library not found";
                return(false);
            }

            // Load library
            LibraryPath = Path.Combine(AppContext.BaseDirectory, "native",
                                       core.Architecture.ToString(), libraryName + core.LibraryExtension);

            // Check Environment path
            if (!File.Exists(LibraryPath))
            {
                var nfile = Environment.GetEnvironmentVariable("NEO_VM_PATH");

                if (string.IsNullOrEmpty(nfile))
                {
                    error = "File not found: " + LibraryPath;
                    return(false);
                }

                LibraryPath = nfile;
                if (!File.Exists(LibraryPath))
                {
                    error = "File not found: " + LibraryPath;
                    return(false);
                }
            }

            if (!core.LoadLibrary(LibraryPath))
            {
                error = "Wrong library file: " + LibraryPath;
                return(false);
            }

            // Free library

            AppDomain.CurrentDomain.ProcessExit += (o, e) => core?.Dispose();

            // Cache delegates using reflection

            var delegateType = typeof(MulticastDelegate);

            foreach (var fi in typeof(NeoVM)
                     .GetFields(BindingFlags.NonPublic | BindingFlags.Static)
                     .Where(fi => fi.FieldType.BaseType == delegateType))
            {
                var del = core.GetDelegate(fi.Name, fi.FieldType);

                if (del == null)
                {
                    error = "Method not found: " + fi.Name;
                    return(false);
                }

                fi.SetValue(null, del);
            }

            // Get version

            GetVersion(out int major, out int minor, out int build, out int revision);
            LibraryVersion = new Version(major, minor, build, revision);
            IsLoaded       = true;

            error = null;
            return(true);
        }
コード例 #3
0
 public static WindowsSession Get(string windowsUserName)
 {
     Checker.Begin().NotNull(windowsUserName, nameof(windowsUserName));
     return(WindowsCore.GetSessions()?.FirstOrDefault(c => c.UserName.Equals(windowsUserName, StringComparison.OrdinalIgnoreCase)) ?? null);
 }
コード例 #4
0
 public static WindowsSession Get(int sessionId)
 {
     Checker.Begin().CheckGreaterThan <int>(sessionId, nameof(sessionId), 1, true);
     return(WindowsCore.GetSessions()?.FirstOrDefault(c => c.SessionId == sessionId) ?? null);
 }