Ejemplo n.º 1
0
 public IImportAssets(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations)
 {
     _sqlConn = sqlConn;
     _metaAPI = MetaAPI;
     _dataAPI = DataAPI;
     _config = Configurations;
 }
        public static string GetAssetOid(string jiraId, string assetTypeStr)
        {
            var config = (JiraConnectionConfiguration)ConfigurationManager.GetSection("jiraAttachments");

            var metaconnector = new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/meta.v1/");
            var dataconnector =
                new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/rest-1.v1/")
                    .WithVersionOneUsernameAndPassword(config.V1Connection.Username, config.V1Connection.Password);

            MetaModel metaModel = new MetaModel(metaconnector);
            Services services = new Services(metaModel, dataconnector);

            var assetType = metaModel.GetAssetType(assetTypeStr);
            var query = new Query(assetType);
            var jiraIdAttribute = assetType.GetAttributeDefinition(GetV1IdCustomFieldName(assetTypeStr));
            query.Selection.Add(jiraIdAttribute);
            var jiraIdTerm = new FilterTerm(jiraIdAttribute);
            jiraIdTerm.Equal(jiraId);
            query.Filter = jiraIdTerm;

            var result = services.Retrieve(query);

            if (result.Assets.Count == 0)
            {
                return String.Empty;
            }
            return result.Assets[0].Oid.ToString();
        }
        public static V1Instance GetV1Instance() {
            string V1Instance = ConfigurationManager.AppSettings["V1Instance"];
            string V1Login = ConfigurationManager.AppSettings["V1InstanceUsername"];
            string V1Password = ConfigurationManager.AppSettings["V1InstancePassword"];
            string proxyServerUri = ConfigurationManager.AppSettings["proxyServerUri"];
            string defaultRole = ConfigurationManager.AppSettings["V1UserDefaultRole"];
            string useIntegratedAuth = ConfigurationManager.AppSettings["IntegratedAuth"];

            if(!V1Instance.EndsWith("/"))
                V1Instance += "/";

            try {
                IAPIConnector metaConnector;
                IAPIConnector dataConnector;
                bool useIntegrated = useIntegratedAuth.Equals("true");
                logger.Info("Attaching to VersionOne at: " + V1Instance);
                
                if (!string.IsNullOrEmpty(proxyServerUri)) {
                    ProxyProvider proxyProvider = GetProxyProvider();
                    metaConnector = new V1APIConnector(V1Instance + @"meta.v1/", null, null, false, proxyProvider);
                    dataConnector = new V1APIConnector(V1Instance + @"rest-1.v1/", V1Login, V1Password, useIntegrated, proxyProvider);
                } else {
                    metaConnector = new V1APIConnector(V1Instance + @"meta.v1/");
                    dataConnector = new V1APIConnector(V1Instance + @"rest-1.v1/", V1Login, V1Password, useIntegrated);
                }

                IMetaModel metaModel = new MetaModel(metaConnector);
                IServices services = new Services(metaModel, dataConnector);
                return new V1Instance(services, metaModel, defaultRole);
            } catch(Exception ex) {
                logger.Error(ex.Message);
                throw ex;
            }
        }
        //Constructor: Initializes the V1 instance connection.
        public VersionOneClient(IntegrationConfiguration Config, Logger Logger)
        {
            _logger = Logger;
            _config = Config;
            _V1_META_URL = Config.V1Connection.Url + "/meta.v1/";
            _V1_DATA_URL = Config.V1Connection.Url + "/rest-1.v1/";
            V1APIConnector metaConnector = new V1APIConnector(_V1_META_URL);
            V1APIConnector dataConnector;

            //Set V1 connection based on authentication type.
            if (_config.V1Connection.UseWindowsAuthentication == true)
            {
                _logger.Debug("-> Connecting with Windows Authentication.");

                //If username is not specified, try to connect using domain credentials.
                if (String.IsNullOrEmpty(_config.V1Connection.Username))
                {
                    _logger.Debug("-> Connecting with default Windows domain account: {0}\\{1}", Environment.UserDomainName, Environment.UserName);
                    dataConnector = new V1APIConnector(_V1_DATA_URL);
                }
                else
                {
                    _logger.Debug("-> Connecting with specified Windows domain account: {0}", _config.V1Connection.Username);
                    dataConnector = new V1APIConnector(_V1_DATA_URL, _config.V1Connection.Username, _config.V1Connection.Password, true);
                }
            }
            else
            {
                _logger.Debug("-> Connecting with V1 account credentials: {0}", _config.V1Connection.Username);
                dataConnector = new V1APIConnector(_V1_DATA_URL, _config.V1Connection.Username, _config.V1Connection.Password);
            }

            _v1Meta = new MetaModel(metaConnector);
            _v1Data = new Services(_v1Meta, dataConnector);
        }
        public static string GetV1IdCustomFieldName(string internalAssetTypeName)
        {
            var config = (JiraConnectionConfiguration)ConfigurationManager.GetSection("jiraAttachments");

            if (!String.IsNullOrEmpty(config.V1Connection.CustomField))
            {
                string customFieldName = String.Empty;

                var metaconnector = new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/meta.v1/");
                var dataconnector =
                    new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/rest-1.v1/")
                        .WithVersionOneUsernameAndPassword(config.V1Connection.Username, config.V1Connection.Password);

                MetaModel metaApi = new MetaModel(metaconnector);
                Services dataApi = new Services(metaApi,dataconnector);

                IAssetType assetType = metaApi.GetAssetType("AttributeDefinition");
                Query query = new Query(assetType);

                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
                query.Selection.Add(nameAttribute);

                IAttributeDefinition isCustomAttribute = assetType.GetAttributeDefinition("IsCustom");
                query.Selection.Add(isCustomAttribute);

                IAttributeDefinition assetNameAttribute = assetType.GetAttributeDefinition("Asset.Name");
                query.Selection.Add(assetNameAttribute);

                FilterTerm assetName = new FilterTerm(assetNameAttribute);
                assetName.Equal(internalAssetTypeName);
                FilterTerm isCustom = new FilterTerm(isCustomAttribute);
                isCustom.Equal("true");
                query.Filter = new AndFilterTerm(assetName, isCustom);

                QueryResult result = dataApi.Retrieve(query);

                foreach (Asset asset in result.Assets)
                {
                    string attributeValue = asset.GetAttribute(nameAttribute).Value.ToString();
                    if (attributeValue.StartsWith(config.V1Connection.CustomField))
                    {
                        customFieldName = attributeValue;
                        break;
                    }
                }
                return customFieldName;
            }
            return null;
        }
        public void Connect()
        {
            Log("Create Meta Connector");
            var metaConnector = V1SsoConnector.CreateMetaConnection(Configuration.Instance());

            Log("Created Meta Model");
            Meta = new MetaModel(metaConnector);

            Log("Creating Data Connector");
            var dataConnector = V1SsoConnector.CreateDataConnection(Configuration.Instance(), false);

            Log("Authenticate");
            dataConnector.Authenticate();

            Log("Created Services");
            Services = new Services(Meta, dataConnector);
        }
        public void Connect(VersionOneSettings settings) {
            var path = settings.Path;
            var username = settings.Username;
            var password = settings.Password;
            var integrated = settings.Integrated;
            var proxy = GetProxy(settings.ProxySettings);
            VersionOneSettings = settings;

            var metaConnector = new V1APIConnector(path + MetaUrlSuffix, username, password, integrated, proxy);
            MetaModel = new MetaModel(metaConnector);

            var localizerConnector = new V1APIConnector(path + LocalizerUrlSuffix, username, password, integrated, proxy);
            Localizer = new Localizer(localizerConnector);

            var dataConnector = new V1APIConnector(path + DataUrlSuffix, username, password, integrated, proxy);
            Services = new Services(MetaModel, dataConnector);

            V1Configuration = LoadV1Configuration();
        }
		public void Connect(VersionOneSettings settings)
		{
			var path = settings.Path;
			var username = settings.Username;
			var password = settings.Password;
			var integrated = settings.Integrated;
			var proxy = GetProxy(settings.ProxySettings);
			VersionOneSettings = settings;

			if (VersionOneSettings.OAuth2)
			{
				var storage = OAuth2Client.Storage.JsonFileStorage.Default;
				var metaConnector = new V1OAuth2APIConnector(path + MetaUrlSuffix, storage, proxy);
				MetaModel = new MetaModel(metaConnector);

				var localizerConnector = new V1OAuth2APIConnector(path + LocalizerUrlSuffix, storage, proxy);
				Localizer = new Localizer(localizerConnector);

				var dataConnector = new V1OAuth2APIConnector(path + DataUrlSuffix, storage, proxy);
				Services = new Services(MetaModel, dataConnector);

			}
			else
			{
				var metaConnector = new V1APIConnector(path + MetaUrlSuffix, username, password, integrated, proxy);
				MetaModel = new MetaModel(metaConnector);

				var localizerConnector = new V1APIConnector(path + LocalizerUrlSuffix, username, password, integrated, proxy);
				Localizer = new Localizer(localizerConnector);

				var dataConnector = new V1APIConnector(path + DataUrlSuffix, username, password, integrated, proxy);
				Services = new Services(MetaModel, dataConnector);
				
			}
			V1Configuration = LoadV1Configuration();
		}
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            var dataConnector = new VersionOneAPIConnector(BASE_URL + "/rest-1.v1/").WithOAuth2(SecretsFile, CredsFile);
            var metaConnector = new VersionOneAPIConnector(BASE_URL + "/meta.v1/");

            var metaModel = new MetaModel(metaConnector);
            var services = new Services(metaModel, dataConnector);

            var scopeType = metaModel.GetAssetType("Member");
            var nameAttr = scopeType.GetAttributeDefinition("Name");
            var descAttr = scopeType.GetAttributeDefinition("Nickname");
            var worksItemsNameAttr = scopeType.GetAttributeDefinition("OwnedWorkitems.Name");

            var query = new Query(scopeType);
            var whereAdmin = new FilterTerm(descAttr);
            whereAdmin.Equal("admin");
            var whereNotTheAdmin = new FilterTerm(nameAttr);
            whereNotTheAdmin.NotEqual("theAdmin");
            var andFilter = new AndFilterTerm(whereAdmin, whereNotTheAdmin);
            query.Filter = andFilter;
            query.Selection.AddRange(new[] { nameAttr, descAttr, worksItemsNameAttr });
            var result = services.Retrieve(query);

            foreach (var asset in result.Assets)
            {
                Console.WriteLine("Name: " + asset.GetAttribute(nameAttr).Value);
                Console.WriteLine("Description: " + asset.GetAttribute(descAttr).Value);
                var workItems = asset.GetAttribute(worksItemsNameAttr).ValuesList;
                Console.WriteLine("Workitems count: " + workItems.Count);
                foreach (var workitem in workItems)
                {
                        Console.WriteLine("Workitem: " + workitem);
                }
            }
            Console.ReadLine();
        }
 public ImportFeatureGroups(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations)
     : base(sqlConn, MetaAPI, DataAPI, Configurations)
 {
 }
 public ExportCustomFields(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations, string InternalAssetType)
     : base(sqlConn, MetaAPI, DataAPI, Configurations)
 {
     _InternalAssetType = InternalAssetType;
 }
