Example #1
0
        public async Task <IActionResult> GetAssetsView(long AssetsId)
        {
            AssetModule invMod = new AssetModule();

            AssetView view = await invMod.Asset.Query().GetViewById(AssetsId);

            return(Ok(view));
        }
Example #2
0
        public async Task <IActionResult> DeleteAssets([FromBody] AssetView view)
        {
            AssetModule invMod = new AssetModule();
            Asset       Assets = await invMod.Asset.Query().MapToEntity(view);

            invMod.Asset.DeleteAsset(Assets).Apply();

            return(Ok(view));
        }
Example #3
0
        public async Task TestAddUpdatDeleteAssets()
        {
            AssetModule assetsMod = new AssetModule();


            Udc equipmentStatus = await assetsMod.Asset.Query().GetUdc("ASSETS_STATUS", "InUse");


            AssetView view = new AssetView()
            {
                AssetCode             = "12345",
                TagCode               = "Amplifier",
                ClassCode             = "SOUND",
                Description           = "PA SYSTEM",
                Manufacturer          = "LIGHTSPEED",
                Model                 = "CAT 855",
                SerialNumber          = "12X34X56",
                AcquiredDate          = DateTime.Parse("5/11/2019"),
                OriginalCost          = 855.57M,
                ReplacementCost       = 855.57M,
                Depreciation          = 0,
                Location              = "Build 1",
                SubLocation           = "Room 1",
                Quantity              = 1,
                EquipmentStatusXrefId = equipmentStatus.XrefId,
                GenericLocationLevel1 = "",
                GenericLocationLevel2 = "",
                GenericLocationLevel3 = ""
            };
            NextNumber nnAssets = await assetsMod.Asset.Query().GetAssetNextNumber();

            view.AssetNumber = nnAssets.NextNumberValue;

            Asset Asset = await assetsMod.Asset.Query().MapToEntity(view);

            assetsMod.Asset.AddAsset(Asset).Apply();

            Asset newAssets = await assetsMod.Asset.Query().GetAssetByNumber(view.AssetNumber);

            Assert.NotNull(newAssets);

            newAssets.Description = "Testing Assets update";

            assetsMod.Asset.UpdateAsset(newAssets).Apply();

            AssetView updateView = await assetsMod.Asset.Query().GetViewById(newAssets.AssetId);

            Assert.Same(updateView.Description, "Testing Assets update");

            assetsMod.Asset.DeleteAsset(newAssets).Apply();
            Asset lookupAssets = await assetsMod.Asset.Query().GetEntityById(view.AssetId);

            Assert.Null(lookupAssets);
        }
Example #4
0
    /// <summary>
    /// TEnemy是脚本类型(逻辑层),string是prefab名(表现层预制件)
    /// 调用一次生成一个敌人并添加到字典
    /// </summary>
    /// <see cref ="m_name"/>
    /// <typeparam name="TEnemy"></typeparam>
    /// <param name="prefabName"></param>
    /// <returns></returns>
    public static TEnemy SpawnEnemy <TEnemy>(string prefabName) where TEnemy : BaseEnemy, new()
    {
        var    prefab = AssetModule.LoadAsset <GameObject>($"Assets/AssetBundles_sai/Enemy/enemy_sword{prefabName}.prefab");
        var    obj    = Object.Instantiate(prefab);
        TEnemy enemy  = new TEnemy();

        //初始化脚本component变量
        //传入的参数name只是prefab名(一个兵种的名称),但会有多个同种兵(所以就用场景中生成的Gobj命名)
        enemy.Init(obj.name, obj);
        enemyDic.Add(obj.name, obj);
        return(enemy);
    }
Example #5
0
        private static Font LoadFontAtPlay(string fontId)
        {
            var font = AssetModule.Load <Font>(fontId);

            if (font == null)
            {
                Debug.LogError($"目标字体{fontId}不存在!");
                return(null);
            }

            fontCaches.Add(fontId, font);
            return(font);
        }
Example #6
0
        public async Task <IActionResult> UpdateAssets([FromBody] AssetView view)
        {
            AssetModule invMod = new AssetModule();

            Asset Assets = await invMod.Asset.Query().MapToEntity(view);


            invMod.Asset.UpdateAsset(Assets).Apply();

            AssetView updateView = await invMod.Asset.Query().GetViewById(Assets.AssetId);

            AssetView retView = await invMod.Asset.Query().GetViewById(Assets.AssetId);

            return(Ok(retView));
        }
        private void CreateModule()
        {
#if UNITY_EDITOR
            if (m_EditorMode)
            {
                var editorModule = new EditorModeAssetModule(this);
                Module = editorModule;
            }
            else
            {
                Module = new AssetModule();
            }
#else
            Module = new AssetModule();
#endif
        }
