Example #1
0
 void iTunesU_OnReceiveData(object sender, iTunesU.OnReceiveDataEventArgs e)
 {
     uploadingBackgroundWorker.CancelAsync();
 }
Example #2
0
        private void uploadingBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            UploadRequest uRequest = e.Argument as UploadRequest;

            iTunesU iTunesU = new iTunesU();
            iTunesU.SiteDomain = uRequest.SiteDomain;
            iTunesU.SharedSecret = uRequest.SharedSecret;

            string handle = uRequest.Handle;
            string[] filesToUpload = uRequest.Files;

            BackgroundWorker worker = sender as BackgroundWorker;
            worker.WorkerReportsProgress = true;

            List<String> newHandleList = new List<string>();

            // setup event for the entire process

            ProgressData pData = new ProgressData();
            iTunesU.OnReceiveData += new iTunesU.OnReceiveDataHandler(delegate(object o, iTunesU.OnReceiveDataEventArgs itunesE)
            {

                int percentUploaded = 0;
                if (itunesE.TotalBytes > 0)
                    percentUploaded = Convert.ToInt32(100 * Convert.ToDouble(itunesE.CurrentByteCount) / Convert.ToDouble(itunesE.TotalBytes));

                pData.TotalBytes = itunesE.TotalBytes;
                pData.BytesUploaded = itunesE.CurrentByteCount;
                pData.Error = itunesE.Error;
                pData.FileCompleted = false;

                worker.ReportProgress(percentUploaded, pData);
            });

            for (int i=0; i<filesToUpload.Length; i++)
            {
                try
                {
                    string fileToUpload = filesToUpload[i];

                    pData.TotalFiles = filesToUpload.Length;
                    pData.FileNumber = i + 1;
                    pData.Filename = System.IO.Path.GetFileName(fileToUpload);

                    // go through each file and upload
                    string fullHandle = iTunesU.UploadFile(handle, fileToUpload);

                    // parse off the end handle
                    string shortHandle = fullHandle.Split(new char[] { '.' })[4];
                    string filename = System.IO.Path.GetFileNameWithoutExtension(fileToUpload);

                    // get the new track's info
                    Track track = iTunesU.GetTrack(shortHandle, true);

                    // DTS Specific code for adding on the date (chapel)
                    if (filename.Length >= 6 && uRequest.AttemptRename)
                    {
                        string datePart = filename.Substring(0, 4) + "-" + filename.Substring(4, 2) + "-" + filename.Substring(6, 2);

                        if (track.Name != "")
                        {
                            track.Name = datePart + " " + track.Name;
                            iTunesU.MergeTrack(shortHandle, track);
                        }
                    }

                    // DTS Specific code for adding on the date (devotional)
                    if (filename.Length == 5 && uRequest.AttemptRename)
                    {
                        string datePart = filename;

                        if (track.Name != "")
                        {
                            track.Name = datePart + " - " + track.Name;
                            iTunesU.MergeTrack(shortHandle, track);
                        }
                    }

                    // send finished
                    pData.FileCompleted = true;
                    pData.ParentTreeNode = uRequest.ParentTreeNode;
                    pData.NewTrackName = track.Name;
                    pData.NewFileHandle = fullHandle;
                    worker.ReportProgress(100, pData);

                    newHandleList.Add(shortHandle);

                }
                catch {
                    ProgressData errorData = new ProgressData();
                    errorData.Error = true;
                    errorData.TotalFiles = filesToUpload.Length;
                    errorData.FileNumber = i + 1;

                    worker.ReportProgress(0, errorData);
                }

            }

            e.Result = String.Join("; ", newHandleList.ToArray());
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (_iTunes == null) {
                _iTunes = new iTunesU();
                _iTunes.SiteDomain = SiteDomain.Text;
                _iTunes.SharedSecret = SharedSecret.Text;
            }

            XmlDocument siteXml = _iTunes.GetSiteXmlDocument(true);

            if (siteXml != null)
                CreateTreeFromXml(siteXml);
            else
                MessageBox.Show("There was an error getting your document tree. Check your domain name and shared secret and try again.");
        }