How to get actual objects from C# Web API DbSet? - c#

I'm trying to get a list of 'recent' donuts that have been added to the box (database) since I last checked. I'm a fatty and want some delicious noms. The problem: the server is giving me JSON that is full of $ids and $refs, so my list ends up being one object, with the rest as null (because response.Content.ReadAsAsync doesn't handle the references).
Please help. I just want some straight up donut objects man. None of this $ref icing or $id filling.
My server side controller:
public class DonutController : ApiController
{
private DonutEntities db = new DonutEntities();
// GET api/PackageEvent/since/{datetime}
public IEnumerable<Donut> GetDonutsSince([FromUri] String datetime) {
List<Donut> donuts = null;
DateTime dt = DateTime.Parse(datetime);
//return db.Donuts.Where(d => d.When > dt).AsEnumerable();
String sql = #"
SELECT *
FROM Donuts
WHERE [Donuts].[When] > CAST(#datetime AS DATETIME)
";
object[] parameters = new object[] {
new SqlParameter("#datetime", DateTime.Parse(datetime).ToString(CultureInfo.InvariantCulture))
};
List<Donut> results = db.Donuts.SqlQuery(sql, parameters).ToList();
if (results.Any()) {
donuts = results;
}
return donuts.AsEnumerable();
}
}
My client side request method:
public static IEnumerable<Donut> GetDonutsSince(DateTime dt) {
HttpClient api = new HttpClient { BaseAddress = new Uri("http://localhost:55174/api/") };
api.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
String url = "Donut/since?datetime=" + dt;
HttpResponseMessage response = api.GetAsync(url).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
// outputs the raw json with $ids and $refs
IEnumerable<Donut> donuts = response.Content.ReadAsAsync<IEnumerable<Donut>>().Result;
return donuts;
}

So it turns out that the solution was to use Json.NET. It handles the $id and $ref attributes, and actually creates a list populated with objects.
New client side request method:
public static IEnumerable<Donut> GetDonutsSince(DateTime dt) {
HttpClient api = new HttpClient { BaseAddress = new Uri("http://localhost:55174/api/") };
api.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
String url = "Donut/since?datetime=" + dt;
HttpResponseMessage response = api.GetAsync(url).Result;
String responseContent = response.Content.ReadAsStringAsync().Result;
IEnumerable<Donut> events = JsonConvert.DeserializeObject<IEnumerable<Donut>>(responseContent);
return donuts;
}

Related

PowerBIAPI - Operation is not supported for selector # - connection details contains parameters" - update ServerName in PowerBI Dataset of the Report

I have a Problem Updating the Server details in the dataset of the uploaded power bi Report. Please Help.
Here I used 2 approaches.
Approach 1
Used the below method in Microsoft.PowerBI.Api.V2
UpdateDatasourcesInGroup
public static void UpdateSqlDatabaseConnectionString(string WorkspaceId, string DatasetId, string Server, string Database)
{
var tokenCredentials = GetTokenCredentials();
using (var pbiClient = new PowerBIClient(new Uri(ApiUrl), tokenCredentials.Item1))
{
Datasource targetDatasource = pbiClient.Datasets.GetDatasourcesInGroup(WorkspaceId, DatasetId).Value.First();
string currentServer = targetDatasource.ConnectionDetails.Server;
string currentDatabase = targetDatasource.ConnectionDetails.Database;
if (Server.ToLower().Equals(currentServer.ToLower()) && Database.ToLower().Equals(currentDatabase.ToLower()))
{
Console.WriteLine("New server and database name are the same as the old names");
return;
}
DatasourceConnectionDetails connectionDetails = new DatasourceConnectionDetails
{
Database = Database,
Server = Server
};
UpdateDatasourceConnectionRequest updateConnRequest =
new UpdateDatasourceConnectionRequest
{
DatasourceSelector = targetDatasource,
ConnectionDetails = connectionDetails
};
UpdateDatasourcesRequest updateDatasourcesRequest = new UpdateDatasourcesRequest(updateConnRequest);
pbiClient.Datasets.UpdateDatasourcesInGroup(WorkspaceId, DatasetId, updateDatasourcesRequest);
}
}
Captured the request in fiddler
Request:
{
"updateDetails": [
{
"connectionDetails": {
"server": "OldServer",
"database": "OldDatabase"
},
"datasourceSelector": {
"datasourceType": "Sql",
"connectionDetails": {
"server": "NewServer",
"database": "NewDatabase"
},
"gatewayId": "gatewayId",
"datasourceId": "datasourceId"
}
}
]
}
Response:
{"error":{"code":"InvalidRequest","message":"Operation is not supported for selector # - connection details contains parameters"}}
Approach 2
Called the Power BI rest API
public static void UpdateServerName_RestAPI(string groupId, string datasetId)
{
var tokenCredentials = InitPowerBI_New();
HttpResponseMessage response;
try
{
var httpClient = new HttpClient();
// Add AccessToken in header
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenCredentials.Item2);
var url = $"https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/Default.UpdateDatasources";
var form = prepareJsonForUpdateServerDetails();
var content = new StringContent(form, Encoding.UTF8, "application/json");
response = httpClient.PostAsync(url, content).Result;
response.EnsureSuccessStatusCode();
httpClient.Dispose();
}
catch (Exception)
{
}
}
Request :
{
"UpdateDetails":[
{
"datasourceSelector":{
"datasourceType":"Sql",
"connectionDetails":{
"server":"OldServer",
"database":"OldDatabase"
}
},
"connectionDetails":{
"server":"NewServer",
"database":"NewDatabase"
}
}
]
}
Response:
{"error":{"code":"InvalidRequest","message":"Operation is not supported for selector # - connection details contains parameters"}}
Please Help.
Thank You
This happens when the report queries connect to a database using a parameter. In this case you cannot update the connection, rather update the parameters or remove the connection from the query.
So, if you see in your query code something like Sql.Database(#"ServerName",... you must use Client.Datasets.UpdateParameters and pass in for details:
UpdateMashupParameterDetails request = new()
{
Name = "ServerName",
NewValue = "newServerName"
};
and similarly for database.
Further details https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/update-parameters

Lsing API to list results in different method

The aim of the program below is to get a list of Reports built in our database and find out how many of these reports use the field NameFirst within them.
I'm able to make an API call and, at GetReports, get a list of the ReportIDs.
However, I'm unable to move forward with calling the list I created at GetReports in the next method, GetNameFirst. I was wondering if someone could please help me out with this.
For the script below, I get a red underline for the variable values. This is understandable because I didn't know where and how to tell my code to bind the list output for GetReports to the variable values in GetNameFirst.
Also, if I could get some help in finding out which reports have the field NameFirst in them once I accomplish calling the list from the first method to the second, I'd appreciate that also. I'm currently heading in the direction of using a foreach, but I'm unsure if that's the best path to take.
Main Program
namespace NameFirstSearch
{
class Program
{
static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
const string username = "Username";
const string password = "Password";
const string baseUrl = "https://example.com/rest/services/";
const string queryString = "query?q=Select * From Report Where LastRanDate is not null";
const string queryNameFirst = "getreport/";
var client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var auth = Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
GetReports(client, queryString).Wait();
GetNameFirst(client, queryNameFirst).Wait();
Console.ReadLine();
}
static async Task<List<Properties>> GetReports(HttpClient client, string queryString)
{
List<Properties> result = new List<Properties>();
var response = await client.GetAsync(queryString);
// Check for a successfull result
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
result = JsonConvert.DeserializeObject<List<Properties>>(json);
Console.WriteLine(result.Count());
}
else
{
// Error code returned
Console.WriteLine("No records found on first method.");
}
return result;
}
static async Task GetNameFirst(HttpClient client, string queryNameFirst)
{
string reportType = "JSON";
foreach (var item in values)
{
var output = await client.GetAsync(queryNameFirst + item.ReportID + reportType);
if (output.IsSuccessStatusCode)
{
var allText = await output.Content.ReadAsStringAsync();
var fields = JsonConvert.DeserializeObject<List<NameFirst>>(allText);
}
else
{
// Error code returned
Console.WriteLine("No records found on second method.");
}
}
}
}
Class for report list
class Properties
{
public int ReportID { get; set; }
}
Class for reports' NameFirst property
class NameFirst
{
public string FirstName { get; set; }
}
I thought this was a partial code, but since you've cleared things out.
you'll need to change your code a bit
this :
GetReports(client, queryString).Wait();
do it like this :
var reportsList = GetReports(client, queryString).Result;
now, you'll need to pass the reportsList to the second method GetNameFirst which would be adjusted to this :
static async Task GetNameFirst(HttpClient client, string queryNameFirst, List<Properties> results)
{
string reportType = "JSON";
foreach (var item in results)
{
var output = await client.GetAsync(queryNameFirst + item.ReportID + reportType);
if (output.IsSuccessStatusCode)
{
var allText = await output.Content.ReadAsStringAsync();
var fields = JsonConvert.DeserializeObject<List<NameFirst>>(allText);
}
else
{
// Error code returned
Console.WriteLine("No records found on second method.");
}
}
}
with this adjustment, you'll need to adjust the call as well :
GetNameFirst(client, queryNameFirst, reportsList).Wait();

Convert JSON Source to c# ASP .NET Output

I'm trying to load data from https://www.quandl.com/api/v3/datatables/WIKI.
Comes out in a form like below
{"datatable":{"data":[["A","2017-11-14",66.98,67.8,66.89,67.46,1682158.0,0.0,1.0,66.98,67.8,66.89,67.46,1682158.0]],"columns":[{"name":"ticker","type":"String"},{"name":"date","type":"Date"},{"name":"open","type":"BigDecimal(34,12)"},{"name":"high","type":"BigDecimal(34,12)"},{"name":"low","type":"BigDecimal(34,12)"},{"name":"close","type":"BigDecimal(34,12)"},{"name":"volume","type":"BigDecimal(37,15)"},{"name":"ex-dividend","type":"BigDecimal(42,20)"},{"name":"split_ratio","type":"double"},{"name":"adj_open","type":"BigDecimal(50,28)"},{"name":"adj_high","type":"BigDecimal(50,28)"},{"name":"adj_low","type":"BigDecimal(50,28)"},{"name":"adj_close","type":"BigDecimal(50,28)"},{"name":"adj_volume","type":"double"}]},"meta":{"next_cursor_id":null}}.
However I try to load in asp .net like below but get an error saying it can't find data.
public partial class _Default : System.Web.UI.Page
{
protected string url = "https://www.quandl.com/api/v3/datatables/WIKI/PRICES?date=2017-11-14&ticker=A&api_key=<YOURAPIKEY>";
protected void Page_Load(object sender, EventArgs e)
{
//create an instance of HttpClient
HttpClient client = new HttpClient();
//DefaultRequestHeader to Json
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Create an instance of HttpResponse & invoke the service asynchronously
HttpResponseMessage response = client.GetAsync(url).Result;
//Http Status code 200
if (response.IsSuccessStatusCode)
{
//Read response content result into string variable
string JSON = response.Content.ReadAsStringAsync().Result;
//Deserialize the string(JSON) object
var jObj = (JObject)JsonConvert.DeserializeObject(JSON);
//access items from anonymous (Json object) type and add to the list
var result = jObj["datatable"].Select(item => new
{
key = item["data"][0],
code = item["data"][1],
description = item["data"][2],
buy = item["data"][3],
sell = item["data"][4],
}).ToList();
//output the data || NOTE: **NSERT into database table**
foreach (var item in result)
{
lblOutput.Text = item.key + "--" + item.code + "--" + item.description + item.buy + item.sell + "<br/>";
}
}
}
}
I can't seem to figure out how to load the data in the beginning bit of the json file
{"datatable":{"data":[["A","2017-11-14",66.98,67.8,66.89,67.46,1682158.0,0.0,1.0,66.98,67.8,66.89,67.46,1682158.0]],
You need to go over the data items not datatable items
var result = jObj["datatable"]["data"].Select(item => new
{
key = item[0],
code = item[1],
description = item[2],
buy = item[3],
sell = item[4],
}).ToList();

C# Web API method returns 403 Forbidden

Solved!!! - See last edit.
In my MVC app I make calls out to a Web API service with HMAC Authentication Filterign. My Get (GetMultipleItemsRequest) works, but my Post does not. If I turn off HMAC authentication filtering all of them work. I'm not sure why the POSTS do not work, but the GETs do.
I make the GET call from my code like this (this one works):
var productsClient = new RestClient<Role>(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"],
"xxxxxxxxxxxxxxx", true);
var getManyResult = productsClient.GetMultipleItemsRequest("api/Role").Result;
I make the POST call from my code like this (this one only works when I turn off HMAC):
private RestClient<Profile> profileClient = new RestClient<Profile>(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"],
"xxxxxxxxxxxxxxx", true);
[HttpPost]
public ActionResult ProfileImport(IEnumerable<HttpPostedFileBase> files)
{
//...
var postResult = profileClient.PostRequest("api/Profile", newProfile).Result;
}
My RestClient builds like this:
public class RestClient<T> where T : class
{
//...
private void SetupClient(HttpClient client, string methodName, string apiUrl, T content = null)
{
const string secretTokenName = "SecretToken";
client.BaseAddress = new Uri(_baseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (_hmacSecret)
{
client.DefaultRequestHeaders.Date = DateTime.UtcNow;
var datePart = client.DefaultRequestHeaders.Date.Value.UtcDateTime.ToString(CultureInfo.InvariantCulture);
var fullUri = _baseAddress + apiUrl;
var contentMD5 = "";
if (content != null)
{
var json = new JavaScriptSerializer().Serialize(content);
contentMD5 = Hashing.GetHashMD5OfString(json); // <--- Javascript serialized version is hashed
}
var messageRepresentation =
methodName + "\n" +
contentMD5 + "\n" +
datePart + "\n" +
fullUri;
var sharedSecretValue = ConfigurationManager.AppSettings[_sharedSecretName];
var hmac = Hashing.GetHashHMACSHA256OfString(messageRepresentation, sharedSecretValue);
client.DefaultRequestHeaders.Add(secretTokenName, hmac);
}
else if (!string.IsNullOrWhiteSpace(_sharedSecretName))
{
var sharedSecretValue = ConfigurationManager.AppSettings[_sharedSecretName];
client.DefaultRequestHeaders.Add(secretTokenName, sharedSecretValue);
}
}
public async Task<T[]> GetMultipleItemsRequest(string apiUrl)
{
T[] result = null;
try
{
using (var client = new HttpClient())
{
SetupClient(client, "GET", apiUrl);
var response = await client.GetAsync(apiUrl).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
await response.Content.ReadAsStringAsync().ContinueWith((Task<string> x) =>
{
if (x.IsFaulted)
throw x.Exception;
result = JsonConvert.DeserializeObject<T[]>(x.Result);
});
}
}
catch (HttpRequestException exception)
{
if (exception.Message.Contains("401 (Unauthorized)"))
{
}
else if (exception.Message.Contains("403 (Forbidden)"))
{
}
}
catch (Exception)
{
}
return result;
}
public async Task<T> PostRequest(string apiUrl, T postObject)
{
T result = null;
try
{
using (var client = new HttpClient())
{
SetupClient(client, "POST", apiUrl, postObject);
var response = await client.PostAsync(apiUrl, postObject, new JsonMediaTypeFormatter()).ConfigureAwait(false); //<--- not javascript formatted
response.EnsureSuccessStatusCode();
await response.Content.ReadAsStringAsync().ContinueWith((Task<string> x) =>
{
if (x.IsFaulted)
throw x.Exception;
result = JsonConvert.DeserializeObject<T>(x.Result);
});
}
}
catch (HttpRequestException exception)
{
if (exception.Message.Contains("401 (Unauthorized)"))
{
}
else if (exception.Message.Contains("403 (Forbidden)"))
{
}
}
catch (Exception)
{
}
return result;
}
//...
}
My Web API Controller is defined like this:
[SecretAuthenticationFilter(SharedSecretName = "xxxxxxxxxxxxxxx", HmacSecret = true)]
public class ProfileController : ApiController
{
[HttpPost]
[ResponseType(typeof(Profile))]
public IHttpActionResult PostProfile(Profile Profile)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
GuidValue = Guid.NewGuid();
Resource res = new Resource();
res.ResourceId = GuidValue;
var data23 = Resourceservices.Insert(res);
Profile.ProfileId = data23.ResourceId;
_profileservices.Insert(Profile);
return CreatedAtRoute("DefaultApi", new { id = Profile.ProfileId }, Profile);
}
}
Here is some of what SecretAuthenticationFilter does:
//now try to read the content as string
string content = actionContext.Request.Content.ReadAsStringAsync().Result;
var contentMD5 = content == "" ? "" : Hashing.GetHashMD5OfString(content); //<-- Hashing the non-JavaScriptSerialized
var datePart = "";
var requestDate = DateTime.Now.AddDays(-2);
if (actionContext.Request.Headers.Date != null)
{
requestDate = actionContext.Request.Headers.Date.Value.UtcDateTime;
datePart = requestDate.ToString(CultureInfo.InvariantCulture);
}
var methodName = actionContext.Request.Method.Method;
var fullUri = actionContext.Request.RequestUri.ToString();
var messageRepresentation =
methodName + "\n" +
contentMD5 + "\n" +
datePart + "\n" +
fullUri;
var expectedValue = Hashing.GetHashHMACSHA256OfString(messageRepresentation, sharedSecretValue);
// Are the hmacs the same, and have we received it within +/- 5 mins (sending and
// receiving servers may not have exactly the same time)
if (messageSecretValue == expectedValue
&& requestDate > DateTime.UtcNow.AddMinutes(-5)
&& requestDate < DateTime.UtcNow.AddMinutes(5))
goodRequest = true;
Any idea why HMAC doesn't work for the POST?
EDIT:
When SecretAuthenticationFilter tries to compare the HMAC sent, with what it thinks the HMAC should be they don't match. The reason is the MD5Hash of the content doesn't match the MD5Hash of the received content. The RestClient hashes the content using a JavaScriptSerializer.Serialized version of the content, but then the PostRequest passes the object as JsonMediaTypeFormatted.
These two types don't get formatted the same. For instance, the JavaScriptSerializer give's us dates like this:
\"EnteredDate\":\"\/Date(1434642998639)\/\"
The passed content has dates like this:
\"EnteredDate\":\"2015-06-18T11:56:38.6390407-04:00\"
I guess I need the hash to use the same data that's passed, so the Filter on the other end can confirm it correctly. Thoughts?
EDIT:
Found the answer, I needed to change the SetupClient code from using this line:
var json = new JavaScriptSerializer().Serialize(content);
contentMD5 = Hashing.GetHashMD5OfString(json);
To using this:
var json = JsonConvert.SerializeObject(content);
contentMD5 = Hashing.GetHashMD5OfString(json);
Now the sent content (formatted via JSON) will match the hashed content.
I was not the person who wrote this code originally. :)
Found the answer, I needed to change the SetupClient code from using this line:
var json = new JavaScriptSerializer().Serialize(content);
contentMD5 = Hashing.GetHashMD5OfString(json);
To using this:
var json = JsonConvert.SerializeObject(content);
contentMD5 = Hashing.GetHashMD5OfString(json);
Now the content used for the hash will be formatted as JSON and will match the sent content (which is also formatted via JSON).

mvc paypal payment details amount dont show

In my project include paypal express check out. I send all details in below class. And My code below;
public class PayPal
{
public static PayPalRedirect ExpressCheckout(PayPalOrder order)
{
var values = new NameValueCollection();
values["USER"] = PayPalSettings.Username;
values["PWD"] = PayPalSettings.Password;
values["SIGNATURE"] = PayPalSettings.Signature;
values["METHOD"] = "SetExpressCheckout";
values["VERSION"] = "63.0";
values["RETURNURL"] = PayPalSettings.ReturnUrl;
values["CANCELURL"] = PayPalSettings.CancelUrl;
values["PAYMENTREQUEST_0_PAYMENTACTION"] = "SALE";
values["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";
values["PAYMENTREQUEST_0_AMT"] = order.Amount.ToString("0.00", CultureInfo.InvariantCulture);
values["PAYMENTREQUEST_0_DESC"] = "Apart Name";
values = Submit(values);
string ack = values["ACK"].ToLower();
if (ack == "success" || ack == "successwithwarning")
{
return new PayPalRedirect
{
Token = values["TOKEN"],
Url = String.Format("https://{0}/cgi-bin/webscr?cmd=_express-checkout&token={1}",
PayPalSettings.CgiDomain, values["TOKEN"])
};
}
throw new Exception(values["L_LONGMESSAGE0"]);
}
private static NameValueCollection Submit(NameValueCollection values)
{
string data = String.Join("&", values.Cast<string>()
.Select(key => String.Format("{0}={1}", key, HttpUtility.UrlEncode(values[key]))));
var request = (HttpWebRequest)WebRequest.Create(
String.Format("https://{0}/nvp", PayPalSettings.ApiDomain));
request.Method = "POST";
request.ContentLength = data.Length;
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(data);
}
using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
{
return HttpUtility.ParseQueryString(reader.ReadToEnd());
}
}
}
and my controller ;
public ActionResult Pay(FormCollection form)
{
var redirect = PayPal.ExpressCheckout(new PayPalOrder { Amount = 50 });
Session["token"] = redirect.Token;
return new RedirectResult(redirect.Url);
}
But I cant show amount on paypal page????? I show desc but I dont show amount??? what is wrong? thanks for reply.
Have you passing Amount or not, I think you are not passing Amount Value If not then add
public class CartController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Pay()
{
PayPalRedirect redirect = PayPal.ExpressCheckout(new PayPalOrder { Amount = 50 });
Session["token"] = redirect.Token;
return new RedirectResult(redirect.Url);
}
}
For More Details Check PayPal with ASP.NET MVC
Hope it helps you.
Try passing over a line item name and amount and see if it shows up in that case. Also, can you provide the actual string of data you are sending over to PayPal, minus your API credentials so that I can test it with my API credentials.
Example:
https://api-3t.sandbox.paypal.com/nvp?USER=paypal_api1.x.com&PWD=NAEWP67N2BMRSD234P2&SIGNATURE=Ae0iZ4smtdchhBLFKKdS8s8OSA220f033rNWM4EYTk1J-tsdbDOFq0JpNi&METHOD=SetExpressCheckout&VERSION=92.0&RETURNURL=https://www.ccaples.com/mts/pp_nvp_quick_test.php&CANCELURL=https://www.ccaples.com/mts/pp_nvp_quick_test.php&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_AMT=200&PAYMENTREQUEST_0_ITEMAMT=200&PAYMENTREQUEST_0_SHIPPINGAMT=0.00&PAYMENTREQUEST_0_TAXAMT=0.0&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_DESC=test EC payment

Categories

Resources