public void RemoteLink_should_assign_the_url_correctly()
        {
            var linkInline = new LinkInline("https://www.google.com", "Title");
            var remoteLink = new RemoteLink(linkInline);

            Assert.AreEqual(linkInline.Url, remoteLink.Url);
        }
Exemplo n.º 2
0
        public RemoteLink UpdateRemoteLink(IssueRef issue, RemoteLink remoteLink)
        {
            try
            {
                var path    = $"issue/{issue.id}/remotelink/{remoteLink.id}";
                var request = CreateRequest(Method.PUT, path);
                request.AddHeader("ContentType", "application/json");

                var updateData = new Dictionary <string, object>();
                if (remoteLink.url != null)
                {
                    updateData.Add("url", remoteLink.url);
                }
                if (remoteLink.title != null)
                {
                    updateData.Add("title", remoteLink.title);
                }
                if (remoteLink.summary != null)
                {
                    updateData.Add("Summary", remoteLink.summary);
                }
                request.AddBody(new { @object = updateData });

                var response = ExecuteRequest(request);
                AssertStatus(response, HttpStatusCode.NoContent);

                return(GetRemoteLinks(issue).Single(rl => rl.id == remoteLink.id));
            }
            catch (Exception ex)
            {
                Trace.TraceError("UpdateRemoteLink(issue, remoteLink) error: {0}", ex);
                throw new JiraClientException("Could not update external link for issue", ex);
            }
        }
Exemplo n.º 3
0
 public RemoteService(RemoteLink link)
 {
     _link             = link;
     _watcher          = new AppDomainFileChangeWatcher(Recycle);
     _serviceDirectory = Path.IsPathRooted(_link.Folder)
         ? _link.Folder
         : PackageRegistry.GetApplicationDirectory().AppendPath(_link.Folder);
 }
Exemplo n.º 4
0
 public RemoteService(RemoteLink link)
 {
     _link = link;
     _watcher = new AppDomainFileChangeWatcher(Recycle);
     _serviceDirectory = Path.IsPathRooted(_link.Folder)
         ? _link.Folder
         : PackageRegistry.GetApplicationDirectory().AppendPath(_link.Folder);
 }
Exemplo n.º 5
0
        public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink)
        {
            try
            {
                var path    = $"issue/{issue.id}/remotelink/{remoteLink.id}";
                var request = CreateRequest(Method.DELETE, path);
                request.AddHeader("ContentType", "application/json");

                var response = ExecuteRequest(request);
                AssertStatus(response, HttpStatusCode.NoContent);
            }
            catch (Exception ex)
            {
                Trace.TraceError("DeleteRemoteLink(issue, remoteLink) error: {0}", ex);
                throw new JiraClientException("Could not delete external link for issue", ex);
            }
        }
Exemplo n.º 6
0
        public RemoteLink CreateRemoteLink(IssueRef issue, RemoteLink remoteLink)
        {
            try
            {
                var path    = $"issue/{issue.id}/remotelink";
                var request = CreateRequest(Method.POST, path);
                request.AddHeader("ContentType", "application/json");
                request.AddBody(new
                {
                    application = new
                    {
                        type = "TechTalk.JiraRestClient",
                        name = "JIRA REST client"
                    },
                    @object = new
                    {
                        // ReSharper disable RedundantAnonymousTypePropertyName
                        url     = remoteLink.url,
                        title   = remoteLink.title,
                        summary = remoteLink.summary
                                  // ReSharper restore RedundantAnonymousTypePropertyName
                    }
                });

                var response = ExecuteRequest(request);
                AssertStatus(response, HttpStatusCode.Created);

                //returns: { "Id": <Id>, "self": <url> }
                var linkId = _deserializer.Deserialize <RemoteLink>(response).id;
                return(GetRemoteLinks(issue).Single(rl => rl.id == linkId));
            }
            catch (Exception ex)
            {
                Trace.TraceError("CreateRemoteLink(issue, remoteLink) error: {0}", ex);
                throw new JiraClientException("Could not create external link for issue", ex);
            }
        }
