Get ProjectName and UserID in Custom Plugin

156 views
Skip to first unread message

nasre...@gmail.com

unread,
May 15, 2013, 3:08:19 AM5/15/13
to devtarge...@googlegroups.com
Hi,
 
I am creating a custom plugin to log user actions like bug creation, Comment deletion etc I need to get the "ProjectName" of the "AttachmentCreated" task and the "UserID" of the person who has created the attachment. Similarly for every user activity like Feature creation, Impediment deletion etc., the projectName and the associated user id is needed. Can you help me on this?
 
Current code:
--------------------
using System.Runtime.Serialization;
using Tp.Integration.Plugin.Common;
using NServiceBus;
using Tp.Integration.Messages.EntityLifecycle.Messages;
using System;
using Twitterizer;
public void Handle(AttachmentCreatedMessage message)

{
   BuildMsg buildmessage = new BuildMsg();
   buildmessage.CustomMessage = "message.Dto.ProjectName + message.Dto.LastCommentUserID.ToString() + DateTime.Now.ToString("HH:mm:ss tt").ToString()";
   MsgLogger.LogDetails(buildmessage);
}
 
Thanks,
Nasreen

Alla

unread,
May 15, 2013, 7:46:54 AM5/15/13
to devtarge...@googlegroups.com
Hi Nasreen,

Almost every entity contains field OwnerID. And some of entities such as Feature, Bug or UserStory contain ProjectName field. So, you can use them directly.
And some entities don't have direct link to Project. For example AttachmentDTO (that contained in AttachmentCreatedMessage) doesn't have such relation.
But AttachmentDTO has GeneralID field. It is ID of entity for which this attachment was created. And one of the solutions is to get Project of this entity via REST calling following query:
http://{your_targetProcess_url}/api/v1/generals/{message.Dto.GeneralID}?include=[Project[Id,Name]]

And AttachmentDTO contains ID of its creator in OwnerID field - message.Dto.OwnerID
For all additional information that you can't get directly from logging Entity you can use REST calls.

To read more about REST you can follow the link: http://dev.targetprocess.com/rest/getting_started
And here you can find description of all TargetProcess entities with their fields accessible via REST http://{your_targetProcess_url}/api/v1/index/meta

Hope this will help.

Best Regards,
Alla

nasre...@gmail.com

unread,
May 15, 2013, 9:20:44 AM5/15/13
to devtarge...@googlegroups.com
Hi Alla,
 
That was really helpful to proceed. Can you give an example on how to use the REST query using .NET:
http://{your_targetProcess_url}/api/v1/generals/{message.Dto.GeneralID}?include=[Project[Id,Name]]
 
Thanks,
Nasreen.

Алла Погоцкая

unread,
May 15, 2013, 9:52:12 AM5/15/13
to devtarge...@googlegroups.com
Hi Nasreen,

You can find example on github: https://github.com/TargetProcess/RestAPISamples
Feel free to ask if you have any other questions.

Best Regards,
Alla


2013/5/15 <nasre...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "DevTargetProcess" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devtargetproce...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

nasre...@gmail.com

unread,
May 16, 2013, 9:24:03 AM5/16/13
to devtarge...@googlegroups.com
Hi Alla,
 
I have referred the sample solution. What does this credential mean? Is this Windows authentication or Target Process credentials?
 