Ejemplo n.º 12
0
 public ImportCustomFields(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations, string AssetType)
     : base(sqlConn, MetaAPI, DataAPI, Configurations)
 {
     _assetType = AssetType;
 }
 public ImportMembers(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations)
     : base(sqlConn, MetaAPI, DataAPI, Configurations) { }
Ejemplo n.º 14
0
        public static bool UploadAttachment(string filename, string jiraId, string rawfile)
        {
            var config = (JiraConnectionConfiguration)ConfigurationManager.GetSection("jiraAttachments");

            var metaconnector = new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/meta.v1/");
            var dataconnector =
                new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/rest-1.v1/")
                    .WithVersionOneUsernameAndPassword(config.V1Connection.Username, config.V1Connection.Password);
            var attachmentconnector =
                                new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/attachment.img/")
                    .WithVersionOneUsernameAndPassword(config.V1Connection.Username, config.V1Connection.Password);

            MetaModel metaModel = new MetaModel(metaconnector);
            Services services = new Services(metaModel, dataconnector);
            Attachments attachments = new Attachments(attachmentconnector);

            string mimeType = MimeType.Resolve(filename);

            string assetoid = GetAssetOid(jiraId, "PrimaryWorkitem");
            if (String.IsNullOrEmpty(assetoid))
            {
                assetoid = GetAssetOid(jiraId, "Task");
            }
            if (String.IsNullOrEmpty(assetoid)) return false;

            Oid attachmentContext = Oid.FromToken(assetoid, metaModel);

            IAssetType attachmentType = metaModel.GetAssetType("Attachment");
            IAttributeDefinition attachmentNameDef = attachmentType.GetAttributeDefinition("Name");
            IAttributeDefinition attachmentContentDef = attachmentType.GetAttributeDefinition("Content");
            IAttributeDefinition attachmentContentTypeDef = attachmentType.GetAttributeDefinition("ContentType");
            IAttributeDefinition attachmentFileNameDef = attachmentType.GetAttributeDefinition("Filename");

            Asset newAttachment = services.New(attachmentType, attachmentContext);
            newAttachment.SetAttributeValue(attachmentNameDef, "Imported from Jira");
            newAttachment.SetAttributeValue(attachmentContentDef, string.Empty);
            newAttachment.SetAttributeValue(attachmentContentTypeDef, mimeType);
            newAttachment.SetAttributeValue(attachmentFileNameDef, rawfile);
            services.Save(newAttachment);

            //Setup and attach the payload
            string attachmentKey = newAttachment.Oid.Key.ToString();
            int buffersize = 4096;

            using (FileStream input = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                using (Stream output = attachments.GetWriteStream(attachmentKey))
                {
                    byte[] buffer = new byte[buffersize];
                    for (; ; )
                    {
                        int read = input.Read(buffer, 0, buffersize);
                        if (read == 0)
                            break;
                        output.Write(buffer, 0, read);
                    }
                }
            }
            attachments.SetWriteStream(attachmentKey, mimeType);
            return true;
        }
 public CleanupDefects(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations)
     : base(sqlConn, MetaAPI, DataAPI, Configurations) { }
 public ExportAttachments(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, V1APIConnector ImageConnector, MigrationConfiguration Configurations)
     : base(sqlConn, MetaAPI, DataAPI, Configurations) 
 {
     _imageConnector = ImageConnector;
 }
