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 5 years ago.
Improve this question
I want to send email remainder. I created a method that will send emails to the users that have an appointment in the next hour. Right now i have to call my method manually. But i want to use HangFire( or if you have a better suggestion) to call my method every hour( 3:00 PM, 4:00 PM, and so on). I don't want to use Windows task scheduler because i won't have access to the server in the future.
//[HttpPost("lll/reminder")]
public IActionResult EventReminder()
{
var date = DateTime.Now;
var events = eventRepository.GetEventsByDateTimeNow();
foreach(Event evnt in events)
{
var usr = userRepository.GetUserById(evnt.AttendeeId);
var message = new MimeMessage();
message.From.Add(new MailboxAddress("", ""));
message.To.Add(new MailboxAddress("User", usr.Email));
message.Subject = "Remainder";
message.Body = new TextPart("html")
{
Text = "message"
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
client.Authenticate("", "");
client.Send(message);
client.Disconnect(true);
}
}
return Ok();
}
This is the method. It's working but i have to call it manually. So, any ideas?
As you've already mentioned, HangFire can help you with this. They have several examples directly on their home page. The one you want is probably the 'recurring job':
Recurring jobs
Recurring jobs fire many times on the specified CRON schedule.
RecurringJob.AddOrUpdate(
() => Console.WriteLine("Recurring!"),
Cron.Daily);
You can setup and configure hangfire a variety of ways, but the most simple is to simply add it to your Startup.cs file.
I'd recommend you follow the quick start guide, since your use case appears fairly straight forward, running the 'server' in the web app is probably good enough for many small sites/apps and use cases.
There are ways to help improve running the server in the web app itself. That said, if you need something extremely robust, setting up the 'server' as a Windows Service or other 'out of process' process is probably time well spent and something hangfire easily supports as well.
Related
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 2 days ago.
Improve this question
I have a Google Cloud Function scheduled to run every day at 00:10 AM, but today the function runned 10 times. I'm using the same approach for more than a year and its the first time this happened. Has someone had the same problem today?
Function
Function log
I'm just concerned about the problem.
Edit:
Thanks for all the comments here. I think its a new "bug" or just a new characteristic of pubsub schedule. In my configs its already. My function was created as bellow:
exports.processarIndicadoresDiaMoldtool = functions.runWith({ memory: '4GB', timeoutSeconds: 540 }).pubsub.schedule('10 0 * * *')
.timeZone('America/Sao_Paulo')
My Pub/Sub retry config are set to 0:
Today the same thing happened in another cloud scheduled function =/
My solution so far was to try make my function idempotent. I ve creat a log in my firestore database to verify when the function was already runned.
//this.nome = function's name
//this.dia = last day the function has runned - I saw some solutions with eventId too
async getFuncaoProcessada() {
const docFuncao = await db.collection("Processamentos")
.doc(this.nome).get();
if(docFuncao.exists){
let dadosFuncao = docFuncao.data();
if(dadosFuncao.dia == this.dia){
return true;
}
}
return false;
}
Thanks a lot for the help.
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 2 years ago.
Improve this question
Is there any woocommerce API for add to cart
So that I can add product to cart via mobile app.
Please help me.
Did not found any "add to cart" functionality in the woocommerce api.
What had been done is that my "add to cart" button will save the product id and its quantity(and other properties) to the shared preferences object.
Firstly getting the products json object from the already shared preferences object and find out that the to-be-added product already is present on the shared preferences object.If it is present already then the execution returns.Otherwise it will advance to add the product property to the shared preferences object.
SharedPreferences pref = getSharedPreferences("CartPref", 0);
String strJson = pref.getString("productCartJson","[]");
JSONArray productsSaveDetailJsonArray = new JSONArray(strJson);
//checking if the product-to-be-added is already present in the shared preferences object
for(int i=0;i<productsSaveDetailJsonArray.length();i++){
if(productsSaveDetailJsonArray.getJSONObject(i).getString("product_id").contentEquals(productIdForDetailsPage)){
strJson = pref.getString("productCartJson","0");
Log.d("strJson",""+strJson);
//if already present then returns.
return;
}
}
JSONObject productSaveDetailJsonObject = new JSONObject();
productSaveDetailJsonObject.put("product_id",""+productIdForDetailsPage);
productSaveDetailJsonObject.put("quantity","1");
productsSaveDetailJsonArray.put(productSaveDetailJsonObject);
SharedPreferences.Editor editor = pref.edit();
editor.putString("productCartJson", ""+productsSaveDetailJsonArray);
editor.apply();
strJson = pref.getString("productCartJson","0");
Log.d("strJson",""+strJson);
If any doubt please comment.
This works for me.Hope it works for you as well.
Please find the following steps to achieve this:
Get the persistent cart. It may be _woocommerce_persistent_cart or _woocommerce_persistent_cart_1; check in the user_meta table.
Create a new cart object.
Add the old cart data to the newly created cart object.
Add the product and quantities coming in from the request to the new cart object.
If there is a current session cart, overwrite it with the new cart.
Update the wp_session table with the updated cart data.
Overwrite the persistent cart with the new cart data.
Please check my answer to the following question with integration of these steps in working code:
Rest API to store products in cart based on the user id in woocommerce
I have been building a Window Form desktop application using C# that interfaces with Asterisk using Asterisk.NET.
My first problem is catch a Incoming call and transfer it to specific exten.
The first my idea is using OriginateAction, when a call come, I use Dial event and catch it and use OriginateAction to call to a specific exten.
RedirectAction originateAction = new RedirectAction();
originateAction.Channel = e.Channel;
originateAction.Context = "default";
originateAction.Exten = "203";
originateAction.Priority = 1;
ManagerResponse originateResponse = manager.SendAction(originateAction);
Console.WriteLine(originateResponse);
But it not work like my wish.
The second my idea is using RedirectAction:
RedirectAction originateAction = new RedirectAction();
originateAction.Channel = e.Channel;
originateAction.Context = "default";
originateAction.Exten = "203";
originateAction.Priority = 1;
ManagerResponse originateResponse = manager.SendAction(originateAction);
Console.WriteLine(originateResponse);
And it not work.
I have find on many websites but the documents is very little.
How can I solve this issue?
Thanks!
I would suggest using some kind of dynamic dialplan instead of "catching" calls reactively. Why not use an AGI script?
Essentially, your application tells a database or other central system what to do when calls matching certain criteria come in. Then Asterisk runs the script you setup when calls reach a certain context (such as all incoming calls), and then the script routes the call dynamically based on the inputs given by your application.
Since you seem to like .NET, here's a .NET AGI project to help you get started: AsterNET. It looks like the library you mentioned, Asterisk.NET, is also capable of Fast CGI (what AGI uses), but the last release was in 2009, whereas AsterNet is active as recently as 3 months ago.
I personally use phpAGI to do all kinds of neat ACD and call routing stuff in our call center.
For more info on AGI, see the official docs.
Edit:
I should probably also explain some basic call flow terminology (from the docs):
Originate: Generates an outgoing call to a Extension/Context/Priority or Application/Data. Example: User clicks a button, Originate a call to their desk phone, when they answer that call, it executes dialplan, or a dialplan application.
Redirect: Redirect (transfer) a call. Example: Agent and Customer are talking, but Manager wants to take over the call. Use Redirect to "take" the call from Agent and ring the Manager.
Dial: (in dialplan only, not AMI) Dial the technology/channel specified. Note that you can only Originate from your .NET application, not Dial.
Can you show your event handler code? It looks like that library would say something like manager.NewChannel += new ManagerEventHandler(new_channel);
First off, this question has been covered a few times (I've done my research), and, for example, on the right side of the SO webpage is a list of related items... I have been through them all (or as many as I could find).
When I publish my pre-compiled .NET web application, it is very slow to load the first time.
I've read up on this, it's the JIT which I understand (sort of).
The problem is, after the home page loads (up to 20 seconds), many other pages load very fast.
However, it would appear that the only reason they load is because the resources have been loaded (or that they share the same compiled dlls). However, some pages still take a long time.
This indicates that maybe the JIT needs to compile different pages in different ways? If so, and using a contact form as an example (where the Thank You page needs to be compiled by the JIT and first time is slow), the user may hit the send button multiple times whilst waiting for the page to be shown.
After I load all these pages which use different models or different shared HTML content, the site loads quickly as expected. I assume this issue is a common problem?
Please note, I'm using .NET 4.0 but, there is no database, XML files etc. The only IO is if an email doesn't send and it writes the error to a log.
So, assuming my understanding is correct, what is the approach to not have to manually go through the website and load every page?
If the above is a little too broad, then can this be resolved in the settings/configuration in Visual Studio (2012) or the web.config file (excluding adding compilation debug=false)?
In this case, there are 2 problems
As per rene's comments, review this http://msdn.microsoft.com/en-us/library/ms972959.aspx... The helpful part was to add the following code to the global.asax file
const string sourceName = ".NET Runtime";
const string serverName = ".";
const string logName = "Application";
const string uriFormat = "\r\n\r\nURI: {0}\r\n\r\n";
const string exceptionFormat = "{0}: \"{1}\"\r\n{2}\r\n\r\n";
void Application_Error(Object sender, EventArgs ea) {
StringBuilder message = new StringBuilder();
if (Request != null) {
message.AppendFormat(uriFormat, Request.Path);
}
if (Server != null) {
Exception e;
for (e = Server.GetLastError(); e != null; e = e.InnerException) {
message.AppendFormat(exceptionFormat,
e.GetType().Name,
e.Message,
e.StackTrace);
}
}
if (!EventLog.SourceExists(sourceName)) {
EventLog.CreateEventSource(sourceName, logName);
}
EventLog Log = new EventLog(logName, serverName, sourceName);
Log.WriteEntry(message.ToString(), EventLogEntryType.Error);
//Server.ClearError(); // uncomment this to cancel the error
}
The server was maxing out during sending of the email! My code was fine, but, viewing Task Scheduler showed it was hitting 100% memory...
The solution was to monitor the errors shown by point 1 and fix it. Then, find out why the server was being throttled when sending an email!
I have a client in the healthcare space, that might need an IVR system to take patients through a simple six question survey (all of the "press 1 for I Strongly Agree, up to 5 for I Strongly Disagree" type). The factors involved...
Small client: We don't need enterprise-level firepower. We'd expect maybe 50-100 surveys per month.
Hosted: We will be setting up an ASP.NET server with a SQL Server database hosted at a co-location facility. We don't have our own server room and pipes to the internet. I'll want something already hosted that I can tie into. (It needn't be on my ASP.NET server, of course.)
Integration: The rest of their system will be .NET and SQL Server based, so I want to be able to automate pulling the data from the IVR system into my own
Ad-Hoc: We won't be robo-calling. A typical scenario for us: My client receives a live call from a patients...and at the end, will say "Do you have another minute? Can I have you take a phone survey?" If the patient says yes, then either...
they hang up, my client dials a few commands into the IVR system, at the IVR calls the patient...or...
my client doesn't hang up, but transfers the current phone call to the IVR system
Suggestions?
Check out twilio
I believe surveymonkey has an implementation over this API that might also work for you.
I've used Microsoft Speech Server 2007 (Part of Office Communications Server 2007) in the past and it will meet all of your requirements. You can find out more about it here: http://gotspeech.net/
It looks like Speech Server 2007 has been renamed Tellme and you can find out more here: http://www.microsoft.com/en-us/Tellme/developers/default.aspx
I have not used the new Tellme version, but Speech Server 2007 was great. You could implement an entire IVR system within Visual Studio using workflows and .NET code. I would expect Tellme probably makes it even easier.
Ricky from Twilio here.
We put together a C# tutorial for this exact use case I wanted to share:
https://www.twilio.com/docs/tutorials/walkthrough/automated-survey/csharp/mvc
There's a sample configuration that lets you set all the survey questions you want to ask:
protected override void Seed(AutomatedSurveysContext context)
{
context.Surveys.AddOrUpdate(
survey => new { survey.Id, survey.Title },
new Survey { Id = 1, Title = "Twilio" });
context.SaveChanges();
context.Questions.AddOrUpdate(
question => new { question.Body, question.Type, question.SurveyId },
new Question
{
Body = "Hello. Thanks for taking the Twilio Developer Education survey. On a scale of 0 to 9 how would you rate this tutorial?",
Type = QuestionType.Numeric,
SurveyId = 1
},
new Question
{
Body = "On a scale of 0 to 9 how would you rate the design of this tutorial?",
Type = QuestionType.Numeric,
SurveyId = 1
},
new Question
{
Body = "In your own words please describe your feelings about Twilio right now? Press the pound sign when you are finished.",
Type = QuestionType.Voice,
SurveyId = 1
},
new Question
{
Body = "Do you like my voice? Please be honest, I dislike liars.",
Type = QuestionType.YesNo,
SurveyId = 1
});
context.SaveChanges();
}