public async Task <int> AddOrUpdateAssetProperty(AssetProperty assetProperty)
        {
            if (assetProperty == null)
            {
                throw new ArgumentException($"assetProperty");
            }

            var assetPropAtDB = GetAssetProperty(ap =>
                                                 ap.AssetId == assetProperty.AssetId && ap.Property == assetProperty.Property)
                                .ToList().FirstOrDefault();

            if (assetPropAtDB == null)
            {
                _logger.Information($"AssetId: '{assetProperty.AssetId}' and Property: '{assetProperty.Property}', could not be found on the DB");
                await InsertAssetProperty(assetProperty);
            }
            else if (assetPropAtDB.Timestamp < assetProperty.Timestamp)
            {
                assetPropAtDB.Value     = assetProperty.Value;
                assetPropAtDB.Timestamp = assetProperty.Timestamp;
                _dbSetAssetProperty.Update(assetPropAtDB);
            }

            _context.Database.ExecuteSqlInterpolated($"SET IDENTITY_INSERT {typeof(Asset).Name} ON;");

            int numberOfChanges = SaveChanges();

            _context.Database.ExecuteSqlInterpolated($"SET IDENTITY_INSERT {typeof(Asset).Name} OFF;");

            return(await Task.Run(() => numberOfChanges));
        }