Exemplo n.º 7
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            Units = doc.GetUnits();

            LinksDict = Link.GetAllLinks(doc);

            GlobalParametersDialog dialog = new GlobalParametersDialog();

            string[] linkarray = LinksDict.Keys.ToArray();

            DataGridView datagrid = dialog.ParametersDataGrid;

            RemoteLink link = LinksDict[linkarray.First()];

            dialog.LinkDropDown.Items.AddRange(linkarray);
            dialog.LinkDropDown.Text = linkarray.First();

            GlobalParameters = new RemoteGlobalParameters(link.Document, Units);

            DrawDatagrid(datagrid, GlobalParameters);

            var result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return(Result.Cancelled);
            }

            link = LinksDict[dialog.LinkDropDown.Text];

            Dictionary <string, string> paramdict = new Dictionary <string, string>();

            for (int i = 0; i < datagrid.Rows.Count; i++)
            {
                if (Convert.ToBoolean(datagrid.Rows[i].Cells["EditColumn"].Value) == true)
                {
                    string p = (string)datagrid.Rows[i].Cells["ParameterColumn"].Value;

                    if (datagrid.Rows[i].Cells["ValueColumn"].Value != null)
                    {
                        paramdict.Add(p, datagrid.Rows[i].Cells["ValueColumn"].Value.ToString());
                    }
                    else
                    {
                        paramdict.Add(p, string.Empty);
                    }
                }
            }

            if (paramdict.Keys.Count == 0)
            {
                return(Result.Cancelled);
            }

            if (!link.Open(uiapp))
            {
                return(Result.Failed);
            }

            Transaction t1 = new Transaction(link.OpenDocument, "Assign Parameters");

            List <string[]> results = new List <string[]> {
            };

            string title = link.Title;

            try
            {
                t1.Start();

                foreach (string parameter in paramdict.Keys)
                {
                    string r = GlobalParameters.EditParameter(link.OpenDocument, parameter, paramdict[parameter]);

                    results.Add(new string[] { parameter, r });
                }

                t1.Commit();

                link.Close(true);
            }
            catch
            {
                if (t1.HasStarted())
                {
                    t1.RollBack();
                }

                link.Close(false);

                return(Result.Failed);
            }

            link.Type.Reload();

            Results resultsdialog = new Results();

            var resultsdatagrid = resultsdialog.ResultsDatagrid;

            Link.GetResults(resultsdatagrid, results);

            resultsdialog.LinkDropDown.Items.Add(title);
            resultsdialog.LinkDropDown.Text = title;

            resultsdialog.ShowDialog();

            return(Result.Succeeded);
        }
Exemplo n.º 8
0
 public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink)
 {
     _client.DeleteRemoteLink(issue, remoteLink);
 }
Exemplo n.º 9
0
 public RemoteLink UpdateRemoteLink(IssueRef issue, RemoteLink remoteLink)
 {
     return(_client.UpdateRemoteLink(issue, remoteLink));
 }
Exemplo n.º 10
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            Units units = doc.GetUnits();

            Reference selected;

            try
            {
                selected = uidoc.Selection.PickObject(ObjectType.LinkedElement, "Select Element from Links");
            }
            catch { return(Result.Cancelled); }

            ElementId id = selected.ElementId;

            ElementId linkid = selected.LinkedElementId;

            RevitLinkInstance linkinstance = doc.GetElement(id) as RevitLinkInstance;

            RemoteLink link = new RemoteLink(doc, linkinstance);

            Element linkedelement = link.Document.GetElement(linkid);

            if (!linkedelement.CanHaveTypeAssigned())
            {
                return(Result.Failed);
            }

            ElementId typeId = linkedelement.GetTypeId();

            ElementType type = link.Document.GetElement(typeId) as ElementType;

            RemoteType remotetype = new RemoteType(type, typeId, units);

            ParametersDialog dialog = new ParametersDialog();

            dialog.FamilyDropDown.Items.Add(type.FamilyName);
            dialog.FamilyDropDown.Text    = type.FamilyName;
            dialog.FamilyDropDown.Enabled = false;

            dialog.TypeDropDown.Items.Add(type.Name);
            dialog.TypeDropDown.Text    = type.Name;
            dialog.TypeDropDown.Enabled = false;

            dialog.LinkDropDown.Items.Add(link.Title);
            dialog.LinkDropDown.Text    = link.Title;
            dialog.LinkDropDown.Enabled = false;

            DataGridView datagrid = dialog.ParametersDataGrid;

            DrawDatagrid(datagrid, remotetype);

            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return(Result.Cancelled);
            }

            Dictionary <string, string> paramdict = new Dictionary <string, string>();

            for (int i = 0; i < datagrid.Rows.Count; i++)
            {
                if (Convert.ToBoolean(datagrid.Rows[i].Cells["EditColumn"].Value) == true)
                {
                    string p = (string)datagrid.Rows[i].Cells["ParameterColumn"].Value;

                    if (datagrid.Rows[i].Cells["ValueColumn"].Value != null)
                    {
                        paramdict.Add(p, datagrid.Rows[i].Cells["ValueColumn"].Value.ToString());
                    }
                    else
                    {
                        paramdict.Add(p, string.Empty);
                    }
                }
            }

            if (paramdict.Keys.Count == 0)
            {
                return(Result.Cancelled);
            }

            if (!link.Open(uiapp))
            {
                return(Result.Failed);
            }

            Transaction t1 = new Transaction(link.OpenDocument, "Assign Parameters");

            List <string[]> results = new List <string[]> {
            };

            string title = link.Title;

            try
            {
                t1.Start();

                foreach (string parameter in paramdict.Keys)
                {
                    string r = remotetype.EditParameter(link.OpenDocument, parameter, paramdict[parameter]);

                    results.Add(new string[] { parameter, r });
                }

                t1.Commit();

                link.Close(true);
            }
            catch
            {
                if (t1.HasStarted())
                {
                    t1.RollBack();
                }

                link.Close(false);

                return(Result.Failed);
            }

            link.Type.Reload();

            Results resultsdialog = new Results();

            var resultsdatagrid = resultsdialog.ResultsDatagrid;

            Link.GetResults(resultsdatagrid, results);

            resultsdialog.LinkDropDown.Items.Add(title);
            resultsdialog.LinkDropDown.Text = title;

            resultsdialog.ShowDialog();

            return(Result.Succeeded);
        }