Example #8
0
    /// <summary>
    ///  创建并获取一个面板实例(同步加载方法)
    /// </summary>
    /// <typeparam name="TPanel"></typeparam>
    /// <returns></returns>
    public static TPanel OpenPanel <TPanel>(System.Action <TPanel> onPanelOpened = null) where TPanel : BasePanel, new()
    {
        //panel脚本实例
        var panel = new TPanel();

        //panelGobj实例(先加载后创建)
        var        prefab    = AssetModule.LoadAsset <GameObject>(panel.Path);
        GameObject panelGobj = Object.Instantiate(prefab, canvasTransform);

        panelGobj.name = typeof(TPanel).Name;
        //初始化panel脚本字段,调用打开时的回调方法
        panel.Init(panelGobj.name, panelGobj);
        panel.OnOpen();

        return(panel);
    }
Example #9
0
        public async Task <IActionResult> AddAssets([FromBody] AssetView view)
        {
            AssetModule invMod = new AssetModule();

            NextNumber nnAssets = await invMod.Asset.Query().GetAssetNextNumber();

            view.AssetNumber = nnAssets.NextNumberValue;

            Asset Assets = await invMod.Asset.Query().MapToEntity(view);

            invMod.Asset.AddAsset(Assets).Apply();

            AssetView newView = await invMod.Asset.Query().GetAssetViewByNumber(view.AssetNumber);


            return(Ok(newView));
        }
Example #10
0
        public void UpdateAssetsModule(AssetModule amLink)
        {
            // look for pair in table, if exists update otherwise add new row
            var assetModulePair = _dbcontext.AssetModules.AsNoTracking().Where(x => x.assetID == amLink.assetID).FirstOrDefault();

            if (assetModulePair != null)
            {
                // update existing record
                _dbcontext.Update(amLink);
                _dbcontext.SaveChanges();
            }
            else
            {
                // module added to existing asset, create new record
                _dbcontext.AssetModules.Add(amLink);
                _dbcontext.SaveChanges();
            }
        }
            private object LoadModelAtPlay(string logicId)
            {
                if (rxModels.ContainsKey(logicId))
                {
                    var targetModel = rxModels[logicId];
                    return(targetModel);
                }

                var app     = ProjectInfoDati.GetActualInstance();
                var type    = GetRxModelType(app.DevelopProjectName, logicId);
                var finalId = logicId ?? type.Name;

                finalId += "_RxModel";
                if (finalId.Contains("@"))
                {
                    finalId = finalId.Replace("@", "_")
                              .Replace("=", "_");
                }

                var assetId = app.DevelopProjectName + "_" + finalId;

                TextAsset textAsset = null;

                try
                {
                    textAsset = AssetModule.Load <TextAsset>(assetId);
                }
                catch (Exception e)
                {
#if DEBUG
                    Debug.LogError(e.Message + e.StackTrace);
#endif
                }
                if (textAsset == null)
                {
                    var newModel = Activator.CreateInstance(type);
                    return(newModel);
                }

                var instance = UnityEngine.JsonUtility.FromJson(textAsset.text, type);
                return(instance);
            }
Example #12
0
        public void GenerateDatabaseEntries(AssetModule module, DataElements input, List <DataSchema> inputSch)
        {
            Asset tempAsset = _dbcontext.Assets.Where(A => A.AssetId == module.assetID).FirstOrDefault();

            _dbcontext.Schemas.AddRange(inputSch);
            _dbcontext.SaveChanges(); //need to know the schema ID later not generated till in database.

            int i = 0;

            foreach (Dictionary <String, String> row in input.rowEntries)
            {
                foreach (DataSchema s in inputSch)
                {
                    if (_dbcontext.AssetData.Any(A => A.assetID == module.assetID && A.dataEntryID == i && A.fieldName.Equals(s.fieldName)))
                    {
                        var data    = _dbcontext.AssetData.Single(A => A.assetID == module.assetID && A.dataEntryID == i && A.fieldName.Equals(s.fieldName));
                        var newData = new AssetData(module.assetID, s.schemaName, i, s.fieldName, s.fieldType, row.GetValueOrDefault(s.fieldName), s.isPrimary, tempAsset);

                        data.asset        = newData.asset;
                        data.schemaName   = newData.schemaName;
                        data.fieldType    = newData.fieldType;
                        data.strValue     = newData.strValue;
                        data.intValue     = newData.intValue;
                        data.floatValue   = newData.floatValue;
                        data.dateValue    = newData.dateValue;
                        data.boolValue    = newData.boolValue;
                        data.isPrimaryKey = newData.isPrimaryKey;
                    }
                    else
                    {
                        _dbcontext.AssetData.AddAsync(new AssetData(module.assetID, s.schemaName, i, s.fieldName, s.fieldType, row.GetValueOrDefault(s.fieldName), s.isPrimary, tempAsset));
                    }
                }
                i++;
            }

            _dbcontext.SaveChanges();
        }
