返回首页

LT,W:PW:rsidR ="00B90185"W:rsidRPr =的"00E6156F"W:rsidRDefault =的"006E7EE3"W:rsidP ="00D9692D"GT,LT; W:pPrgt; LT; W:间距后W:=" 0"/>

回答

评论会员:SAKryukov 时间:2012/02/07
你的接口没有成员,所以其执行不能可能"破"由于实现此接口的事实。在更一般的情况下,它也不会是一个问题:任何类的任何方法可以调用任何类的任何方法(静态方法),或一个类的实例(实例方法)没有接口的实现有关的任何关注。你可能面临的唯一问题是成员与接口成员冲突的声明,但解决这个问题,使用显式接口成员实现,见

如果你面临的一些问题("停止工作"),原因是在别处。你没有提供足够的信息,才能看到它

mdash;的SA
评论会员:lxmyers 时间:2012/02/07
你好SA,
感谢你的答复,但我有一个小麻烦的理解...
我有一个通过代码看看,我似乎无法找到任何会导致冲突和运行程序是没有问题的。唯一的问题是,当我添加基类(
internal class SendAlarmCommand : MainWindow, IMyJob
)石英不会触发工作。

下面是所有的代码,我想获得工作...如果你可以看一看,那将不胜感激。

再次谢谢您的帮助,
亚历克斯。
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using Common.Logging;

using Quartz;

using Quartz.Impl;

using System.Threading;

using System.Net;

using System.ComponentModel;

using Scheduler.SVC;

using System.Configuration;

using System.Windows.Threading;

using System.ServiceModel;

 

namespace Scheduler

{

    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    public partial class MainWindow : Window, SVC.ICommsCallback