var client = new WebClient    {     Credentials = new NetworkCredential("admin", "admin"), // Use Basic Authentication };
 
Thanks,
Nasreen.

Alex Fomin

unread,
May 17, 2013, 7:14:09 AM5/17/13
to devtarge...@googlegroups.com
Hi,

NetworkCredential will be transformed to corresponding authentication regarding server response header with 401 status code. If you use windows authentication, you should provide domain user\password for rest api call (or you can bypass Win authentication for rest calls - ask our support for more details). If you're using on-demand or forms authentication on-site, this credentials will be treated as Basic authentication.

Thanks,
Alex, TP Team

nasre...@gmail.com

unread,
May 17, 2013, 7:59:00 AM5/17/13
to devtarge...@googlegroups.com
Hi,
 
Anything wrong in this code snippet? I am not getting anything out of it. Also is there anyway to use breakpoints for debugging?
 
using System.Runtime.Serialization;
using Tp.Integration.Plugin.Common;
using NServiceBus;
using Tp.Integration.Messages.EntityLifecycle.Messages;
using System;
using Twitterizer;
public void Handle(AttachmentCreatedMessage message)
{               
                var client = new WebClient
                             {     
                                 Credentials = new NetworkCredential("admin", "password", "domain"), // Use Basic Authentication
                             };
                string strTemp = client.DownloadString(PathToTp + "api/v1/generals/{message.Dto.GeneralID}?include=[Project[Id,Name]]");
                BuildMsg buildmessage = new BuildMsg();
                buildmessage.CustomMessage = strTemp;                   
                MsgLogger.LogDetails(buildmessage);
}
 
Thanks,
Nasreen.

Алла Погоцкая

unread,
May 17, 2013, 8:24:45 AM5/17/13
to devtarge...@googlegroups.com
Hi Nasreen,

As far as I can guess, you don't have Profile created. Without this your plugin will not receive any messages. That's why you don't stopped on your breakpoints.
http://dev.targetprocess.com/plugins/overview - here you can read more about Profile.
Find a sample of Twitter plugin https://github.com/TargetProcess/PluginsContrib/tree/master/Tp.Twitter . In it you can find how to create Profile from UI.

Best Regards,
Alla



2013/5/17 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 17, 2013, 9:12:37 AM5/17/13
to devtarge...@googlegroups.com
Hi,
 
I have created the profile already but still unable to use breakpoints. I am using "NServiceBus.Host.exe" in Debug and trying to attach a file to see the breakpoint to hit but it is not happening. Do you see anything wrong in the code snippet which I have attached earlier?
 
Thanks,
Nasreen

Алла Погоцкая

unread,
May 17, 2013, 9:49:42 AM5/17/13
to devtarge...@googlegroups.com
Hi Nasreen,

I see. So, to debug Plugin you need to do following actions:
- in Visual Studio set your plugin project as StartUp Project
- configure debug information for your project in order to run NServiceBus.Host.exe when you start the Plugin
- run application
These steps are described in details in this article http://dev.targetprocess.com/plugins/getting_started. But in your case you'll need to run your application in Debug mode using F5 instead of Cntrl+F5.

Hope this will help

Best Regards,
Alla

nasre...@gmail.com

unread,
May 17, 2013, 11:11:25 AM5/17/13
to devtarge...@googlegroups.com
Hi Alla,
 
Great.. The breakpoint is working now. I am getting the following error on the REST query line:  
 
string arr = client.DownloadString(PathToTp + "/api/v1/Plugins.asmx/TestPlugin/Profiles/Default");
 
Exception Info:
---------------------
Locating source for 'c:\code\structuremap\Source\StructureMap\Pipeline\ConstructorInstance.cs'. Checksum: MD5 {ec 28 1e 4b 32 a0 bc ed 2 31 25 70 fa 8c c 1b}
The file 'c:\code\structuremap\Source\StructureMap\Pipeline\ConstructorInstance.cs' does not exist.
Looking in script documents for 'c:\code\structuremap\Source\StructureMap\Pipeline\ConstructorInstance.cs'...
Looking in the projects for 'c:\code\structuremap\Source\StructureMap\Pipeline\ConstructorInstance.cs'.
The file was not found in a project.
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\crt\src\'...
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\atlmfc\src\mfc\'...
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\atlmfc\src\atl\'...
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\code\structuremap\Source\StructureMap\Pipeline\ConstructorInstance.cs.
The debugger could not locate the source file 'c:\code\structuremap\Source\StructureMap\Pipeline\ConstructorInstance.cs'.
 
Can you please help me on this?
 
Thanks,
Nasreen

nasre...@gmail.com

unread,
May 20, 2013, 4:12:05 AM5/20/13
to devtarge...@googlegroups.com
Hi Alla,

I have attached the dialog which has popped up for your reference.

Thanks,
Nasreen.
FindSource.jpg

nasre...@gmail.com

unread,
May 20, 2013, 9:02:47 AM5/20/13
to devtarge...@googlegroups.com
Hi Alla,

The RestAPI is throwing WebException for the following code snippet(guessign some issue in REST query in retrieving projectName). Also the OwnerID is returning "1" always. Can you help me on this?

var webClient = new WebClient();  
webClient.Credentials = new NetworkCredential("admin", "admin"); 

string arr = webClient.DownloadString(PathToTp + "api/v1/generals/{" + message.Dto.ID + "}?include=[Project[Id,Name]]");

Thanks,
Nasreen



On Wednesday, May 15, 2013 5:16:54 PM UTC+5:30, Alla wrote:

Алла Погоцкая

unread,
May 20, 2013, 9:17:32 AM5/20/13
to devtarge...@googlegroups.com
Hi Nasreen,

This is a mistake in the last line. It should be: string arr = webClient.DownloadString(PathToTp + "api/v1/generals/" + message.Dto.ID + "?include=[Project[Id,Name]]");
Have you resolve previous issues? Please let me know if it is still reproduced.

Best Regards,
Alla


2013/5/20 <nasre...@gmail.com>
--

nasre...@gmail.com

unread,
May 20, 2013, 10:08:12 AM5/20/13
to devtarge...@googlegroups.com
Hi Alla,

Getting that FindSource window followed by that exception message sometimes. Also the REST query which you have sent is also throwing WebException. Not sure what else is wrong.

Thanks,
Nasreen

Алла Погоцкая

unread,
May 20, 2013, 10:20:40 AM5/20/13
to devtarge...@googlegroups.com
Hi Nasreen,

Could you please provide callctack of WebException that you get?
And about OwnerID, it should work correctly. What type of entity do you try to create when get that constant 1?

Best Regards,
Alla

nasre...@gmail.com

unread,
May 21, 2013, 3:17:45 AM5/21/13
to devtarge...@googlegroups.com
Hi Alla,
 
Please find the CallStack furnished below:
 
Call stack location:
----------------------------
StructureMap.DLL!StructureMap.ObjectFactory.GetInstance<Tp.Integration.Plugin.Common.Activity.IActivityLogger>() Line 131
 
Source file information:
---------------------------------
Locating source for 'c:\code\structuremap\Source\StructureMap\ObjectFactory.cs'. Checksum: MD5 {df 34 53 97 ee c0 b df 8c aa 24 72 4c f5 e9 43}
The file 'c:\code\structuremap\Source\StructureMap\ObjectFactory.cs' does not exist.
Looking in script documents for 'c:\code\structuremap\Source\StructureMap\ObjectFactory.cs'...
Looking in the projects for 'c:\code\structuremap\Source\StructureMap\ObjectFactory.cs'.

The file was not found in a project.
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\crt\src\'...
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\atlmfc\src\mfc\'...
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\atlmfc\src\atl\'...
Looking in directory 'D:\SystemApps\VisualStudio2010\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\code\structuremap\Source\StructureMap\ObjectFactory.cs.
The debugger could not locate the source file 'c:\code\structuremap\Source\StructureMap\ObjectFactory.cs'.
 
Also, I have tried the REST query directly in web browser:
 
 
and got the below output:
 

<General Id="8013">
<Project Id="895" Name="DPT Test Project" />
<EntityType Id="4" />
</General>

But when I tried "http://servername.domain.name/DevTP/api/v1/generals/8013?include=[Project[Id,Name]], it prompted me for windows security. Eventhough, I have provided the right credentials, it had ran into error saying UNAUTHORIZED.

HTTP Error 401.5 - Unauthorized

The URL you tried to reach has an ISAPI or CGI application installed that verifies user credentials before proceeding. This application cannot verify your credentials.

 
Right now the IIS Manager DevTP site authentication is set to Forms and Anonymous only. The Windows authentication has been disabled as per support teams suggestion.
Hope this gives you some idea to narrow down the issue.
 
Regarding OwnerID, I have just tried "message.Dto.OwnerID.ToString()" which is returning just 1 always.
 
Thanks,
Nasreen.

nasre...@gmail.com

unread,
May 21, 2013, 10:12:45 AM5/21/13
to devtarge...@googlegroups.com
Hi Alla,
 
I am using Token based Authentication which helped me to resolve the Authorization issue. Expecting your help in getting the OwnerID value.
 
Thanks,
Nasreen.

Алла Погоцкая

unread,
May 21, 2013, 10:50:59 AM5/21/13
to devtarge...@googlegroups.com
Hi Nasreen,

OwnerID should return valid value. We don't have some special logic for it. And what type of entity do you try to create when get that constant 1?

Best Regards,
Alla


2013/5/21 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 22, 2013, 8:26:50 AM5/22/13
to devtarge...@googlegroups.com
Hi Alla,
 
This is the code which I am using to retrieve OwnerID.
 
            public void Handle(UserStoryUpdatedMessage message)
            {
                if (message.Dto.EntityStateName == "Open")
                {
                    buildmessage.CustomMessage = message.Dto.OwnerID.ToString().PadRight(10);
                    MsgLogger.LogDetails(buildmessage);
                }
            }
 
For some events like UserCreatedMessage, TestCaseRunUpdatedMessage how to get the UserID? It doesn't support OwnerID directly. Can you help on this?
 
Thanks,
Nasreen

Алла Погоцкая

unread,
May 22, 2013, 8:47:34 AM5/22/13
to devtarge...@googlegroups.com
Hi Nasreen,

I see. Probably in case of UserStoryUpdatedMessage you need LastEditorID not OwnerID. This is valid for all Update actions. Owner is a person who created entity and LastEdiotor is person who perform last change.
User entity doesn't have field that will tell you who created or updated it, so you can't tell who created the User based on UserCreatedMessage. And the same for TestCaseRun - you can't tell who created or changed it.

Best Regards,
Alla




2013/5/22 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 22, 2013, 10:28:38 AM5/22/13
to devtarge...@googlegroups.com
Hi Alla,
 
Thanks for your quick attention. I have tried that solution and that didnt helped to solve the issue.
 

1)message.Dto.LastEditorID is returning 1 in the event "UserStoryUpdatedMessage" and "UserStoryDeletedMessage"

