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);
        }
コード例 #2
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);
        }
コード例 #3
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();
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: utility.cs プロジェクト: weijx-xa/test
        /// <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);
        }
コード例 #7
0
        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");
        }
コード例 #8
0
ファイル: MFilesPerformService.cs プロジェクト: weijx-xa/test
        /// <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);
        }
コード例 #9
0
        private void btn_Connect_Click(object sender, EventArgs e)
        {
            if (txt_Password.Text.Trim() == "" || txt_ServerAddress.Text.Trim() == "" || txt_Password.Text.Trim() == "" && userTypeList.SelectedIndex != -1)
            {
                MessageBox.Show("Lütfen tüm alanları doldurunuz.", "M-Files Code Extractor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var userType = userTypeList.SelectedItem as UserType;

            try
            {
                if (userType.Id == 1)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    serverApp.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, txt_Username.Text, txt_Password.Text, "", "ncacn_ip_tcp", txt_ServerAddress.Text);
                }
                else
                {
                    Cursor.Current = Cursors.WaitCursor;
                    serverApp.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, txt_Username.Text, txt_Password.Text, "", "ncacn_ip_tcp", txt_ServerAddress.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Sunucuya bağlanılamadı.", "M-Files Code Extractor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
                return;
            }



            //Get Online Vaults
            var onlineVaults = serverApp.GetOnlineVaults();



            //Pop The Vaults Form
            var oForm = new OnlineVaultsForm(onlineVaults);

            oForm.ShowDialog();
        }
コード例 #10
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();
        }
コード例 #11
0
        public static void LogIntoVault()
        {
            //Connect With M-Files Account
            serverApp.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, TestConstants.Username, TestConstants.Password);

            //Connect With Current Windows User
            //serverApp.Connect(MFAuthType.MFAuthTypeLoggedOnWindowsUser);


            //Connect With Another Windows Account
            //serverApp.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, "gokaykivircioglu", "1", "MECHSOFT");

            //Remote Server Connection
            //serverApp.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, TestConstants.Username, TestConstants.Password, "", "ncacn_ip_tcp", TestConstants.ServerAddress);

            //See M-Files API Documantation for further server connection info.

            //Login to a Vault
            loggedInVault = serverApp.LogInToVault(TestConstants.VaultGUID);
        }
コード例 #12
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"));
            }
        }
コード例 #13
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);
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: weijx-xa/test
        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);
            }
        }
コード例 #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));
        }
コード例 #16
0
ファイル: utility.cs プロジェクト: weijx-xa/test
        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);
        }
コード例 #17
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);
        }
コード例 #19
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);
                }
            }
        }
コード例 #20
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);
                }
            }
        }
コード例 #21
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);
        }
コード例 #22
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
                );
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: aaron-hardin/TestExample
        static void Main(string[] args)
        {
            MFilesServerApplication server = new MFilesServerApplication();

            server.Connect();
            Vault vault = server.LogInToVault("{82FB2FA4-6FBE-4546-A200-11CEF3DF2169}");

            PropertyDefAdmin ownerChangeElement = vault.PropertyDefOperations.GetPropertyDefAdmin(1213);

            ownerChangeElement.SemanticAliases.Value = "M-Files.Property.OwnerChangeElement";
            ownerChangeElement.PropertyDef.Name      = "Owner (Change Element)";
            vault.PropertyDefOperations.UpdatePropertyDefAdmin(ownerChangeElement);

            PropertyDefAdmin ownerChangeRequest = vault.PropertyDefOperations.GetPropertyDefAdmin(1229);

            ownerChangeRequest.SemanticAliases.Value = "M-Files.Property.OwnerChangeRequest";
            ownerChangeRequest.PropertyDef.Name      = "Owner (Change Request)";
            vault.PropertyDefOperations.UpdatePropertyDefAdmin(ownerChangeRequest);

            Console.Write("Press any key to exit...");
            Console.ReadKey();
        }
