Exemple #1
0
        public void AddIfc(string ifcPath)
        {
            Initialize();

            var ifcObj = GetIfc();

            var pvs = GetAdditionalPropsForIFC();

            if (ifcObj != null)
            {
                ClientUtils.AddFiles(_vault, ifcObj, true, new[] { ifcPath }, pvs);
                return;
            }

            var ifcClassId = _aliases.CsDict[CS.IfcModel];

            if (ifcClassId == -1)
            {
                ifcClassId = (int)MFBuiltInDocumentClass.MFBuiltInDocumentClassOtherDocument;
            }
            var objClass = _vault.ClassOperations.GetObjectClass(ifcClassId);
            var nameProp = objClass.NamePropertyDef;

            var objType = objClass.ObjectType;

            var classPV = new PropertyValue {
                PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
            };

            classPV.Value.SetValue(MFDataType.MFDatatypeLookup, ifcClassId);
            pvs.Add(-1, classPV);

            var namePV = new PropertyValue {
                PropertyDef = nameProp
            };

            namePV.Value.SetValue(MFDataType.MFDatatypeText, _name);
            pvs.Add(-1, namePV);


            var filesPV = new PropertyValue {
                PropertyDef = _aliases.PdDict[PD.OwnedModel]
            };

            filesPV.Value.SetValue(MFDataType.MFDatatypeLookup, _obj.ObjVer.ID);
            pvs.Add(-1, filesPV);

            var sf = new SourceObjectFile();

            sf.Extension      = Path.GetExtension(ifcPath).TrimStart('.');
            sf.Title          = _name;
            sf.SourceFilePath = ifcPath;


            _vault.ObjectOperations.CreateNewSFDObject(objType, pvs, sf, true, new AccessControlList());
        }
Exemple #2
0
        private static SourceObjectFile GetFileObject(string rootPath, SelectedFile file)
        {
            var sourcePath = Path.Combine(rootPath, file.Filepath);
            var ext        = Path.GetExtension(sourcePath);

            ext = ext.TrimStart('.');
            var sof = new SourceObjectFile {
                Title = file.NewFilename, SourceFilePath = sourcePath, Extension = ext
            };

            return(sof);
        }
        public static void CreateNewDocument()
        {
            LogIntoVault();

            //Prerequisites for creating an object in mfiles;
            //Type of object E.g. 0 is for document
            //PropertyValues
            //Source files if the object's type is document or any other type that can have documents

            var properties = new PropertyValues();

            //Class 0 -> Sınıflandırılmamış Doküman
            var classProperty = new PropertyValue();

            classProperty.PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass; //Simply 100
            classProperty.TypedValue.SetValue(MFDataType.MFDatatypeLookup, 0);
            properties.Add(0, classProperty);

            //Name or Title -> İsim veya başlık
            var nameProperty = new PropertyValue();

            nameProperty.PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle; //Simply 0
            nameProperty.TypedValue.SetValue(MFDataType.MFDatatypeText, "Emre");
            properties.Add(0, nameProperty);

            //File from fileSystem
            var sourceObjectFile = new SourceObjectFile();

            sourceObjectFile.Title          = "SampleTextFile";
            sourceObjectFile.SourceFilePath = "SampleTextFile.txt";
            sourceObjectFile.Extension      = "txt";

            //Using Existing ACL
            //ACL with the ID of -10
            var aCL = loggedInVault.NamedACLOperations.GetNamedACL(-10);

            loggedInVault.ObjectOperations.CreateNewSFDObject(
                0
                , properties
                , sourceObjectFile
                , true
                , aCL.AccessControlList);
        }
