Ejemplo n.º 1
0
        internal void UploadContacts(string accessToken)
        {
            FacebookContactsUploader.Tracer.TraceFunction((long)this.GetHashCode(), "Entering FacebookContactsUploader.UploadContacts.");
            if (string.IsNullOrEmpty(accessToken))
            {
                throw new FacebookContactUploadException(Strings.FacebookEmptyAccessToken);
            }
            bool continueOnContactUploadFailure = this.configuration.ContinueOnContactUploadFailure;

            try
            {
                this.performanceTracker.Start();
                int maximumContactsToUpload = this.configuration.MaximumContactsToUpload;
                IEnumerable <IStorePropertyBag> enumerable = this.contactsEnumerator.Where(new Func <IStorePropertyBag, bool>(this.ShouldExportContact)).Take(maximumContactsToUpload);
                ContactsExporter contactsExporter          = new ContactsExporter(FacebookContactsUploader.ContactPropertiesToExport, enumerable);
                using (Stream streamFromContacts = contactsExporter.GetStreamFromContacts())
                {
                    this.performanceTracker.AddTimeBookmark(ContactsUploaderPerformanceTrackerBookmarks.ExportTime);
                    using (MultipartFormDataContent multipartFormDataContent = FacebookContactsUploader.CreateMultipartFormDataContent(FacebookContactsUploader.MultipartFormDataBoundary, contactsExporter.ContentType, "contacts", streamFromContacts))
                    {
                        this.performanceTracker.AddTimeBookmark(ContactsUploaderPerformanceTrackerBookmarks.FormatTime);
                        using (Stream result = multipartFormDataContent.ReadAsStreamAsync().Result)
                        {
                            this.performanceTracker.ExportedDataSize      = (double)result.Length;
                            this.performanceTracker.ReceivedContactsCount = this.UploadContactsToFacebook(accessToken, contactsExporter.Format, FacebookContactsUploader.GetMultipartFormDataContentType(), result);
                        }
                        this.performanceTracker.AddTimeBookmark(ContactsUploaderPerformanceTrackerBookmarks.UploadTime);
                    }
                }
            }
            catch (TimeoutException exception)
            {
                this.ProcessFacebookFailure(exception, Strings.FacebookTimeoutError, !continueOnContactUploadFailure);
            }
            catch (ProtocolException exception2)
            {
                FacebookClient.AppendDiagnoseDataToException(exception2);
                this.ProcessFacebookFailure(exception2, Strings.FacebookAuthorizationError, !continueOnContactUploadFailure);
            }
            catch (CommunicationException exception3)
            {
                FacebookClient.AppendDiagnoseDataToException(exception3);
                this.ProcessFacebookFailure(exception3, Strings.FacebookCommunicationError, !continueOnContactUploadFailure);
            }
            catch (SerializationException exception4)
            {
                this.ProcessFacebookFailure(exception4, Strings.FacebookCommunicationError, !continueOnContactUploadFailure);
            }
            finally
            {
                this.performanceTracker.Stop();
                FacebookContactsUploader.Tracer.TraceFunction((long)this.GetHashCode(), "Leaving FacebookContactsUploader.UploadContacts.");
            }
        }