2)message.Dto.OwnerID is returning 1 in the event "UserStoryCreatedMessage"

At this point, I would like to clarify that the userid which I am looking for is not an integer. It is nothing but the username using which the users login. To put it simple, I am looking for the Name of the user who made the changes like creation, updation or deletion. Does this needs a separate REST query? If so can you help me on that?

            public void Handle(UserStoryUpdatedMessage message)
            {
                    buildmessage.CustomMessage = message.Dto.OwnerID.ToString().PadRight(10);
                    MsgLogger.LogDetails(buildmessage);

            }

Thanks,

nasre...@gmail.com

unread,
May 23, 2013, 9:05:52 AM5/23/13
to devtarge...@googlegroups.com
Hi Alla,
 
Did you get a chance to look into it? All I need is to get the User name who is making the changes like creation, deletion or updation. Is it possible to get that directly or does it needs any REST query?
 
Thanks,
Nasreen.

Алла Погоцкая

unread,
May 23, 2013, 10:22:05 AM5/23/13
to devtarge...@googlegroups.com
Hi Nasrees,

LastEditorID is an ID of last editor. To get User information you can use REST call like this
http://{_yout_targetprocess_}/api/v1/Users/10?include=[FirstName,LastName]
and to know what fields does have User that can be included in result take a look at http://{_your_targetprocess_}/api/v1/Users/meta

