Пример #1
0
 public PublishingResult Publish(PublisherSettings settings, PublishingRecord record, IDictionary<string, string[]> fieldsValues, List<Attachment> attachments)
 {
     Task.Factory.StartNew(() =>
         AssemblaUtils.Automate(
             settings,
             record,
             attachments,
             fieldsValues["Space"][0]));
     return null;
 }
Пример #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)
 {
     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();
     }
 }
Пример #4
0
        public static void Automate(PublisherSettings settings,
            PublishingRecord record,
            IDictionary<string, bool> attachments,
            string spaceId)
        {
            try
            {
                // Launch a FireFox instance
                var driver = new FirefoxDriver();

                // How long WebDriver will wait for an element to exist in the DOM before timeout
                driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 20));

                // Go to login page, fill in credentials and click Login
                driver.Navigate().GoToUrl(string.Format("{0}/login", settings.Url));
                driver.FindElement(By.Name("user[login]")).SendKeys(settings.UserName);
                driver.FindElement(By.Name("user[password]")).SendKeys(settings.Password);
                driver.FindElement(By.Name("commit")).Click();

                // Go to ticket page, fill in summary and description
                driver.Navigate().GoToUrl(string.Format("{0}/spaces/{1}/tickets/new",
                                                settings.Url, spaceId));
                driver.FindElement(By.Name("ticket[summary]")).SendKeys(record.Title);

                // append link-only attachment to defect summary
                string summary = record.Summary + ToEmbeddedLinks(attachments.Where(x => x.Value).Select(x => x.Key).ToArray());
                driver.FindElement(By.Name("ticket[description]")).SendKeys(ReplaceMarkers(record.Summary));

                // Add attachments
                int i = 0;
                foreach (var attachment in attachments.Where(x => !x.Value))
                {
                    // Click the "Add attachments" link
                    driver.FindElement(By.ClassName("item-attachment")).Click();

                    // Fill file path to the file upload control
                    driver.FindElement(By.Name(string.Format("ticket[new_attachment_attributes][{0}][file]", ++i)))
                            .SendKeys(attachment.Key);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #5
0
        public PublishingResult Publish(
            PublisherSettings settings, 
            PublishingRecord record, 
            IDictionary<string, string[]> fieldsValues, 
            List<Attachment> attachments)
        {
            // Simulate connecting...
            Thread.Sleep(1000);

            return new PublishingResult {
                RecordId = new Random().Next(1, 100).ToString(),
                Message = "Published successfully!"
            };
        }