Example #13
0
 public void AddAssetsModule(AssetModule amLink)
 {
     _dbcontext.AssetModules.Add(amLink);
     _dbcontext.SaveChanges();
 }
Example #14
0
        public void LoadCSV(AssetModule module, StreamReader csv, StreamReader importSchema)
        {
            Models.Module tempModule = _dbcontext.Modules.Where(M => M.moduleID == module.moduleID).First();
            DataElements  dataImport = new DataElements();

            String[]          colNames = null;
            List <DataSchema> entries  = new List <DataSchema>();

            int n = 0;

            while (csv.Peek() >= 0)
            {
                String   tempLine = csv.ReadLine();
                String[] cols     = tempLine.Split(",");

                if (n == 0)
                {
                    colNames = cols;
                    n++;
                    continue;
                }

                Dictionary <String, String> row = new Dictionary <String, String>();

                for (int i = 0; i < colNames.Length; i++)
                {
                    row.Add(colNames[i], cols[i]);
                }
                dataImport.AddRow(row);
            }

            String schemaName  = null;
            int    count       = 0;
            String assetTypeID = tempModule.typeID;

            while (importSchema.Peek() >= 0)
            {
                String   tempLine = importSchema.ReadLine();
                String[] cols     = tempLine.Split(":");
                if (count == 0)
                {
                    schemaName = tempLine;
                }
                else if (count == 1)
                {
                    if (_dbcontext.Schemas.Any(x => x.schemaName.Equals(schemaName) && x.fieldName.Equals(cols[0])))
                    {
                        continue;
                    }
                    entries.Add(new DataSchema(schemaName, cols[0], cols[1], true, assetTypeID));
                }
                else
                {
                    if (_dbcontext.Schemas.Any(x => x.schemaName.Equals(schemaName) && x.fieldName.Equals(cols[0])))
                    {
                        continue;
                    }
                    entries.Add(new DataSchema(schemaName, cols[0], cols[1], false, assetTypeID));
                }
                count++;
            }

            GenerateDatabaseEntries(module, dataImport, entries);
        }