Exemple #4
0
        public int CreateNewSFDObjectQuick(int objectType, PropertyValues properties, SourceObjectFile sourceFile, bool checkIn, AccessControlList accessControlList = null)
        {
            vault.MetricGatherer.MethodCalled();

            throw new NotImplementedException();
        }
        public static void CreateNewDocumentWithNewACL()
        {
            LogIntoVault();

            //Prerequisites for creating an object in mfiles;
            //Type of object E.g. 0 is for document
            //PropertyValues
            //Source files if the object's type is document or any other type that can have documents

            var properties = new PropertyValues();

            //Class 0 -> Sınıflandırılmamış Doküman
            var classProperty = new PropertyValue();

            classProperty.PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass; //Simply 100
            classProperty.TypedValue.SetValue(MFDataType.MFDatatypeLookup, 0);
            properties.Add(0, classProperty);

            //Name or Title -> İsim veya başlık
            var nameProperty = new PropertyValue();

            nameProperty.PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle; //Simply 0
            nameProperty.TypedValue.SetValue(MFDataType.MFDatatypeText, "SampleTextFile");
            properties.Add(0, nameProperty);

            //File from fileSystem
            var sourceObjectFile = new SourceObjectFile();

            sourceObjectFile.Title          = "SampleTextFile";
            sourceObjectFile.SourceFilePath = "SampleTextFile.txt";
            sourceObjectFile.Extension      = "txt";


            //Create New ACL
            var accessControlList = new AccessControlList();

            accessControlList.IsFullyAuthoritative = true;

            //Create Component
            var aclComponent = new AccessControlListComponent();


            //Create Entry
            var aclEntryKey = new AccessControlEntryKey();

            aclEntryKey.SetUserOrGroupID(1, true);

            //Create Data (Permissions for Entry)
            var aclData = new AccessControlEntryData();

            aclData.DeletePermission            = MFPermission.MFPermissionNotSet;
            aclData.ReadPermission              = MFPermission.MFPermissionAllow;
            aclData.EditPermission              = MFPermission.MFPermissionNotSet;
            aclData.AttachObjectsPermission     = MFPermission.MFPermissionAllow;
            aclData.ChangePermissionsPermission = MFPermission.MFPermissionNotSet;

            //Set Entry Key, Data
            aclComponent.AccessControlEntries.Add(aclEntryKey, aclData);

            //Add to ACL
            accessControlList.CustomComponent = aclComponent;

            var namedACLAdmin = new NamedACLAdmin();
            var namedACL      = new NamedACL();

            namedACL.AccessControlList = accessControlList;
            namedACL.Name = "NewACL" + Guid.NewGuid().ToString().Substring(7);

            namedACLAdmin.NamedACL = namedACL;

            //Add ACL TO Server
            var newCreatedACL = loggedInVault.NamedACLOperations.AddNamedACLAdmin(namedACLAdmin);

            //Use newly Added ACL
            loggedInVault.ObjectOperations.CreateNewSFDObject(
                0
                , properties
                , sourceObjectFile
                , true
                , newCreatedACL.NamedACL.AccessControlList);
        }
