static void Main(string[] args)
        {
            DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");
            // TODO: Instantiate an Authenticator object according to your authentication
            // mechanism (e.g. OAuth2Authenticator).
            // Authenticator authenticator =  ...
            // Instantiate a DocumentEntry object to be inserted.
            DocumentEntry entry = new DocumentEntry();

            // Set the document title
            entry.Title.Text = "Legal Contract";
            // Set the media source
            entry.MediaSource = new MediaFileSource("c:\\contract.txt", "text/plain");
            // Define the resumable upload link
            Uri      createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
            AtomLink link            = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.Links.Add(link);
            // Set the service to be used to parse the returned entry
            entry.Service = service;
            // Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            // Set the handlers for the completion and progress events
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
            uploader.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(OnProgress);
            // Start the upload process
            uploader.InsertAsync(authenticator, entry, new object());
        }
    public async Task UploadToYouTube(HttpPostedFile postedFile, string title)
    {
        UploadingDispatcher.SetProgress(uploadId, 2);
        Video video = new Video();

        video.Title = title;
        video.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
        video.Private     = false;
        video.MediaSource = new MediaFileSource(postedFile.InputStream, postedFile.FileName, postedFile.ContentType);

        var link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads");

        link.Rel = ResumableUploader.CreateMediaRelation;
        video.YouTubeEntry.Links.Add(link);

        var youtubeApiKey    = ConfigurationManager.AppSettings["youtubeApiKey"];
        var applicationName  = ConfigurationManager.AppSettings["applicationName"];
        var youtubeUserName  = ConfigurationManager.AppSettings["youtubeUserName"];
        var youtubePassword  = ConfigurationManager.AppSettings["youtubePassword"];
        var youtubeChunksize = int.Parse(ConfigurationManager.AppSettings["youtubeChunksize"]);

        var resumableUploader = new ResumableUploader(youtubeChunksize);

        resumableUploader.AsyncOperationCompleted += resumableUploader_AsyncOperationCompleted;
        resumableUploader.AsyncOperationProgress  += resumableUploader_AsyncOperationProgress;


        var youTubeAuthenticator = new ClientLoginAuthenticator(applicationName, ServiceNames.YouTube, youtubeUserName, youtubePassword);

        youTubeAuthenticator.DeveloperKey = youtubeApiKey;

        resumableUploader.InsertAsync(youTubeAuthenticator, video.YouTubeEntry, uploadId);
    }
        /// <summary>
        /// insert a new video.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="retryCounter"></param>
        /// <returns></returns>
        private bool InsertVideo(DataGridViewRow row, int retryCounter)
        {
            Trace.TraceInformation("Entering InsertVideo: starting a new upload");
            Video v = new Video();

            v.Title       = row.Cells[0].Value.ToString();
            v.Description = row.Cells[1].Value.ToString();
            v.Keywords    = row.Cells[2].Value.ToString();
            v.Tags.Add(new MediaCategory(row.Cells[3].Value.ToString()));
            v.Private = row.Cells[4].Value.ToString().ToLower() == "true";

            string contentType = MediaFileSource.GetContentTypeForFileName(row.Cells[COLUMNINDEX_FILENAME].Value.ToString());

            v.MediaSource = new MediaFileSource(row.Cells[COLUMNINDEX_FILENAME].Value.ToString(), contentType);

            // add the upload uri to it
            AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + this.youtubeAccount + "/uploads");

            link.Rel = ResumableUploader.CreateMediaRelation;
            v.YouTubeEntry.Links.Add(link);

            UserState u = new UserState(row);

            u.RetryCounter = retryCounter;

            lock (this.flag) {
                this.queue.Add(u);
            }
            ru.InsertAsync(this.youTubeAuthenticator, v.YouTubeEntry, u);

            row.Cells[COLUMNINDEX_STATUS].Value = "Queued up...";
            row.Cells[COLUMNINDEX_STATUS].Tag   = u;

            return(true);
        }