Example #15
0
        public JsonResult ModifyAsset(int assetId, string name, string shortDescription, string longDescription, Boolean isPreferredAsset, string assetType, string owner, string moduleName)
        {
            try
            {
                // trim whitespace on non null text input
                name             = name == null ? null : name.Trim();
                shortDescription = shortDescription == null ? null : shortDescription.Trim();
                longDescription  = longDescription == null ? null : longDescription.Trim();
                owner            = owner == null ? null : owner.Trim();

                // check provided owner is a registered user in the database
                var userDetails = _dbcontext.Users.Where(x => x.UserName == owner || x.Email == owner).FirstOrDefault();
                if (userDetails == null)
                {
                    return(Json(new { validOwner = false, message = "The owner you provided for the asset is not a registered user in BAMS.  Please provide a registered user as the owner." }));
                }

                // check that asset does not already exist in system (only if name of asset changed)
                var nameChange = _dbcontext.Assets.AsNoTracking().Where(x => x.AssetId == assetId).FirstOrDefault();
                if (nameChange != null)
                {
                    if (nameChange.AssetName != name)
                    {
                        bool isDuplicateAsset = CheckDuplicateAsset(name);
                        if (isDuplicateAsset == true)
                        {
                            return(Json(new { duplicateAsset = true, message = "The asset provided already exists in BAMS.  Please modify the existing asset's record or check you have entered the correct asset information." }));
                        }
                    }
                }

                // check to make sure that the asset a user is modifying hasn't been similtaneously
                // deleted by another user
                bool isAssetDeleted = isDeleted(assetId);
                if (isAssetDeleted == true)
                {
                    return(Json(new { deletedAsset = true, message = "Unable to modify asset.  The asset you attempted to modify has been deleted by another user." }));
                }

                var findAssetType = _dbcontext.AssetTypes.Where(x => x.typeID == Convert.ToInt32(assetType)).FirstOrDefault();

                Asset modifiedAsset = new Asset();
                modifiedAsset.AssetId          = assetId;
                modifiedAsset.AssetName        = name;
                modifiedAsset.ShortDescription = shortDescription;
                modifiedAsset.LongDescription  = longDescription;
                modifiedAsset.Owner            = owner;

                if (findAssetType == null)
                {
                    modifiedAsset.typeName = null;
                }
                else
                {
                    modifiedAsset.typeName = findAssetType.typeName;
                }
                modifiedAsset.isDeleted = false;

                // set preferred asset for current user
                if (isPreferredAsset == true)
                {
                    SaveUsersPreferredAsset(assetId, false);
                }
                else
                {
                    SaveUsersPreferredAsset(assetId, true);
                }

                _dbcontext.Update(modifiedAsset);
                _dbcontext.SaveChanges();

                // get recently modified asset and update module linked to that asset if the asset was assigned a module
                if (moduleName != null)
                {
                    AssetModule assetModuleLink = new AssetModule();
                    assetModuleLink.assetID  = assetId;
                    assetModuleLink.moduleID = Convert.ToInt32(moduleName); // number passed back corresponds to ID in database
                    UpdateAssetsModule(assetModuleLink);
                }

                JsonResult updatedAssetList = GetCurrentAssets();

                return(Json(new { isUpdated = true, message = "Successfully updated the selected asset.", updatedAssets = updatedAssetList }));
            }
            catch (Exception ex)
            {
                // EVENTUALLY LOG EXCEPTION
                return(Json(new { isUpdated = false, message = "An error occured while attempting to update the selected asset.  Please try again or contact a system admin." }));
            }
        }
Example #16
0
        public static void Seed(IServiceProvider services)
        {
            var context = services.GetRequiredService <BamsDbContext>();
            var dataAPI = services.GetRequiredService <IDataAPIService>();
            var logger  = services.GetRequiredService <ILogger <Program> >();

            context.Database.Migrate();
            logger.LogInformation("Applied pending migrations");

            dataAPI.LoadConfigurationXml();
            if (context.Assets.Any())
            {
                logger.LogInformation("Database is already seeded");
                dataAPI.StartDataMonitoringThread();
                return;
            }

            Asset asset1 = new Asset
            {
                AssetName        = "VM Server",
                ShortDescription = "The Server which controls access to a number of virtual machines",
                LongDescription  = "Reports on statuses of different instances.",
                typeName         = context.AssetTypes.Where(A => A.typeName.Equals("Server")).First().typeName
            };

            Asset asset2 = new Asset
            {
                AssetName        = "Vulnerability Analyzer",
                ShortDescription = "Gains information from the Vulnerability Analysis Service",
                LongDescription  = "Information on particular Vulnerabilities which are present on our systems.",
                typeName         = context.AssetTypes.Where(A => A.typeName.Equals("Server")).First().typeName
            };

            Asset asset3 = new Asset
            {
                AssetName        = "Certificates Manager",
                ShortDescription = "Gives information on the current Status of Various Certificates",
                LongDescription  = "Lists system certificates and all of their statuses.",
                typeName         = context.AssetTypes.Where(A => A.typeName.Equals("Database")).First().typeName
            };

            Asset asset4 = new Asset
            {
                AssetName        = "Fantasy Football Manager",
                ShortDescription = "Gives NFL passing stats because it's a CSV I had handy.",
                LongDescription  = "Throwing a Football",
                typeName         = context.AssetTypes.Where(A => A.typeName.Equals("CSV File")).First().typeName
            };

            context.Assets.Add(asset1);
            context.Assets.Add(asset2);
            context.Assets.Add(asset3);
            context.Assets.Add(asset4);
            logger.LogDebug("Seeded Assets");

            TaskQueue task1 = new TaskQueue
            {
                AssetId      = asset1.AssetId,
                Name         = "BAYVM800",
                alertMessage = "Needs software patches applied",
                resolvedBy   = "",
                isComplete   = false,
                dateComplete = null
            };

            TaskQueue task2 = new TaskQueue
            {
                AssetId      = asset2.AssetId,
                Name         = "HRDATA500",
                alertMessage = "Data not in sync with HRDATABU500 - number of employees not equal",
                resolvedBy   = "",
                isComplete   = false,
                dateComplete = null
            };

            TaskQueue task3 = new TaskQueue
            {
                AssetId      = asset3.AssetId,
                Name         = "CERTMGMT500",
                alertMessage = "Update server version",
                resolvedBy   = "",
                isComplete   = false,
                dateComplete = null
            };

            context.TaskQueues.Add(task1);
            context.TaskQueues.Add(task2);
            context.TaskQueues.Add(task3);
            logger.LogDebug("Seeded TaskQueues");


            context.SaveChanges();

            Module      csvModule     = context.Modules.Where(M => M.moduleName.Equals("CSVImporter")).First();
            AssetModule csvTestModule = new AssetModule(asset4.AssetId, csvModule.moduleID);

            context.AssetModules.Add(csvTestModule);
            logger.LogDebug("Seeded AssetModules");

            context.SaveChanges();
            logger.LogInformation("Seeded database successfully");

            dataAPI.StartDataMonitoringThread();
        }