Exemple #6
0
        public static string GetSecureNoticeNew(EventHandlerEnvironment env) //程序划图片表格
        {
            var rpd = new ReportPrintData();

            Writelog(env.Vault.Name + env.Input + "GetSecureNotice : 查询条件");
            try
            {
                var input = JsonConvert.DeserializeObject <ReportInput>(env.Input);

                #region search issuenotice

                var conditions = new SearchConditions();
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeEqual,
                        Expression    =
                        {
                            DataStatusValueType = MFStatusType.MFStatusTypeObjectTypeID
                        }
                    };
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = OtSecureAdjustNotice.ID
                    });
                    //    Writelog("OtSecureAdjustNotice=" + OtSecureAdjustNotice.ID);
                    conditions.Add(-1, condition);
                }
                {
                    var sc = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeNotEqual,
                        Expression    = { DataStatusValueType = MFStatusType.MFStatusTypeDeleted }
                    };
                    sc.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                    conditions.Add(-1, sc);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeGreaterThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    //   Writelog("PropCheckDate=" + PropCheckDate.ID);
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.StartDate);
                    conditions.Add(-1, condition);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeLessThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.EndDate);
                    conditions.Add(-1, condition);
                }
                if (input.Principal != 0)
                {
                    var condition = new SearchCondition();
                    //  Writelog("PropPrincipal=" + PropPrincipal.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropPrincipal.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Principal
                    });
                    conditions.Add(-1, condition);
                }
                if (input.Receiver != 0)
                {
                    var condition = new SearchCondition();
                    //    Writelog("PropSecureReceiver=" + PropSecureReceiver.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropSecureReceiver.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Receiver
                    });
                    conditions.Add(-1, condition);
                }
                ObjectVersions allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                                         MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();

                #endregion search issuenotice

                //  Writelog("allwork=" + allwork.Count);

                string templatefile = GetTemplateFile(env);

                try
                {
                    object oMissing = Missing.Value;
                    object objWhat  = WdGoToItem.wdGoToPage;
                    object objWhich = WdGoToDirection.wdGoToLast;
                    var    app      = new Application();
                    object unknow   = Type.Missing;
                    //  var msocoding = MsoEncoding.msoEncodingSimplifiedChineseGB18030;
                    Document doc = app.Documents.Open(templatefile,
                                                      ref unknow, false, ref unknow, ref unknow, ref unknow,
                                                      //        ref unknow, ref unknow, ref unknow, ref unknow, msocoding,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);

                    int    issueindex = 0;//问题唯一序号,跨页接续
                    int    tableindex = 1;
                    string temppath   = Path.GetTempPath();
                    doc.Content.Copy();

                    Writelog(String.Format("vault:{0},conditions{1},results:{2}", env.Vault.Name, env.Input,
                                           allwork.Count));
                    int  rowpos  = 1;//问题填写位置,每页刷新
                    bool newpage = false;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        // Writelog("debug info aaaa");
                        if (newpage)
                        {
                            newpage = false;
                            //   Writelog("debug info bbbb");
                            object    nothing = Missing.Value;
                            Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                            object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                            para.Range.InsertBreak(ref pBreak);
                            //   Writelog("debug info bbbb1111");

                            app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);
                            //    Writelog("debug info dddd");

                            app.Selection.Paste();
                            //   Writelog("debug info ffff");
                            tableindex++;
                            rowpos = 1;
                        }

                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);
                        issueindex++;

                        string issuename = env.Vault.Name;
                        //  Writelog("debug info 6666");
                        doc.Tables[tableindex].Cell(4, 2).Range.Text = issuename;


                        //   Writelog("debug info 7777");
                        int rowindex = 6 + rowpos;

                        string secureissuename = onepvs.SearchForProperty(PropIssueCategory).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 1).Range.Text =
                            issueindex.ToString(CultureInfo.InvariantCulture);

                        doc.Tables[tableindex].Cell(rowindex, 2).Range.Text = secureissuename;
                        doc.Tables[tableindex].Cell(rowindex, 3).Range.Text =
                            onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 4).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMeasure.ID).GetValueAsLocalizedText();

                        doc.Tables[tableindex].Cell(rowindex, 5).Range.Text =
                            onepvs.SearchForProperty(PropPrincipal.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 6).Range.Text =
                            onepvs.SearchForProperty(PropSecureReceiver.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 7).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMan.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 8).Range.Text =
                            onepvs.SearchForProperty(PropFuChaRen.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 9).Range.Text =
                            onepvs.SearchForProperty(PropCountercheckDescription.ID)
                            .GetValueAsLocalizedText();
                        //       Writelog(string.Format("表 {0}, 行 {1},序号 {2}, 行号 {3}",tableindex,rowindex,issueindex,rowpos));
                        if (rowpos++ >= 10)
                        {
                            newpage = true;
                        }
                    }

                    int index = 0;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);

                        object    nothing = Missing.Value;
                        Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                        object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                        para.Range.InsertBreak(ref pBreak);

                        app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);

                        app.Selection.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
                        Range range = app.Selection.Range;
                        Table table = app.Selection.Tables.Add(range, 7, 1, ref oMissing, ref oMissing);

                        table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDouble;
                        table.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table.Cell(1, 1).Split(1, 2);
                        for (int i = 2; i <= 3; i++)
                        {
                            table.Cell(i, 1).Split(1, 4);
                        }

                        //Writelog("debug info 888111");
                        //app.Selection.TypeText("序号:" + page);
                        //Writelog("debug info 999000 v1");
                        table.Cell(1, 1).Range.Text = "序号:";
                        table.Cell(1, 2).Range.Text = (++index).ToString(CultureInfo.InvariantCulture);
                        //table.Cell(1, 3).Range.Text = "存在问题:";
                        //table.Cell(1, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        //Writelog("debug info 1111 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "检查负责人:";
                        table.Cell(2, 1).Range.Text = "检查日期:";
                        //table.Cell(2, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropPrincipal.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(2, 2).Range.Text =
                            onepvs.SearchForProperty(PropCheckDate.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 222 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "接收人  :";
                        //table.Cell(rowindex++, 3).Range.Text = "整改人:";
                        //table.Cell(3, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureReceiver.ID)
                        //        .GetValueAsLocalizedText();
                        //table.Cell(3, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropAdjustMan.ID)
                        //        .GetValueAsLocalizedText();
                        //   Writelog("debug info 333 v1-" + tableindex);
                        table.Cell(2, 3).Range.Text = "整改期限  :";
                        table.Cell(3, 3).Range.Text = "整改次数:";
                        table.Cell(2, 4).Range.Text =
                            onepvs.SearchForProperty(PropZhengGaiQiXin.ID)
                            .GetValueAsLocalizedText();
                        table.Cell(3, 4).Range.Text =
                            onepvs.SearchForProperty(PropRectificationCount.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 444 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "复查人  :";
                        table.Cell(3, 1).Range.Text = "复查日期:";
                        //table.Cell(5, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropFuChaRen.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(3, 2).Range.Text =
                            onepvs.SearchForProperty(PropReviewDate.ID)
                            .GetValueAsLocalizedText();
                        //    Writelog("debug info 555 v1-" + tableindex);
                        // int rowindex = 2;
                        table.Cell(4, 1).Range.Text = "整改前照片:";
                        table.Cell(6, 1).Range.Text = "复查照片:";
                        ObjectFiles files  = env.Vault.ObjectFileOperations.GetFiles(objectVersion.ObjVer);
                        int         picrow = 5;
                        //  Writelog("before 000000000000");
                        foreach (ObjectFile objectFile in files)
                        {
                            string apicture = temppath + objectFile.GetNameForFileSystem();
                            env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID,
                                                                        objectFile.Version, apicture);
                            object      linkToFile       = false;
                            object      saveWithDocument = true;
                            object      anchor           = table.Cell(picrow, 1).Range;
                            InlineShape insh             = doc.InlineShapes.AddPicture(apicture, ref linkToFile,
                                                                                       ref saveWithDocument,
                                                                                       ref anchor);
                            insh.Height = 259;
                            insh.Width  = 416;
                            picrow     += 2;
                            if (picrow > 7)
                            {
                                break;
                            }
                        }
                    }
                    doc.Close();
                    app.Quit();
                }
                catch (Exception ex)
                {
                    Writelog(ex.Message);
                }

                var pvs = new PropertyValues();
                var pv  = new PropertyValue {
                    PropertyDef = 0
                };
                pv.Value.SetValue(MFDataType.MFDatatypeText, "securenoticereport");
                pvs.Add(-1, pv);
                pv.PropertyDef = 100;
                pv.Value.SetValueToLookup(new Lookup {
                    Item = ClassSecureReport
                });
                pvs.Add(-1, pv);
                var file = new SourceObjectFile {
                    Title = "report", SourceFilePath = templatefile, Extension = "docx"
                };

                try
                {
                    ObjectVersionAndProperties t = env.Vault.ObjectOperations.CreateNewSFDObject(0, pvs, file, true);
                    ObjectFiles f = env.Vault.ObjectFileOperations.GetFiles(t.ObjVer);

                    rpd.Objid       = t.ObjVer.ID;
                    rpd.Objtype     = t.ObjVer.Type;
                    rpd.Objversion  = t.ObjVer.Version;
                    rpd.Fileid      = f[1].FileVer.ID;
                    rpd.Fileversion = f[1].FileVer.Version;
                }
                catch (Exception ex)
                {
                    Writelog("getsecurenotice - create object :" + ex.Message);
                }
            }
            catch (Exception ex)
            {
                Writelog(env.Input + "GetSecureNotice error:" + ex.Message);
            }
            var ret = JsonConvert.SerializeObject(rpd, Formatting.None);
            Writelog("GetSecureNotice ok return:" + ret);
            return(ret);
        }
