示例#1
0
        public static SelectedFiles GetFiles(string dir)
        {
            var files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);

            if (!dir.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                dir += Path.DirectorySeparatorChar;
            }

            var sf = new SelectedFiles {
                RootDir = dir
            };

            foreach (var f in files)
            {
                var rf   = f.Substring(dir.Length);
                var selF = new SelectedFile {
                    Filepath = rf, NewFilename = Path.GetFileName(f)
                };
                sf.Files.Add(selF);
            }
            return(sf);
        }
示例#2
0
文件: MfVault.cs 项目: weijx-xa/test
        private SearchConditions GetSearchPropValues(SelectedFiles files, SelectedFile file,
                                                     List <MfClassPropDef> selProps, List <string> addedValues, TraceSource log)
        {
            var scs    = new SearchConditions();
            var values = files.GetProps(file);

            for (var i = 0; i < values.Count; i++)
            {
                var vv = values[i];
                if (i == 0)
                {
                    var dotIndex = vv.LastIndexOf('.');
                    vv = vv.Substring(0, dotIndex);
                }
                //if (selProps[i].Required)
                {
                    var def = selProps[i].Def;
                    var sc  = new SearchCondition {
                        ConditionType = MFConditionType.MFConditionTypeEqual
                    };
                    sc.Expression.DataPropertyValuePropertyDef = def;
                    if (!String.IsNullOrEmpty(vv))
                    {
                        var mfVal = GetValue(selProps[i].PropDef, vv, log);
                        sc.TypedValue.SetValue((MFDataType)selProps[i].DataType, mfVal);
                    }
                    else
                    {
                        sc.TypedValue.SetValueToNULL((MFDataType)selProps[i].DataType);
                    }

                    scs.Add(-1, sc);
                }
            }
            var diff = selProps.Count - values.Count;

            if (diff > 0)
            {
                if (addedValues.Count < diff)
                {
                    addedValues =
                        addedValues.Concat(Enumerable.Range(1, diff - addedValues.Count).Select(c => String.Empty))
                        .ToList();
                }
                for (var i = 0; i < diff; i++)
                {
                    var selProp = selProps[values.Count + i];
                    var def     = selProp.Def;
                    var sc      = new SearchCondition {
                        ConditionType = MFConditionType.MFConditionTypeEqual
                    };
                    sc.Expression.DataPropertyValuePropertyDef = def;
                    var vv = addedValues[i];
                    if (!String.IsNullOrEmpty(vv))
                    {
                        var mfVal = GetValue(selProp.PropDef, vv, log);
                        sc.TypedValue.SetValue((MFDataType)selProp.DataType, mfVal);
                    }
                    else
                    {
                        sc.TypedValue.SetValueToNULL((MFDataType)selProp.DataType);
                    }
                    scs.Add(-1, sc);
                }
            }
            return(scs);
        }
示例#3
0
文件: MfVault.cs 项目: weijx-xa/test
        public string FileToSystem(SelectedFiles files, SelectedFile f, MfClass mfClass, List <MfClassPropDef> selProps, List <string> addedPropValues)
        {
            var err     = String.Empty;
            var log     = TraceLog.GetLogger <MfVault>(MethodBase.GetCurrentMethod().Name);
            var classId = mfClass.Id;

            try
            {
                var scs     = GetSearchPropValues(files, f, selProps, addedPropValues, log);
                var classSC = new SearchCondition {
                    ConditionType = MFConditionType.MFConditionTypeEqual
                };
                classSC.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass;
                classSC.TypedValue.SetValue(MFDataType.MFDatatypeLookup, classId);
                scs.Add(-1, classSC);

                var ext = Path.GetExtension(f.Filepath) ?? String.Empty;
                ext = ext.TrimStart('.');
                if (!String.IsNullOrEmpty(ext))
                {
                    var namePattern = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeMatchesWildcardPattern
                    };
                    namePattern.Expression.SetFileValueExpression(MFFileValueType.MFFileValueTypeFileName);
                    namePattern.TypedValue.SetValue(MFDataType.MFDatatypeText, "*." + ext);
                    scs.Add(-1, namePattern);
                }
                var res = _vault.ObjectSearchOperations.SearchForObjectsByConditions(scs,
                                                                                     MFSearchFlags.MFSearchFlagNone, false).GetAsObjectVersions();
                if (res.Count > 0)
                {
                    err = "对象已存在:" + res[1].Title;
                    log.TraceEvent(TraceEventType.Warning, 0, err);
                    return(err);
                }
                else
                {
                    try
                    {
                        var pvs = GetCreationPropValues(classId, files, f, selProps, addedPropValues, log);
                        var sof = GetFileObject(files.RootDir, f);
                        var obj =
                            _vault.ObjectOperations.CreateNewSFDObject(
                                (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument
                                , pvs, sof, true, new AccessControlList());
                        log.TraceInformation("创建对象:" + obj.VersionData.Title);
                        return(err);
                    }
                    catch (Exception ex)
                    {
                        err = "创建对象失败:" + ex.Message; //files.GetFullpath(f.Filepath) + " # " +
                        log.TraceEvent(TraceEventType.Error, 0, err);
                        return(err);
                    }
                }
            }
            catch (Exception ex)
            {
                err = "属性值有误:" + ex.Message;
                log.TraceEvent(TraceEventType.Error, 0, err);
                return(err);
            }
            finally
            {
                log.Close();
            }
        }
示例#4
0
文件: MfVault.cs 项目: weijx-xa/test
        private PropertyValues GetCreationPropValues(int classId, SelectedFiles files, SelectedFile file,
                                                     List <MfClassPropDef> selProps, List <string> addedPropValues, TraceSource log)
        {
            var pvs = new PropertyValues();

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

            classPV.TypedValue.SetValue(MFDataType.MFDatatypeLookup, classId);
            pvs.Add(-1, classPV);

            var values = files.GetProps(file);

            for (var i = 0; i < values.Count; i++)
            {
                var vv = values[i];
                if (i == 0)
                {
                    var dotIndex = vv.LastIndexOf('.');
                    vv = vv.Substring(0, dotIndex);
                }
                var v = GetValue(selProps[i].PropDef, vv, log);
                if (v != null)
                {
                    var pv = new PropertyValue {
                        PropertyDef = selProps[i].Def
                    };
                    pv.TypedValue.SetValue((MFDataType)selProps[i].DataType, v);
                    pvs.Add(-1, pv);
                }
            }
            var diff = selProps.Count - values.Count;

            if (diff > 0)
            {
                for (var i = 0; i < diff; i++)
                {
                    var p  = selProps[i + values.Count];
                    var vv = addedPropValues[i];
                    var v  = GetValue(p.PropDef, vv, log);
                    if (v != null)
                    {
                        var pv = new PropertyValue {
                            PropertyDef = p.Def
                        };
                        pv.TypedValue.SetValue((MFDataType)p.DataType, v);
                        pvs.Add(-1, pv);
                    }
                    else if (p.Required)
                    {
                    }
                    //var pv = new PropertyValue {PropertyDef = p.Def};
                    //if (String.IsNullOrEmpty(v))
                    //{
                    //    pv.TypedValue.SetValueToNULL(MFDataType.MFDatatypeText);
                    //}
                    //else
                    //{
                    //    pv.TypedValue.SetValue(MFDataType.MFDatatypeText, v);
                    //}
                    //pvs.Add(-1, pv);
                }
            }
            return(pvs);
        }