Ejemplo n.º 17
0
        //Verifies the connection to the V1 source instance.
        private static void VerifyV1TargetConnection()
        {
            try
            {
                _targetMetaConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/meta.v1/");

                if (_config.V1TargetConnection.AuthenticationType == "standard")
                {
                    _targetDataConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/rest-1.v1/", _config.V1TargetConnection.Username, _config.V1TargetConnection.Password, false);
                    _targetImageConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/attachment.img/", _config.V1TargetConnection.Username, _config.V1TargetConnection.Password, false);
                }
                else if (_config.V1TargetConnection.AuthenticationType == "windows")
                {
                    _logger.Info("Connecting with user {0}.", System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                    _targetDataConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/rest-1.v1/", null, null, true);
                    _targetImageConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/attachment.img/", null, null, true);

                }
                else if (_config.V1TargetConnection.AuthenticationType == "oauth")
                {
                    throw new Exception("OAuth authentication is not supported -- yet.");
                }
                else
                {
                    throw new Exception("Unable to determine the V1TargetConnection authentication type in the config file. Value used must be standard|windows|oauth.");
                }

                _targetMetaAPI = new MetaModel(_targetMetaConnector);
                _targetDataAPI = new Services(_targetMetaAPI, _targetDataConnector);

                IAssetType assetType = _targetMetaAPI.GetAssetType("Member");
                Query query = new Query(assetType);
                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Username");
                query.Selection.Add(nameAttribute);
                FilterTerm idFilter = new FilterTerm(nameAttribute);
                idFilter.Equal(_config.V1TargetConnection.Username);
                query.Filter = idFilter;
                QueryResult result = _targetDataAPI.Retrieve(query);
                if (result.TotalAvaliable > 0)
                {
                    _logger.Info("-> Connection to V1 target instance \"{0}\" verified.", _config.V1TargetConnection.Url);
                    _logger.Info("-> V1 target instance version: {0}.", _targetMetaAPI.Version.ToString());
                    MigrationStats.WriteStat(_sqlConn, "Target API Version", _targetMetaAPI.Version.ToString());
                }
                else
                {
                    throw new Exception(String.Format("Unable to validate connection to {0} with username {1}. You may not have permission to access this instance.", _config.V1TargetConnection.Url, _config.V1TargetConnection.Username));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("-> Unable to connect to V1 source instance \"{0}\".", _config.V1TargetConnection.Url);
                throw ex;
            }
        }
 public ImportRegressionTests(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations)
     : base(sqlConn, MetaAPI, DataAPI, Configurations) { }
 public ExportIterations(SqlConnection sqlConn, MetaModel MetaAPI, Services DataAPI, MigrationConfiguration Configurations)
     : base(sqlConn, MetaAPI, DataAPI, Configurations) { }
Ejemplo n.º 20
0
        private static void Run()
        {
            V1APIConnector dataConnector = new V1APIConnector(_v1Url + DATA_API, _v1Username, _v1Password);
            V1APIConnector metaConnector = new V1APIConnector(_v1Url + META_API);

            MetaModel = new MetaModel(metaConnector);
            Services = new Services(MetaModel, dataConnector);

            //Check if we need to add TeamRooms.
            if (ConfigurationManager.AppSettings["UseTeamRoom"] == "true")
                _useTeamRoom = true;

            Utils.Logger.Info("Verifying configuration...");
            VerifyConfiguration();

            Project.HideFutureStatus();

            if (_isCatalyst == false) 
                Team.SaveTeams(Team.GetAllTeams());

            //Use for loop to create multiple project sets based on config value. Each project set contains 40 distinct projects.
            for (int i = 0; i < _v1ProjectSetCount; i++)
            {
                Utils.Logger.Info("Creating projects...");
                IList<Project> projects = Project.GetProjects(i);

                Utils.Logger.Info("Saving projects...");
                Project.SaveProjects(projects, "Scope:0", null, null, _isUltimate, _isCatalyst, _isEnteprisePlus, _useTeamRoom);

                Utils.Logger.Info("Training data saved. Rolling back dates.");
                RollDatesBackOneDay();

                Utils.Logger.Info("Dates rolled back. Saving second day of data.");

                SaveSecondDay(projects);
                Utils.Logger.Info("Second day of data saved. Rolling back dates.");

                RollDatesBackOneDay();
                Utils.Logger.Info("Dates rolled back. Saving third day of data.");

                SaveThirdDay(projects);
                Utils.Logger.Info("Third day of data saved. Rolling back dates.");

                RollDatesBackOneDay();
                Utils.Logger.Info("Dates rolled back. Saving fourth day of data.");

                SaveFourthDay(projects);
                Utils.Logger.Info("Fourth day of data saved. Rolling back dates.");

                RollDatesBackOneDay();
                Utils.Logger.Info("Dates rolled back. Saving fifth day of data.");

                SaveFifthDay(projects);
                Utils.Logger.Info("Fifth day of data saved. Rolling back dates.");

                RollDatesBackOneDay();
                Utils.Logger.Info("Dates rolled back. Saving sixth day of data.");

                SaveSixthDay(projects);
                Utils.Logger.Info("Sixth day of data saved. Rolling back dates.");

                RollDatesBackOneDay();
                Utils.Logger.Info("Dates rolled back. Saving seventh day of data.");

                SaveSeventhDay(projects);
                Utils.Logger.Info("Seventh day of data saved.");

                ProcessClientSpecificData(projects);

                Utils.Logger.Info("Training data generation completed.");
            }
        }