    {

        static IScheduler _scheduler;

 

        static string ServerIPAddress;

        static string UnitName;

 

        static ScheduleDataContext ScheduleDC = new ScheduleDataContext();

        static ClientDataContext ClientDC = new ClientDataContext();

 

        SVC.CommsClient proxy = null;

        SVC.Client receiver = null;

        SVC.Client localClient = null;

 

        private delegate void FaultedInvoker();

 

        Dictionary<string, SVC.Client> OnlineClients = new Dictionary<string, Client>();    

 

        public MainWindow()

        {

            InitializeComponent();

 

            //Get configuration information from app.config

            ServerIPAddress = ConfigurationManager.AppSettings["ServerAddress"];

            UnitName = ConfigurationManager.AppSettings["DeviceName"];

 

            //Start Quartz

            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();

            _scheduler = schedulerFactory.GetScheduler();

            _scheduler.Start();

            Console.WriteLine("Scheduler Started");

        }

 

        protected override void OnInitialized(EventArgs e)

        {

            this.Loaded += new RoutedEventHandler(Scheduler_Loaded);

            this.Closed += new EventHandler(Scheduler_Closed);

            base.OnInitialized(e);

        }

 

        private void Scheduler_Loaded(object sender, RoutedEventArgs e)

        {

            //Add active Alarm jobs to _scheduler

            var AlarmsQuery = from aq in ScheduleDC.schedule_ALARMs

                              where aq.alarm_STATE == 1

                              select aq;

 

            foreach (var aq in AlarmsQuery)

            {

                AddAlarmJob(aq.alarm_ID, Convert.ToInt16(aq.client_ID), Convert.ToInt16(aq.clock_ID), aq.time_CRON, aq.command);

            }

 

            //Connect to ServiceHost

            proxy = null;

            Connect();

        }

 

        private void Scheduler_Closed(object sender, EventArgs e)

        {

            //Disconnect from ServiceHost

            if (proxy != null)

            {

                if (proxy.State == CommunicationState.Opened)

                {

                    proxy.Disconnect(this.localClient);

                    Console.WriteLine("Disconnected from server");

                }

                else

                {

                    HandleProxy();

                }

            }

 

            //Shutdown Quartz

            _scheduler.Shutdown();

        }

 

        public void AddAlarmJob(int AlarmID, int ClientID, int ClockID, string TimeCRON, string Command)

        {

            string JobName = ("AlarmJob" + AlarmID);

            string TriggerName = ("AlarmTrigger" + AlarmID);

 

            JobDetail jobDetail = new JobDetail(JobName, null, typeof(SendAlarmCommand));

 

            jobDetail.JobDataMap["ClientID"] = Convert.ToString(ClientID);

            jobDetail.JobDataMap["ClockID"] = Convert.ToString(ClockID);

            jobDetail.JobDataMap["Command"] = Command;

 

            CronTrigger trigger = new CronTrigger(TriggerName, null, TimeCRON); //run at 2am every day - use CronMaker

            _scheduler.ScheduleJob(jobDetail, trigger);

 

            DateTime JobTimeUTC = Convert.ToDateTime(trigger.GetNextFireTimeUtc());

            DateTime JobTimeLocal = JobTimeUTC.ToLocalTime();

            Console.WriteLine("Job Added - " + JobName);

            Console.WriteLine("Next Fire Time: " + JobTimeLocal);

        }

 

        public static void UpdateTVGuide(string GuideID, string GuideURL)

        {

            string JobName = ("TVGuideUpdateJob" + GuideID);

            string TriggerName = ("TVGuideUpdateTrigger" + GuideID);

 

            //IMyJob myJob = new TVGuideUpdate(); //This Constructor needs to be parameterless

            JobDetail jobDetail = new JobDetail(JobName, null, typeof(TVGuideUpdate));

 

            jobDetail.JobDataMap["GuideURL"] = GuideURL;

 

            CronTrigger trigger = new CronTrigger(TriggerName, null, "0 15 18 * * ? *"); //run at 2am every day - use CronMaker

            _scheduler.ScheduleJob(jobDetail, trigger);

 

            DateTime JobTimeUTC = Convert.ToDateTime(trigger.GetNextFireTimeUtc());

            DateTime JobTimeLocal = JobTimeUTC.ToLocalTime();

            Console.WriteLine("Job Added - " + JobName);

            Console.WriteLine("Next Fire Time:" + JobTimeLocal);

        }

 

        # region COMMS - Private Methods

 

        private void HandleProxy()

        {

            if (proxy != null)

            {

                switch (this.proxy.State)

                {

                    case CommunicationState.Closed:

                        proxy = null;

                        break;

                    case CommunicationState.Closing:

                        break;

                    case CommunicationState.Created:

                        break;

                    case CommunicationState.Faulted:

                        proxy.Abort();

                        proxy = null;

                        break;

                    case CommunicationState.Opened:

 

                        Console.WriteLine("Connection Successful");

 

                        break;

                    case CommunicationState.Opening:

                        break;

                    default:

                        break;

                }

            }

 

        }

 

        private void Connect()

        {

            Console.WriteLine("Connecting to server, please wait a moment...");

 

            if (proxy == null)

            {

                try

                {

                    this.localClient = new SVC.Client();

                    this.localClient.Name = UnitName;

                    this.localClient.UnitType = 1;

                    InstanceContext context = new InstanceContext(this);

                    proxy = new SVC.CommsClient(context);

 

                    proxy.Endpoint.Address = new EndpointAddress("net.tcp://" + ServerIPAddress + ":6555/ServiceHost/tcp");

 

                    proxy.Open();

 

                    proxy.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted);

                    proxy.InnerDuplexChannel.Opened += new EventHandler(InnerDuplexChannel_Opened);

                    proxy.InnerDuplexChannel.Closed += new EventHandler(InnerDuplexChannel_Closed);

                    proxy.ConnectAsync(this.localClient);

                    proxy.ConnectCompleted += new EventHandler<ConnectCompletedEventArgs>(proxy_ConnectCompleted);

                }

                catch (Exception ex)

                {

                    Console.WriteLine("Epic Fail" + ex);

                }

            }

            else

            {

                HandleProxy();

            }

        }

 

