コード例 #1
0
ファイル: MFVaultService.cs プロジェクト: weijx-xa/test
 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);
 }
コード例 #2
0
        /// <summary>
        /// Retrieves the vaults from the server.
        /// </summary>
        /// <remarks>Exceptions during connection will be thrown.</remarks>
        public IEnumerable <VaultOnServer> GetVaults()
        {
            // 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.GetVaults().Cast <VaultOnServer>())
                {
                    yield return(vault);
                }
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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();
        }
コード例 #5
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();
        }