コード例 #1
0
        private string[] ExportAttachmentToDropbox(AttachmentFunc createAttachments)
        {
            var uploadedAttachments = new List <string>();

            // generate file(s) to temp folder first
            string[] files = createAttachments(CreateTempFolder(), null, null);

            // create a unique folder name to stored uploading file(s)
            var folder = Guid.NewGuid().ToString();

            if (files != null && files.Length > 0)
            {
                try {
                    foreach (var file in files)
                    {
                        var fileUrl = Context.UploadToDropbox(file, folder);
                        if (!string.IsNullOrEmpty(fileUrl))
                        {
                            uploadedAttachments.Add(fileUrl);
                        }
                    }
                }
                catch (Exception ex) {
                    Context.Error("Error while trying to upload files to Dropbox: " + ex.Message);
                }
            }
            return(uploadedAttachments.ToArray());
        }
コード例 #2
0
        public PublishingResult Publish(
            PublisherSettings settings,
            PublishingRecord record,
            AttachmentFunc createAttachments)
        {
            Space selectedSpace             = null;
            bool  uploadAttachmentToDropbox = false;

            var selectedSpaceLock = new object();

            // open submission screen
            Context.ExecuteOnUIThread(() =>
            {
                var view = new SpacePromptView
                {
                    IsConnectedToDropbox = Context.IsDropboxConnected,
                    Spaces = new ObservableCollection <Space>(AssemblaUtils.LoadSpaces(settings))
                };
                lock (selectedSpaceLock)
                {
                    if (view.ShowDialog() == true)
                    {
                        selectedSpace             = view.SelectedSpace;
                        uploadAttachmentToDropbox = view.UploadAttachmentToDropbox;
                    }
                }
            });
            if (selectedSpace == null)
            {
                return(null);
            }

            Context.ShowProgressIndicator(message: "Starting...");
            try {
                var attachments = new Dictionary <string, bool>();

                // Generate the attachments before starting background thread
                if (uploadAttachmentToDropbox)
                {
                    foreach (var file in ExportAttachmentToDropbox(createAttachments))
                    {
                        attachments.Add(file, true);
                    }
                }
                else
                {
                    foreach (var file in createAttachments())
                    {
                        attachments.Add(file, false);
                    }
                }
                // Automate browser in a worker thread
                Task.Factory.StartNew(() => AssemblaUtils.Automate(settings, record, attachments, selectedSpace.Id));
            }
            finally {
                Context.HideProgressIndicator();
            }
            return(null);
        }
コード例 #3
0
        public PublishingResult Publish(
            PublisherSettings settings,
            PublishingRecord record,
            AttachmentFunc createAttachments)
        {
            Space selectedSpace = null;
            bool uploadAttachmentToDropbox = false;

            var selectedSpaceLock = new object();

            // open submission screen
            Context.ExecuteOnUIThread(() =>
            {
                var view = new SpacePromptView
                {
                    IsConnectedToDropbox = Context.IsDropboxConnected,
                    Spaces = new ObservableCollection<Space>(AssemblaUtils.LoadSpaces(settings))
                };
                lock (selectedSpaceLock)
                {
                    if (view.ShowDialog() == true)
                    {
                        selectedSpace = view.SelectedSpace;
                        uploadAttachmentToDropbox = view.UploadAttachmentToDropbox;
                    }
                }
            });
            if (selectedSpace == null)
                return null;

            Context.ShowProgressIndicator(message: "Starting...");
            try {
                var attachments = new Dictionary<string, bool>();

                // Generate the attachments before starting background thread
                if (uploadAttachmentToDropbox)
                {
                    foreach (var file in ExportAttachmentToDropbox(createAttachments)) {
                        attachments.Add(file, true);
                    }
                }
                else {
                    foreach(var file in createAttachments()) {
                        attachments.Add(file, false);
                    }
                }
                // Automate browser in a worker thread
                Task.Factory.StartNew(() => AssemblaUtils.Automate(settings, record, attachments, selectedSpace.Id));
            }
            finally {
                Context.HideProgressIndicator();
            }
            return null;
        }
コード例 #4
0
ファイル: Ftp.cs プロジェクト: buunguyen/qtrace-samples
 public PublishingResult Publish(PublisherSettings settings, PublishingRecord record, AttachmentFunc createAttachments)
 {
     Context.ShowProgressIndicator(message: "Publishing to FTP...");
     try {
         var tasks = from attachment in createAttachments()
                     select Task.Factory.StartNew(() => Upload(settings, attachment));
         Task.WaitAll(tasks.ToArray());
         return new PublishingResult();
     }
     catch (AggregateException e) {
         throw new PublishingException(e.InnerExceptions[0].Message, e.InnerExceptions[0]);
     }
     finally {
         Context.HideProgressIndicator();
     }
 }
コード例 #5
0
        private string[] ExportAttachmentToDropbox(AttachmentFunc createAttachments)
        {
            var uploadedAttachments = new List<string>();
            // generate file(s) to temp folder first
            string[] files = createAttachments(CreateTempFolder(), null, null);

            // create a unique folder name to stored uploading file(s)
            var folder = Guid.NewGuid().ToString();
            if (files != null && files.Length > 0) {
                try {
                    foreach (var file in files) {
                        var fileUrl = Context.UploadToDropbox(file, folder);
                        if (!string.IsNullOrEmpty(fileUrl)) {
                            uploadedAttachments.Add(fileUrl);
                        }
                    }
                }
                catch (Exception ex) {
                    Context.Error("Error while trying to upload files to Dropbox: " + ex.Message);
                }
            }
            return uploadedAttachments.ToArray();
        }
コード例 #6
0
        public PublishingResult Publish(PublisherSettings settings, PublishingRecord record, AttachmentFunc createAttachments)
        {
            Context.ShowProgressIndicator(message: "Publishing to FTP...");
            try {
                var tasks = from attachment in createAttachments()
                            select Task.Factory.StartNew(() => Upload(settings, attachment));

                Task.WaitAll(tasks.ToArray());
                return(new PublishingResult());
            }
            catch (AggregateException e) {
                throw new PublishingException(e.InnerExceptions[0].Message, e.InnerExceptions[0]);
            }
            finally {
                Context.HideProgressIndicator();
            }
        }