private void ReceiveSaveWorkItemToDiskCmd(SaveWorkItemToDiskCmd cmd)
        {
            try
            {
                var contract = new SqlWorkItem()
                {
                    SqlQuery      = cmd.ScheduleMessage.SqlQuery,
                    SqlConnection = cmd.ScheduleMessage.SqlConnection,
                    Interval      = cmd.ScheduleMessage.Interval,
                    LastRun       = cmd.ScheduleMessage.LastRun,
                    EndPoint      = cmd.ScheduleMessage.EndPoint,
                    SpParameters  = cmd.ScheduleMessage.SpParameters
                };
                _workItems.Add(cmd.ScheduleMessage.Id, contract);

                using (var file = File.Open(_filePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    Serializer.Serialize(file, _workItems);
                    file.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }
        }
Beispiel #2
0
        public Task ReceiveAsync(IContext context)
        {
            var msg = context.Message;

            if (msg is Started)
            {
                StartUp();
            }
            else if (msg is SaveWorkItemToDiskCmd)
            {
                try
                {
                    var cmd = (SaveWorkItemToDiskCmd)msg;

                    var contract = new SqlWorkItem()
                    {
                        SqlQuery      = cmd.ScheduleMessage.SqlQuery,
                        SqlConnection = cmd.ScheduleMessage.SqlConnection,
                        Interval      = cmd.ScheduleMessage.Interval,
                        LastRun       = cmd.ScheduleMessage.LastRun,
                        EndPoint      = cmd.ScheduleMessage.EndPoint,
                        SpParameters  = cmd.ScheduleMessage.SpParameters.Select(x => new ProtoParameter()
                        {
                            ParameterName  = x.ParameterName,
                            ParameterValue = x.ParameterValue.ToString()
                        }
                                                                                ).ToArray()
                    };

                    _workItems.Add(cmd.ScheduleMessage.Id, contract);
                    Save();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e.Message);
                }
            }
            else if (msg is RemoveWorkItemFromDiskCmd)
            {
                try
                {
                    var cmd      = (RemoveWorkItemFromDiskCmd)msg;
                    var workItem = _workItems[cmd.Id];

                    if (workItem != null)
                    {
                        _workItems.Remove(cmd.Id);
                        Save();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e.Message);
                }
            }
            else if (msg is UpdateLastRunTickCmd)
            {
                try
                {
                    var cmd = (UpdateLastRunTickCmd)msg;
                    _workItems[cmd.Id].LastRun = cmd.NewValue;
                    Save();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e.Message);
                }
            }

            return(Actor.Done);
        }