Suggest Me Best Local Storage Option [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I created a web api using C# and also created a mobile application using cordova.
I am retrieving all data on cordova app using JSON.
Now I want to save this JSON data to client side. Please suggest me the best option to save all the data to client side.
SQLLite
websql
JSON file directly saved to client side or other option.

If you need to keep your client-side and server-side DBs in sync, PouchDB is a good choice - you can use pouchdb-phonegap-cordova to implement it in the app. You'd also need implement a CouchDB REST interface on the server-side.
Or since your data is already formatted as JSON, you may want to try cordova-sqlite-porter as a convenient way to store the data - it will interface with either the WebView's WebSQL DB or native SQLite in conjunction with Cordova-sqlite-storage plugin.
You can pass your data as a JSON structure to importJsonToDb() which makes optimisations to perform the operation as fast as possible. This is good if you have a large amount of data to insert. Example usage:
var db = window.openDatabase("Test", "1.0", "TestDB", 1 * 1024);
var json = {
"structure":{
"tables":{
"Artist":"([Id] PRIMARY KEY, [Title])"
},
"otherSQL": [
"CREATE UNIQUE INDEX Artist_ID ON Artist(Id)"
]
},
"data":{
"inserts":{
"Artist":[
{"Id":"1","Title":"Fred"},
{"Id":"2","Title":"Bob"},
{"Id":"3","Title":"Jack"},
{"Id":"4","Title":"John"}
]
}
}
};
var successFn = function(count){
alert("Successfully imported JSON to DB; equivalent to "+count+" SQL statements");
};
var errorFn = function(error){
alert("The following error occurred: "+error.message);
};
var progressFn = function(current, total){
console.log("Imported "+current+"/"+total+" statements";
};
cordova.plugins.sqlitePorter.importJsonToDb(db, json, {
successFn: successFn,
errorFn: errorFn,
progressFn: progressFn,
batchInsertSize: 500
});

You can use pouchdb no SQL database here, also you can use cordova sqlite plugin here.

Related

How to prevent users to add entries for a given time using ASP NET MVC? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have this scenario:
Add a product but block adding for 1 minute for other users. After 1 min they can normally add one.
Adding a product it is not blocked for the user itself who added it
but for others.
I have this and it is working like a charm:
public async Task<JsonResult> AddProducts(string citaId, string paciente, string medico, string modalidad)
{
var usuario = System.Web.HttpContext.Current.User.Identity.GetUserName();
if (Session["User"] != null)
{
if(Session["User"].ToString() != usuario)
{
var med = await _context.MEDICOS.FindAsync(medico);
var objetoerrr1 = new
{
type = "error",
message = $"you cannot add a product, WAIT 1 MIN."
};
return Json(objetoerrr1, JsonRequestBehavior.AllowGet);
}
}
... the rest of the code for adding a product
// create a session
Session["User"] = usuario;
Session.Timeout = 1;
But my problem is that it is not working when using different browsers or PCs and It is like session is empty in different devices.
Well I have never worked with sessions in ASP NET MVC5 before so when I heard this requeriment, sessions came to my mind so I used them.
How can I achieve such thing? Should I use database to store the session or something? Or should not I be using sessions for this approach?
You should save the sessions into database, not only for this, also for security reasons. And give that session an unique identifier (and save it inside the cookie and retrieve and check it everytime) in order to know login timestamp, logout timestamp, prevent cookie-copy between browsers, prevent cookie-copy after log out, prevent browser-copy, duplicated sessions, if roles changes meanwhile the user is logged in, etc.
Of course there are a lot of ways to do this without database, but this is my answer. I use only database for this because I save user logins into database, as their roles.

Calculate lines of code change for a commit? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to calculate lines of code in a Pull Request API in Azure Devops for each file. I have gone through below two links and but was not of much help.
Is there a way to get the amount of lines changed in a Pull Request via the Dev Ops Service REST API?
Lines of Code modified in each Commit in TFS rest api. How do i get?
Thank you.
Steps:
a. Get the commit IDs for the specified pull request
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/commits?api-version=6.1-preview.1
b. Get commit path via the commit ID
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=5.0
c. Get parents commit ID via commit ID
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.0
d. Get the result via below API and request body.
POST https://dev.azure.com/{Org name}/_apis/Contribution/HierarchyQuery/project/{Project name}?api-version=5.1-preview
Request Body:
{
"contributionIds": [
"ms.vss-code-web.file-diff-data-provider"
],
"dataProviderContext": {
"properties": {
"repositoryId": "{Repo ID}",
"diffParameters": {
"includeCharDiffs": true,
"modifiedPath": "{Commit path}",
"modifiedVersion": "GC{Commit ID}",
"originalPath": "{Commit path}",
"originalVersion": "GC{parents commit ID}",
"partialDiff": true
}
}
}
}
Result:

Service did not receive API Data through WebClient [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to send data from API to web service. But it is always receiving null
Code in API - WEB CLIENT:
using (var webClient = new WebClient())
{
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
var url = string.Format("End Point URL /SomeAction");
var user= new User()
{
...
};
var data = JsonConvert.SerializeObject(user);
webClient.UploadString(url, data);
}
Service:
public ActionResult SomeAction([System.Web.Http.FromBody]string data)
{
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
FOUsers dataFromXBO =
(FOUsers)json_serializer.DeserializeObject(data);
//statements
}
Please advice, How can i receive data that passed from API
To answer your question directly, to extract a string from a request body, wrap your "string" in another object as per this SO link. ie.
class UserPostRequest{
public string UserJson{get; set;}
}
And change the signature in your controller as follows:
public ActionResult SomeAction([System.Web.Http.FromBody]UserPostRequest data)
With that said, in this specific instance it's likely that you can just do:
public ActionResult SomeAction([System.Web.Http.FromBody]FOUsers data)
and let the API take care of deserialization for you.
EDIT:
After further research, to add completeness to the first half of my answer let me acknowledge that there are many ways to skin that particular cat. The answer provided is just the one I've historically used. Here's another SO post that enumerates other solutions, including accepting a dynamic or HttpRequestMessage in your API method signature. These would be particularly helpful if for some reason you didn't want to change your client code. That said, again, I don't see a particular reason to do manual serialization if you're just going to end up consuming the out-of-the-box functionality.

Connect to Stack Overflow API [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to connect to the Stack Overflow API as one of my first api calls, but I am struggling.
Can someone tell me why this code does not return a success code?
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("https://api.stackexchange.com/");
var response = await client.GetAsync("questions");
if (response.IsSuccessStatusCode)
{
}
else
{
Console.WriteLine(response.ToString());
}
}
The response tells you site is required. Hit https://api.stackexchange.com/questions?site=stackoverflow instead.
You're getting back
{"error_id":400,"error_message":"site is required","error_name":"bad_parameter"}
If you read the error and documentation, it needs to know which StackExchange site you want. Try:
https://api.stackexchange.com/questions?site=stackoverflow

C# PHP Connection Flood Protection

So let's say I created a feedback form in C#.
It sens the feedback to my PHP Page and my PHP Page adds it to my MySQL Database.
Code:
private void PostFeed(string Params)
{
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers["Accept"] = #"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
wc.Headers["Accept-Language"] = #"en-US,en;q=0.5";
string HtmlResult = wc.UploadString("http://website/feedtest.php", "POST", Params);
Console.WriteLine(HtmlResult);
}
}
On my PHP I have a code that looks similar to:
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$desc = $_REQUEST['description'];
connect
post result...
close connection
The question I have is: is there a way to protect against flood ? I understand anyone can just spam/flood it by sending feedback continuously or even creating a third party app that sends like 1000 post request per second. I was thinking of implementing some sort of check on the PHP side, for example: if the connection password from the c# app matches, then continue if not, exit.
Basically, I dont want people to take advantage of the feedback method and spam me.
Can anyone suggest a method ? or Should I not even worry about this ?
Any help is appreciated.
A typical technique is to have some kind of submissions per X unit of time limit where you have a last_submitted_at column in a table associated with some kind of identifier. For example, you might associate it with a user if you have a fairly robust user registration system, or you might associate it with an IP if you don't.
This is the system that Stack Overflow uses if you try and vote, post, or as questions too often. Each of these has a separate timer which probably translates to a separate last_X_at column in the database somewhere.
If the last time is less than some threshold, present an error instead of accepting the submission.

Categories

Resources