Beispiel #1
0
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs) {
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     BITSJobs ds = new BITSJobs();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "FilesDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     return type;
 }
Beispiel #2
0
        void ThreadProc()
        {
            _stopEvent.Reset();
            string serverAddress = Properties.Settings.Default.ServerAddress;
            double minCheckDelay = Properties.Settings.Default.MinCheckForUpdateDelayInSeconds;
            string bitsJobsFileName = Properties.Settings.Default.BITSJobsFileName;
            string tempFilePath = Properties.Settings.Default.TempFilePath;
            string downloadWebFolderName = Properties.Settings.Default.DownloadWebFolderName;

            if (serverAddress.Length == 0 /*|| !Uri.IsWellFormedUriString(serverUrl, UriKind.Absolute)*/)
            {
                log.WriteLog("No valid ServerAddress specified for update checks. Exiting.");
                return;
            }
            Uri serverUri = new Uri(string.Format("{0}{1}{2}", Uri.UriSchemeHttp, Uri.SchemeDelimiter, serverAddress));

            //if (serverUri.Scheme != Uri.UriSchemeHttp && serverUri.Scheme != Uri.UriSchemeHttps)
            //{
            //    log.WriteLog("The ServerUrl specified must start with http:// or https://: " + serverUrl);
            //}
            if (tempFilePath.Length == 0)
            {
                tempFilePath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                    @"\" + AppInfo.Title + @"\DownloadedFiles";
                if (!Directory.Exists(tempFilePath))
                {
                    Directory.CreateDirectory(tempFilePath);
                    log.WriteLog("Temp File Path created. See below.");
                }
            }
            if (bitsJobsFileName.Length == 0)
            {
                bitsJobsFileName = "BITSJobs.xml";
            }
            if (downloadWebFolderName.Length == 0)
            {
                downloadWebFolderName = AppInfo.Title;
            }
            string bitsJobsLocalFilePath = Path.Combine(tempFilePath, bitsJobsFileName);
            string tempBitsDownloadFilePath = Path.Combine(tempFilePath, "downloaded." + bitsJobsFileName);
            DateTime NextCheckForNewContentTime = DateTime.MinValue;
            bool execute = false;
            BITSJobs jobsRemote = null;

            log.WriteLog("Configuration: " + "\n" +
                "\tServer Address: " + serverAddress + "\n" +
                "\tWeb Folder Name: " + downloadWebFolderName + "\n" +
                "\tBITS Job file name: " + bitsJobsFileName + "\n" +
                "\tServer URI: " + serverUri + "\n" +
                "\tMinimum Check for Update Delay (sec): " + minCheckDelay + "\n" +
                "\tTemp File Path: " + tempFilePath + "\n" +
                "\tBITS Jobs local file path: " + bitsJobsLocalFilePath + "\n" +
                "\tTemp BITS file path: " + tempBitsDownloadFilePath);

            TimeSpan TimeTillNextLogUpdate = TimeSpan.FromMinutes(1.0);
            DateTime NextLogUpdateTime = DateTime.MinValue;
            Manager manager = new Manager();
            while (!_done)
            {
                execute = false;
                if (DateTime.Now >= NextCheckForNewContentTime && !IsActiveJobRunning)
                {	// check for a new job
                    try
                    {
                        Uri requestUri;
                        if (Uri.TryCreate(serverUri, downloadWebFolderName + "/" + bitsJobsFileName,
                            out requestUri))
                        {
                            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
                            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                            log.WriteLog(string.Format("{0} is {1} bytes long.", requestUri.AbsoluteUri, response.ContentLength));
                            Stream receiveStream = response.GetResponseStream();
                            StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
                            StreamWriter writer = new StreamWriter(tempBitsDownloadFilePath, false);
                            writer.Write(reader.ReadToEnd());
                            writer.Close();
                            reader.Close();
                            try
                            {
                                jobsRemote = new BITSJobs();
                                jobsRemote.ReadXml(tempBitsDownloadFilePath);
                                if (System.IO.File.Exists(bitsJobsLocalFilePath))
                                {
                                    BITSJobs jobsLocal = new BITSJobs();

                                    jobsLocal.ReadXml(bitsJobsLocalFilePath);
                                    if (jobsRemote.BITSJobVersion[0].FileCreatedOn >
                                        jobsLocal.BITSJobVersion[0].FileCreatedOn)
                                        execute = true;
                                }
                                else
                                    execute = true;
                                if (execute)
                                {
                                    if (System.IO.File.Exists(bitsJobsLocalFilePath))
                                    {
                                        System.IO.File.Copy(bitsJobsLocalFilePath, Path.Combine(tempFilePath,
                                            "previously.downloaded." + bitsJobsFileName), true);
                                    }
                                    jobsRemote.WriteXml(bitsJobsLocalFilePath);
                                }
                            }
                            catch (Exception ex)
                            {
                                log.WriteLog(
                                    string.Format("There was a problem with the downloaded or local file {0}: {1}",
                                    serverUri.ToString(), ex.Message));
                            }
                            finally
                            {
                                receiveStream.Close();
                                response.Close();
                            }
                        }
                        else
                        {
                            log.WriteLog("Could not create a valid request URI.");
                        }
                    }
                    catch (WebException webex)
                    {
                        log.WriteLog("Web Exception while getting update info from web server: " + webex.Message);
                    }
                    catch (Exception ex)
                    {
                        log.WriteLog("Exception while getting update info from web server: " + ex.Message);
                    }
                    finally
                    {
                        NextCheckForNewContentTime = DateTime.Now +	TimeSpan.FromSeconds(minCheckDelay);
                        log.WriteLog("Next check for update at: " + NextCheckForNewContentTime.ToString());
                    }
                }
            TryAfterDisconnect:
                if (execute)
                {	// time ta git bizzy
                    try
                    {
                        List<Job> bitsJobs = new List<Job>();
                        foreach (BITSJobs.JobsRow job in jobsRemote.Jobs)
                        {
                            log.WriteLog("Creating " + job.Name);
                            JobType jobType = JobType.Download;
                            JobPriority jobPriority = JobPriority.Normal;
                            if (job.JobType.Length > 0)
                            {
                                log.WriteLog("Setting Job Type to " + job.JobType);
                                jobType = (JobType)Enum.Parse(typeof(JobType), job.JobType);
                            }
                            if (job.JobPriority.Length > 0)
                            {
                                try
                                {
                                    log.WriteLog("Setting Job Type to " + job.JobPriority);
                                    jobPriority = (JobPriority)Enum.Parse(typeof(JobPriority), job.JobPriority);
                                }
                                catch
                                {
                                    log.WriteLog("Job Priority is invalid. Setting to Normal");
                                    jobPriority = JobPriority.Normal;
                                }
                            }
                            if (job.Name.Length == 0)
                            {
                                job.Name = "Job_" + Guid.NewGuid().ToString();
                            }
                            Job bitsJob = new Job(job.Name, jobType, jobPriority);
                            string localPath = Path.Combine(tempFilePath, job.Name);
                            if (job.AfterCompletedRun.Length > 0)
                            {
                                bitsJob.NotifyCmdLine.Program = Path.Combine(localPath, job.AfterCompletedRun);
                            }
                            List<System.Net.BITS.File> bitsFiles = new List<System.Net.BITS.File>();
                            foreach (BITSJobs.FilesRow file in job.GetFilesRows())
                            {
                                if (!Directory.Exists(localPath))
                                {
                                    Directory.CreateDirectory(localPath);
                                }
                                log.WriteLog("Adding file: " + file.LocalPath);
                                string localFilePath = Path.Combine(localPath, file.LocalPath);
                                bitsFiles.Add(new System.Net.BITS.File(file.RemoteUrl, localFilePath));
                                log.WriteLog("Putting " + file.LocalPath + " at " + localFilePath);
                            }
                            bitsJob.Files.AddRange(bitsFiles.ToArray());
                            bitsJobs.Add(bitsJob);
                        }
                        log.WriteLog("Adding " + bitsJobs.Count + (bitsJobs.Count == 1 ? " job" : " jobs") + " to BITS");
                        manager.Jobs.AddRange(bitsJobs.ToArray());
                        manager.OnFileTransferred += new EventHandler<FileTransferredEventArgs>(manager_OnFileTransferred);
                        manager.OnError += new EventHandler<JobErrorEventArgs>(manager_OnError);
                        manager.OnModfication += new EventHandler<JobModificationEventArgs>(manager_OnModfication);

                        _jobCompleteEvent.Reset();
                        foreach (Job job in bitsJobs)
                        {
                            job.EventsEnabled = true;
                            job.Resume();
                        }
                        //_jobCompleteEvent.WaitOne();
                    }
                    catch (MyException execex)
                    {
                        if (execex.HResult == -2146233088)
                        {
                            manager = new Manager();
                            goto TryAfterDisconnect;
                        }
                        log.WriteLog("During Job creation, something went wrong. The job will not be created. " +
                            "Error text: " + execex.ToString());
                    }
                    finally
                    {
                        foreach (Job job in manager.Jobs)
                        {
                            log.WriteLog(JobUpdateText(job));
                        }
                    }
                }
                else
                {
                    if (IsActiveJobRunning && DateTime.Now >= NextLogUpdateTime)
                    {
                        foreach (Job job in manager.Jobs)
                        {
                            log.WriteLog(JobUpdateText(job));
                        }
                        NextLogUpdateTime = DateTime.Now + TimeTillNextLogUpdate;
                    }
                }
                System.Threading.Thread.Sleep(500);
            }
            _stopEvent.Set();
        }
Beispiel #3
0
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     BITSJobs ds = new BITSJobs();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     return type;
 }