IScheduledTask - Task not created again - orchardcms-1.6

I have a Service method which is run by task scheduler. The task is created and is executed, but the task does not gets created again. Please see the following code:
Feature Handler : Task is created here
public class NewsFeatureEventHandler : IFeatureEventHandler
{
private const int TimeIntervalMinutes = 1;
private const string TaskType = "Feeds";
...
public void Enabled(Feature feature)
{
if (feature.Descriptor.Id.Equals("My.Module"))
_taskManager.CreateTask(TaskType, DateTime.UtcNow.AddMinutes(TimeIntervalMinutes), null);
}
...
}
ScheduledTaskHandler : Task is re-created here
public class MyScheduledTaskHandler : IScheduledTaskHandler
{
private const int TimeIntervalMinutes = 1;
private const string TaskType = "Feeds";
public void Process(ScheduledTaskContext context)
{
try
{
...
}
catch
{
...
}
finally
{
_taskManager.CreateTask(TaskType, DateTime.UtcNow.AddMinutes(TimeIntervalMinutes), null);
}
}
}
Can you see any problem with the above code. Please give some suggestions and direction.
Regards,

Related

variable not getting updated as expected in Java

I am learning Java and have encountered an unexpected problem:
variable i is getting updated in mouse listener but updated value is not getting passed back to main program. But if I uncomment Thread.sleep(1) block everything is back to normal.
Here is the program:
import java.awt.*;
import java.awt.event.*;
public class MouseEventDemo extends Frame
implements MouseListener {
String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse
static int i=0;//State variable
public MouseEventDemo()
{
addMouseListener(this);
addWindowListener(new MyWindowAdapter());
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me)
{
i=1;
msg = "Click received. i= "+i;
mouseX = me.getX();
mouseY = me.getY();
repaint();
}
public void mouseMoved(MouseEvent me)
{
}
public void mouseDragged(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
public void mousePressed(MouseEvent me)
{
}
// Display msg in the window at current X,Y location.
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
public static void main(String[] args)
{
MouseEventDemo appwin = new MouseEventDemo();
appwin.setSize(new Dimension(300, 300));
appwin.setTitle("MouseEventDemo");
appwin.setVisible(true);
while (true)
{
if(i==1)
{
System.out.println("Value of i is: "+i);
i=0;
}
/*
try
{
Thread.sleep(1);
}
catch(Exception e)
{
System.out.println(e);
};
*/
}
}
}
class MyWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}
This program behaves not like I have expected, but with Thread.sleep(1) it changes it behaviour

Passing parameters to a SignalR Hub (ASP NET Core 6)

how can i pass parameters to a asynchronous task of a SignalR Hub?
The paramaeters id, dis and dg have to be passes to the asynchronous task SendResults().
My hub:
public class ResultHub : Hub
{
ResultRepository ResultRepository;
public ResultHub(IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("DefaultConnection");
ResultRepository = new ResultRepository(connectionString);
}
public async Task SendResults()
{
int id = 2977;
int dis = 3;
int dg = 1;
var Results = ResultRepository.GetResults(id, dis, dg);
await Clients.All.SendAsync("ReceivedResults", Results);
}
}
The asynchronous task SendResults gets the results with ResultRepository.GetResults.
SendResults is called in the Javascript within the chtml file:
function InvokeResults() {
connection.invoke("SendResults").catch(function (err) {
return console.error(err.toString());
});
}
and in the method TableDependency_OnChanged of the class SubscribeResultTableDependency
public class SubscribeResultTableDependency : ISubscribeTableDependency
{
SqlTableDependency<Result> tableDependency;
ResultHub ResultHub;
public SubscribeResultTableDependency(ResultHub resultHub)
{
this.resultHub = resultHub;
}
public void SubscribeTableDependency(string connectionString)
{
tableDependency = new SqlTableDependency<Result>(connectionString);
tableDependency.OnChanged += TableDependency_OnChanged;
tableDependency.OnError += TableDependency_OnError;
tableDependency.Start();
}
private void TableDependency_OnChanged(object sender, TableDependency.SqlClient.Base.EventArgs.RecordChangedEventArgs<Result> e)
{
if (e.ChangeType != TableDependency.SqlClient.Base.Enums.ChangeType.None)
{
resultHub.SendResults();
}
}
private void TableDependency_OnError(object sender, TableDependency.SqlClient.Base.EventArgs.ErrorEventArgs e)
{
Console.WriteLine($"{nameof(Result)} SqlTableDependency error: {e.Error.Message}");
}
}
Passing of parameters in the connection.invoke of the Javascript works, but how can this be done in both calls?
(Microsoft.NETCore.App\6.0.13)
According to your description, if you want to how to pass the parameter from the js to the Hub method, I suggest you could refer to below example:
1.Modify the hub method to add parameter, like below:
public class ChatHub : Hub
{
public async Task SendResults(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
2.Modify the js to add the parameter:
connection.invoke("SendResults", "parameter1", "parameter2").catch(function (err) {
return console.error(err.toString());
});

Class-based enums in Vala?

I'm wondering how to create class-based enums in Vala.
In Java you can do the following:
public class Main {
public static void main(String[] args) {
Action action = Action.COMPRESS;
System.out.printf("Action name: %s, index %d", action.getName(), action.getIndex());
}
}
class Action {
public static final Action COMPRESS = new Action("Compress", 60);
public static final Action DECOMPRESS = new Action("Decompress", 70);
private String name;
private int index;
private Action(String name, int index) {
this.name = name;
this.index = index;
}
public String getName() {
return name;
}
public int getIndex() {
return index;
}
}
But when I try the following in Vala, COMPRESS and DECOMPRESS are always null when accessing from outside the Action class.
public static int main(string[] args) {
stderr.printf("Action name: %s\n", UC.Action.COMPRESS.get_name());
}
public class UC.Action : GLib.Object {
public static UC.Action COMPRESS = new UC.Action("Compress");
public static UC.Action DECOMPRESS = new UC.Action("Decompress");
private string name;
[CCode (construct_function = null)]
private Action(string name) {
this.name = name;
}
public string get_name() {
return name;
}
}
That code outputs the following: Performing (null).
Any ideas how to accomplish this?
In Vala, static class members are initialized during the class_init GObject function, so they're not available until that has been called.
The easiest work-around is to just create an instance; you can throw it away immediately since all you're after is the side-effects.

PhoneStateListener causing problems in outgoin calls

Outgoing calls are ended automatically when phonestatelistener is used to monitor the calls.
This is my code and when this is executed it blocks the outgoing calls :
public class CallHelper {
public String number;
private Context ctx;
private TelephonyManager tm;
private CallStateListener callStateListener;
private OutgoingReceiver outgoingReceiver;
SharedPreferences trackMeData;
public CallHelper(Context ctx) {
this.ctx = ctx;
number ="";
callStateListener = new CallStateListener();
outgoingReceiver = new OutgoingReceiver();
trackMeData = ctx.getSharedPreferences("LockedSIM", 0);
}
private class CallStateListener extends PhoneStateListener {
#Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
number = incomingNumber;
sendsmstoph(number);
System.out.println("Incomgin");
Toast.makeText(ctx, "Incoming: " + incomingNumber,Toast.LENGTH_LONG).show();
break;
}
}
}
public class OutgoingReceiver extends BroadcastReceiver {
public OutgoingReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(ctx, "Outgoing: " + number, Toast.LENGTH_LONG).show();
sendsmstoph(number);
}
}