Exemple #7
0
        public static ObjectVersionAndProperties CreateSingleFileObject(this Vault vault, int objType, int classId,
                                                                        PropertyValues pvs, SourceObjectFile file, bool checkIn)
        {
            var classPV = MFPropertyUtils.Class(classId);

            pvs.Add(0, classPV);

            return(vault.ObjectOperations.CreateNewSFDObject(objType, pvs, file, checkIn));
        }
Exemple #8
0
        private string GetSecureNotice(EventHandlerEnvironment env)
        {
            ReportInput input = new ReportInput();

            Writelog(env.Input + "GetSecureNotice :");
            try
            {
                input = JsonConvert.DeserializeObject <ReportInput>(env.Input);
            }
            catch (Exception ex)
            {
                Writelog(env.Input + "GetSecureNotice error:" + ex.Message);
                return(JsonConvert.SerializeObject("-1", Formatting.None));
            }
            #region search issuenotice
            var conditions = new SearchConditions();
            {
                var condition = new SearchCondition();
                condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                condition.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass;
                condition.TypedValue.SetValueToLookup(new Lookup {
                    Item = ClassSecureNotice.ID
                });
                conditions.Add(-1, condition);
            }
            {
                var condition = new SearchCondition();
                condition.ConditionType = MFConditionType.MFConditionTypeGreaterThanOrEqual;
                condition.Expression.DataPropertyValuePropertyDef = PropCheckDate.ID;
                condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.startDate);
                conditions.Add(-1, condition);
            }
            {
                var condition = new SearchCondition();
                condition.ConditionType = MFConditionType.MFConditionTypeLessThanOrEqual;
                condition.Expression.DataPropertyValuePropertyDef = PropCheckDate.ID;
                condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.endDate);
                conditions.Add(-1, condition);
            }
            if (input.principal != 0)
            {
                var condition = new SearchCondition();

                condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                condition.Expression.DataPropertyValuePropertyDef = PropPrincipal.ID;
                condition.TypedValue.SetValueToLookup(new Lookup {
                    Item = input.principal
                });
                conditions.Add(-1, condition);
            }
            if (input.receiver != 0)
            {
                var condition = new SearchCondition();

                condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                condition.Expression.DataPropertyValuePropertyDef = PropSecureReceiver.ID;
                condition.TypedValue.SetValueToLookup(new Lookup {
                    Item = input.receiver
                });
                conditions.Add(-1, condition);
            }
            var allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                          MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();
            #endregion search issuenotice

            var templatefile = GetTemplateFile(env);
            if (string.IsNullOrEmpty(templatefile))
            {
                return(JsonConvert.SerializeObject("-2", Formatting.None));
            }
            try
            {
                var app    = new Microsoft.Office.Interop.Word.Application();
                var unknow = Type.Missing;
                //  var msocoding = MsoEncoding.msoEncodingSimplifiedChineseGB18030;
                var doc = app.Documents.Open(templatefile,
                                             ref unknow, false, ref unknow, ref unknow, ref unknow,
                                             //        ref unknow, ref unknow, ref unknow, ref unknow, msocoding,
                                             ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,
                                             ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
                //var num = 0;
                //foreach (Table table in doc.Tables)
                //{
                //    Writelog(string.Format("table[{0}],Columns[{1}],,Rows[{2}]", num, table.Columns.Count, table.Rows.Count));
                //    for (int i = 0; i < table.Columns.Count; i++)
                //    {
                //        for (int j = 0; j < table.Rows.Count; j++)
                //        {
                //            try
                //            {
                //                var text = table.Cell(j, i).Range.Text;

                //                Writelog(string.Format("table[{0}],Columns[{1}],Rows[{2}],text[{3}]", num, i, j, text));
                //            }
                //            catch (Exception ex)
                //            {
                //                Writelog(string.Format("table[{0}],Columns[{1}],Rows[{2}],message[{3}]", num, i, j, ex.Message));
                //            }
                //        }
                //    }
                //    num++;
                //}
                //Writelog("num=" + num);


                var page       = 0;
                var tableindex = 0;
                var temppath   = System.IO.Path.GetTempPath();
                doc.Tables[1].Range.Copy();
                var issuename       = string.Empty;
                var secureissuename = string.Empty;

                foreach (ObjectVersion objectVersion in allwork)
                {
                    if (page > 0)
                    {
                        doc.Content.InsertParagraphAfter();
                        doc.Content.InsertAfter(" ");
                        object WdLine   = Microsoft.Office.Interop.Word.WdUnits.wdLine; //换一行;
                        var    movedown = app.Selection.MoveDown(ref WdLine, 21);       //移动焦点
                        Writelog(string.Format(" before paste table num=[{0}],count=[{1}],down==[{2}]", doc.Tables.Count.ToString(), movedown));
                        app.Selection.Paste();
                    }

                    var onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);
                    page++;
                    tableindex++;
                    issuename = onepvs.SearchForProperty(0).GetValueAsLocalizedText();

                    doc.Tables[tableindex].Cell(4, 2).Range.Text = issuename;
                    doc.Tables[tableindex].Cell(4, 4).Range.Text = DateTime.Now.ToShortDateString();
                    doc.Tables[tableindex].Cell(4, 6).Range.Text = page.ToString();
                    doc.Tables[tableindex].Cell(0, 1).Range.Text = "整改期限:" + onepvs.SearchForProperty(PropZhengGaiQiXin.ID).GetValueAsLocalizedText();
                    doc.Tables[tableindex].Cell(0, 2).Range.Text = "接收人:" + onepvs.SearchForProperty(PropSecureReceiver.ID).GetValueAsLocalizedText();
                    doc.Tables[tableindex].Cell(0, 3).Range.Text = "检查负责人:" + onepvs.SearchForProperty(PropPrincipal.ID).GetValueAsLocalizedText();
                    doc.Tables[tableindex].Cell(0, 4).Range.Text = "复查人:" + onepvs.SearchForProperty(PropFuChaRen.ID).GetValueAsLocalizedText();

                    var serial = 1;
                    var lus    = onepvs.SearchForProperty(PropSecureIssues.ID).Value.GetValueAsLookups();
                    foreach (Lookup lookup in lus)
                    {
                        var rowindex = 6 + serial;
                        var objid    = new ObjID();
                        objid.SetIDs(OtSecureIssue.ID, lookup.Item);
                        var issuepvs = env.Vault.ObjectOperations.GetLatestObjectVersionAndProperties(objid, true).Properties;
                        secureissuename = issuepvs.SearchForProperty(0).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 1).Range.Text = serial.ToString();
                        doc.Tables[tableindex].Cell(rowindex, 2).Range.Text = secureissuename;
                        doc.Tables[tableindex].Cell(rowindex, 3).Range.Text = issuepvs.SearchForProperty(PropAdjustMeasure.ID).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 4).Range.Text = issuepvs.SearchForProperty(PropAdjustMan.ID).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 5).Range.Text = issuepvs.SearchForProperty(PropSecureAdjustDate.ID).GetValueAsLocalizedText();

                        var beforepictures = issuepvs.SearchForProperty(PropBeforePictures.ID).Value.GetValueAsLookups();
                        foreach (Lookup beforepicture in beforepictures)
                        {
                            var objver =
                                env.Vault.ObjectOperations.GetLatestObjVer(
                                    new ObjID {
                                ID = beforepicture.Item, Type = beforepicture.ObjectType
                            }, true);
                            var files = env.Vault.ObjectFileOperations.GetFiles(objver);
                            foreach (ObjectFile objectFile in files)
                            {
                                var apicture = temppath + objectFile.GetNameForFileSystem();
                                env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID,
                                                                            objectFile.Version, apicture);
                                object unite   = Microsoft.Office.Interop.Word.WdUnits.wdStory;
                                object nothing = System.Reflection.Missing.Value;
                                //    doc.Content.InsertParagraphAfter();
                                doc.Content.InsertAfter(string.Format("{3}安全隐患整改名称:{0},{3}安全问题名称:{1},{3}整改前照片名称:{2}{3}", issuename, secureissuename, beforepicture.DisplayValue, Environment.NewLine));
                                app.Selection.EndKey(ref unite, ref nothing);//将光标移至文末

                                object LinkToFile       = false;
                                object SaveWithDocument = true;
                                object Anchor           = app.Selection.Range;

                                doc.InlineShapes.AddPicture(apicture, ref LinkToFile, ref SaveWithDocument, ref Anchor);
                            }
                        }

                        var afterpictures = issuepvs.SearchForProperty(PropAfterPictures.ID).Value.GetValueAsLookups();
                        foreach (Lookup after in afterpictures)
                        {
                            var objver =
                                env.Vault.ObjectOperations.GetLatestObjVer(
                                    new ObjID {
                                ID = after.Item, Type = after.ObjectType
                            }, true);
                            var files = env.Vault.ObjectFileOperations.GetFiles(objver);
                            foreach (ObjectFile objectFile in files)
                            {
                                var apicture = temppath + objectFile.GetNameForFileSystem();
                                env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID,
                                                                            objectFile.Version, apicture);
                                object unite   = Microsoft.Office.Interop.Word.WdUnits.wdStory;
                                object nothing = System.Reflection.Missing.Value;
                                //      doc.Content.InsertParagraphAfter();
                                doc.Content.InsertAfter(string.Format("{3}安全隐患整改名称:{0},{3}安全问题名称:{1},{3}复查现场照片名称:{2}{3}", issuename, secureissuename, after.DisplayValue, Environment.NewLine));
                                app.Selection.EndKey(ref unite, ref nothing);//将光标移至文末

                                object LinkToFile       = false;
                                object SaveWithDocument = true;
                                object Anchor           = app.Selection.Range;

                                doc.InlineShapes.AddPicture(apicture, ref LinkToFile, ref SaveWithDocument, ref Anchor);
                            }
                        }

                        serial++;
                        if (serial > 12)
                        {
                            doc.Content.InsertParagraphAfter();
                            doc.Content.InsertAfter(" ");
                            object WdLine   = Microsoft.Office.Interop.Word.WdUnits.wdLine; //换一行;
                            var    movedown = app.Selection.MoveDown(ref WdLine, 21);       //移动焦点
                            Writelog(string.Format(" before paste table num=[{0}],count=[{1}],down==[{2}]", doc.Tables.Count.ToString(), movedown));
                            app.Selection.Paste();
                            page++;
                            tableindex++;
                            doc.Tables[tableindex].Cell(4, 2).Range.Text = "project name";
                            doc.Tables[tableindex].Cell(4, 4).Range.Text = DateTime.Now.ToShortDateString();
                            doc.Tables[tableindex].Cell(4, 6).Range.Text = page.ToString();
                            doc.Tables[tableindex].Cell(0, 1).Range.Text = "整改期限:" + onepvs.SearchForProperty(PropZhengGaiQiXin.ID).GetValueAsLocalizedText();
                            doc.Tables[tableindex].Cell(0, 2).Range.Text = "接收人:" + onepvs.SearchForProperty(PropSecureReceiver.ID).GetValueAsLocalizedText();
                            doc.Tables[tableindex].Cell(0, 3).Range.Text = "检查负责人:" + onepvs.SearchForProperty(PropPrincipal.ID).GetValueAsLocalizedText();
                            doc.Tables[tableindex].Cell(0, 4).Range.Text = "复查人:" + onepvs.SearchForProperty(PropFuChaRen.ID).GetValueAsLocalizedText();
                        }
                    }
                }

                doc.Close();
                app.Quit();
            }
            catch (Exception ex)
            {
                Writelog(ex.Message);
            }


            var pvs = new PropertyValues();
            var pv  = new PropertyValue();
            pv.PropertyDef = 0;
            pv.Value.SetValue(MFDataType.MFDatatypeText, "securenoticereport");
            pvs.Add(-1, pv);
            pv.PropertyDef = 100;
            pv.Value.SetValueToLookup(new Lookup {
                Item = ClassSecureReport
            });
            pvs.Add(-1, pv);
            var file = new SourceObjectFile();
            file.Title          = "report";
            file.SourceFilePath = templatefile;
            file.Extension      = "docx";

            var t   = env.Vault.ObjectOperations.CreateNewSFDObject(0, pvs, file, true);
            var f   = env.Vault.ObjectFileOperations.GetFiles(t.ObjVer);
            var rpd = new ReportPrintData();
            rpd.objid       = t.ObjVer.ID;
            rpd.objtype     = t.ObjVer.Type;
            rpd.objversion  = t.ObjVer.Version;
            rpd.fileid      = f[1].FileVer.ID;
            rpd.fileversion = f[1].FileVer.Version;

            return(JsonConvert.SerializeObject(rpd, Formatting.None));
        }