        void proxy_ConnectCompleted(object sender, ConnectCompletedEventArgs e)

        {

            if (e.Error != null)

            {

                Console.WriteLine(e.Error.Message.ToString());

            }

            else if (e.Result)

            {

                HandleProxy();

            }

            else if (!e.Result)

            {

                Console.WriteLine("Name found");

            }

 



        }

 

        private void Send(string Command)

        {

            if (proxy != null)

            {

                if (proxy.State == CommunicationState.Faulted)

                {

                    HandleProxy();

                    Console.WriteLine("Failed");

                }

                else

                {

                    SVC.Message msg = new SVC.Message();

                    msg.Sender = this.localClient.Name;

                    msg.Content = Command;

 

                    proxy.SendAsync(msg);

 

                    proxy.IsWritingAsync(null);

                }

            }

        }

 

        private void SendPrivate(string command)

        {

            if (proxy != null)

            {

                if (proxy.State == CommunicationState.Faulted)

                {

                    HandleProxy();

                }

                else

                {

                    SVC.Message msg = new SVC.Message();

                    msg.Sender = this.localClient.Name;

                    msg.Content = (command);

 

                    proxy.SendPrivateAsync(msg, this.receiver);

 

                    proxy.IsWritingAsync(null);

                }

            }

        }

 

        public void ProccessMessage(string command)

        {

 

        }

 

        public void ProccessPrivateMessage(string command)

        {

 

        }

 

        #endregion

 

        #region COMMS - IChatCallback Members

 

        public void RefreshClients(List<Scheduler.SVC.Client> clients)

        {

            OnlineClients.Clear();

            foreach (SVC.Client c in clients)

            {

                OnlineClients.Add(c.Name, c);

            }

        }

 

        public void Receive(Scheduler.SVC.Message msg)

        {

 

        }

 

        public void ReceivePrivate(Scheduler.SVC.Message msg, Scheduler.SVC.Client receiver)

        {

            Console.WriteLine(msg.Sender + " whispers " + receiver.Name + " : " + msg.Content);

        }

 

        public void IsWritingCallback(Scheduler.SVC.Client client)

        {

            if (client == null)

            {

                //chatLabelWritingMsg.Content = "";

            }

            else

            {

                //chatLabelWritingMsg.Content += client.Name +

                //      " is writing a message.., ";

            }

        }

 

        public void ClientConnect(Scheduler.SVC.Client client)

        {

            //MessagesListBox.Items.Add(client.UnitType + "------------ " + client.Name + " joined chat ------------");

        }

 

        public void ClientDisconnect(Scheduler.SVC.Client client)

        {

            //MessagesListBox.Items.Add(client.UnitType + "------------ " + client.Name + " left chat ------------");

        }

 

        #endregion

 

        # region COMMS - InnerDuplexChannel

 

        void InnerDuplexChannel_Closed(object sender, EventArgs e)

        {

            if (!this.Dispatcher.CheckAccess())

            {

                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,

                                new FaultedInvoker(HandleProxy));

                return;

            }