Beispiel #4
0
        public void DoWorkbookUpload(object in_instance)
        {
            var instance = in_instance as Google2uData;

            if (instance == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(instance.WorkbookUploadPath))
            {
                try
                {
                    // We need a DocumentService
                    var service  = new DocumentsService("Google2Unity");
                    var mimeType = Google2uMimeType.GetMimeType(instance.WorkbookUploadPath);

                    var authenticator = new OAuth2Authenticator("Google2Unity", _authParameters);

                    // Instantiate a DocumentEntry object to be inserted.
                    var entry = new DocumentEntry
                    {
                        MediaSource = new MediaFileSource(instance.WorkbookUploadPath, mimeType)
                    };

                    // Define the resumable upload link
                    var createUploadUrl =
                        new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
                    var link = new AtomLink(createUploadUrl.AbsoluteUri)
                    {
                        Rel = ResumableUploader.CreateMediaRelation
                    };

                    entry.Links.Add(link);

                    // Set the service to be used to parse the returned entry
                    entry.Service = service;


                    // Instantiate the ResumableUploader component.
                    var uploader = new ResumableUploader();

                    // Set the handlers for the completion and progress events
                    uploader.AsyncOperationCompleted += OnSpreadsheetUploadDone;
                    uploader.AsyncOperationProgress  += OnSpreadsheetUploadProgress;

                    // Start the upload process
                    uploader.InsertAsync(authenticator, entry, instance);
                }
                catch (Exception)
                {
                    PushNotification(
                        "There is a problem with your credentials. Clear the credentials and Re-Authorize G2U");
                    //instance.Messages.Add(new G2GUIMessage(GFGUIMessageType.InvalidLogin, ex.Message));
                    instance.Commands.Remove(GFCommand.WaitingForUpload);
                }
            }
        }
Beispiel #5
0
        public string Sling(string path)
        {
            string token = Guid.NewGuid().ToString("N");

            zipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(zipPath, path, true, "", "");

            int CHUNK_SIZE = 10485760;

            ClientLoginAuthenticator cla = new ClientLoginAuthenticator("commanigy-slingshot-v1", ServiceNames.Documents, "username", "password");

            // Set up resumable uploader and notifications
            ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);

            ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            ru.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(this.OnProgress);

            // Set metadata for our upload.
            Document entry = new Document();

            entry.Title = string.Format("testupload", token);
            //entry.MediaSource = new MediaFileSource(new FileStream(zipPath, FileMode.Open), "test.zip", "application/zip");
            //entry.MediaSource = new MediaFileSource(zipPath, "application/zip");
            entry.MediaSource = new MediaFileSource(zipPath, "application/zip");

            // Add the upload uri to document entry.
            Uri      createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
            AtomLink link            = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.DocumentEntry.Links.Add(link);

            string userObject = "Just a sample text";

            ru.InsertAsync(cla, entry.DocumentEntry, userObject);
            //ru.InsertAsync(cla, createUploadUrl, new FileStream(zipPath, FileMode.Open), "application/zip", "mytest.zip", userObject);

            return(token);
        }
Beispiel #6
0
        public void uploadFile(string fileName, DocumentEntry parentFolder)
        {
            if (cancel())
            {
                return;
            }
            string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();

            if (!m_fileFilters.ContainsKey(fileExtension))
            {
                return;
            }
            int CHUNK_SIZE       = 1;
            ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);

            ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            ru.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(this.OnProgress);

            // Check if entry exists
            FolderQuery contentQuery = new FolderQuery(parentFolder.ResourceId);

            contentQuery.Title      = Path.GetFileName(fileName);
            contentQuery.TitleExact = true;
            DocumentsFeed contents   = m_service.Query(contentQuery);
            bool          fileExists = contents.Entries.Count > 0;
            DocumentEntry entry      = fileExists?contents.Entries[0] as DocumentEntry:new DocumentEntry();

            entry.Title.Text = Path.GetFileName(fileName);
            string mimeType = m_fileFilters[fileExtension];

            entry.MediaSource = new MediaFileSource(fileName, mimeType);
            // Define the resumable upload link
            string notConvert = "?convert=false";
            Uri    createUploadUrl;

            if (parentFolder == null)
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full" + notConvert);
            }
            else
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full/" + parentFolder.ResourceId + "/contents" + notConvert);
            }
            AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.Links.Add(link);

            // Set the service to be used to parse the returned entry
            entry.Service = m_service;

            // Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            // Set the handlers for the completion and progress events
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
            uploader.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(OnProgress);
            ClientLoginAuthenticator cla = new ClientLoginAuthenticator("uploader", ServiceNames.Documents, m_username, m_password);

            // Start the upload process
            if (cancel())
            {
                return;
            }
            if (fileExists)
            {
                uploader.UpdateAsync(cla, entry, new Object());
            }
            else
            {
                uploader.InsertAsync(cla, entry, new Object());
            }
        }