Ejemplo n.º 1
0
        /// <summary>
        /// 设置客户端MFiles连接
        /// </summary>
        /// <param name="user"></param>
        /// <param name="vault"></param>
        public static Vault GetUserVault1(UserDto user, VaultDto vault)
        {
            if (VaultGuids.Contains(vault.Guid))
            {
                return(GetVault(user, vault.Guid));
            }
            var server = vault.Server;
            var conn   = new VaultConnection();
            var domain = user.Domain;

            conn.AuthType         = MFAuthType.MFAuthTypeSpecificWindowsUser;
            conn.AutoLogin        = false;
            conn.NetworkAddress   = server.Ip;     // "192.168.2.129";
            conn.Endpoint         = server.Port;   // "2266";
            conn.Name             = vault.Name;    //"我的云盘";
            conn.ServerVaultName  = vault.Name;    // "示例库";
            conn.ServerVaultGUID  = vault.Guid;    // "{08ED46E7-C0FF-4D16-BA38-5043144CCD15}";
            conn.UserName         = user.UserName; // "qiuge";
            conn.Password         = user.Password; // "sd2350139";
            conn.Domain           = domain;        // "simuladesign";
            conn.UserSpecific     = true;
            conn.ProtocolSequence = "ncacn_ip_tcp";
            var app           = new MFilesClientApplication();
            var conns         = app.GetVaultConnections();
            var connsSameName = new VaultConnections();

            foreach (VaultConnection co in conns)
            {
                var coGUID = co.ServerVaultGUID;
                if (coGUID == conn.ServerVaultGUID) // && co.Name == conn.Name
                {
                    connsSameName.Add(-1, co);
                }
            }
            if (connsSameName.Count > 0)
            {
                foreach (VaultConnection co in connsSameName)
                {
                    app.RemoveVaultConnection(co.Name, co.UserSpecific);
                }
            }
            app.AddVaultConnection(conn);
            Vault mfVault = null;

            try
            {
                //   Writelog(string.Format(" in getuservault1,userName={0}, pwd={1}, domai={2}", user.UserName, user.Password, domain));
                mfVault = LoginVault(conn, user.UserName, user.Password, domain);
            }
            catch
            {
            }
            VaultGuids.Add(vault.Guid);
            return(mfVault);
        }