And to see list of all entities that you can get via REST and to know what fields do they have use this url:
http://{_your_targetprocess_}/api/v1/index/meta

Best Regards,
Alla


2013/5/23 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 27, 2013, 5:07:16 AM5/27/13
to devtarge...@googlegroups.com
Alla,
 
That was really helpful. Is there a way to get the "ProjectName" from "AttachmentCreatedMessage" Event? Do you see anythign wrong in this REST query:
 
string strOutput = client.DownloadString(PathToTp + "api/v1/generals/" + message.Dto.OwnerID + "?include=[Project[Id,Name]]&token=" + strToken);
 
The Output is always:
 
- <General Id="1">
  <Project nil="true" />
  <EntityType Id="10" />
  </General>
 
Thanks in advance,
Nasreen.

Алла Погоцкая

unread,
May 27, 2013, 6:08:17 AM5/27/13
to devtarge...@googlegroups.com
Nasreen,

There is a typo in your query it should as this:
string strOutput = client.DownloadString(PathToTp + "api/v1/generals/" + message.Dto.GeneralID + "?include=[Project[Id,Name]]&token=" + strToken);

Best Regards,
Alla




2013/5/27 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 27, 2013, 9:20:07 AM5/27/13
to devtarge...@googlegroups.com
Alla,
 
If I Attach a File in both UserStory and in a Project, the "AttachmentCreatedMessage" event is getting invoked. But for UserStory Attachment, the Project Name is getting retrieved with this REST query but for Project Attachment it is returning null.
 
string strOutput = client.DownloadString(PathToTp + "api/v1/generals/" + message.Dto.GeneralID + "?include=[Project[Id,Name]]&token=" + strToken);
 
Not sure of the difference between the events "AttachmentCreatedMessage" and "AttachmentFileCreatedMessage".
 
Thanks,
Nasreen.

nasre...@gmail.com

unread,
May 27, 2013, 9:50:25 AM5/27/13
to devtarge...@googlegroups.com
Alla,
 
This REST query helped in handling attachments with projects..
 
string strOutput = client.DownloadString(PathToTp + "api/v1/generals/" + message.Dto.GeneralID + "?include=[Name]&token=" + strToken);
 
Please help me in understanding the difference between "AttachmentCreatedMessage" and "AttachmentFileCreatedMessage".
 
Thanks,
Nasreen.