コード例 #24
0
 private void buttonenableusers_Click(object sender, EventArgs e)
 {
     try
     {
         var app = new MFilesServerApplication();
         app.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, textBoxuser.Text, textBoxpass.Text, "",
                     "ncacn_ip_tcp",
                     textBoxmfserver.Text);
         var accs = app.LoginAccountOperations.GetLoginAccounts();
         foreach (LoginAccount acc in accs)
         {
             acc.Enabled = true;
             app.LoginAccountOperations.ModifyLoginAccount(acc);
             richTextBox1.AppendText(Environment.NewLine + string.Format("{0},{1},{2} enabled", acc.FullName, acc.UserName, acc.AccountName));
         }
         app.Disconnect();
     }
     catch (Exception ex)
     {
         richTextBox1.AppendText(Environment.NewLine + ex.Message);
     }
 }
コード例 #25
0
        public static void Run(string serverName, string userName, string password, string[] vaultNames, string viewName,
                               DateTime startDate, IDictionary <string, IEnumerable <PropertyListType> > listProperties, IProcessor processor)
        {
            _mfilesServer = new MFilesServerApplication();
            MFServerConnection result;

            try
            {
                result = _mfilesServer.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, userName, password,
                                               NetworkAddress: serverName);
            }
            catch (COMException ex)
            {
                ClassLogger.Error(ex, $"Could not connect to M-Files server");
                return;
            }
            if (result != MFServerConnection.MFServerConnectionAuthenticated)
            {
                ClassLogger.Error("Could not connect to M-Files server");
                return;
            }

            var topContext = processor.CreateContext();


            var vaultsOnServer = _mfilesServer.GetVaults();

            IList <Tuple <string, Vault, IView> > data = new List <Tuple <string, Vault, IView> >();

            foreach (var vaultName in vaultNames)
            {
                IVaultOnServer vaultOnServer;
                try
                {
                    vaultOnServer = vaultsOnServer.GetVaultByName(vaultName);
                }
                catch (COMException)
                {
                    ClassLogger.Error($"Could not find vault '{vaultName}'");
                    continue;
                }

                Vault vault = vaultOnServer.LogIn();
                if (!vault.LoggedIn)
                {
                    ClassLogger.Error($"Could not logging to vault '{vaultName}'");
                    continue;
                }

                if (listProperties.ContainsKey(vaultName))
                {
                    foreach (var listProperty in listProperties[vaultName])
                    {
                        var def =
                            vault.PropertyDefOperations.GetPropertyDefs()
                            .Cast <PropertyDef>()
                            .SingleOrDefault(x => x.Name == listProperty.PropertyName);

                        if (def == null || !def.BasedOnValueList)
                        {
                            ClassLogger.Error($"Property {listProperty.PropertyName} in {vaultName} is not a list");
                            continue;
                        }

                        ValueListItems items = vault.ValueListItemOperations.GetValueListItems(def.ValueList, true, MFExternalDBRefreshType.MFExternalDBRefreshTypeQuick);

                        foreach (ValueListItem item in items)
                        {
                            Guid guid;
                            if (!Guid.TryParse(item.DisplayID, out guid))
                            {
                                guid = Guid.NewGuid();
                            }

                            listProperty.Items.Add(new PropertyListItem(guid, item.Name));
                        }

                        topContext.ProcessListProperty(listProperty);
                    }
                }

                IView view = vault.ViewOperations.GetViews().Cast <IView>().FirstOrDefault(v => v.Name == viewName);
                if (view == null)
                {
                    ClassLogger.Warn($"Could not find view '{viewName}' in vault  '{vaultName}'");
                    continue;
                }
                data.Add(Tuple.Create(vaultName, vault, view));
            }

            IList <Task> tasks = new List <Task>();

            foreach (var taskData in data)
            {
                var task =
                    new Task(() => ProcessData(taskData.Item1, taskData.Item2, taskData.Item3, startDate, processor));
                tasks.Add(task);
                task.Start();
            }

            foreach (var task in tasks)
            {
                task.Wait();
            }
            processor.AfterProcessing();
        }