            HandleProxy();

        }

 

        void InnerDuplexChannel_Opened(object sender, EventArgs e)

        {

            if (!this.Dispatcher.CheckAccess())

            {

                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,

                                new FaultedInvoker(HandleProxy));

                return;

            }

            HandleProxy();

        }

 

        void InnerDuplexChannel_Faulted(object sender, EventArgs e)

        {

            if (!this.Dispatcher.CheckAccess())

            {

                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,

                                new FaultedInvoker(HandleProxy));

                return;

            }

            HandleProxy();

        }

 

        #endregion

 

        #region COMMS - Async

 

        public IAsyncResult BeginClientDisconnect(Scheduler.SVC.Client client, AsyncCallback callback, object asyncState)

        {

            throw new NotImplementedException();

        }

 

        public void EndClientDisconnect(IAsyncResult result)

        {

            throw new NotImplementedException();

        }

 

        public IAsyncResult BeginClientConnect(Scheduler.SVC.Client client, AsyncCallback callback, object asyncState)

        {

            throw new NotImplementedException();

        }

 

        public void EndClientConnect(IAsyncResult result)

        {

            throw new NotImplementedException();

        }

 

        public IAsyncResult BeginIsWritingCallback(Scheduler.SVC.Client client, AsyncCallback callback, object asyncState)

        {

            throw new NotImplementedException();

        }

 

        public void EndIsWritingCallback(IAsyncResult result)

        {

            throw new NotImplementedException();

        }

 

        public IAsyncResult BeginReceivePrivate(Scheduler.SVC.Message msg, Scheduler.SVC.Client receiver, AsyncCallback callback, object asyncState)

        {

            throw new NotImplementedException();

        }

 

        public void EndReceivePrivate(IAsyncResult result)

        {

            throw new NotImplementedException();

        }

 

        public IAsyncResult BeginReceive(Scheduler.SVC.Message msg, AsyncCallback callback, object asyncState)

        {

            throw new NotImplementedException();

        }

 

        public void EndReceive(IAsyncResult result)

        {

            throw new NotImplementedException();

        }

 

        public IAsyncResult BeginRefreshClients(List<Scheduler.SVC.Client> clients, AsyncCallback callback, object asyncState)

        {

            throw new NotImplementedException();

        }

 

        public void EndRefreshClients(IAsyncResult result)

        {

            throw new NotImplementedException();

        }

 

        #endregion

 

        #region Quartz Jobs

 

        internal class SendAlarmCommand : MainWindow, IMyJob

        {

            public void Execute(JobExecutionContext context)

            {

                Console.WriteLine("In MyJob class : " + context.JobDetail.Name);

                Console.WriteLine(string.Format("Running Alarm Job - {0}", System.DateTime.Now.ToString("r")));

 

                JobDataMap dataMap = context.JobDetail.JobDataMap;

 

                Console.WriteLine("Client ID - " + dataMap.GetString("ClientID"));

                Console.WriteLine("Clock ID - " + dataMap.GetString("ClockID"));

                Console.WriteLine("Command - " + dataMap.GetString("Command"));

 

                string command = (dataMap.GetString("Command"));

                Send(command); //Function in MainWindow



            }

        }

 

        internal class TVGuideUpdate : IMyJob

        {

            string GuideDirectory = ConfigurationManager.AppSettings["GuideDirectory"];

 

            public void Execute(JobExecutionContext context)

            {

                JobDataMap dataMap = context.JobDetail.JobDataMap;

 

                string guideURL = dataMap.GetString("GuideURL");

                string fileName = "iceguide.xml";

                string destFile = System.IO.Path.Combine(GuideDirectory, fileName);

 

                Console.WriteLine(string.Format("Running TV Guide Update Job - {0}", System.DateTime.Now.ToString("r")));

                Console.WriteLine("Downloading TV Guide...");

 

                if (!System.IO.Directory.Exists(GuideDirectory))

                {

                    System.IO.Directory.CreateDirectory(GuideDirectory);

                }

 

                WebClient webClient = new WebClient();

                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);

                webClient.DownloadFileAsync(new Uri(guideURL), destFile);

            }

 

            public void DownloadCompleted(object sender, AsyncCompletedEventArgs e)

            {

                Console.WriteLine("TV Guide download completed.");

            }

        }

 

        internal interface IMyJob : IJob

        {

        }

 

        #endregion Quartz Jobs

 

    }

 

    

}
评论会员:lxmyers 时间:2012/02/07
嗨,大家好,
延迟很抱歉,我已经设法找到一个simplet解决方案。
只是柜面的人有类似的问题,我发现一个非常类似的职位...

{A}

亲切的问候,
亚历克斯