/// <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); }
private static Vault LoginVault(VaultConnection vc, string userName, string pwd, string domain) { // Writelog(string.Format(" userName={0}, pwd={1}, domai={2}", userName, pwd, domain)); if (!String.IsNullOrEmpty(domain)) { return(vc.LogInAsUser(MFAuthType.MFAuthTypeSpecificWindowsUser, userName, pwd, domain)); } else { return(vc.LogInAsUser(MFAuthType.MFAuthTypeSpecificMFilesUser, userName, pwd, "")); } }
private static MfVaultConnection ConvertToData(VaultConnection conn) { var path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); path = Path.Combine(path, @"M-Files\Icons"); var iconPath = Path.Combine(path, conn.ServerVaultGUID + ".ico"); var mfConn = new MfVaultConnection { Name = conn.Name, Guid = conn.ServerVaultGUID }; if (File.Exists(iconPath)) { mfConn.IconPath = iconPath;//File.ReadAllBytes(iconPath); } return(mfConn); }
public DavisInvoice() { InitializeComponent(); //connect to mFiles var mFilesApp = new MFilesClientApplication(); //open vault var vaultConnect = new VaultConnection(); vaultConnect = mFilesApp.GetVaultConnectionsWithGUID("{" + Properties.Settings.Default.vaultGUID + "}").Cast <VaultConnection>().FirstOrDefault(); var currVault = new Vault(); currVault = vaultConnect.BindToVault(this.Handle, true, false); //export button1.Click += delegate(object sender, EventArgs e) { button1_Click(sender, e, currVault, mFilesApp); }; //import button2.Click += delegate(object sender, EventArgs e) { button2_Click(sender, e, currVault, mFilesApp); }; }
public void PromoteLabelVersion(string filePath, string label, long newVersion) { VaultClientFile file = root.FindFileRecursive(filePath); file.Version = newVersion; VaultLabelPromotionItem item = new VaultLabelPromotionItem(); item.ChangeType = VaultLabelPromotionChangeType.Modify; item.ItemName = file.Name; item.ItemPath = file.FullPath; item.Version = file.Version; item.ID = file.ID; long labelId = GetLabelId(root, label); item.Version = newVersion; SynchObVerId(item); long currentLabeledVersion = findVersionWithLabel(file, label); // Move if (currentLabeledVersion != -1) { item.ChangeType = VaultLabelPromotionChangeType.Modify; } else // Add { item.ChangeType = VaultLabelPromotionChangeType.Add; } VaultLabelPromotionItem [] items = new VaultLabelPromotionItem [] { item }; DateTime lastDate = VaultDate.EmptyDate(); int nIdxFailed = 0; string conflict = null; int promoteResult = Client.PromoteLabelItems(root.FullPath, labelId, label, ref lastDate, items, out nIdxFailed, out conflict); string resultString = VaultConnection.GetSoapExceptionMessage(promoteResult); }
private static bool Need2Remove(VaultDto vault, VaultConnection vc, string vaultName) { vaultName = vaultName ?? vault.Name; if (vc.Name == vaultName) { if (vc.NetworkAddress != vault.Server.Ip) { return(true); } if (vc.Endpoint != vault.Server.Port) { return(true); } if (vc.ServerVaultGUID != vault.Guid) { return(true); } } if (vc.ServerVaultGUID != vault.Guid) { return(false); } if (vc.Name != vaultName) { return(true); } if (vc.NetworkAddress != vault.Server.Ip) { return(true); } if (vc.Endpoint != vault.Server.Port) { return(true); } return(false); }
/// <summary> /// Checks the specified file or folder into the repository. /// </summary> /// <exception>Exception</exception> private void Checkin(string fileName) { string normalizedPath = RepositoryPath.NormalizeFolder(fileName); if (IsVaultFolder(normalizedPath)) { VaultClientFolder vaultClientFolder = ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFolder.FullPath, WorkingFolder); } ClientInstance.Refresh(); ChangeSetItemColl changeSet; BuildChangeSetOfCheckedOutFiles(vaultClientFolder, out changeSet); if (!ClientInstance.Commit(changeSet)) { string errMsg = VaultConnection.GetSoapExceptionMessage(changeSet[0].Request.Response.Status); throw new Exception(string.Format(Properties.Resources.VaultCheckinFolderException, normalizedPath, errMsg)); } else { Version = Convert.ToInt32(vaultClientFolder.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckinSuccessful), vaultClientFolder.Name); } } else if (IsVaultFile(normalizedPath)) { string previousWorkingFolder = ""; string repositoryFolderPath = ""; string tmpdiskPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("msbuild_checkinfor_{0}", System.IO.Path.GetFileName(normalizedPath))); VaultClientFile vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFile.Parent.FullPath, WorkingFolder); } string diskFilename = System.IO.Path.Combine(ClientInstance.GetWorkingFolder(vaultClientFile).GetLocalFolderPath(), normalizedPath.Substring(normalizedPath.LastIndexOf(VaultDefine.PathSeparator) + 1)); bool bChangeWorkingFolder = false; if (!Misc.stringIsBlank(_diskFile) && _diskFile != diskFilename) { bChangeWorkingFolder = true; if (!File.Exists(_diskFile)) { throw new Exception(string.Format(Properties.Resources.VaultDiskFileDoesNotExist, _diskFile)); } // They've specified a different disk file (no working folder) repositoryFolderPath = vaultClientFile.Parent.FullPath; previousWorkingFolder = ClientInstance.TreeCache.GetWorkingFolder(repositoryFolderPath); if (Directory.Exists(tmpdiskPath) == false) { Directory.CreateDirectory(tmpdiskPath); } // Set a different working folder to avoid interference with the real working folder ClientInstance.TreeCache.SetWorkingFolder(repositoryFolderPath, tmpdiskPath); diskFilename = System.IO.Path.Combine(tmpdiskPath, vaultClientFile.Name); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultSetNewWorkingFolder, repositoryFolderPath, tmpdiskPath, previousWorkingFolder)); ClientInstance.CheckOut(vaultClientFile, 2, "Temp checkout for MSBuild Vault task."); ClientInstance.Get(vaultClientFile, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); if (File.Exists(diskFilename)) { File.SetAttributes(diskFilename, FileAttributes.Normal); File.Delete(diskFilename); } File.Copy(_diskFile, diskFilename); ClientInstance.Refresh(); } try { ChangeSetItemColl requestedChange = new ChangeSetItemColl(); requestedChange.Add(new ChangeSetItem_Modified(DateTime.Now, _comment, "", vaultClientFile.ID, vaultClientFile.ObjVerID, diskFilename, normalizedPath, false, vaultClientFile.EOL)); if (!ClientInstance.Commit(requestedChange)) { string errMsg = VaultConnection.GetSoapExceptionMessage(requestedChange[0].Request.Response.Status); throw new Exception(string.Format(Properties.Resources.VaultCheckinFileException, normalizedPath, errMsg)); } else { Version = Convert.ToInt32(vaultClientFile.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckinSuccessful, vaultClientFile.Name)); } } finally { if (bChangeWorkingFolder) { if (Misc.stringIsBlank(previousWorkingFolder)) { Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultWorkingFolderCleared, repositoryFolderPath)); ClientInstance.TreeCache.RemoveWorkingFolder(repositoryFolderPath); } else { Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultWorkingFolderRestored, repositoryFolderPath, previousWorkingFolder)); ClientInstance.TreeCache.SetWorkingFolder(repositoryFolderPath, previousWorkingFolder); } } if (Directory.Exists(tmpdiskPath)) { Misc.DeleteDirectoryRecursivelyIncludingReadOnly(tmpdiskPath); } } } else { throw new Exception(string.Format(Properties.Resources.VaultCheckinFileNotFoundException, normalizedPath)); } }
public static Vault LoginVault(VaultConnection vc, UserDto user) { // Writelog(string.Format(" in loginvault,userName={0}, pwd={1}, domai={2}", user.UserName, user.Password, user.Domain)); return(LoginVault(vc, user.UserName, user.Password, user.Domain)); }
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); }
/// <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); }