private void btnConnect_Click(object sender, EventArgs e)
        {
            WCFClient client = new WCFClient(textBoxPlayer.Text,textBoxPass.Text);
            int count = client.CheckScheduleCount();
            List<Schedule> schedules = new List<Schedule>();
            if (count >= 0)
            {
                for (int i = 0; i < count; i++)
                {

                    Schedule sche = client.CheckSchedule(i);
                    if (sche != null)
                        schedules.Add(sche);
                }
                MessageBox.Show("Test Succeed!", "Result");
            }
            else
                MessageBox.Show("Test Failed!", "Result");
        }
Exemplo n.º 2
0
        private void ReceiveInformation()
        {
            while (!formClose)
            {
                try {

                    string UserName="";
                    string Password="";
                    int waittime = 0;
                    AccountHelper accounthelper = new AccountHelper();
                    if (accounthelper.ReadFromFile())
                    {
                        UserName = accounthelper.Account;
                        Password = accounthelper.Password;
                        waittime = accounthelper.UpdateInterval;

                        WCFClient client = new WCFClient(UserName, Password);
                        int count = client.CheckScheduleCount();
                        List<Schedule> schedules = new List<Schedule>();
                        if (count >= 0)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                Schedule sche = client.CheckSchedule(i);
                                if (sche != null)
                                    schedules.Add(sche);
                            }
                            if (downloadAllFiles(schedules, client))
                            {
                                DisplayController newController = new DisplayController(schedules);
                                String tmppath = Path.Combine(DownloadDir, "Schedule.xml");
                                String schepath = Path.Combine(ScheduleDir, "Schedule.xml");
                                String oldschepath = Path.Combine(ScheduleDir, DateTime.Now.ToString("MMddyy_Hmmss")+"Schedule.old");
                                try
                                {
                                    if (File.Exists(oldschepath))
                                    {
                                        File.Delete(oldschepath);
                                    }
                                    if (File.Exists(tmppath))
                                    {
                                        File.Delete(tmppath);
                                    }
                                    newController.WriteToXML(tmppath);
                                    if (!FileCompare(tmppath, schepath))
                                    {
                                        if (File.Exists(schepath))
                                            File.Move(schepath, oldschepath);
                                        File.Move(tmppath, schepath);
                                        newScheUpdated = true;
                                    }

                                    // better make a lock here

                                }
                                catch (Exception exp)
                                {

                                }
                            }
                        }
                        DateTime time = DateTime.Now;
                        while (DateTime.Now.Subtract(time).TotalMinutes < waittime)
                        {
                            Thread.Sleep(100);
                            if (formClose)
                                return;
                        }
                    }
                    else
                    {
                        Thread.Sleep(10000);
                    }
                }
                catch (Exception exp)
                {
                }
            }
        }
Exemplo n.º 3
0
        private bool downloadAllFiles(List<Schedule> Schedules, WCFClient client)
        {
            List<string> downloadedItems = new List<string>();
            try
            {
                foreach (Schedule sche in Schedules)
                {
                    foreach (PlayItem item in sche.PlayItems)
                    {
                        string dstpath = Path.Combine(ContentDir, Path.GetFileName(item.Path));
                        string svrpath = string.Copy( item.Path);
                        item.Path = Path.Combine(ContentDir, Path.GetFileName(item.Path));;
                        try
                        {
                            if (!File.Exists(dstpath))
                            {
                                string downloadpath = Path.Combine(DownloadDir, Path.GetFileName(item.Path) + ".down");
                                if (client.DownloadFile(svrpath, downloadpath))
                                {
                                    if (File.Exists(downloadpath))
                                    {
                                        File.Move(downloadpath, dstpath);
                                        downloadedItems.Add(dstpath);
                                    }
                                }
                            }
                        }
                        catch (Exception exp)
                        {

                        }
                        Thread.Sleep(1000);
                    }

                }
                return true;
            }
            catch (Exception exp)
            { }
            return false;
        }