Ejemplo n.º 2
0
        public static VaultConnection InitialVaultConnection(UserDto user, VaultDto vault)
        {
            var app   = new MFilesClientApplication();
            var conns = app.GetVaultConnectionsWithGUID(vault.Guid);
            //var count = conns.Count;
            var             removeConns = new List <VaultConnection>();
            VaultConnection connection  = null;

            foreach (VaultConnection vc in conns)
            {
                if (vc.NetworkAddress != vault.Server.Ip ||
                    vc.Name != vault.Name ||
                    vc.Endpoint != vault.Server.Port)
                {
                    removeConns.Add(vc);
                }
                else
                {
                    connection = vc;
                }
            }
            if (removeConns.Count > 0)
            {
                foreach (var vc in removeConns)
                {
                    app.RemoveVaultConnection(vc.Name, vc.UserSpecific);
                }
            }
            if (connection == null)
            {
                connection = new VaultConnection
                {
                    AuthType         = MFAuthType.MFAuthTypeSpecificWindowsUser,
                    AutoLogin        = false,
                    NetworkAddress   = vault.Server.Ip,
                    Endpoint         = vault.Server.Port,
                    Name             = vault.Name,
                    ServerVaultName  = vault.Name,
                    ServerVaultGUID  = vault.Guid,
                    UserName         = user.UserName,
                    Password         = user.Password,
                    Domain           = user.Domain,
                    UserSpecific     = true,
                    ProtocolSequence = "ncacn_ip_tcp"
                };
                app.AddVaultConnection(connection);
            }
            //var now = DateTime.Now;
            Vault mfVault = null;

            if (connection.IsLoggedIn())
            {
                var v = connection.BindToVault(IntPtr.Zero, true, true);
                if (v != null)
                {
                    var accountName = v.SessionInfo.AccountName;
                    var index       = accountName.IndexOf('\\');
                    var userName    = accountName.Substring(index + 1);
                    if (StringComparer.OrdinalIgnoreCase.Equals(userName, user.UserName))
                    {
                        mfVault = v;
                    }
                    else
                    {
                        v.LogOutWithDialogs(IntPtr.Zero);
                    }
                }
            }
            return(connection);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="vault"></param>
        /// <param name="forceLogout">是否强制退出</param>
        /// <param name="vaultName">库名称</param>
        /// <returns></returns>
        public static Vault GetUserVault(UserDto user, VaultDto vault, bool forceLogout, string vaultName)
        {
            log.Info(" GetUserVault username="******",vault=" + vault.Name);
            if (VaultGuids.Contains(vault.Guid))
            {
                return(GetVault(user, vault.Guid));
            }
            vaultName = vaultName ?? vault.Name;
            var app         = new MFilesClientApplication();
            var removeConns = new List <VaultConnection>();

            try
            {
                var sameVC = app.GetVaultConnection(vault.Name);
                var needR  = Need2Remove(vault, sameVC, vaultName);
                if (needR)
                {
                    removeConns.Add(sameVC);
                }
            }
            catch (Exception ex)
            {
                log.Info(string.Format("GetUserVault error:{0},{1}", vaultName, ex.Message));
            }
            var conns = app.GetVaultConnectionsWithGUID(vault.Guid);

            VaultConnection connection = null;

            foreach (VaultConnection vc in conns)
            {
                var needR = Need2Remove(vault, vc, vaultName);
                if (needR)
                {
                    removeConns.Add(vc);
                }
                else
                {
                    connection = vc;
                }
            }
            if (removeConns.Count > 0)
            {
                foreach (var vc in removeConns)
                {
                    app.RemoveVaultConnection(vc.Name, vc.UserSpecific);
                }
            }
            if (connection == null)
            {
                connection = new VaultConnection
                {
                    AuthType         = MFAuthType.MFAuthTypeSpecificWindowsUser,
                    AutoLogin        = false,
                    NetworkAddress   = vault.Server.Ip,
                    Endpoint         = vault.Server.Port,
                    Name             = vaultName,
                    ServerVaultName  = vault.Name,
                    ServerVaultGUID  = vault.Guid,
                    UserName         = user.UserName,
                    Password         = user.Password,
                    Domain           = user.Domain,
                    UserSpecific     = true,
                    ProtocolSequence = "ncacn_ip_tcp"
                };
                if (String.IsNullOrEmpty(user.Domain))
                {
                    connection.AuthType = MFAuthType.MFAuthTypeSpecificMFilesUser;
                }
                app.AddVaultConnection(connection);
            }
            //var now = DateTime.Now;
            Vault mfVault = null;

            if (connection.IsLoggedIn())
            {
                var v = connection.BindToVault(IntPtr.Zero, true, true);
                if (v != null)
                {
                    if (forceLogout)
                    {
                        try
                        {
                            v.LogOutWithDialogs(IntPtr.Zero);
                        }
                        catch
                        {
                            log.Info("Remote Loggin time11111: " + DateTime.Now);
                        }
                    }
                    else
                    {
                        var accountName = v.SessionInfo.AccountName;
                        var index       = accountName.IndexOf('\\');
                        var userName    = accountName.Substring(index + 1);
                        if (StringComparer.OrdinalIgnoreCase.Equals(userName, user.UserName))
                        {
                            mfVault = v;
                        }
                        else
                        {
                            try
                            {
                                v.LogOutWithDialogs(IntPtr.Zero);
                            }
                            catch
                            {
                                log.Info("Remote Loggin time 22222: " + DateTime.Now);
                            }
                        }
                    }
                }
            }
            log.Info("Remote Loggin time: " + DateTime.Now);

            try
            {
                //now = DateTime.Now;
                var has = false;
                log.Info(string.Format(" in getuservault,userName={0}, pwd={1}, domai={2}", user.UserName, user.Password, user.Domain));
                if (forceLogout)
                {
                    mfVault = LoginVault(connection, user.UserName, user.Password, user.Domain);
                    has     = true;
                }
                if (mfVault == null || !has)
                {
                    mfVault = LoginVault(connection, user.UserName, user.Password, user.Domain);
                }
                log.Info("Loggin time: " + DateTime.Now);
            }
            catch
            {
                log.Info("Remote Loggin time: 33333" + DateTime.Now);
            }
            VaultGuids.Add(vault.Guid);
            return(mfVault);
        }