Exemple #1
0
 public async Task AddAssetSummaryAsync(AssetSummary assetSummary)
 {
     try
     {
         await _context.assetsummaries.AddAsync(assetSummary);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
 public void AddAssetSummary(AssetSummary assetSummary)
 {
     try
     {
         _context.assetsummaries.Add(assetSummary);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
        public List<AssetSummary> CalcSummary()
        {
            List<AssetSummary> result = new List<AssetSummary>();

            // cash
            List<Cash> cashList = db.Cash.ToList();
            decimal cashAmount = (from cash in cashList select cash.AmountSGD).Sum();

            AssetSummary assetSummary = new AssetSummary();
            assetSummary.Category = "Cash";
            assetSummary.Amount = cashAmount;
            result.Add(assetSummary);

            // portofolio
            List<Portfolio> portfolioList = db.Portfolios.ToList();
            // stock, etf
            decimal stockAmount = (from p in portfolioList.Where(x=>x.Stock.Category==StockCategory.STOCK || x.Stock.Category == StockCategory.ETF) select p.AmountSGD).Sum();
            assetSummary = new AssetSummary();
            assetSummary.Category = "Stock";
            assetSummary.Amount = stockAmount;
            result.Add(assetSummary);

            // reits
            decimal reitsAmount = (from p in portfolioList.Where(x => x.Stock.Category == StockCategory.REITS) select p.AmountSGD).Sum();
            assetSummary = new AssetSummary();
            assetSummary.Category = "Reits";
            assetSummary.Amount = reitsAmount;
            result.Add(assetSummary);

            // bond
            decimal bondAmount = (from p in portfolioList.Where(x => x.Stock.Category == StockCategory.BOND) select p.AmountSGD).Sum();
            assetSummary = new AssetSummary();
            assetSummary.Category = "Bond";
            assetSummary.Amount = bondAmount;
            result.Add(assetSummary);

            // property

            // calculate percentage
            decimal amount = (from asset in result select asset.Amount).Sum();
            foreach (AssetSummary a in result)
            {
                a.Percentage = a.Amount / amount;
            }

            return result;
        }
        public async Task PostAsset([FromBody] AssetDTO assetDTO)
        {
            try
            {
                var asset = new Asset
                {
                    AssignedOn   = assetDTO.AssignedOn,
                    Condition    = assetDTO.Condition,
                    DepartmentId = assetDTO.DepartmentId,
                    Description  = assetDTO.Description,
                    Name         = assetDTO.Name,
                    EmployeeId   = assetDTO.AssignedTo,
                    SerialNumber = assetDTO.SerialNumber,
                    Signature    = string.Format($"I {assetDTO.AssignedTo}, received {assetDTO.Name}  on {DateTime.Now}"),
                    Status       = assetDTO.Status,
                    Location     = assetDTO.Location,
                    ReturnedOn   = assetDTO.ReturnedOn
                };
                await _unitOfWork.Asset.AddAssetAsync(asset);

                //Get previous staff record
                var getAssetSummary = await _unitOfWork.AssetSummary.GetAssetSummariesAsync(x => x.EmployeeId == asset.EmployeeId);

                //Determin whether the employee is assigned to a device already
                if (getAssetSummary.Count() <= 0)
                {
                    var emp          = _unitOfWork.Employee.GetEmployee(asset.EmployeeId);
                    var dept         = _unitOfWork.Department.GetDepartment(asset.DepartmentId);
                    var assetSummary = new AssetSummary
                    {
                        Department   = dept.Name,
                        EmployeeId   = asset.EmployeeId,
                        EmployeeName = emp.FirstName + " " + emp.MiddleName + " " + emp.LastName
                                       //Location = asset.Location
                    };
                    _unitOfWork.AssetSummary.AddAssetSummary(assetSummary);
                    await _unitOfWork.AssetSummary.SaveAsync();
                }
                await _unitOfWork.Asset.SaveAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #5
0
        public AssetReader(Stream asset, Stream exp, Stream bulk = null, bool ignoreErrors = true)
        {
            BinaryReader reader  = new BinaryReader(asset);
            var          summary = new AssetSummary(reader);

            reader.BaseStream.Seek(summary.name_offset, SeekOrigin.Begin);
            FNameEntrySerialized[] name_map = new FNameEntrySerialized[summary.name_count];
            for (int i = 0; i < summary.name_count; i++)
            {
                name_map[i] = new FNameEntrySerialized(reader);
            }

            reader.BaseStream.Seek(summary.import_offset, SeekOrigin.Begin);
            FObjectImport[] import_map = new FObjectImport[summary.import_count];
            for (int i = 0; i < summary.import_count; i++)
            {
                import_map[i] = new FObjectImport(reader, name_map, import_map);
            }

            reader.BaseStream.Seek(summary.export_offset, SeekOrigin.Begin);
            FObjectExport[] export_map = new FObjectExport[summary.export_count];
            for (int i = 0; i < summary.export_count; i++)
            {
                export_map[i] = new FObjectExport(reader, name_map, import_map);
            }

            long export_size = export_map.Sum(v => v.serial_size);

            reader = new BinaryReader(exp);

            var bulkReader = bulk == null ? null : new BinaryReader(bulk);

            int asset_length = summary.total_header_size;

            Exports = new ExportObject[summary.export_count];

            int ind = 0;

            foreach (FObjectExport v in export_map)
            {
                string export_type = v.class_index.import;
                long   position    = v.serial_offset - asset.Length;
                reader.BaseStream.Seek(position, SeekOrigin.Begin);
                try
                {
                    switch (export_type)
                    {
                    case "Texture2D":
                        Exports[ind] = new Texture2D(reader, name_map, import_map, asset_length, export_size, bulkReader);
                        break;

                    case "FontFace":
                        Exports[ind] = new FontFace(reader, name_map, import_map);
                        break;

                    case "DataTable":
                        Exports[ind] = new UDataTable(reader, name_map, import_map);
                        break;

                    case "CurveTable":
                        Exports[ind] = new UCurveTable(reader, name_map, import_map);
                        break;

                    case "SkeletalMesh":
                        Exports[ind] = new USkeletalMesh(reader, name_map, import_map);
                        break;

                    case "AnimSequence":
                        Exports[ind] = new UAnimSequence(reader, name_map, import_map);
                        break;

                    case "Skeleton":
                        Exports[ind] = new USkeleton(reader, name_map, import_map);
                        break;

                    case "SoundWave":
                        Exports[ind] = new USoundWave(reader, name_map, import_map, asset_length, export_size, bulkReader);
                        break;

                    default:
                        Exports[ind] = new UObject(reader, name_map, import_map, export_type, true);
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (!ignoreErrors)
                    {
                        throw e;
                    }
                }
                long valid_pos = position + v.serial_size;
                if (reader.BaseStream.Position != valid_pos)
                {
                    Console.WriteLine($"Did not read {export_type} correctly. Current Position: {reader.BaseStream.Position}, Bytes Remaining: {valid_pos - reader.BaseStream.Position}");
                    reader.BaseStream.Seek(valid_pos, SeekOrigin.Begin);
                }
                ind++;
            }
            //Exports[Exports.Length - 1] = new AssetInfo(name_map, import_map, export_map);
        }
Exemple #6
0
        /// <summary>
        /// Generate a UI Event based on the information passed in
        /// Add any new fields that need populating to this method
        /// </summary>
        private AssetAggregateStatus GenerateEvent(Guid customerUid, Guid projectUid, Guid?assetUid, MachineStatus machineStatus, AssetDetails details, AssetSummary summary)
        {
            var result = new AssetAggregateStatus
            {
                ProjectUid         = projectUid,
                CustomerUid        = customerUid,
                AssetUid           = assetUid,
                UtilizationSummary = summary
            };

            // This is where all the magic happens, in terms of mapping data we have from 3d / 2d endpoints into an event for the UI
            // details / summary can be null, machineStatus won't be.
            var lastLocationTimeUtc = machineStatus.lastKnownTimeStamp;

            // These values are in radians, where the AssetDetails values are in degrees
            result.Latitude    = machineStatus.lastKnownLatitude?.LatRadiansToDegrees();
            result.Longitude   = machineStatus.lastKnownLongitude?.LonRadiansToDegrees();
            result.Design      = machineStatus.lastKnownDesignName;
            result.LiftNumber  = machineStatus.lastKnownLayerId;
            result.MachineName = machineStatus.MachineName;

            // If we have a Asset ID (which matches Asset ID in Fleet management) from UF, use that, otherwise machine name
            result.AssetIdentifier = !string.IsNullOrEmpty(details?.AssetId)
        ? details.AssetId
        : machineStatus.MachineName;

            // Extract data from Asset Details
            if (details != null)
            {
                // Do we have a newer location?
                if (lastLocationTimeUtc == null || details.LastLocationUpdateUtc > lastLocationTimeUtc)
                {
                    result.Latitude     = details.LastReportedLocationLatitude;
                    result.Longitude    = details.LastReportedLocationLongitude;
                    lastLocationTimeUtc = details.LastLocationUpdateUtc;
                }

                result.FuelLevel = details.FuelLevelLastReported;
                result.FuelLevelLastUpdatedUtc = details.FuelReportedTimeUtc;
                result.AssetIcon         = details.AssetIcon;
                result.AssetSerialNumber = details.AssetSerialNumber;
                if (details.Devices?.Count > 0)
                {
                    result.DeviceName = string.Join(", ", details.Devices.Select(d => d.DeviceType));
                }
            }

            // Clear the values if we don't have everything
            if (lastLocationTimeUtc == null || result.Latitude == null || result.Longitude == null)
            {
                _log.LogWarning($"Clearing event information due to missing data. Lat: {result.Latitude}, Lon: {result.Longitude}, Time: {result.LocationLastUpdatedUtc}");
                result.LocationLastUpdatedUtc = null;
                result.Latitude  = null;
                result.Longitude = null;
            }
            else
            {
                result.LocationLastUpdatedUtc = lastLocationTimeUtc;
            }

            return(result);
        }