Jump to content

Custom integrations?


iceball12

Recommended Posts

  • 9 months later...

As promised, here is a sample extension. It connects to a postgres database to retrieve the task data. This is the LoadTask method.

You need to reference the extensioncommon.dll assembly to build it. Basically you'll want to implement the methods in ITaskProvider (reflektor is your friend ;)

To use it, add an <Extensions> section to your client.conf pointing to your assembly. (Configure one extension from the gui and replace the entry created in client.conf with your assembly)

using System;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;

using Codice.Client.Extension;

using Npgsql;
using log4net;

namespace Codice.Client.Extension
{

public class TtsExtensionConfiguration : BaseExtensionConfiguration
{
	public string User = "tts";
	public string Password = "tts";
	public string DatabaseConnectionString ="SERVER=192.168.1.2;PORT=5432;USER ID={0};PASSWORD={1};DATABASE=tts;ENCODING=UNICODE";
	public string TtsViewDefectUrl = "http://juno/tts/visualize.php?iddefect={0}";
}

internal class ConnectionFactory
{
	public static IDbConnection GetConnection(TtsExtensionConfiguration config)
	{			
		IDbConnection result = new NpgsqlConnection(config.DatabaseConnectionString);

		result.Open();

		return result;
	}
}

public class TtsExtension: BasePlasticExtension
{

	protected TtsExtensionConfiguration mConfig;
	protected IExtensionContainer mInstance;
	private static readonly ILog mLog = LogManager.GetLogger("extensions");

	private string mConfigFile = "druidextension.conf";

	public TtsExtension()
	{
		// Load config from disk
		mConfig = (TtsExtensionConfiguration) ExtensionServices.LoadConfig(mConfigFile, typeof(TtsExtensionConfiguration));
		if (mConfig == null)
			mConfig = new TtsExtensionConfiguration();

		mConfig.DatabaseConnectionString = String.Format(mConfig.DatabaseConnectionString, mConfig.User, mConfig.Password);			
		mConfig.SetDefaultAttributePrefix ("druid");
		mBaseConfig = mConfig;
	}

	#region Miembros de IPlasticExtension

	public override string GetName()
	{
		return "Druid TTS sample extension";
	}

	#endregion

	#region Miembros de ITaskProvider

	public override PlasticTask[] LoadTask (string[] ids, string repName)
	{
		if (ids[0] == null || ids[0] == String.Empty)
			return null;

		ArrayList result = new ArrayList();

		for (int i = 0; i < ids.Length; i++)
		{
			PlasticTask task = new PlasticTask();

			IDbConnection conn = ConnectionFactory.GetConnection(mConfig);

			try
			{
				IDbCommand command = conn.CreateCommand();
				command.CommandText = "SELECT d.iid, sheadline, s.sname as status, stext " +
					"FROM defect d, enclosure e, defectstatus s " +
					"WHERE d.iiddefectstatus = s.iid AND d.iid = e.iiddefect AND d.iid = " + ids[i];

				IDataReader reader = command.ExecuteReader();

				if (reader.Read())
				{
					task.Id = ids[i];
					task.Title = (string)reader["sheadline"];
					task.Description = (string)reader["stext"];
					task.Owner = string.Empty;
					task.Status = (string)reader["status"];
				}
				reader.Close();
			}
			catch (Exception ex)
			{
				mLog.ErrorFormat("TTSExtension: {0}\n\t{1}", ex.Message, ex.StackTrace);
				return null;
			}
			finally
			{
				conn.Close();
			}

			result.Add(task);
		}

		return (PlasticTask[])result.ToArray(typeof (PlasticTask));

	}

	public override void OpenTask(string id, string repName)
	{
		System.Diagnostics.Process.Start(string.Format(mConfig.TtsViewDefectUrl, id) );
	}

	public bool Checkin(PlasticChangeset[] changesets)
	{
		return false;
	}

	#endregion
}

}

Does this API still work for plastic 4.1? Also, will i still be able to set a branch prefix and projectKey=MULTI_PROJECTS just like the JIRA integration works? I guess a screenshot of an implemented custom plugin settings window would help a lot. thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Hi Manu,

Out of interest i'm creating a extension (not tied to any system yet) but i'm having some problems/questions.

1) I coded:

public DrupalSupportExtension()
{
Debug.WriteLine("DrupalSupportExtension()");

// Load config from disk
mConfig = (DrupalSupportExtensionConfiguration)ExtensionServices.LoadConfig(mConfigFile, typeof(DrupalSupportExtensionConfiguration));

if (mConfig == null)
{
 mConfig = new DrupalSupportExtensionConfiguration();
}

mConfig.SetDefaultAttributePrefix("support");
mBaseConfig = mConfig;
}

and

public override PlasticTask[] LoadTask(string[] ids, string repName)
{
Debug.WriteLine("LoadTask({" + String.Join(", ", ids) + " }, " + repName + ")");
...

The prefix is 'support' and i created a branch named 'support072' in one of my repositories.

but always see the following output (and no tasks in the branch viewer at all).

LoadTask({, }, )

The other methods are also called (Checkin/GetName/Constructor).

2) How do i code some user-interface (to enter configuration settings) in the preference dialog?

regards

Link to comment
Share on other sites

Hi Manu

The prefix seems be be the problem. When changed to the default 'scm' things start to work and i see dummy tasks in the client. Even the jump to browser button work nicely.

Small gui issue: when the issue is shown (right side of the client) the height of the selection background of the issue (just click it with a mouse) changes in height (to full height) when the window is resized (it colors blue on my machine). Clicking the table button twice restores the smaller height initially shown.

regards

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Hi Manuel.

Sorry foro posting on an old thread, but is it the source code still available?, or any Java source code examples?

I was not able to find the "labs" section of your site, so I couldn't download any of it.

I guess the guide is still not available, is it?

 

Thanks in advance.

                               JP

Link to comment
Share on other sites

Hi Manuel,

                

Thanks for the link. I am not really trying to support an issue tracking system, but to figure out how to add some model-aware functionality to Plastic (yes, I know that is not its purpouse). Right now I'm trying to find a way in which to plug into it, and perform some queries, file contents queries mostly. Any help in that direction would also be very much appreciatted.

 

Thanks again,

                       JP

Link to comment
Share on other sites

  • 2 weeks later...

Hey,

 

If you need to query file contents, cm shell and cm cat are your friends.

 

 

cm cat can cat several files in a single command, good for performance, which will be something you'll be looking for.

 

Automating cm shell (or checkin the CmdRunner) is what you really need to get this finished.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...