Beispiel #1
0
        public bool TryConnect()
        {
            MFilesServerApp = new MFilesServerApplication();

            string domain = "null";

            if (MFilesSettings.AuthType == MFAuthType.MFAuthTypeSpecificWindowsUser)
            {
                domain = MFilesSettings.Domain;
            }

            MFServerConnection serverConnection = MFilesServerApp.Connect(
                MFilesSettings.AuthType
                , MFilesSettings.Username
                , MFilesSettings.Password
                , domain
                , null
                , MFilesSettings.Server
                , null
                , ""
                , true);

            if (MFServerConnection.MFServerConnectionAnonymous.Equals(serverConnection))
            {
                Console.WriteLine($"[ERROR] There was a problem connecting to {MFilesSettings.Server}...");
                Console.WriteLine("[ERROR] Incorrect username or password...");
                Console.WriteLine("[ERROR] Please try again...\n");
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            // Using the Server mode to connect to the M-Files Server.
            app = new MFilesServerApplication();

            string host = hostTextBox.Text;

            // Using the default values for connecting to server (HTTP, 2266, current Windows user, etc.),
            // for details and options see:
            // https://www.m-files.com/api/documentation/latest/index.html#MFilesAPI~MFilesServerApplication.html
            conn = app.Connect(NetworkAddress: host);

            //// Populate the combo box so that the user can choose which vault to use.
            //VaultsOnServer vaults = app.GetOnlineVaults();
            //foreach (VaultOnServer v in vaults)
            //{
            //    vaultComboBox.Items.Add(new VaultComboBoxItem(v.Name, v.GUID));
            //}
            //vaultComboBox.Enabled = true;

            //// Must re-start the tool if need to connect to another server.
            //hostTextBox.Enabled = false;
            //connectButton.Enabled = false;
            //EnableTopButtons(true);
            populateVaults();
        }
Beispiel #3
0
        public bool ConnectToServer(string userName, string password, VaultServer server, bool windowsUser)
        {
            var app = new MFilesServerApplication();

            try
            {
                var authType = MFAuthType.MFAuthTypeSpecificMFilesUser;
                if (windowsUser)
                {
                    authType = MFAuthType.MFAuthTypeSpecificWindowsUser;
                }
                var status = app.Connect(authType, userName, password, "", "ncacn_ip_tcp",
                                         server.LocalIp, server.ServerPort);
                var ok = status == MFServerConnection.MFServerConnectionAuthenticated;
                try
                {
                    app.Disconnect();
                }
                catch
                {
                }
                return(ok);
            }
            catch (Exception ex)
            {
                Log.Error("登录服务器失败:" + ex.Message, ex);
            }
            return(false);
        }
        private void ConnectAndReinstall(string applicationGuid, FileInfo applicationPackageFile)
        {
            MFilesServerApplication server = new MFilesServerApplication();

            Console.WriteLine($"[INFO] Connecting to <{MFilesSettings.Server}>...");
            server.Connect(MFilesSettings.AuthType, MFilesSettings.Username, MFilesSettings.Password, MFilesSettings.Domain, null, MFilesSettings.Server, null, "", true);
            Console.WriteLine($"[INFO] Successully connected to <{MFilesSettings.Server}>...");
            Vaults = server.GetOnlineVaults();
            VaultOnServer VaultOnServer    = null;
            bool          isUsingVaultGuid = !string.IsNullOrWhiteSpace(MFilesSettings.VaultGUID);
            string        vaultGuidName    = isUsingVaultGuid ? MFilesSettings.VaultGUID : MFilesSettings.VaultName;

            if (isUsingVaultGuid)
            {
                VaultOnServer            = Vaults.GetVaultByGUID(vaultGuidName);
                MFilesSettings.VaultName = VaultOnServer.Name;
            }
            else
            {
                VaultOnServer = Vaults.GetVaultByName(vaultGuidName);
            }
            Console.WriteLine($"[INFO] Connecting to <{VaultOnServer.Name}>...");
            RetryingVaultConnection vaultConnection = new RetryingVaultConnection(VaultOnServer, vos => vos.LogIn());

            ReinstallApplication(applicationPackageFile, server, VaultOnServer, vaultConnection, applicationGuid);
        }
 private static void UninstallVAE(MFilesServerApplication server, VaultOnServer vaultOnServer, RetryingVaultConnection vaultConnection, string applicationGuid)
 {
     if (!vaultConnection.DoWithReconnect(vault => TryUninstallCustomApplication(vault, applicationGuid)))
     {
         return;
     }
     Console.WriteLine("[INFO] Completed uninstallation...");
 }
Beispiel #6
0
        /// <summary>
        /// <see cref="MFilesServerApplication"/>.Connect() extension method that accepts a class type that is decorated with a <see cref="MFServerAttribute"/>.
        /// </summary>
        /// <param name="sa"><see cref="MFilesServerApplication"/> instance</param>
        /// <param name="decoratedType"><see cref="Type"/> of the class with the connection info decorations</param>
        /// <returns><see cref="MFServerAttribute"/></returns>
        public static MFServerAttribute Connect(this MFilesServerApplication sa, Type decoratedType)
        {
            MFServerAttribute serverInfo = (MFServerAttribute)Attribute.GetCustomAttribute(decoratedType, typeof(MFServerAttribute));

            sa.Connect(serverInfo);

            return(serverInfo);
        }
        public void GenerateVault()
        {
            MFilesServerApplication mfserver = new MFilesServerApplication();

            mfserver.Connect(NetworkAddress: "mfbuilderdl01");
            Vault vault = mfserver.LogInToVault("{1C6A118E-DD8E-411C-8E6F-DAF8805FC781}");

            StructureGenerator.VaultToJsonFile(vault, "VaultStructure.json");
        }
 private static VaultOnServer GetVaultOnServer(MFilesServerApplication server, string vaultName = null)
 {
     try {
         return(server.GetOnlineVaults().GetVaultByName(vaultName));
     } catch (Exception ex) {
         Console.WriteLine("[ERROR] Problem connecting to the vault: " + vaultName + "\n" + ex.Message);
     }
     return(null);
 }
Beispiel #9
0
        public static IList <LoginAccount> GetLoginAccounts(MFilesServerApplication app)
        {
            var accs = app.LoginAccountOperations.GetLoginAccounts();

            return((from LoginAccount a in accs
                    where a.Enabled && a.LicenseType != MFLicenseType.MFLicenseTypeNone &&
                    a.ServerRoles != MFLoginServerRole.MFLoginServerRoleSystemAdministrator
                    select a).ToList());
        }
Beispiel #10
0
        /// <summary>
        /// vault登录服务端
        /// </summary>
        /// <param name="user"></param>
        /// <param name="vaultGuid"></param>
        /// <returns></returns>
        private Vault Connect2VaultOnServer(UserDto user, string vaultGuid)
        {
            var serverApp = new MFilesServerApplication();

            serverApp.Connect(user.MfType, user.UserName, user.PassWord, user.Domain, "ncacn_ip_tcp", user.ip);
            Vault gVault = serverApp.LogInToVault(vaultGuid);

            //conn
            return(gVault);
        }
Beispiel #11
0
        public void Init()
        {
            ServerApp = new MFilesServerApplication();

            Vault v;
            MFVaultConnectionAttribute vaultConnInfo = ServerApp.Connect(GetType(), out v);

            this.V        = v;
            this.Tools    = new AliasTools(this.V);
            this.Settings = new AliasTools.Settings();
        }
Beispiel #12
0
 internal static bool HasVault(MFilesServerApplication app, MFilesVault vault)
 {
     foreach (VaultOnServer vos in app.GetVaults())
     {
         if (vos.GUID == vault.Guid || vos.Name == vault.Name)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #13
0
 /// <summary>
 /// 获取MF服务器的登录账户
 /// </summary>
 /// <param name="app"></param>
 /// <param name="accountName">用户名(若为Windows账户,需要包含域名)</param>
 /// <returns></returns>
 public static LoginAccount GetLoginAccount(MFilesServerApplication app, string accountName)
 {
     try
     {
         var la = app.LoginAccountOperations.GetLoginAccount(accountName);
         return(la);
     }
     catch
     {
         return(null);
     }
 }
Beispiel #14
0
 public void Connect()
 {
     Server = new MFilesServerApplication();
     Server.Connect(AuthType: (MFAuthType)this.AuthType,
                    UserName: this.UserName,
                    Password: this.Password,
                    Domain: this.Domain,
                    ProtocolSequence: this.ProtocolSequence.ToString(),
                    NetworkAddress: this.ServerName,
                    Endpoint: this.EndPoint,
                    LocalComputerName: Environment.MachineName);
 }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="port"></param>
        /// <param name="authType"></param>
        /// <returns>[GUID, NAME]</returns>
        public static Dictionary <string, string> GetVaults(string host, string username, string password, string port = "2266",
                                                            MFAuthType authType = MFAuthType.MFAuthTypeSpecificWindowsUser)
        {
            var serverApp  = new MFilesServerApplication();
            var connectRes = serverApp.Connect(authType, username, password, "", "ncacn_ip_tcp", host, port);

            if (connectRes == MFServerConnection.MFServerConnectionAnonymous)
            {
                return(null);
            }
            return(serverApp.GetOnlineVaults().Cast <VaultOnServer>().ToDictionary(c => c.GUID, c => c.Name));
        }
Beispiel #16
0
        public Form1()
        {
            InitializeComponent();
            app = new MFilesServerApplication();
            var conn   = app.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, "admin", "111111");
            var vaults = app.GetOnlineVaults();

            foreach (VaultOnServer vaultOnServer in vaults)
            {
                comboBox1.Items.Add(vaultOnServer.GUID + vaultOnServer.Name);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Connects to a vault on the server.
        /// </summary>
        /// <param name="vaultGuid">The Guid of the vault to connect to.</param>
        /// <param name="vault">The connected vault, or null if connection failed.</param>
        /// <param name="serverApplication">The server application</param>
        /// <remarks>Exceptions during connection will be thrown.</remarks>
        public void ConnectToVault(Guid vaultGuid, out Vault vault, out MFilesServerApplication serverApplication)
        {
            vault             = null;
            serverApplication = new MFilesServerApplication();

            // Attempt to connect to the vault using the extension method.
            if (serverApplication.Connect(this) == MFServerConnection.MFServerConnectionAuthenticated)
            {
                // Attempt to log into the vault.
                vault = serverApplication.LogInToVault(vaultGuid.ToString("B"));
            }
        }
Beispiel #18
0
        public static MFilesServerApplication ConnectToServer(string userName, string password, string ip, string port, bool isAdUser)
        {
            var mfAuthType = MFAuthType.MFAuthTypeSpecificMFilesUser;

            if (isAdUser)
            {
                mfAuthType = MFAuthType.MFAuthTypeSpecificWindowsUser;
            }
            var app = new MFilesServerApplication();

            app.Connect(mfAuthType, userName, password, "", "ncacn_ip_tcp", ip, port);
            return(app);
        }
Beispiel #19
0
        /// <summary>
        /// Retrieves the vaults from the server.
        /// </summary>
        /// <remarks>Exceptions during connection will be thrown.</remarks>
        public IEnumerable <VaultOnServer> GetOnlineVaults()
        {
            // Attempt to connect to the vault using the extension method.
            var serverApplication = new MFilesServerApplication();

            if (serverApplication.Connect(this) == MFServerConnection.MFServerConnectionAuthenticated)
            {
                foreach (var vault in serverApplication.GetOnlineVaults().Cast <VaultOnServer>())
                {
                    yield return(vault);
                }
            }
        }
        private static bool TryConnect()
        {
            MFilesServer = new MFilesServerApplication();
            MFServerConnection serverConnection =
                MFilesServer.Connect(SERVER_CONN.AuthType, SERVER_CONN.Username, SERVER_CONN.Password, SERVER_CONN.Domain, null, SERVER_CONN.Name, null, "", true);

            if (MFServerConnection.MFServerConnectionAnonymous.Equals(serverConnection))
            {
                Console.WriteLine($"[ERROR] There was a problem connecting to {SERVER_CONN.Name}.");
                Console.WriteLine("[ERROR] Incorrect username or password.\n");
                return(false);
            }
            return(true);
        }
Beispiel #21
0
        internal void CreateMFilesLoginAccount(User user, MFilesServerApplication app,
                                               MFLoginAccountType accountType, MFLicenseType licenseType)
        {
            var account  = new LoginAccount();
            var fullName = user.FullName;

            if (String.IsNullOrEmpty(fullName))
            {
                fullName = user.UserName;
            }
            account.Set(accountType, user.Domain.ToUpper(), user.UserName,
                        MFLoginServerRole.MFLoginServerRoleLogIn, fullName, user.Email, licenseType);
            app.LoginAccountOperations.AddLoginAccount(account);
        }
Beispiel #22
0
        private void Start()
        {
            var traceFile = GetTraceFile();

            Trace.AutoFlush = true;
            Trace.Listeners.Clear();
            Trace.Listeners.Add(new TextWriterTraceListener(traceFile));
            var basePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            Trace.TraceInformation("开始执行---" + basePath);
            var i = 0L;

            try
            {
                app = new MFilesServerApplication();
                app.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, "admin", "cadsimula@123A");
            }
            catch (Exception ex)
            {
                Trace.TraceError("MFilesServerApplication Connect error:", ex);
                return;
            }
            while (true)
            {
                //设置Log
                var traceFileTemp = GetTraceFile();
                if (traceFile != traceFileTemp)
                {
                    traceFile = traceFileTemp;
                    Trace.Listeners.Clear();
                    Trace.Listeners.Add(new TextWriterTraceListener(traceFile));
                }

                try
                {
                    i++;
                    Trace.TraceInformation("第{0}次执行,{1}", i, DateTime.Now);
                    OneSynchronization();
                }
                catch (Exception ex)
                {
                    Trace.TraceInformation("未知错误" + ex.Message);
                }
                finally
                {
                    Thread.Sleep(1000 * 60 * 60 * 24);
                }
            }
        }
Beispiel #23
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                GlobalVar.OVault = null;
                var oServerApp = new MFilesServerApplication();
                if (radioButton2.Checked == true)
                {
                    GlobalVar.Domain     = textBox4.Text;
                    GlobalVar.MfAuthType = "MFAuthTypeLoggedOnWindowsUser";
                }
                else if (radioButton1.Checked == true)
                {
                    GlobalVar.MfAuthType = "MFAuthTypeSpecificMFilesUser";
                }
                GlobalVar.UserName      = textBox2.Text;
                GlobalVar.Password      = textBox3.Text;
                GlobalVar.NetworkAdress = textBox1.Text;

                var mfsc = oServerApp.Connect(GlobalVar.GetMfAuthType(), GlobalVar.UserName, GlobalVar.Password, GlobalVar.Domain,
                                              GlobalVar.ProtocolSequence,
                                              GlobalVar.NetworkAdress);


                GlobalVar.gVaultsOnServer = oServerApp.GetVaults();
                comboBox1.Items.Clear();
                foreach (VaultOnServer vos in GlobalVar.gVaultsOnServer)
                {
                    comboBox1.Items.Add(vos.Name + vos.GUID);
                }
                richTextBoxlog.AppendText(Environment.NewLine + "成功连接" + GlobalVar.NetworkAdress + "MFiles服务器!");

                comboBox1.Focus();
            }
            catch (Exception ex)
            {
                richTextBoxlog.AppendText(Environment.NewLine + ex.Message);
                if (radioButton2.Checked == true)
                {
                    MessageBox.Show("域用户登陆方式连接MFiles服务器失败,用户名=" + GlobalVar.UserName + ",密码=" + GlobalVar.Password +
                                    ",ip地址或机器名=" + GlobalVar.NetworkAdress + ",域名=" + GlobalVar.Domain + ex.Message);
                }
                else
                {
                    MessageBox.Show("MFiles用户登陆方式连接MFiles服务器失败,用户名=" + GlobalVar.UserName + ",密码=" + GlobalVar.Password +
                                    ",ip地址或机器名=" + GlobalVar.NetworkAdress + ex.Message);
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// <see cref="MFilesServerApplication"/>.Connect() extension method that accepts a class type that is decorated with a <see cref="MFVaultConnectionAttribute"/>.
        /// </summary>
        /// <param name="sa"><see cref="MFilesServerApplication"/> instance</param>
        /// <param name="decoratedType"><see cref="Type"/> of the class with the connection info decorations</param>
        /// <param name="vault">Out <see cref="Vault"/></param>
        /// <returns><see cref="MFVaultConnectionAttribute"/></returns>
        public static MFVaultConnectionAttribute Connect(this MFilesServerApplication sa, Type decoratedType, out Vault vault)
        {
            // Extract the MFVaultConnectionAttribute info attribute.
            MFVaultConnectionAttribute vaultConn = (MFVaultConnectionAttribute)Attribute.GetCustomAttribute(decoratedType, typeof(MFVaultConnectionAttribute));

            // Connect to the server.
            sa.Connect(vaultConn);

            // Login to the vault using the GUID provided.
            // Set the out vault value.
            vault = sa.LogInToVault(vaultConn.VaultGuid);

            // Return the Vault Connection info.
            return(vaultConn);
        }
Beispiel #25
0
 /// <summary>
 /// Tries to connect to a vault on the server.
 /// </summary>
 /// <param name="vaultGuid">The Guid of the vault to connect to.</param>
 /// <param name="vault">The connected vault, or null if connection failed.</param>
 /// <param name="serverApplication">The server application, or null if connection failed.</param>
 /// <returns>true if the connection happened without exceptions, false otherwise.</returns>
 public bool TryConnectToVault(Guid vaultGuid, out Vault vault, out MFilesServerApplication serverApplication)
 {
     try
     {
         this.ConnectToVault(vaultGuid, out vault, out serverApplication);
         return(true);
     }
     catch
     {
         // HACK: Exception handling.
         vault             = null;
         serverApplication = null;
         return(false);
     }
 }
        protected override MFilesServerApplication GetServerApp(string username, string password, string domain, string protocolSequence,
                                                                string networkAddress, string endpoint, bool encryptedConnection, string localComputerName, MFAuthType authType)
        {
            var serverApp = new MFilesServerApplication();

            serverApp.ConnectEx(AuthType: authType,
                                UserName: username,
                                Password: password,
                                Domain: domain,
                                ProtocolSequence: protocolSequence,
                                NetworkAddress: networkAddress,
                                Endpoint: endpoint,
                                EncryptedConnection: encryptedConnection,
                                LocalComputerName: localComputerName);
            return(serverApp);
        }
 private static void ReinstallApplication(FileInfo appFile, MFilesServerApplication server, VaultOnServer vaultOnServer, RetryingVaultConnection vaultConnection, string applicationGuid)
 {
     Console.WriteLine("[INFO] Checking for previous installation of the application...");
     if (vaultConnection.DoWithReconnect(vault => IsApplicationInstalled(vault, applicationGuid)))
     {
         Console.WriteLine("[INFO] Found previous installation of the application...");
         Console.WriteLine("[INFO] Uninstalling the previous installation of the application...");
         UninstallVAE(server, vaultOnServer, vaultConnection, applicationGuid);
     }
     Console.WriteLine("[INFO] Installing the application...");
     vaultConnection.DoWithReconnect(vault => vault.CustomApplicationManagementOperations.InstallCustomApplication(appFile.FullName));
     Console.WriteLine("[INFO] Completed installation of the application...");
     Console.WriteLine($"[INFO] Restarting the vault <{vaultOnServer.Name}>...");
     server.VaultManagementOperations.TakeVaultOffline(vaultOnServer.GUID, true);
     server.VaultManagementOperations.BringVaultOnline(vaultOnServer.GUID);
     Console.WriteLine($"[INFO] Completed restarting the vault <{vaultOnServer.Name}>...");
 }
Beispiel #28
0
        /// <summary>
        /// <see cref="MFilesServerApplication"/>.Connect() extension method that accepts a class type that is decorated with the MFVaultConnectionAttribute attribute.
        /// </summary>
        /// <param name="sa"><see cref="MFilesServerApplication"/> instance</param>
        /// <param name="serverInfo"><see cref="MFServerAttribute"/> server connection info.</param>
        public static void Connect(this MFilesServerApplication sa, MFServerAttribute serverInfo)
        {
            // Test the connection to the server.
            int ms = sa.TestConnectionToServer(serverInfo.NetworkAddress, serverInfo.Endpoint, serverInfo.ProtocolSequence);

            sa.Connect(
                serverInfo.AuthType,
                serverInfo.UserName,
                serverInfo.Password,
                serverInfo.Domain,
                serverInfo.ProtocolSequence,
                serverInfo.NetworkAddress,
                serverInfo.Endpoint,
                serverInfo.LocalComputerName,
                serverInfo.AllowAnonymousConnection
                );
        }
        private List <MFilesSettings> GetAdminServerNames(MFilesServerApplication serverApp)
        {
            List <MFilesSettings> serverNamesList = new List <MFilesSettings>();
            string      name         = string.Format("Software\\Motive\\M-Files\\{0}\\ServerTools\\MFAdmin\\Servers", (object)serverApp.GetAPIVersion().Display);
            RegistryKey registryKey1 = Registry.CurrentUser.OpenSubKey(name, false);

            foreach (string subKeyName in registryKey1.GetSubKeyNames())
            {
                RegistryKey registryKey2 = registryKey1.OpenSubKey(subKeyName);
                serverNamesList.Add(new MFilesSettings()
                {
                    Alias  = subKeyName,
                    Server = (string)registryKey2.GetValue("NetworkAddress")
                });
            }

            return(serverNamesList);
        }
Beispiel #30
0
        /// <summary>
        /// 获取MFiles服务端连接
        /// </summary>
        /// <param name="adminName">管理员账户</param>
        /// <param name="adminPwd">管理员密码</param>
        /// <param name="ip">服务器ip</param>
        /// <param name="port">服务端口</param>
        /// <returns></returns>
        public static MFilesServerApplication ConnectToServer(string adminName, string adminPwd, string ip, string port)
        {
            var app = new MFilesServerApplication();

            if (adminName.Contains('\\'))
            {
                var strs     = adminName.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                var domain   = strs[0];
                var userName = strs[1];
                app.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, userName, adminPwd, domain, "ncacn_ip_tcp", ip, port);
            }
            else
            {
                app.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, adminName, adminPwd, "", "ncacn_ip_tcp", ip, port);
            }

            return(app);
        }
Beispiel #31
0
        /// <summary>
        /// Installer Method - Install app to Vault.
        /// </summary>
        /// <param name="packedApp">mfappx Path</param>
        /// <param name="settings">Populated UXDevSettings Object</param>
        private static void InstallApp( string packedApp, UXDevSettings settings)
        {
            // Create a caption block for the installation.
            using( Logger.CaptionBlock( "Connecting to Vault" ) )
            {
                // Connect to Vault
                var serverApp = new MFilesServerApplication();

                // report the creation
                Logger.WriteLine("Server App Created => Connecting Administratively");

                // Connect Administrative => As the Take Vault on/off-line requires it.
                serverApp.ConnectAdministrative(
                    null,
                    settings.AuthType,
                    settings.Username,
                    settings.Password,
                    settings.Domain,
                    settings.ProtocolSequence,
                    settings.ServerAddress,
                    settings.Port,
                    settings.LocalComputerName
                    );

                // Report the successful connection.
                Logger.WriteLine(@"Connected to server.");

                // Log into the Vault
                Vault vault = serverApp.LogInToVault(settings.VaultGuid);

                // Report the successful Log On.
                Logger.WriteLine(@"Logged into Vault: " + vault.Name);

                // create a caption block to make the output more readable.
                using( Logger.CaptionBlock( "Installing Application" ) )
                {
                    // Try to install the application.
                    try
                    {
                        Logger.WriteLine(@"Attempting Application Installation");

                        // Install the Application to the Vault.
                        vault.CustomApplicationManagementOperations.InstallCustomApplication(packedApp);

                        // If no error was thrown, report the success.
                        Logger.WriteLine(@"Application Installed Successfully");
                    }
                    catch (Exception ex)
                    {
                        // A common error is the already exists.
                        Logger.WriteLine( ex.Message.StartsWith( @"Already exists" )
                            ? ex.Message.Substring( 0, ex.Message.IndexOf( '\n' ) )
                            : ex.Message );
                    }
                }

                // create a caption block to make the output more readable.
                using (Logger.CaptionBlock("Post Installation Processing"))
                {
                    // Determine if a Auto-Allow Installation Registry file should be created.
                    if (settings.GenerateAutoInstallReg)
                    {
                        Logger.WriteLine("Generating the Auto Installation Registry File");

                        // Get the Template Text and inject values
                        string reg = StringTemplate.AllowSilentInstall;
                        reg = reg.Replace("$VERSION", vault.GetServerVersionOfVault().Display);
                        reg = reg.Replace("$NAME", Path.GetFileNameWithoutExtension(settings.Outputname));
                        reg = reg.Replace("$VAULTGUID", vault.GetGUID());
                        reg = reg.Replace("$APPGUID", settings.AppDef.guid);

                        // create the registry file path.
                        string regPath = Path.Combine(settings.DirectoryToZip, @"allow_auto_install.reg");

                        // Delete and destroy the existing reg file... if there is one.
                        if (File.Exists(regPath))
                            File.Delete(regPath);

                        // Write the reg file to disk.
                        File.WriteAllText(regPath, reg);

                        Logger.WriteLine("Registry File Created: " + regPath);
                    }

                    // Should the vault be restarted after processing?
                    if (settings.RestartVault)
                    {
                        Logger.WriteLine("About to Restart the Vault");

                        Logger.WriteLine("\t- Logging out.");

                        // TODO - This does not seem to work, a manual logout is recommended.
                        vault.LogOutSilent();

                        // Try to take the vault on/off-line.
                        try
                        {
                            Logger.WriteLine("\t- Taking Vault Offline");
                            serverApp.VaultManagementOperations.TakeVaultOffline(settings.VaultGuid, true);

                            Logger.WriteLine("\t- Bringing Vault back Online");
                            serverApp.VaultManagementOperations.BringVaultOnline(settings.VaultGuid);
                            Logger.WriteLine("Vault Now Online");
                        }
                        catch (Exception ex)
                        {
                            // report the error
                            Logger.WriteLine(ex.Message);
                        }

                        // TODO - I need to find a better way to close open client windows, but until then...
                        if (settings.KillExplorerWindows)
                        {
                            Logger.WriteLine("Closing Open Explorer Windows.");
                            foreach (Process p in Process.GetProcessesByName("explorer"))
                                p.Kill();
                        }

                        Logger.WriteLine(@"Waiting a few seconds...");
                        Thread.Sleep(1000 * 2);
                    }

                    // Determine if we should open the Vault Window for the Developer.
                    if (Settings.OpenVault)
                    {
                        Logger.WriteLine(@"Opening Path: " + settings.LocalVaultPath);

                        // Open the path in the default application.
                        Process.Start(Settings.LocalVaultPath);
                    }
                }
            }

            // Should we leave the console window open or not?
            if (!settings.AutoExitApp)
            {
                Logger.NewLine();
                Logger.WriteLine(@"Press any key to exit...");
                Console.ReadKey();
            }
        }
Beispiel #32
0
 private void Connect()
 {
     _server = new MFilesServerApplication();
     _server.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser,
         _user, _pass,
         null, "ncacn_ip_tcp",
         _host, _port,
         "", false);
 }