コード例 #26
0
        public static Vault ConnectServer(
            ref string ErrMsg,
            string vautGUId,
            string vaultLogin, // baymain/jutta.ipsen --- split domain
            string vaultPWD,
            bool isWindowsUser,
            string VaultNetworkAddress,
            string VaultEndpoint,
            string VaultProtocol,
            string windowUser   = "",
            string windowDomain = ""
            )
        {
            Vault _vault = null;

            try
            {
                MFilesServerApplication _server = new MFilesServerApplication();
                //MFilesClientApplication _client = new MFilesClientApplication();
                splitDomain(ref windowUser, ref windowDomain, vaultLogin);
                if (VaultNetworkAddress.Equals("localhost"))
                {
                    if (isWindowsUser == true)
                    {
                        if (windowDomain.Equals(""))
                        {
                            _server.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, windowUser, vaultPWD);
                        }
                        else
                        {
                            _server.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, windowUser, vaultPWD, windowDomain);
                        }
                    }
                    else
                    {
                        _server.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, vaultLogin, vaultPWD);
                    }
                }
                else// network
                {
                    string Protocol;
                    if (String.IsNullOrEmpty(VaultProtocol))
                    {
                        Protocol = "ncacn_ip_tcp"; //(TCP/IP protocol)
                    }
                    else
                    {
                        Protocol = VaultProtocol;
                    }
                    if (isWindowsUser == true)
                    {
                        if (windowDomain.Equals(""))
                        {
                            _server.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, windowUser, vaultPWD, Type.Missing,
                                            Protocol, VaultNetworkAddress, VaultEndpoint);
                        }
                        else
                        {
                            _server.Connect(MFAuthType.MFAuthTypeSpecificWindowsUser, windowUser, vaultPWD, windowDomain,
                                            Protocol, VaultNetworkAddress, VaultEndpoint);
                        }
                    }
                    else
                    {
                        _server.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, vaultLogin, vaultPWD, Type.Missing,
                                        Protocol, VaultNetworkAddress, VaultEndpoint);
                    }
                }


                _vault = _server.LogInToVault(vautGUId);



                //var vaultConnection = _client.GetVaultConnection(vaultName);
                //IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle;
                //_vault = vaultConnection.BindToVault(hwnd, true, true);
                return(_vault);
            }
            catch (Exception e)
            {
                ErrMsg = e.Message;
                return(_vault);
            }
        }
コード例 #27
0
ファイル: Utils.cs プロジェクト: JulienHortoneda/Winterfell
 private void Connect()
 {
     _server = new MFilesServerApplication();
     _server.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser,
         _user, _pass,
         null, "ncacn_ip_tcp",
         _host, _port,
         "", false);
 }