nasre...@gmail.com

unread,
May 27, 2013, 11:00:01 PM5/27/13
to devtarge...@googlegroups.com
Alla,
 
Is there anyway to get the Username of TestCaseRun creation,deletion and updation?
 
Thanks,
Nasreen.

Алла Погоцкая

unread,
May 29, 2013, 7:07:00 AM5/29/13
to devtarge...@googlegroups.com
Hi Nasreen,

TestCaseRun doesn't contains such information as User that created/updated it. 

The difference between AttachmentCreatedMessage and AttachmentFileCreatedMessage is following. The first one describes the file - it's name, creation date, owner, etc. The second has the file content.
So, you are probably interested in the first one. In it you could get OwnerID and GeneralID for which this attachment was created.

Best Regards,
Alla


2013/5/28 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 29, 2013, 8:36:59 AM5/29/13
to devtarge...@googlegroups.com
Alla,
 
Thanks for your continuous help.. I am in the last leg of plugin development. couple of quick questions..
 
I would like to get the value of a control from the Profile(Profile.aspx page). Can you tell me how to get that through IHandleProfile? Is there any sample code snippet available?
If I want to deploy my plugin in the production server, what has to be done?
 
Thanks in advance,
Nasreen.

Алла Погоцкая

unread,
May 29, 2013, 9:24:21 AM5/29/13
to devtarge...@googlegroups.com
Hi Nasreen,

You are welcome.

And here are the answers (hope they will be helpful):
To get some info from Profile page you should save it to the Profile. This data should be posted to Plugin. How to do it you can find in the Twitter plugin from github https://github.com/TargetProcess/PluginsContrib/tree/master/Tp.Twitter. In ProfileEditor.js file _post method is sending profile data to the server.
And when you saved data to your Profile you can access it via IStorageRepository like this:
ObjectFactory.GetInstance<IStorageRepository>().GetProfile<_your_profile_type_>()
Here you can read more about Profile and Storage http://dev.targetprocess.com/plugins/overview
If this doesn't answer your question please specify in more details what actually you need to do.

And here is described how to install Plugin http://dev.targetprocess.com/plugins/overview#install


Best Regards,
Alla



2013/5/29 <nasre...@gmail.com>

nasre...@gmail.com

unread,
May 31, 2013, 10:41:13 AM5/31/13
to devtarge...@googlegroups.com
Hi Alla,
 
I am trying to send the LogPath along with the profilename from the Profile page. Attached is the code of the Profile page.
 
Here is how I am accessing the profile:
 
using StructureMap;
using Tp.Integration.Plugin.Common.Domain;
public static void LogDetails(BuildMsg buildmessage)
{
 var profile = ObjectFactory.GetInstance<IStorageRepository>().GetProfile<Profile>();
}
 
But variable profile is not having logPathTextbox. Not sure what else I am missing.
 
Thanks,
Nasreen.
Profile.js

nasre...@gmail.com

unread,
Jun 3, 2013, 6:06:53 AM6/3/13
to devtarge...@googlegroups.com
Hi,
 
Did you get a chance to look into this?
 
Thanks,
Nasreen

nasre...@gmail.com

unread,
Jun 3, 2013, 8:33:00 AM6/3/13
to devtarge...@googlegroups.com
Hi,
 
After dating the DataMember "logPath" to the Profile.cs, I am able to access the logPath attribute but it is always null. Also, everytime when I click the saved Profile, the logPath textbox is always empty. from this I guess that I am missing to store the value of logPath is ProfileEditor.js. But not sure where exactly I am going wrong. Can you help me on this?
 
Thanks,
Nasreen.

nasre...@gmail.com

unread,
Jun 3, 2013, 9:34:17 AM6/3/13
to devtarge...@googlegroups.com
Alla,
 
Somehow found the gap and fixed it and It is working now. Now for deploying the plugin, I have found the command
 
NServiceBus.Host.exe /install /serviceName:{YourServiceName} /displayName:"{YourDisplayName}" /description:"{YourDescription}"
 
Whether the "YourServiceName" is the plugin Name?
Whether the YourDisplayName and YourDescription are the user-defined text to be provided for the Plugin?
 
Thanks,
Nasreen.

nasre...@gmail.com

unread,
Jun 3, 2013, 10:03:17 AM6/3/13
to devtarge...@googlegroups.com
Alla,
 
Thank you so much for your continuous support through out. Finally, I have installed the plugin.
Appreciate your great support.
 
Thanks,
Nasreen.
Reply all
Reply to author
Forward
0 new messages