Beispiel #1
0
        private void CreateJob(string localfilename, string serverfilename)
        {
            try
            {
                Manager manager = new Manager();
                Job     jobTest = new Job("CDS" + DateTime.Now.ToString("yyyy-MM-dd"));

                manager.Jobs.AddRange(new System.Net.BITS.Job[] { jobTest });
                manager.OnModfication     += new System.EventHandler <System.Net.BITS.JobModificationEventArgs>(this.manager_OnModfication);
                manager.OnFileTransferred += new System.EventHandler <System.Net.BITS.FileTransferredEventArgs>(this.manager_OnFileTransferred);
                manager.OnTransferred     += new System.EventHandler <System.Net.BITS.JobTransferredEventArgs>(this.manager_OnTransferred);
                manager.OnError           += new System.EventHandler <System.Net.BITS.JobErrorEventArgs>(this.manager_OnError);
                //
                // jobTest
                //
                FileInfo fi      = new FileInfo(localfilename);
                string   zipfile = fi.DirectoryName + "\\ZIP\\" + fi.Name + ".zip";

                if (!Directory.Exists(fi.DirectoryName + "\\ZIP"))
                {
                    Directory.CreateDirectory(fi.DirectoryName + "\\ZIP");
                }
                try
                {
                    using (ZipFile zip = new ZipFile(zipfile))
                    {
                        zip.AddFile(localfilename, "");

                        zip.Save();
                    }
                }
                catch (System.Exception ex1)
                {
                    eventLog1.WriteEntry("Exception :" + ex1.ToString());
                }


                eventLog1.WriteEntry("About to send :" + CDS.Server.Backup.Properties.Settings.Default.remoteserver + serverfilename + ".zip," + zipfile);
                jobTest.DisplayName = "DataUpload";
                jobTest.Files.AddRange(new System.Net.BITS.File[] { new System.Net.BITS.File(CDS.Server.Backup.Properties.Settings.Default.remoteserver + serverfilename + ".zip", zipfile), });
                jobTest.Type     = JobType.Upload;
                jobTest.Priority = System.Net.BITS.JobPriority.Foreground;

                jobTest.Activate();
                jobTest.Resume();
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry("Exception :" + ex.ToString());
            }
        }