Ejemplo n.º 1
0
        internal static void Create(Vault vault, MFObject obj)
        {
            //  Writelog(string.Format("--11--{0},{1},{2}",obj.Id,obj.Properties.Count,obj));
            var objType = MfAlias.GetObjType(vault, obj.ObjDef.TypeAlias);
            //   Writelog("--22--");
            var objClass = MfAlias.GetObjectClass(vault, obj.ObjDef.ClassAlias);
            //   Writelog("--33--");
            var pvs     = new PropertyValues();
            var classPV = MFPropertyUtils.Class(objClass);

            pvs.Add(-1, classPV);
            //   Writelog("--44--");
            SetProperties(vault, pvs, obj);

            var isSingleFile = false;
            //   Writelog("--55--");
            SourceObjectFiles files = null;

            if (obj.Filepaths != null && obj.Filepaths.Count > 0)
            {
                files = new SourceObjectFiles();
                //todo
                if (obj.Filepaths.Count == 1)
                {
                    isSingleFile = true;
                }
                //    Writelog("--66--");
            }
            var singleFilePV = MFPropertyUtils.SingleFile(isSingleFile);

            pvs.Add(-1, singleFilePV);
            //   Writelog("--77--");
            try
            {
                var objVersion = vault.ObjectOperations.CreateNewObject(objType, pvs, files);
                //     Writelog("--88--");
                var newObjVersion = vault.ObjectOperations.CheckIn(objVersion.ObjVer);

                obj.Id = newObjVersion.ObjVer.ID;
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("CreateNewObject error:{0},{1},{2}", objType, pvs.Count, ex.Message));
            }
        }
Ejemplo n.º 2
0
        private static void SetProperties(Vault vault, PropertyValues pvs, MFObject obj)
        {
            foreach (var key in obj.Properties.Keys)
            {
                var value = obj.Properties[key];
                try
                {
                    //if (!obj.ObjDef.Properties.ContainsKey(key))
                    //{

                    //}
                    var propId = MfAlias.GetPropDef(vault, obj.ObjDef.Properties[key]);
                    var pv     = MFPropertyUtils.Create(vault, propId, value);
                    pvs.Add(-1, pv);
                }
                catch (Exception ex)
                {
                    Log.Error("创建MF对象失败:" + ex.Message, ex);
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成对象属性
        /// </summary>
        /// <param name="vault">MFiles库对象</param>
        /// <param name="aliasName">类的别名</param>
        /// <param name="properties">属性集合</param>
        /// <returns></returns>
        private static PropertyValues GetContactsPropertyValues(Vault vault, string aliasName, IEnumerable <MfProperty> properties)
        {
            var oPropValues = new PropertyValues();

            var propValue1 = MFPropertyUtils.Lookup(
                (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass,
                vault.ClassOperations.GetObjectClassIDByAlias(aliasName));

            oPropValues.Add(-1, propValue1);

            foreach (var item in properties)
            {
                var propValue3 = new PropertyValue
                {
                    PropertyDef = vault.PropertyDefOperations.GetPropertyDefIDByAlias(item.PropertyName)
                };
                propValue3.TypedValue.SetValue(item.PropertyType, item.PropertyValue);
                oPropValues.Add(-1, propValue3);
            }

            return(oPropValues);
        }