コード例 #28
0
        static void Main(string[] args)
        {
            try
            {
                var count   = args.Count();
                var appname = AppDomain.CurrentDomain.SetupInformation.ApplicationName;
                Console.WriteLine("Usage : " + Environment.NewLine
                                  + "\t1) 如果使用域用户登陆并且当前登陆的域用户在目标vault中存在,命令格式为:" + appname + "  excel文件全名包括扩展名" + "  目标vault的guid" + Environment.NewLine
                                  + "\t2)否则命令格式为:" + appname + "  excel文件全名包括扩展名" + "  目标vault的guid" + "  M-Files用户  用户密码");
                if (count != 4 && count != 2)
                {
                    Console.WriteLine("Please specify command line parameters correctly {0}!", count);
                    Console.WriteLine("Any key to exit !");
                    Console.ReadKey();
                    return;
                }
                var filename   = args[0];
                var oServerApp = new MFilesServerApplication();
                var oVault     = new Vault();
                try
                {
                    switch (count)
                    {
                    case 2:
                    {
                        oServerApp.Connect(MFAuthType.MFAuthTypeLoggedOnWindowsUser);
                        var a = oServerApp.GetVaults();
                        oVault = a.GetVaultByGUID(args[1]).LogIn();
                        //登录到M-files文档库
                    }
                    break;

                    case 4:
                    {
                        oServerApp.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, args[2], args[3]);
                        var gVaultsOnServer = oServerApp.GetVaults();
                        oVault = gVaultsOnServer.GetVaultByGUID(args[1]).LogIn();
                    }
                    break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("vault connect error! {0}", ex.Message);
                    return;
                }
                if (!File.Exists(filename))
                {
                    Console.WriteLine("please input correct excel filename! {0}", filename);
                    return;
                }
                int PropContractedProfessionid               = -1;
                var PropContractorNameid                     = -1;
                var PropBusinessLicenseNumber                = -1;
                var PropTaxRegistrationNumber                = -1;
                var PropQualificationCertificateNumber       = -1;
                var PropLevelOfQualification                 = -1;
                var PropSafetyProductionLicenseNumber        = -1;
                var PropTelephoneAndFaxOfLegalRepresentative = -1;
                var PropDetailedAddress       = -1;
                var PropDeputiesAndTelephones = -1;
                var PropLevel             = -1;
                var classID               = -1;
                var typeid                = -1;
                var PropRegisteredCapital = -1;
                try
                {
                    PropContractedProfessionid =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropContractedProfession");
                    PropContractorNameid =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropContractorName");
                    PropBusinessLicenseNumber =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropBusinessLicenseNumber");
                    PropTaxRegistrationNumber =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropTaxRegistrationNumber");
                    PropQualificationCertificateNumber =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropQualificationCertificateNumber");
                    PropLevelOfQualification =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropLevelOfQualification");
                    PropSafetyProductionLicenseNumber =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropSafetyProductionLicenseNumber");
                    PropRegisteredCapital =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropRegisteredCapital");
                    PropTelephoneAndFaxOfLegalRepresentative =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropTelephoneAndFaxOfLegalRepresentative");
                    PropDetailedAddress =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropDetailedAddress");
                    PropDeputiesAndTelephones =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropDeputiesAndTelephones");
                    PropLevel =
                        oVault.PropertyDefOperations.GetPropertyDefIDByAlias("PropLevel");
                    classID = oVault.ClassOperations.GetObjectClassIDByAlias("ClassContractor");
                    typeid  = oVault.ObjectTypeOperations.GetObjectTypeIDByAlias("OtContractor");
                }
                catch (Exception alex)
                {
                    Console.WriteLine("取别名定义错: {0}", alex.Message);
                    return;
                }
                foreach (var tablename in GetExcelTableName(filename))
                {
                    Console.WriteLine("GetExcelTableName: {0}-开始导入", tablename);
                    if (tablename == "规定$")
                    {
                        continue;
                    }
                    //   if (tablename != "主体土建工程$") continue;
                    //  if (tablename != "智能化工程$") continue;
                    // if (tablename != "地基基础工程$") continue;
                    //   if (tablename != "装饰装修工程$") continue;
                    //  if (tablename != "防水防腐保温工程$") continue;
                    // // if (tablename != "电力工程$") continue;
                    var dt     = GetExcelTableByOleDb(filename, tablename);
                    var num    = 0;
                    var mempvs = new PropertyValues();
                    var currentlineisadditionline = false;
                    var memtels     = string.Empty;
                    var lastmemtels = string.Empty;
                    //    Console.WriteLine("GetExcelTableName111: {0}", dt.Rows.Count);
                    foreach (DataRow row in dt.Rows)
                    {
                        //  Console.WriteLine("GetExcelTableName222: {0}", tablename);
                        var newPropertyValues = new PropertyValues();
                        var classid           = new PropertyValue
                        {
                            PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
                        };
                        classid.TypedValue.SetValue(MFDataType.MFDatatypeLookup, classID);
                        newPropertyValues.Add(-1, classid);

                        var numcol = 0;
                        num++;
                        if (num < 6)
                        {
                            continue;
                        }
                        //       if (num > 11) continue;//only for debug
                        #region begin one line
                        //    Console.WriteLine("GetExcelTableName333: {0}", tablename);
                        foreach (DataColumn column in dt.Columns)
                        {
                            numcol++;
                            if (numcol < 2 || numcol > 16)
                            {
                                continue;
                            }
                            if (numcol == 3)
                            {
                                currentlineisadditionline = row[column].ToString() == string.Empty;
                            }

                            //     if (row[column].ToString() == string.Empty) continue;

                            #region begin deal with properties
                            var newvalue = new PropertyValue();
                            //   Console.WriteLine("GetExcelTableName444: {0}", tablename);
                            switch (numcol)
                            {
                            case 2:
                                newvalue.PropertyDef = PropContractedProfessionid;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 3:
                                newvalue.PropertyDef = PropContractorNameid;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 4:
                                newvalue.PropertyDef = PropQualificationCertificateNumber;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 5:
                                newvalue.PropertyDef = PropLevelOfQualification;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 6:
                                newvalue.PropertyDef = PropBusinessLicenseNumber;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 7:
                                newvalue.PropertyDef = PropSafetyProductionLicenseNumber;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 9:
                                newvalue.PropertyDef = PropTaxRegistrationNumber;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 10:
                                newvalue.PropertyDef = PropRegisteredCapital;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 11:
                                newvalue.PropertyDef = PropDetailedAddress;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, row[column]);
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 12:
                                newvalue.PropertyDef = PropTelephoneAndFaxOfLegalRepresentative;
                                newvalue.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, row[column].ToString().Replace("\r", " ").Replace("\n", " "));
                                newPropertyValues.Add(-1, newvalue);
                                break;

                            case 16:
                                //newvalue.PropertyDef = PropDeputiesAndTelephones;
                                //newvalue.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, row[column]);
                                //newPropertyValues.Add(-1, newvalue);
                                // lastmemtels += memtels + "//r//n" + '-' + "\\r\\n"+"-\r\n-/r/n";
                                lastmemtels += memtels;
                                if (row[column].ToString().Trim() != string.Empty)
                                {
                                    memtels = row[column].ToString().Replace("\r", "").Replace("\n", "").Replace("  ", " ") + "\r\n";
                                }
                                else
                                {
                                    memtels = row[column].ToString();
                                }
                                break;

                            case 14:
                                newvalue.PropertyDef = PropLevel;
                                try
                                {
                                    var vlid   = oVault.ValueListOperations.GetValueListIDByAlias("VlLevel");
                                    var values = oVault.ValueListItemOperations.GetValueListItems(vlid);
                                    var lu     = new Lookup();
                                    lu.Item = 4;
                                    var found = false;
                                    foreach (ValueListItem vlitem in values)
                                    {
                                        if (vlitem.Name == row[column].ToString())
                                        {
                                            lu.Item = vlitem.ID;
                                            found   = true;
                                            break;
                                        }
                                    }
                                    newvalue.TypedValue.SetValue(MFDataType.MFDatatypeLookup, lu);
                                    newPropertyValues.Add(-1, newvalue);
                                    if (!found && row[column].ToString() != string.Empty)
                                    {
                                        Console.WriteLine("-级别未定义,请手动修改-: {0},{1},-{2}-", num, numcol, row[column]);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("--: {0},{1},-{2}-{3}", num, numcol, row[column], e.Message);
                                }
                                break;

                            default:
                                break;
                            }
                            #endregion end deal with properties
                            // Console.WriteLine("--: {0},{1},-{2}-", num, numcol, row[column]);
                        }
                        if (!currentlineisadditionline)
                        {
                            var newvalue = new PropertyValue();
                            newvalue.PropertyDef = PropDeputiesAndTelephones;
                            newvalue.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, Specialsplit(lastmemtels));
                            mempvs.Add(-1, newvalue);
                            lastmemtels = string.Empty;

                            if (mempvs.Count > 5)
                            {
                                var oObjectVersionAndProperties = oVault.ObjectOperations.CreateNewObject(101,
                                                                                                          mempvs);
                                var objVersion =
                                    oVault.ObjectOperations.CheckIn(oObjectVersionAndProperties.ObjVer);
                            }
                            mempvs = newPropertyValues;
                        }

                        #endregion end one line
                    }
                    {
                        var newvalue = new PropertyValue();
                        newvalue.PropertyDef = PropDeputiesAndTelephones;
                        newvalue.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, Specialsplit(lastmemtels + memtels));
                        mempvs.Add(-1, newvalue);

                        if (mempvs.Count > 5)
                        {
                            var oObjectVersionAndProperties = oVault.ObjectOperations.CreateNewObject(typeid,
                                                                                                      mempvs);
                            var objVersion =
                                oVault.ObjectOperations.CheckIn(oObjectVersionAndProperties.ObjVer);
                        }
                    }
                    Console.WriteLine("GetExcelTableName end: {0}-sheet页总计导入记录-{1}条", tablename, num);
                    //  break;//for debug one sheet
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("big end exception: {0}", ex.Message);
            }
            Console.WriteLine("Done, Any key to exit !");
            Console.ReadKey();
        }