Пример #1
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);
        }
Пример #2
0
        private static List <string> GetProps(SelectedFile file, int propCount)
        {
            var filePath       = file.Filepath;
            var strs           = filePath.Split(Path.DirectorySeparatorChar);
            var emptyPropCount = propCount - strs.Length;
            var list           = new List <string>();
            var fileName       = file.NewFilename;

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = strs[strs.Length - 1];
            }
            list.Add(fileName);
            list.AddRange(strs.Take(strs.Length - 1));
            if (emptyPropCount > 0)
            {
                list.AddRange(Enumerable.Range(0, emptyPropCount).Select(c => ""));
            }
            return(list);
        }
Пример #3
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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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();
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
 /// <summary>
 /// 获取文件夹层次列表,文件名或放在第一位,后位补空字符串
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public List <string> GetProps(SelectedFile file)
 {
     return(GetProps(file, LayerCount));
 }