示例#2
0
        public async Task <ActionResult> Post(IFormFile file)
        {
            try
            {
                List <asset_csv> rows           = new List <asset_csv>();
                AssetProperty    _assetProperty = new AssetProperty();
                Services         _services      = new Services(_dbcontext);

                if (file != null && file.FileName.Length > 0 && file.FileName.EndsWith(".csv"))
                {
                    rows = _services.ReadCSVFileUpload(file);
                }
                else
                {
                    rows = _services.ReadCSVFile(_Configuration.GetValue <string>("AppIdentitySettings:InputPath"));
                }

                if (rows != null)
                {
                    foreach (var row in rows)
                    {
                        //If asset from file cannot be found in DB it has to be logged (anyhow can be even console).
                        var _assetInstance = _dbcontext.asset.Where(x => x.id == row.assetid).FirstOrDefault();
                        if (_assetInstance == null)
                        {
                            Console.WriteLine("Skipping row: " + row.assetid.ToString() + row.properties.ToString());
                            continue;
                        }

                        var _assetPropertyInstance = _dbcontext.asset_property.Where(x => x.asset.id == row.assetid && x.name == row.properties).FirstOrDefault();
                        if (_assetPropertyInstance == null)
                        {
                            var _newAssetProperty = new AssetProperty
                            {
                                asset = _assetInstance,
                                name  = row.properties,
                                value = false
                            };
                            _dbcontext.asset_property.Add(_newAssetProperty);
                            await _dbcontext.SaveChangesAsync();
                        }
                        else if (_assetPropertyInstance.time_stamp < row.time_stamp)
                        {
                            _assetPropertyInstance.value      = row.value;
                            _assetPropertyInstance.time_stamp = row.time_stamp;
                            await _dbcontext.SaveChangesAsync();
                        }
                        else
                        {
                            Console.WriteLine("Skipping row: " + row.assetid.ToString() + row.properties.ToString());
                        }
                    }
                }
                return(Ok("Data Successfully Inserted !!!"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#3
0
        public static MatType GetMaterialType(Asset asset)
        {
            string str = "";
            for (int index = 0; index < asset.Size; ++index)
            {
                AssetProperty assetProperty = asset[index];
                if (assetProperty.Name == "ImplementationOGS")
                {
                    str = (assetProperty as AssetPropertyString).Value;
                    break;
                }
            }
            string n = "";
#if _Revit2016
            string path = GetProteinLibraryPath() + "2016\\assetlibrary_base.fbm\\" + str;
#elif _Revit2017
            string path = GetProteinLibraryPath() + "2017\\assetlibrary_base.fbm\\" + str;
#elif _Revit2018
            string path = GetProteinLibraryPath() + "2018\\assetlibrary_base.fbm\\" + str;
#endif
            if (File.Exists(path))
            {
                XmlDocument xmlDocument = new XmlDocument();
                string filename = path;
                xmlDocument.Load(filename);
                foreach (XmlNode xmlNode in xmlDocument.DocumentElement.SelectNodes("/implementation/bindings/desc"))
                {
                    n = xmlNode.Attributes[1].Value;
                    if (n != "")
                        break;
                }
            }

            return GetMaterialType(n);
        }
        public async Task <int> Handle(UpdateAssetPropertyCommand request, CancellationToken cancellationToken)
        {
            try
            {
                if (request.AssetId <= 0)
                {
                    throw new ArgumentException("assetId <= 0 ");
                }

                // Other validations could come here

                AssetProperty assetProperty = new AssetProperty()
                {
                    AssetId   = request.AssetId,
                    Property  = request.Property,
                    Value     = request.Value,
                    Timestamp = request.Timestamp
                };

                return(await _assetRepository.AddOrUpdateAssetProperty(assetProperty));
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#5
0
        private string FindTexturePathInAssetProperty(AssetProperty assetProperty)
        {
            AssetPropertyType type = assetProperty.Type;

            if (type != AssetPropertyType.String)             //String = 11,非字符串类型,判定为Asset类型。
            {
                if (type == AssetPropertyType.Asset)          //Asset = 15
                {
                    string text = FindTexturePathInAsset(assetProperty as Asset);
                    if (text.Length > 0)
                    {
                        return(text);
                    }
                }
            }
            else if (assetProperty.Name == "unifiedbitmap_Bitmap")
            {
                return((assetProperty as AssetPropertyString).Value.ToString());
            }
            for (int i = 0; i < assetProperty.NumberOfConnectedProperties; i++)
            {
                string text2 = FindTexturePathInAssetProperty(assetProperty.GetConnectedProperty(i));
                if (text2.Length > 0)
                {
                    return(text2);
                }
            }
            return("");
        }
示例#6
0
        //以下参考Command类。
        private string GetAssetDescription(Asset asset)
        {
            //获取资产说明

            //定义初始化字符串
            string str = "";

            //如果当前连接的属性数是否大于零。那么加入字符串“Asset CONNECTED START\n”。
            if (asset.NumberOfConnectedProperties > 0)
            {
                str += "Asset CONNECTED START\n";
            }
            //
            for (int i = 0; i < asset.NumberOfConnectedProperties; i++)
            {
                str = str + "       " + GetPropertyDescription(asset.GetConnectedProperty(i));
            }
            if (asset.NumberOfConnectedProperties > 0)
            {
                str += "Asset CONNECTED END\n";
            }
            str += "Asset prop START\n";
            for (int j = 0; j < asset.Size; j++)
            {
                AssetProperty assetProperty = asset.Get(j);
                str += GetPropertyDescription(assetProperty);
            }
            return(str + "Asset prop EEND\n");
        }
            /// <summary>
            /// Get Asset's property descriptors
            /// </summary>
            private void GetAssetProperties()
            {
                if (null == m_propertyDescriptors)
                {
                    m_propertyDescriptors = new PropertyDescriptorCollection(new AssetPropertyPropertyDescriptor[0]);
                }
                else
                {
                    return;
                }

                //For each AssetProperty in Asset, create an AssetPropertyPropertyDescriptor.
                //It means that each AssetProperty will be a property of Asset
                for (int index = 0; index < m_asset.Size; index++)
                {
                    //AssetProperty assetProperty = m_asset[index]; // 2018
                    AssetProperty assetProperty = m_asset.Get(index); // 2019

                    if (null != assetProperty)
                    {
                        AssetPropertyPropertyDescriptor assetPropertyPropertyDescriptor = new AssetPropertyPropertyDescriptor(assetProperty);
                        m_propertyDescriptors.Add(assetPropertyPropertyDescriptor);
                    }
                }
            }
 /// <summary>
 /// 自定义方法,用递归找到包含贴图信息:Asset包含的AssetProperty有多种类型,其中Asset、Properties
 /// 和Reference这三种必须递归处理。贴图信息的AssetProperty名字是unifiedbitmap_Bitmap,类型是String。
 /// </summary>
 /// <param name="ap"></param>
 /// <returns></returns>
 private Autodesk.Revit.DB.Visual.Asset FindTextureAsset(AssetProperty ap)
 {
     Autodesk.Revit.DB.Visual.Asset result = null;
     if (ap.Type == AssetPropertyType.Asset)
     {
         if (!IsTextureAsset(ap as Autodesk.Revit.DB.Visual.Asset))
         {
             for (int i = 0; i < (ap as Autodesk.Revit.DB.Visual.Asset).Size; i++)
             {
                 if (null != FindTextureAsset((ap as Autodesk.Revit.DB.Visual.Asset)[i]))
                 {
                     result = FindTextureAsset((ap as Autodesk.Revit.DB.Visual.Asset)[i]);
                     break;
                 }
             }
         }
         else
         {
             result = ap as Autodesk.Revit.DB.Visual.Asset;
         }
         return(result);
     }
     else
     {
         for (int j = 0; j < ap.NumberOfConnectedProperties; j++)
         {
             if (null != FindTextureAsset(ap.GetConnectedProperty(j)))
             {
                 result = FindTextureAsset(ap.GetConnectedProperty(j));
             }
         }
         return(result);
     }
 }
示例#9
0
        public static string GetStringValueFromAsset(AssetProperty assetProp, out double scaleX, out double scaleY)
        {
            scaleX = 1.0;
            scaleY = 1.0;

            if (assetProp == null)
                return string.Empty;

            if (assetProp.NumberOfConnectedProperties < 1)
                return string.Empty;

            var connectedAsset = assetProp.GetConnectedProperty(0) as Asset;
            if (connectedAsset == null)
                return string.Empty;

            double x, y;
            string res = string.Empty;
            GetMapNameAndScale(connectedAsset, out res, out x, out y);
            if (string.IsNullOrEmpty(res))
                return string.Empty;

            scaleX = x;
            scaleY = y;

            return res;
        }
示例#10
0
        private void addButton_Click(object sender, EventArgs e)
        {
            AssetProperty newProperty = new AssetProperty(propertyTextBox.Text, valueTextBox.Text);

            assetPropertyList.Add(newProperty);
            propertyListBox.Items.Add(String.Format("{0}={1}", newProperty.Name, newProperty.Value) as object);
            somethingChanged = true;
        }
示例#11
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(AssetProperty model)
 {
     using (var conn = DapperHelper.CreateConnection())
     {
         string sql =
             "Insert into AssetProperty(Id, Name, DictionaryId, AssetTypeId, CreateTime, CreateBy, ModifyTime, ModifyBy) values(@Id, @Name, @DictionaryId, @AssetTypeId, @CreateTime, @CreateBy, @ModifyTime, @ModifyBy)";
         return(conn.Execute(sql, model));
     }
 }
示例#12
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(AssetProperty model)
 {
     using (var conn = DapperHelper.CreateConnection())
     {
         string sql =
             "Update AssetProperty set Name=@Name,ModifyTime=@ModifyTime,ModifyBy=@ModifyBy where AssetTypeId=@AssetTypeId";
         return(conn.Execute(sql, model));
     }
 }
示例#13
0
 /// <summary>
 /// 读取Asset
 /// </summary>
 /// <param name="asset"></param>
 /// <param name="ttrgb"></param>
 public void ReadAsset(Asset asset, string ttrgb)
 {
     // 遍历Asset中的各个属性.
     for (int idx = 0; idx < asset.Size; idx++)
     {
         AssetProperty prop = asset[idx];
         ReadAssetProperty(prop, ttrgb);
     }
 }
示例#14
0
 public void ReadAsset(Asset asset, StreamWriter objWriter)
 {
     _priexFix += "\t";
     for (int idx = 0; idx < asset.Size; idx++)
     {
         AssetProperty prop = asset[idx];
         ReadAssetProperty(prop, objWriter);
     }
     _priexFix = _priexFix.Substring(0, _priexFix.Length - 1);
 }
        /// <summary>
        /// 自定义方法,判断Asset是否包含贴图信息
        /// </summary>
        /// <param name="asset"></param>
        /// <returns></returns>
        private bool IsTextureAsset(Autodesk.Revit.DB.Visual.Asset asset)
        {
            AssetProperty assetProprty = GetAssetProprty(asset, "assettype");

            if (assetProprty != null && (assetProprty as AssetPropertyString).Value == "texture")
            {
                return(true);
            }
            return(GetAssetProprty(asset, "unifiedbitmap_Bitmap") != null);
        }
示例#16
0
 //未使用的方法
 //在资源中查找纹理路径
 private string FindTexturePathInAsset(Asset asset)
 {
     for (int i = 0; i < asset.Size; i++)
     {
         AssetProperty assetProperty = asset.Get(i);                //获取给定索引处的属性。
         string        text          = FindTexturePathInAssetProperty(assetProperty);
         if (text.Length > 0)
         {
             return(text);
         }
     }
     return("");
 }
示例#17
0
        private static AssetProperty CreateFromReadLine(ref string line)
        {
            line = line.Replace("\"", "");
            var           values        = line.Split(',');
            AssetProperty assetProperty = new AssetProperty()
            {
                AssetId   = Convert.ToInt32(values[0]),
                Property  = values[1].Trim(),
                Value     = Boolean.Parse(values[2].Trim()),
                Timestamp = DateTime.ParseExact(values[3].Trim(), "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture)
            };

            return(assetProperty);
        }
示例#18
0
        private static void SetCustomProperty<T>(AssetInfo assetInfo, string key, T value)
        {
            if (assetInfo.details == null)
                assetInfo.details = new AssetProperty[0];

            var existing = assetInfo.details.FirstOrDefault(x => x.name == key);
            if (existing != null)
            {
                existing.value = value.ToString();
            }
            else
            {
                ArrayUtility.Add(ref assetInfo.details, AssetProperty.Create(key, value));
            }
        }
    // Show a dialog with the asset proprieties
    private string GetAssetProperties(Asset theAsset)
    {
        List <AssetProperty> assets = new List <AssetProperty>();

        for (int idx = 0; idx < theAsset.Size; idx++)
        {
            AssetProperty ap = theAsset[idx];
            assets.Add(ap);
        }

        String res = "";

        // order the properties!
        assets = assets.OrderBy(ap => ap.Name).ToList();
        for (int idx = 0; idx < assets.Count; idx++)
        {
            AssetProperty ap    = assets[idx];
            Type          type  = ap.GetType();
            object        apVal = null;
            try
            {
                // using .net reflection to get the value
                var prop = type.GetProperty("Value");
                if (prop != null &&
                    prop.GetIndexParameters().Length == 0)
                {
                    apVal = prop.GetValue(ap);
                }
                else
                {
                    apVal = "<No Value Property>";
                }
            }
            catch (Exception ex)
            {
                apVal = ex.GetType().Name + "-" + ex.Message;
            }

            if (apVal is DoubleArray)
            {
                var doubles = apVal as DoubleArray;
                apVal = doubles.Cast <double>().Aggregate("", (s, d) => s + Math.Round(d, 5) + ",");
            }
            res += idx + " : [" + ap.Type + "] " + ap.Name + " = " + apVal + "\n";
        }

        return(res);
    }
示例#20
0
        void ChangeRenderingTexturePath(Document doc)
        {
            // As there is only one material in the sample
            // project, we can use FilteredElementCollector
            // and grab the first result

            Material mat = new FilteredElementCollector(doc).OfClass(typeof(Material)).FirstElement() as Material;

            // Fixed path for new texture
            // Texture included in sample files

            string texturePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "new_texture.png");

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Changing material texture path");

                using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
                {
                    Asset editableAsset = editScope.Start(mat.AppearanceAssetId);

                    // Getting the correct AssetProperty

                    AssetProperty assetProperty = editableAsset["generic_diffuse"];


                    Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;

                    // Getting the right connected Asset

                    if (connectedAsset.Name == "UnifiedBitmapSchema")
                    {
                        AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;

                        if (path.IsValidValue(texturePath))
                        {
                            path.Value = texturePath;
                        }
                    }
                    editScope.Commit(true);
                }
                TaskDialog.Show("Material texture path", "Material texture path changed to:\n" + texturePath);

                t.Commit();
                t.Dispose();
            }
        }
示例#21
0
        /// <summary>
        /// 更改外观
        /// </summary>
        /// <param name="material"></param>
        /// <param name="bumpmapImageFilepath"></param>
        public static void ChangeRenderingTexturePath(Material mat, Document doc, string texturePath, double x, double y)
        {
            using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
            {
                Asset editableAsset = editScope.Start(mat.AppearanceAssetId);

#if VERSION2018
                AssetProperty assetProperty = editableAsset["generic_diffuse"];
#else
                // VERSION2019
                AssetProperty assetProperty = editableAsset.FindByName("generic_diffuse");
#endif
                Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;

                /*if (connectedAsset == null)
                 * {
                 *
                 *  // Add a new default connected asset
                 *  assetProperty.AddConnectedAsset("UnifiedBitmap");
                 *  connectedAsset = assetProperty.GetSingleConnectedAsset();
                 * }*/
                if (connectedAsset.Name == "UnifiedBitmapSchema")
                {
                    // TaskDialog.Show("Tip", "成功");
                    AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;

                    AssetPropertyBoolean scalelock = connectedAsset.FindByName(UnifiedBitmap.TextureScaleLock) as AssetPropertyBoolean;
                    scalelock.Value = false;
                    AssetPropertyDistance sizeY = connectedAsset.FindByName(UnifiedBitmap.TextureRealWorldScaleY) as AssetPropertyDistance;
                    sizeY.Value = y;
                    AssetPropertyDistance sizeX = connectedAsset.FindByName(UnifiedBitmap.TextureRealWorldScaleX) as AssetPropertyDistance;
                    sizeX.Value = x;
                    if (path.IsValidValue(texturePath))
                    {
                        path.Value = texturePath;
                    }
                    else
                    {
                        throw new Exception("找不到文件:" + texturePath);
                        //TaskDialog.Show("Tip", "文件路径错误");
                    }
                }

                editScope.Commit(true);
            }
        }
示例#22
0
        public async Task <SaveResponseDto> Update(AssetProperty entity)
        {
            if (entity.DataId == null)
            {
                var id = _assetPropertyRepository.GetLast().Id;

                entity.DataId = DataIdGenerationService.GenerateDataId(id, "AR");
            }
            var response = await _assetPropertyRepository.UpdateAsync(entity, entity.Id);

            return(new SaveResponseDto
            {
                SavedDataId = entity.DataId,
                SavedEntityId = entity.AssetId,
                SaveSuccessful = response != null,
                ErrorMessage = response == null ? string.Empty : "update failed"
            });
        }
示例#23
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //获取当前文档
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;
            //指定输出信息的文件
            FileStream   fs = new FileStream(@"C:\Users\11265\Desktop\0.txt", FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs);
            //指定存放贴图路径的列表
            List <string> oldPathList           = new List <string>();
            List <string> newPathList           = new List <string>();
            List <string> fileNameList          = new List <string>();
            Dictionary <string, string> dicPath = new Dictionary <string, string>();



            // 获取元素
            IList <Reference> referList = uiDoc.Selection.PickObjects(ObjectType.Element, "请框选需要的构件");
            Element           elem      = doc.GetElement(referList.First().ElementId);
            //获取元素的材质
            ICollection <ElementId> ids = elem.GetMaterialIds(false);
            Material material           = doc.GetElement(ids.First()) as Material;
            AppearanceAssetElement appearanceAssetElement = doc.GetElement(material.AppearanceAssetId) as AppearanceAssetElement;
            Asset asset = appearanceAssetElement.GetRenderingAsset();

            for (int i = 0; i < asset.Size; i++)
            {
                AssetProperty prop = asset[i];
                ReadAssetProperty(prop, sw, oldPathList);
            }
            sw.Flush();
            sw.Close();
            TaskDialog.Show("demo", "转换完成");
            foreach (var item in oldPathList)
            {
                TaskDialog.Show("result", item);
            }

            //复制文件更改材质路径



            return(Result.Succeeded);
        }
示例#24
0
        private Asset FindTextureAsset(AssetProperty assetProperty)
        {
            //查找纹理贴图资源
            //获取资源属性的数据类型。
            AssetPropertyType type = assetProperty.Type;

            if (type.Equals(AssetPropertyType.Asset))
            {
                try
                {
                    Asset asset = assetProperty as Asset;
                    if (IsTextureAsset(asset))
                    {
                        Asset result = asset;
                        return(result);
                    }
                    for (int i = 0; i < asset.Size; i++)
                    {
                        Asset asset2 = FindTextureAsset(asset.Get(i));
                        if (asset2 != null)
                        {
                            Asset result = asset2;
                            return(result);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            if (assetProperty.Name.IndexOf("bump", StringComparison.OrdinalIgnoreCase) < 0 && assetProperty.Name.IndexOf("opacity", StringComparison.OrdinalIgnoreCase) < 0 && assetProperty.Name.IndexOf("shader", StringComparison.OrdinalIgnoreCase) < 0 && assetProperty.Name.IndexOf("pattern", StringComparison.OrdinalIgnoreCase) < 0 && assetProperty.Name.IndexOf("_map", StringComparison.OrdinalIgnoreCase) < 0 && assetProperty.Name.IndexOf("transparency", StringComparison.OrdinalIgnoreCase) < 0)
            {
                for (int j = 0; j < assetProperty.NumberOfConnectedProperties; j++)
                {
                    Asset asset3 = FindTextureAsset(assetProperty.GetConnectedProperty(j));
                    if (asset3 != null)
                    {
                        return(asset3);
                    }
                }
            }
            return(null);
        }
示例#25
0
        public void ReadAsset(Asset asset)
        {
            // Get the asset name, type and library name.
            //AssetType type = asset.AssetType;
            //string name = asset.Name;
            //string libraryName = asset.LibraryName;
            var          tempPath = Path.Combine(Path.GetTempPath(), "c.txt");
            FileStream   fs       = new FileStream(tempPath, FileMode.OpenOrCreate);
            StreamWriter sw       = new StreamWriter(fs);

            // travel the asset properties in the asset.
            for (int idx = 0; idx < asset.Size; idx++)
            {
                AssetProperty prop = asset[idx];
                ReadAssetProperty(prop, sw);
            }
            sw.Flush();
            fs.Close();
        }
        // 定义修改贴图路径的方法
        public string ChangeRenderingTexturePath(Document doc, Material mat, string newPath)
        {
            try
            {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("更改贴图位置");

                    using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
                    {
                        Asset editableAsset = editScope.Start(mat.AppearanceAssetId);
                        // Getting the correct AssetProperty
                        AssetProperty assetProperty = editableAsset.FindByName("generic_diffuse");
                        if (assetProperty is null)
                        {
                            assetProperty = editableAsset.FindByName("masonrycmu_color");
                        }

                        Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;
                        // getting the right connected Asset
                        if (connectedAsset.Name == "UnifiedBitmapSchema")
                        {
                            AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;
                            if (path.IsValidValue(newPath))
                            {
                                path.Value = newPath;
                            }
                        }
                        editScope.Commit(true);
                    }
                    t.Commit();
                    t.Dispose();
                }
                return(mat.Name);
            }
            catch (Exception)
            {
                TaskDialog.Show("错误提示!!!", "材质【" + mat.Name + "】的贴图更改失败,请手动更改材质贴图");
                return(null);
            }
        }
示例#27
0
        public async Task <SaveResponseDto> Insert(AssetProperty entity)
        {
            var asset = new Domain.Asset.Asset
            {
                AssetTypeId              = 1,
                AddedBy                  = 1,
                AddedDate                = DateTime.UtcNow,
                IsArchived               = false,
                IsDeleted                = false,
                ManagingAgentId          = 1,
                ManagingAgentPortfolioId = 2,
                SubPortfolioId           = null,
                PortfolioId              = null,
            };

            var assetSavedResponse = await _assetRepository.AddAsync(asset);

            if (assetSavedResponse == null)
            {
                return new SaveResponseDto
                       {
                           SaveSuccessful = false,
                           ErrorMessage   = "Failed adding new property."
                       }
            }
            ;
            entity.AssetId = asset.Id;
            var id = await _assetPropertyRepository.GetLast();

            entity.DataId = DataIdGenerationService.GenerateDataId(id, "AR");
            var propertySavedResponse = await _assetPropertyRepository.AddAsync(entity);

            return(new SaveResponseDto
            {
                SavedDataId = entity.DataId,
                SavedEntityId = entity.AssetId,
                RecordId = entity.Id,
                SaveSuccessful = propertySavedResponse != null,
            });
        }
        public async Task InsertAssetProperty(AssetProperty assetProperty)
        {
            if (assetProperty == null || assetProperty.AssetId <= 0)
            {
                throw new ArgumentException($"assetProperty");
            }

            Asset asset = GetAssets(a => a.AssetId == assetProperty.AssetId)
                          .ToList()
                          .FirstOrDefault();

            if (asset == null)
            {
                asset = new Asset()
                {
                    AssetId   = assetProperty.AssetId,
                    AssetName = $"Asset {assetProperty.AssetId}"
                };
                await InsertAsset(asset);
            }

            await _dbSetAssetProperty.AddAsync(assetProperty);
        }
示例#29
0
        private static List <AssetProperty> ReadAssetsWithoutDuplicates()
        {
            List <AssetProperty> assetsOnFile = new List <AssetProperty>();

            string filePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\assets\\assetsFile.csv";

            using (StreamReader reader = new StreamReader(filePath))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (line != null)
                    {
                        AssetProperty assetPropertyLine = CreateFromReadLine(ref line);

                        var existingAssetProp = assetsOnFile.Find(a =>
                                                                  a.AssetId == assetPropertyLine.AssetId &&
                                                                  a.Property == assetPropertyLine.Property);

                        if (existingAssetProp != null)
                        {
                            if (existingAssetProp.Timestamp < assetPropertyLine.Timestamp)
                            {
                                assetsOnFile.Remove(existingAssetProp);
                                assetsOnFile.Add(assetPropertyLine);
                            }
                        }
                        else
                        {
                            assetsOnFile.Add(assetPropertyLine);
                        }
                    }
                }
            }

            return(assetsOnFile);
        }
示例#30
0
        /// <summary>
        /// Update Asset category
        /// </summary>
        /// <param name="objUI"></param>
        /// <param name="objDb"></param>
        /// <param name="msg"></param>
        private void Update(AssetProperty objUI, AssetProperty objDb, ref Message msg)
        {
            if (!IsDBChanged(objUI, objDb))
            {
                if (!IsDublicateName(objUI))
                {
                    objDb.Name = objUI.Name;
                    objDb.AssetCategoryId = objUI.AssetCategoryId;
                    objDb.DisplayOrder = objUI.DisplayOrder;
                    objDb.MasterData = objUI.MasterData;

                    objDb.UpdateDate = DateTime.Now;
                    objDb.UpdatedBy = objUI.UpdatedBy;

                    dbContext.SubmitChanges();
                    msg = new Message(MessageConstants.I0001, MessageType.Info, "Asset Property '" + objUI.Name + "'", "updated");
                }
                else
                {
                    msg = new Message(MessageConstants.E0020, MessageType.Error, "'" + objUI.Name + "'", "Asset Property");
                }
            }
            else
            {
                msg = new Message(MessageConstants.E0025, MessageType.Error, "Asset Category'" + objDb.Name + "'");
            }
        }
示例#31
0
 /// <summary>
 /// Check data was changed by another user.
 /// Return true if data of this item is changed
 /// </summary>
 /// <param name="objUI"></param>
 /// <param name="objDb"></param>
 /// <returns></returns>
 private bool IsDBChanged(AssetProperty objUI, AssetProperty objDb)
 {
     bool isChannged = true;
     if (objDb.UpdateDate.ToString() == objUI.UpdateDate.ToString())
     {
         isChannged = false;
     }
     return isChannged;
 }
示例#32
0
        IList <string> GetAssetPropValueFromMaterial(AppearanceAssetElement currentAppearance, IList <string> targetList)
        {
            IList <string> valuesToReturn = new List <string>();

            if (currentAppearance != null)
            {
                Asset thisAsset = currentAppearance.GetRenderingAsset();
                if (thisAsset != null)
                {
                    for (int i = 0; i < thisAsset.Size; i++)
                    {
                        AssetProperty currentProp = thisAsset[i];

                        if (currentProp != null)
                        {
                            AssetPropertyString currentPropString = currentProp as AssetPropertyString;
                            if (currentPropString != null)
                            {
                                if (currentPropString.Value != null && currentPropString.Value != "")
                                {
                                    CheckStringAValidTexturePathCorrectItAndAddToList(currentPropString.Value, targetList);
                                }
                            }
                        }

                        IList <AssetProperty> allProp = currentProp.GetAllConnectedProperties();

                        if (allProp != null && allProp.Count > 0)
                        {
                            foreach (AssetProperty currentConnectedProp in allProp)
                            {
#if R2016 || R2017
                                if (currentConnectedProp.Type == AssetPropertyType.APT_Asset)
                                {
                                    Asset currentConnectedAsset = currentConnectedProp as Asset;
                                    if (currentConnectedAsset != null)
                                    {
                                        for (int j = 0; j < currentConnectedAsset.Size; j++)
                                        {
                                            AssetProperty currentConnectedAssetProp = currentConnectedAsset[j];
                                            if (currentConnectedAssetProp != null)
                                            {
                                                AssetPropertyString currentConnectedAssetPropString = currentConnectedAssetProp as AssetPropertyString;
                                                if (currentConnectedAssetPropString != null)
                                                {
                                                    if (currentConnectedAssetPropString.Value != null && currentConnectedAssetPropString.Value != "")
                                                    {
                                                        CheckStringAValidTexturePathCorrectItAndAddToList(currentConnectedAssetPropString.Value, targetList);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
#else
                                if (currentConnectedProp.Type == AssetPropertyType.Asset)
                                {
                                    Asset currentConnectedAsset = currentConnectedProp as Asset;
                                    if (currentConnectedAsset != null)
                                    {
                                        for (int j = 0; j < currentConnectedAsset.Size; j++)
                                        {
                                            AssetProperty currentConnectedAssetProp = currentConnectedAsset[j];
                                            if (currentConnectedAssetProp != null)
                                            {
                                                AssetPropertyString currentConnectedAssetPropString = currentConnectedAssetProp as AssetPropertyString;
                                                if (currentConnectedAssetPropString != null)
                                                {
                                                    if (currentConnectedAssetPropString.Value != null && currentConnectedAssetPropString.Value != "")
                                                    {
                                                        CheckStringAValidTexturePathCorrectItAndAddToList(currentConnectedAssetPropString.Value, targetList);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
#endif
                            }
                        }
                    }
                }
            }
            return(valuesToReturn);
        }
示例#33
0
        /// <summary>
        /// Delete by set DeleteFlag = true
        /// </summary>
        /// <param name="objUI"></param>
        private Message Delete(AssetProperty objUI)
        {
            Message msg = null;
            try
            {
                if (objUI != null)
                {
                    AssetProperty objDb = GetById(objUI.ID);
                    if (objDb != null && !IsInUse(objUI))
                    {
                        List<AssetProperty> list = dbContext.AssetProperties.Where(c => c.ID == objUI.ID).ToList<AssetProperty>();

                        // Set delete info
                        objDb.DeleteFlag = true;
                        objDb.UpdateDate = DateTime.Now;
                        objDb.UpdatedBy = objUI.UpdatedBy;
                        msg = new Message(MessageConstants.I0001, MessageType.Info, "Asset Category", "deleted");
                    }
                    else
                    {
                        msg = new Message(MessageConstants.E0006, MessageType.Error, "delete", "it");
                    }
                    // Submit changes to dbContext

                    dbContext.SubmitChanges();
                }
            }
            catch
            {
                msg = new Message(MessageConstants.E0006, MessageType.Error, "delete", "it");
            }
            return msg;
        }
示例#34
0
        /// <summary>
        /// Update asset category
        /// </summary>
        /// <param name="objUI"></param>
        /// <returns></returns>
        public Message Update(AssetProperty objUI)
        {
            Message msg = null;
            try
            {
                AssetProperty objDb = GetById(objUI.ID);

                if (objDb != null)
                {
                    Update(objUI, objDb, ref msg);
                }
                else
                {
                    msg = new Message(MessageConstants.E0040, MessageType.Error, "Asset Category '" + objUI.ID + "'");
                }
            }
            catch (Exception)
            {
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }

            return msg;
        }
示例#35
0
 public bool IsInUse(AssetProperty objUI)
 {
     AssetPropertyDetailDao assPropDetailDao = new AssetPropertyDetailDao();
     if (assPropDetailDao.GetByPropertyId(objUI.ID.ToString()).Count == 0)
         return false;
     return true;
 }
示例#36
0
 /// <summary>
 /// Insert asset category
 /// </summary>
 /// <param name="objUI"></param>
 /// <returns></returns>
 public Message Insert(AssetProperty objUI)
 {
     Message msg = null;
     try
     {
         if (!IsDublicateName(objUI))
         {
             dbContext.AssetProperties.InsertOnSubmit(objUI);
             dbContext.SubmitChanges();
             msg = new Message(MessageConstants.I0001, MessageType.Info, "Asset Property '" + objUI.Name + "'", "added");
         }
         else
         {
             msg = new Message(MessageConstants.E0020, MessageType.Error, "Name '" + objUI.Name + "'", "Asset Property");
         }
     }
     catch (Exception)
     {
         msg = new Message(MessageConstants.E0007, MessageType.Error);
     }
     return msg;
 }
示例#37
0
 private bool IsDublicateName(AssetProperty objUI)
 {
     bool isDublicateName = true;
     AssetProperty dublicateName = dbContext.AssetProperties.Where(a => a.Name.Equals(objUI.Name) && !a.DeleteFlag && a.AssetCategoryId.Equals(objUI.AssetCategoryId)).FirstOrDefault<AssetProperty>();
     if (dublicateName == null || dublicateName.ID == objUI.ID)
     {
         isDublicateName = false;
     }
     return isDublicateName;
 }