Exemple #9
0
        /// <summary>
        /// 接收的邮件写入MFiles
        /// </summary>
        /// <param name="vault">库</param>
        /// <param name="msg">邮件对象</param>
        /// <param name="folderId">文件ID</param>
        public static bool SaveRecvMailToMf(Vault vault, MimeMessage msg, int folderId)
        {
            var verIds   = new List <int>();
            var fileList = new List <string>();

            try
            {
                //保存附件
                var attachments = msg.Attachments.OfType <MimePart>().ToList();
                for (int i = 0; i < attachments.Count; i++)
                {
                    var attach   = attachments[i];
                    var filePath = GetTempFilePath(Path.GetExtension(attach.FileName));
                    MimePartToFile(attach, filePath);
                    fileList.Add(filePath);

                    //保存到MFiles
                    var sourceFiles = new SourceObjectFiles();
                    var sourceFile  = new SourceObjectFile
                    {
                        SourceFilePath = filePath,
                        Title          = attach.FileName.Substring(0, attach.FileName.LastIndexOf('.')),
                        Extension      = attach.FileName.Substring(attach.FileName.LastIndexOf('.') + 1),
                    };
                    sourceFiles.Add(i, sourceFile);

                    var versionAndProperties = vault.ObjectOperations.CreateNewObject(
                        (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
                        GetAttachmentPropertyValues(vault, sourceFile.Title, "ClassMailAttachments"),
                        sourceFiles);
                    vault.ObjectOperations.CheckIn(versionAndProperties.ObjVer);
                    verIds.Add(versionAndProperties.ObjVer.ObjID.ID);
                }

                {
                    //保存邮件
                    var filePath = GetTempFilePath(".html");
                    using (var writer = File.CreateText(filePath))
                    {
                        writer.Write(GetMailHtml(msg));
                        writer.Flush();
                        writer.Close();
                    }
                    fileList.Add(filePath);

                    //保存到MFiles
                    var properties = new List <MfProperty>
                    {
                        new MfProperty("PropMailSender", MFDataType.MFDatatypeLookup, ConvertAddrsToIds(vault, msg.From.Mailboxes)),
                        new MfProperty("PropMailReceiver", MFDataType.MFDatatypeMultiSelectLookup, ConvertAddrsToIds(vault, msg.To.Mailboxes)),
                        new MfProperty("PropMailCc", MFDataType.MFDatatypeMultiSelectLookup, ConvertAddrsToIds(vault, msg.Cc.Mailboxes)),
                        new MfProperty("PropMailSubject", MFDataType.MFDatatypeText, msg.Subject),
                        new MfProperty("PropMailCreatedTime", MFDataType.MFDatatypeDate, msg.Date.DateTime),
                        new MfProperty("PropMailFolders", MFDataType.MFDatatypeLookup, folderId),
                        new MfProperty("PropTags", MFDataType.MFDatatypeText, msg.MessageId),
                        new MfProperty("PropEmailAttachments", MFDataType.MFDatatypeMultiSelectLookup, verIds.ToArray()),
                        new MfProperty("PropIsRead", MFDataType.MFDatatypeBoolean, false)
                    };

                    var sourceFiles = new SourceObjectFiles();
                    var sourceFile  = new SourceObjectFile
                    {
                        SourceFilePath = filePath,
                        Title          = msg.Subject,
                        Extension      = "html"
                    };
                    sourceFiles.Add(0, sourceFile);

                    var versionAndProperties = vault.ObjectOperations.CreateNewObject(
                        (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
                        GetMailContentPropertyValues(vault, "ClassProjMail", properties),
                        sourceFiles);
                    vault.ObjectOperations.CheckIn(versionAndProperties.ObjVer);
                }
            }
            catch (Exception ex)
            {
                Common.Logger.Log.ErrorFormat("exception. save received email to mfiles error: {0}", ex.Message);
                return(false);
            }

            //删除临时文件
            DelFileList(fileList);
            return(true);
        }
Exemple #10
0
        /// <summary>
        /// 发送的邮件写入MFiles
        /// </summary>
        /// <param name="vault">库</param>
        /// <param name="msg">邮件对象</param>
        /// <param name="folderId">文件夹ID</param>
        public static bool SaveSendMailToMf(Vault vault, MailMessage msg, int folderId)
        {
            var result   = false;
            var verIds   = new List <int>();
            var fileList = new List <string>();

            try
            {
                //保存附件
                var attachs = msg.Attachments;
                if (attachs.Count > 0)
                {
                    for (var i = 0; i < attachs.Count; i++)
                    {
                        //保存到本地
                        var attach     = attachs[i];
                        var filePath   = GetTempFilePath(Path.GetExtension(attach.Name));
                        var fileStream = attach.ContentStream as FileStream;
                        fileList.Add(filePath);

                        //保存到MFiles
                        var sourceFiles = new SourceObjectFiles();
                        if (fileStream != null)
                        {
                            var sourceFile = new SourceObjectFile
                            {
                                SourceFilePath = fileStream.Name,
                                Title          = attach.Name.Substring(0, attach.Name.LastIndexOf('.')),
                                Extension      = attach.Name.Substring(attach.Name.LastIndexOf('.') + 1),
                            };
                            sourceFiles.Add(i, sourceFile);

                            var versionAndProperties = vault.ObjectOperations.CreateNewObject(
                                (int)MFilesAPI.MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
                                GetAttachmentPropertyValues(vault, sourceFile.Title, "ClassMailAttachments"),
                                sourceFiles);
                            vault.ObjectOperations.CheckIn(versionAndProperties.ObjVer);
                            verIds.Add(versionAndProperties.ObjVer.ObjID.ID);
                        }
                    }
                }

                //保存邮件
                var html = CombineHtmlString(msg.Body);
                if (html.Length > 0)
                {
                    //保存到本地
                    var filePath = GetTempFilePath(".html");
                    using (var writer = new StreamWriter(filePath, false, Encoding.UTF8))
                    {
                        writer.Write(html);
                        writer.Flush();
                        writer.Close();
                    }
                    fileList.Add(filePath);

                    //保存到MFiles
                    var properties = new List <MfProperty>
                    {
                        new MfProperty("PropMailSender", MFDataType.MFDatatypeLookup, ConvertAddrToId(vault, msg.From)),
                        new MfProperty("PropMailReceiver", MFDataType.MFDatatypeMultiSelectLookup, ConvertAddrsToIds(vault, msg.To)),
                        new MfProperty("PropMailCc", MFDataType.MFDatatypeMultiSelectLookup, ConvertAddrsToIds(vault, msg.CC)),
                        new MfProperty("PropMailSubject", MFDataType.MFDatatypeText, msg.Subject),
                        new MfProperty("PropMailCreatedTime", MFDataType.MFDatatypeDate, DateTime.Now.ToUniversalTime()),
                        new MfProperty("PropMailFolders", MFDataType.MFDatatypeLookup, folderId),
                        new MfProperty("PropTags", MFDataType.MFDatatypeText, msg.Headers.Get("MessageId")),
                        new MfProperty("PropEmailAttachments", MFDataType.MFDatatypeMultiSelectLookup, verIds.ToArray()),
                        new MfProperty("PropIsRead", MFDataType.MFDatatypeBoolean, true)
                    };

                    var sourceFiles = new SourceObjectFiles();
                    var sourceFile  = new SourceObjectFile
                    {
                        SourceFilePath = filePath,
                        Title          = msg.Subject,
                        Extension      = "html"
                    };
                    sourceFiles.Add(0, sourceFile);

                    //
                    var searchObj = SearchMailFromMf(vault, msg.Headers.Get("MessageId"));
                    if (searchObj.Count == 0)
                    {
                        //创建邮件对象
                        result = CreateMailToMf(vault, GetMailContentPropertyValues(vault, "ClassProjMail", properties), sourceFiles);
                    }
                    else
                    {
                        //更新邮件对象
                        result = UpdateMailToMf(vault, searchObj[1], GetMailContentPropertyValues(vault, properties), sourceFiles);
                    }

                    //Todo
                    //发送草稿
                }
            }
            catch (Exception ex)
            {
                Common.Logger.Log.ErrorFormat("exception. save sent email to mfiles error: {0}", ex.Message);
                result = false;
            }

            //删除临时文件
            DelFileList(fileList);
            return(result);
        }