Example #17
0
        public JsonResult AddAsset(int assetId, string name, string shortDescription, string longDescription, Boolean isPreferredAsset, string assetType, string owner, string moduleName)
        {
            try
            {
                // trim whitespace on non null text input
                name             = name == null ? null : name.Trim();
                shortDescription = shortDescription == null ? null : shortDescription.Trim();
                longDescription  = longDescription == null ? null : longDescription.Trim();
                owner            = owner == null ? null : owner.Trim();

                // check provided owner is a registered user in the database
                var userDetails = _dbcontext.Users.Where(x => x.UserName == owner || x.Email == owner).FirstOrDefault();
                if (userDetails == null)
                {
                    return(Json(new { validOwner = false, message = "The owner you provided for the asset is not a registered user in BAMS.  Please provide a registered user as the owner." }));
                }

                // check that asset does not already exist in system
                bool isDuplicateAsset = CheckDuplicateAsset(name);
                if (isDuplicateAsset == true)
                {
                    return(Json(new { duplicateAsset = true, message = "The asset provided already exists in BAMS.  Please modify the existing asset's record or check you have entered the correct asset information." }));
                }

                var findAssetType = _dbcontext.AssetTypes.Where(x => x.typeID == Convert.ToInt32(assetType)).FirstOrDefault();

                Asset newAsset = new Asset();
                newAsset.AssetId          = assetId;
                newAsset.AssetName        = name;
                newAsset.ShortDescription = shortDescription;
                newAsset.LongDescription  = longDescription;
                newAsset.Owner            = owner;

                if (findAssetType == null)
                {
                    newAsset.typeName = null;
                }
                else
                {
                    newAsset.typeName = findAssetType.typeName;
                }
                newAsset.isDeleted = false;

                _dbcontext.Assets.Add(newAsset);
                _dbcontext.SaveChanges();

                // find recently added asset and update module linked to that asset if the asset was assigned a module
                var newlyAddedAsset = _dbcontext.Assets.Where(x => x.AssetName == name &&
                                                              x.LongDescription == longDescription && x.ShortDescription == shortDescription &&
                                                              x.Owner == owner).FirstOrDefault();

                var newAssetId = newlyAddedAsset.AssetId;

                if (moduleName != null)
                {
                    AssetModule assetModuleLink = new AssetModule();
                    assetModuleLink.assetID  = newAssetId;
                    assetModuleLink.moduleID = Convert.ToInt32(moduleName); // number passed back corresponds to ID in database
                    AddAssetsModule(assetModuleLink);
                }

                // also set is preferred asset using the newly added asset's asset id
                if (isPreferredAsset == true)
                {
                    SaveUsersPreferredAsset(newAssetId, false);
                }
                else
                {
                    SaveUsersPreferredAsset(newAssetId, true);
                }

                JsonResult updatedAssetList = GetCurrentAssets();

                return(Json(new { isAdded = true, message = "Successfully added new asset " + name + ".", updatedAssets = updatedAssetList }));
            }
            catch (Exception ex)
            {
                // EVENTUALLY LOG EXCEPTION
                return(Json(new { isAdded = false, message = "An error occured while attempting to add the new asset " + name + ".  Please try again or contact a system admin." }));
            }
        }