Flex MultiCore PureMVC Notifier initialization error

I am trying to write a simple multicore PureMVC helloword. I am getting Error: multitonKey for this Notifier not yet initialized!
at org.puremvc.as3.multicore.patterns.observer::Notifier/get facade()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3_MultiCore\src\org\puremvc\as3\multicore\patterns\observer\Notifier.as:89]
at com.jacksutest.view::ApplicationMediator()[C:\myworkspace\MyPureMVC\src\com\jacksutest\view\ApplicationMediator.as:15]
Here is the main mxml:
public static const APP_NAME : String = "MyPureMVC";
private var facade : ApplicationFacade = ApplicationFacade.getInstance(APP_NAME);
public function init() : void
{
facade.startup(this);
}
...
<components:WordForm id="theWordForm"/>
This is the ApplicationFacade.
public class ApplicationFacade extends Facade implements IFacade
{
public static const STARTUP : String = "Startup";
public static const VERIFY_WORD : String = "VerifyWord";
public function ApplicationFacade(key:String)
{
super(key);
}
public static function removeInstance(key:String):void
{
if( null != instanceMap )
{
if( null != instanceMap[key] )
{
delete instanceMap[key];
}
}
}
/**
* Singleton ApplicationFacade Factory Method
*/
public static function getInstance(key:String):ApplicationFacade
{
if ( null == instanceMap[key] )
{
instanceMap[key] = new ApplicationFacade(key);
}
return instanceMap[key] as ApplicationFacade;
}
/**
* Register Commands with the Controller
*/
override protected function initializeController():void
{
super.initializeController();
registerCommand(STARTUP, StartupCommand);
registerCommand(VERIFY_WORD, VerifyWordCommand);
}
public function startup(app : MyPureMVC):void
{
trace("In facade startup");
sendNotification(STARTUP, app);
}
public function verifyWord(wordDTO : WordDTO) : void
{
sendNotification(VERIFY_WORD, wordDTO);
}
}
}
This is startup command
public class StartupCommand extends MacroCommand
{
public function StartupCommand()
{
trace("Startup command created");
addSubCommand(ModelPrepCommand);
addSubCommand(ViewPrepCommand);
}
}
This is ViewPrepCommand
public class ViewPrepCommand extends SimpleCommand
{
override public function execute( note : INotification ) : void
{
var app : MyPureMVC = note.getBody() as MyPureMVC;
facade.registerMediator(new ApplicationMediator(app));
}
}
And this is ApplicationMediator:
public class ApplicationMediator extends Mediator implements IMediator
{
public static const NAME : String = "MyPureMVCApplicationMediator";
public function ApplicationMediator(mainApp : MyPureMVC)
{
facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
}
Error happens when facade.registerMediator.
Find the problem. I should not reference facade in the constructor of ApplicationMediator.
Instead, I should call the facade.registerMediator in onRegister method.
public static const NAME : String = "MyPureMVCApplicationMediator";
public function ApplicationMediator(viewComponent : MyPureMVC)
{
super( NAME, viewComponent );
}
override public function onRegister():void
{
// Retrieve reference to frequently consulted Proxies
facade.registerMediator(new WordFormMediator(mainApp.theWordForm));
}
public function get mainApp() : MyPureMVC
{
return viewComponent as MyPureMVC;
}

Resources