/// <inheritdoc/> public override List <ResourceRequest> GetResourcesNeededForActivity() { List <ResourceRequest> requests = new List <ResourceRequest>(); earned = 0; spent = 0; // get data currentEntries = fileResource.GetCurrentResourceData(clock.Today.Month, clock.Today.Year); resourceList = new List <IResourceType>(); if (currentEntries.Count > 0) { IResourceType resource = null; foreach (DataRowView item in currentEntries) { // find resource string resName = item[fileResource.ResourceNameColumnName].ToString(); if (resName.Contains(".")) { resource = Resources.FindResourceType <ResourceBaseWithTransactions, IResourceType>(this, resName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop); } else { var found = Resources.FindAllDescendants <IResourceType>(resName); if (found.Count() == 1) { resource = found.FirstOrDefault(); // highlight unsupported resource types // TODO: add ability to include labour (days) and ruminants (number added/removed) switch (resource.GetType().ToString()) { case "Models.CLEM.Resources.LandType": case "Models.CLEM.Resources.RuminantType": case "Models.CLEM.Resources.LabourType": case "Models.CLEM.Resources.GrazeFoodStoreType": case "Models.CLEM.Resources.OtherAnimalsType": string warn = $"[a={this.Name}] does not support [r={resource.GetType()}]\r\nThis resource will be ignored. Contact developers for more information"; Warnings.CheckAndWrite(warn, Summary, this); resource = null; break; default: break; } // if finances if (resource != null && bankAccount != null) { double amount = Convert.ToDouble(item[fileResource.AmountColumnName], CultureInfo.InvariantCulture); // get price of resource ResourcePricing price = resource.Price((amount > 0 ? PurchaseOrSalePricingStyleType.Purchase : PurchaseOrSalePricingStyleType.Sale)); double amountAvailable = (amount < 0) ? Math.Min(Math.Abs(amount), resource.Amount) : amount; double packets = amountAvailable / price.PacketSize; if (price.UseWholePackets) { packets = Math.Truncate(packets); } if (amount < 0) { earned += packets * price.PricePerPacket; } else { spent += packets * price.PricePerPacket; } } } else { string warn = ""; if (found.Count() == 0) { warn = $"[a={this.Name}] could not find a resource [r={resName}] provided by [x={fileResource.Name}] in the local [r=ResourcesHolder]\r\nExternal transactions with this resource will be ignored\r\nYou can either add this resource to your simulation or remove it from the input file to avoid this warning"; } else { warn = $"[a={this.Name}] could not distinguish between multiple occurences of resource [r={resName}] provided by [x={fileResource.Name}] in the local [r=ResourcesHolder]\r\nEnsure all resource names are unique across stores, or use ResourceStore.ResourceType notation to specify resources in the input file"; } Warnings.CheckAndWrite(warn, Summary, this); } } if (resource != null) { resourceList.Add(resource); } } } return(requests); }