예제 #1
0
 //ZYL add this method
 public void UpdateSpecs(int specIndex)
 {
     while (TestSpecList.Count <= specIndex)
     {
         TestSpecList.Add(new TestTraceSpec());
     }
 }
        public static TestSpecList ToSpecList(this List <ExportedAgileTestPlatformSpec> agileTestPlatformSpecs)
        {
            TestSpecList tsl = new TestSpecList();

            tsl.AddRange(agileTestPlatformSpecs.Select(aitem => (TestSpec)aitem));
            return(tsl);
        }
예제 #3
0
파일: TRTestItem.cs 프로젝트: Maxzyl/Repos
 public void AddDefaultMarker(int specIndex)
 {
     while (TestSpecList.Count <= specIndex)
     {
         TestSpecList.Add(new TRTestItemSpec());
     }
     TestSpecList[specIndex].TestMarkerList.Add(new XYTestMarker());
 }
예제 #4
0
파일: TRTestItem.cs 프로젝트: Maxzyl/Repos
        public void CalcInfo()
        {
            if (Data == null || Data.Length == 0)
            {
                foreach (var spec in TestSpecList)
                {
                    spec.PassFail = null;
                }
                return;
            }
            foreach (var spec in TestSpecList)
            {
                #region
                foreach (var marker in spec.TestMarkerList)
                {
                    if (marker is XYTestMarker)
                    {
                        var xyMarker = marker as XYTestMarker;
                        xyMarker.MarkerResult.Clear();
                        switch (xyMarker.Type)
                        {
                        case XYTestMarkerTypeEnum.ABSMax:
                            double yAbsMax = GeneFun.GetTwoArraryMax(Data, true);
                            double xAbsMax = FreqList[0];
                            xyMarker.MarkerResult.Add(new XYData(xAbsMax, yAbsMax));
                            break;

                        case XYTestMarkerTypeEnum.ABSMin:
                            double yAbsMin = GeneFun.GetTwoArrayMin(Data, true);
                            double xAbsMin = FreqList[0];
                            xyMarker.MarkerResult.Add(new XYData(xAbsMin, yAbsMin));
                            break;

                        case XYTestMarkerTypeEnum.Max:
                            double yMax = GeneFun.GetTwoArraryMax(Data, false);
                            double xMax = FreqList[0];
                            xyMarker.MarkerResult.Add(new XYData(xMax, yMax));
                            break;

                        case XYTestMarkerTypeEnum.Min:
                            double yMin = GeneFun.GetTwoArrayMin(Data, false);
                            double xMin = FreqList[0];
                            xyMarker.MarkerResult.Add(new XYData(xMin, yMin));
                            break;

                        case XYTestMarkerTypeEnum.Peak:
                            double y1Max = GeneFun.GetTwoArraryMax(Data, false);
                            double y1Min = GeneFun.GetTwoArrayMin(Data, false);
                            if (Math.Abs(y1Max) >= Math.Abs(y1Min))
                            {
                                xyMarker.MarkerResult.Add(new XYData(FreqList[0], y1Max));
                            }
                            else
                            {
                                xyMarker.MarkerResult.Add(new XYData(FreqList[0], y1Min));
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    marker.JudgePassFail();
                }
                #endregion
                #region
                List <bool>           boolList = new List <bool>();
                CalcEngine.CalcEngine ce       = new CalcEngine.CalcEngine();
                ce.Variables.Add("att", null);
                ce.Variables.Add("phase", null);
                ce.Variables.Add("freq", null);
                for (int i = 0; i < Data.GetLength(0); i++)
                {
                    for (int j = 0; j < Data.GetLength(1); j++)
                    {
                        ce.Variables["att"]   = StateList[i].Att;
                        ce.Variables["phase"] = StateList[i].Phase;
                        ce.Variables["freq"]  = FreqList[j];
                        object highLimitStr;
                        object lowLimitStr;
                        if (string.IsNullOrWhiteSpace(spec.HighLimit))
                        {
                            highLimitStr = null;
                        }
                        else
                        {
                            highLimitStr = ce.Evaluate(spec.HighLimit);
                        }
                        if (string.IsNullOrWhiteSpace(spec.LowLimit))
                        {
                            lowLimitStr = null;
                        }
                        else
                        {
                            lowLimitStr = ce.Evaluate(spec.LowLimit);
                        }
                        double?highLimitValue = highLimitStr.ToNullDouble();
                        double?lowLimitValue  = lowLimitStr.ToNullDouble();
                        bool   passFail       = GeneFun.IsPassFail(Data[i, j], highLimitValue, lowLimitValue);
                        boolList.Add(passFail);
                    }
                }
                spec.PassFail = GeneFun.NullBoolAndList(boolList);
                spec.PassFail = GeneFun.NullBoolAnd(GeneFun.NullBoolAndList(spec.TestMarkerList.Select(x => x.PassFail).ToList()), spec.PassFail);
                #endregion
            }
            PassFail = GeneFun.NullBoolAndList(TestSpecList.Select(x => x.PassFail).ToList());
        }
 public static TestSpecList ToSpecList(this List<ExportedAgileTestPlatformSpec> agileTestPlatformSpecs)
 {
     TestSpecList tsl = new TestSpecList();
     tsl.AddRange(agileTestPlatformSpecs.Select(aitem => (TestSpec)aitem));
     return tsl;
 }
예제 #6
0
        //[System.Xml.Serialization.XmlIgnore]
        //public bool IsTest { get; set; }
        //[System.Xml.Serialization.XmlIgnore]
        //[Newtonsoft.Json.JsonIgnore]
        //public bool? PassFail { get; set; }
        //public string Unit { get; set; }
        public void CalcInfo()
        {
            if (ResultData == null || ResultData.Count == 0)
            {
                return;
            }
            for (int i = 0; i < ResultData.Count(); i++)
            {
                ResultData[i] = new XYData()
                {
                    X = ResultData[i].X, Y = ResultData[i].Y + Compensation
                };
            }
            foreach (var spec in TestSpecList)
            {
                foreach (var marker in spec.TestMarkerList)
                {
                    #region
                    if (marker is XYTestMarker)
                    {
                        var xyMarker = marker as XYTestMarker;
                        xyMarker.MarkerResult.Clear();
                        switch (xyMarker.Type)
                        {
                        case XYTestMarkerTypeEnum.Normal:
                            double[] lstXData = ResultData.Select(x => x.X).ToArray();
                            double[] lstYData = ResultData.Select(x => x.Y).ToArray();

                            double xData = xyMarker.Start;

                            double yData = GeneFun.LinearInterp(lstXData, lstYData, xData);
                            xyMarker.MarkerResult.Add(new XYData(xData, yData));
                            break;

                        case XYTestMarkerTypeEnum.Max:
                            double ymax = ResultData.Select(x => x.Y).Max();
                            double xmax = ResultData.Find(x => x.Y == ymax).X;
                            xyMarker.MarkerResult.Add(new XYData(xmax, ymax));
                            break;

                        case XYTestMarkerTypeEnum.Min:
                            double ymin = ResultData.Select(x => x.Y).Min();
                            double xmin = ResultData.Find(x => x.Y == ymin).X;
                            xyMarker.MarkerResult.Add(new XYData(xmin, ymin));
                            break;

                        case XYTestMarkerTypeEnum.ABSMax:
                            double yAbsmax = ResultData.Select(x => Math.Abs(x.Y)).Max();
                            double xAbsmax = ResultData.Find(x => Math.Abs(x.Y) == yAbsmax).X;
                            xyMarker.MarkerResult.Add(new XYData(xAbsmax, yAbsmax));
                            break;

                        case XYTestMarkerTypeEnum.ABSMin:
                            double yAbsmin = ResultData.Select(x => Math.Abs(x.Y)).Min();
                            double xAbsmin = ResultData.Find(x => Math.Abs(x.Y) == yAbsmin).X;
                            xyMarker.MarkerResult.Add(new XYData(xAbsmin, yAbsmin));
                            break;

                        case XYTestMarkerTypeEnum.Peak:
                            double y1Max = ResultData.Select(x => x.Y).Max();
                            double x1Max = ResultData.Find(x => x.Y == y1Max).X;
                            double y1Min = ResultData.Select(x => x.Y).Min();
                            double x1Min = ResultData.Find(x => x.Y == y1Min).X;
                            if (Math.Abs(y1Max) >= Math.Abs(y1Min))
                            {
                                xyMarker.MarkerResult.Add(new XYData(x1Max, y1Max));
                            }
                            else
                            {
                                xyMarker.MarkerResult.Add(new XYData(x1Min, y1Max));
                            }
                            break;

                        case XYTestMarkerTypeEnum.Mean:
                            double avg = ResultData.Select(x => x.Y).Average();
                            double xx  = ResultData.Select(x => x.X).First();
                            xyMarker.MarkerResult.Add(new XYData(xx, avg));
                            break;

                        case XYTestMarkerTypeEnum.PhaseRipple:
                            double phaseNolin = GeneFun.CalcPhaseNonlin(ResultData.Select(x => x.Y).ToArray(),
                                                                        10000, 0.01);
                            xyMarker.MarkerResult.Add(new XYData(ResultData.Select(x => x.X).First(), phaseNolin));
                            break;

                        case XYTestMarkerTypeEnum.Ripple:
                            double ymin1 = ResultData.Select(x => x.Y).Min();
                            double ymax1 = ResultData.Select(x => x.Y).Max();
                            xyMarker.MarkerResult.Add(new XYData(ResultData.Select(x => x.X).First(),
                                                                 ymax1 - ymin1));
                            break;

                        case XYTestMarkerTypeEnum.InRange:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.Target:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.Q_Value:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.BandWidth:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.LeftFreq:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.RightFreq:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.CenterFreq:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.InsertionLoss:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.Pin_NdB:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.Po_NdB:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.RippleInRange:
                            xyMarker.MarkerResult.Add(new XYData(0, 0));
                            break;

                        case XYTestMarkerTypeEnum.RippleHalf:
                            double ymin2 = ResultData.Select(x => x.Y).Min();
                            double ymax2 = ResultData.Select(x => x.Y).Max();
                            xyMarker.MarkerResult.Add(new XYData(ResultData.Select(x => x.X).First(),
                                                                 (ymax2 - ymin2) / 2));
                            break;

                        case XYTestMarkerTypeEnum.PowerMean:
                            double avg1 = ResultData.Select(x => Math.Pow(10, ((x.Y - 30) / 10))).Average();
                            double xx1  = ResultData.Select(x => x.Y).First();
                            xyMarker.MarkerResult.Add(new XYData(xx1, avg1));
                            break;

                        default:
                            break;
                        }
                    }
                    marker.JudgePassFail();
                    #endregion
                }
                if (!spec.TestLimit.Enable)
                {
                    bool?specPassFail = null;
                    if (spec.UpLimit != null && spec.LowLimit != null)
                    {
                        int upCount  = ResultData.Where(x => x.Y > spec.UpLimit).Count();
                        int lowCount = ResultData.Where(x => x.Y < spec.LowLimit).Count();
                        if (upCount > 0 || lowCount > 0)
                        {
                            specPassFail = false;
                        }
                        else
                        {
                            specPassFail = true;
                        }
                    }
                    else if (spec.UpLimit != null && spec.LowLimit == null)
                    {
                        int upCount = ResultData.Where(x => x.Y > spec.UpLimit).Count();
                        if (upCount > 0)
                        {
                            specPassFail = false;
                        }
                        else
                        {
                            specPassFail = true;
                        }
                    }
                    else if (spec.UpLimit == null && spec.LowLimit != null)
                    {
                        int lowCount = ResultData.Where(x => x.Y < spec.LowLimit).Count();
                        if (lowCount > 0)
                        {
                            specPassFail = false;
                        }
                        else
                        {
                            specPassFail = true;
                        }
                    }
                    else
                    {
                        specPassFail = null;
                    }
                    spec.PassFail = GeneFun.NullBoolAnd(GeneFun.NullBoolAndList(spec.TestMarkerList.Select(x => x.PassFail).ToList()), specPassFail);
                }
            }
            PassFail = GeneFun.NullBoolAndList(TestSpecList.Select(x => x.PassFail).ToList());
        }
        private void ButtonImport_OnClick(object sender, RoutedEventArgs e)
        {
            foreach (var item in this.DataGridBuildsToImport.Items)
            {
                BuildImport bi = item as BuildImport;
                try
                {
                    if (bi == null)
                    {
                        return;
                    }

                    if (!File.Exists(bi.JsonFile))
                    {
                        bi.Status = "Failed";
                        bi.StatusImage = "Graphics/Failed.png";
                        bi.Message = "File not found";
                    }
                    else
                    {
                        ExportedBuildDefinition exdef = JsonConvert.DeserializeObject<ExportedBuildDefinition>(File.ReadAllText(bi.JsonFile));
                        var newBuildDefinition = this.buildServer.CreateBuildDefinition(this.lableTeamProject.Content.ToString());
                        newBuildDefinition.Name = exdef.Name;
                        newBuildDefinition.Description = exdef.Description;
                        newBuildDefinition.ContinuousIntegrationType = exdef.ContinuousIntegrationType;
                        newBuildDefinition.ContinuousIntegrationQuietPeriod = exdef.ContinuousIntegrationQuietPeriod;

                        newBuildDefinition.QueueStatus = exdef.QueueStatus;
                        if (exdef.SourceProviders.All(s => s.Name != "TFGIT"))
                        {
                            foreach (var mapping in exdef.Mappings)
                            {
                                newBuildDefinition.Workspace.AddMapping(mapping.ServerItem, mapping.LocalItem, mapping.MappingType);
                            }
                        }

                        newBuildDefinition.RetentionPolicyList.Clear();
                        foreach (var ret in exdef.RetentionPolicyList)
                        {
                            newBuildDefinition.AddRetentionPolicy(ret.BuildReason, ret.BuildStatus, ret.NumberToKeep, ret.DeleteOptions);
                        }

                        foreach (var sp in exdef.SourceProviders)
                        {
                            var provider = newBuildDefinition.CreateInitialSourceProvider(sp.Name);
                            if (exdef.SourceProviders.All(s => s.Name == "TFGIT"))
                            {
                                provider.Fields["RepositoryName"] = sp.Fields["RepositoryName"];
                                provider.Fields["DefaultBranch"] = sp.Fields["DefaultBranch"];
                                provider.Fields["CIBranches"] = sp.Fields["CIBranches"];
                                provider.Fields["RepositoryUrl"] = sp.Fields["RepositoryUrl"];
                            }

                            newBuildDefinition.SetSourceProvider(provider);
                        }

                        newBuildDefinition.BuildController = this.buildServer.GetBuildController(exdef.BuildController);
                        var x = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString());
                        if (x.All(p => p.ServerPath != exdef.ProcessTemplate))
                        {
                            bi.Status = "Failed";
                            bi.StatusImage = "Graphics/Failed.png";
                            bi.Message = "Process Template not found - " + exdef.ProcessTemplate;
                            continue;
                        }

                        newBuildDefinition.Process = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString()).First(p => p.ServerPath == exdef.ProcessTemplate);
                        newBuildDefinition.DefaultDropLocation = exdef.DefaultDropLocation;
                        foreach (var sched in exdef.Schedules)
                        {
                            var newSched = newBuildDefinition.AddSchedule();
                            newSched.DaysToBuild = sched.DaysToBuild;
                            newSched.StartTime = sched.StartTime;
                            newSched.TimeZone = sched.TimeZone;
                        }

                        var process = WorkflowHelpers.DeserializeProcessParameters(newBuildDefinition.ProcessParameters);

                        foreach (var param in exdef.ProcessParameters)
                        {
                            if (param.Key != "AgentSettings" && param.Key != "BuildSettings" && param.Key != "TestSpecs")
                            {
                                Newtonsoft.Json.Linq.JArray arrayItem = param.Value as Newtonsoft.Json.Linq.JArray;
                                if (arrayItem == null)
                                {
                                    Newtonsoft.Json.Linq.JObject objectItem = param.Value as Newtonsoft.Json.Linq.JObject;
                                    if (objectItem == null)
                                    {
                                        if (param.Key == "CleanWorkspace")
                                        {
                                            process.Add(param.Key, (CleanWorkspaceOption)Enum.Parse(typeof(CleanWorkspaceOption), param.Value.ToString()));
                                        }
                                        else if (param.Key == "RunCodeAnalysis")
                                        {
                                            process.Add(param.Key, (CodeAnalysisOption)Enum.Parse(typeof(CodeAnalysisOption), param.Value.ToString()));
                                        }
                                        else
                                        {
                                            process.Add(param.Key, param.Value);
                                        }
                                    }
                                    else
                                    {
                                        Microsoft.TeamFoundation.Build.Common.BuildParameter paramItem = new Microsoft.TeamFoundation.Build.Common.BuildParameter(param.Value.ToString());
                                        process.Add(param.Key, paramItem);
                                    }
                                }
                                else
                                {
                                    string[] arrayItemList = new string[arrayItem.Count];
                                    for (int i = 0; i < arrayItem.Count; i++)
                                    {
                                        arrayItemList[i] = arrayItem[i].ToString();
                                    }

                                    process.Add(param.Key, arrayItemList);
                                }
                            }
                        }

                        if (exdef.ProjectsToBuild != null)
                        {
                            process.Add("BuildSettings", new BuildSettings { ProjectsToBuild = exdef.ProjectsToBuild, PlatformConfigurations = exdef.ConfigurationsToBuild });
                        }

                        if (exdef.TfvcAgentSettings != null)
                        {
                            process.Add("AgentSettings", new AgentSettings { MaxExecutionTime = exdef.TfvcAgentSettings.MaxExecutionTime, MaxWaitTime = exdef.TfvcAgentSettings.MaxWaitTime, Name = exdef.TfvcAgentSettings.Name, TagComparison = exdef.TfvcAgentSettings.Comparison, Tags = exdef.TfvcAgentSettings.Tags });
                        }
                        else if (exdef.GitAgentSettings != null)
                        {
                            process.Add("AgentSettings", exdef.GitAgentSettings);
                        }

                        if (exdef.AgileTestSpecs != null)
                        {
                            TestSpecList tsl = new TestSpecList();
                            foreach (var aitem in exdef.AgileTestSpecs)
                            {
                                AgileTestPlatformSpec agileSpec = new AgileTestPlatformSpec();
                                agileSpec.AssemblyFileSpec = aitem.AssemblyFileSpec;
                                agileSpec.ExecutionPlatform = aitem.ExecutionPlatform;
                                agileSpec.FailBuildOnFailure = aitem.FailBuildOnFailure;
                                agileSpec.RunName = aitem.RunName;
                                agileSpec.TestCaseFilter = aitem.TestCaseFilter;
                                agileSpec.RunSettingsForTestRun = new RunSettings();
                                agileSpec.RunSettingsForTestRun.ServerRunSettingsFile = aitem.RunSettingsFileName;
                                agileSpec.RunSettingsForTestRun.TypeRunSettings = aitem.TypeRunSettings;
                                tsl.Add(agileSpec);
                            }

                            process.Add("TestSpecs", tsl);
                        }

                        if (exdef.BuildReasons != null)
                        {
                            foreach (var key in exdef.BuildReasons.Keys)
                            {
                                if (process.ContainsKey(key))
                                {
                                    process[key] = exdef.BuildReasons[key];
                                }
                            }
                        }

                        if (exdef.IntegerParameters != null)
                        {
                            foreach (var key in exdef.IntegerParameters.Keys)
                            {
                                if (process.ContainsKey(key))
                                {
                                    process[key] = exdef.IntegerParameters[key];
                                }
                            }
                        }

                        if (exdef.BuildVerbosities != null)
                        {
                            foreach (var key in exdef.BuildVerbosities.Keys)
                            {
                                if (process.ContainsKey(key))
                                {
                                    process[key] = exdef.BuildVerbosities[key];
                                }
                            }
                        }

                        newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
                        newBuildDefinition.Save();
                        bi.Status = "Succeeded";
                        bi.StatusImage = "Graphics/Succeeded.png";
                        bi.Message = string.Empty;
                    }
                }
                catch (Exception ex)
                {
                    bi.Status = "Failed";
                    bi.StatusImage = "Graphics/Failed.png";
                    bi.Message = ex.Message;
                }
                finally
                {
                    this.DataGridBuildsToImport.ItemsSource = null;
                    this.DataGridBuildsToImport.ItemsSource = this.buildFiles;
                }
            }
        }
예제 #8
0
        private void ButtonImport_OnClick(object sender, RoutedEventArgs e)
        {
            foreach (var item in this.DataGridBuildsToImport.Items)
            {
                BuildImport bi = item as BuildImport;
                try
                {
                    if (bi == null)
                    {
                        return;
                    }

                    if (!File.Exists(bi.JsonFile))
                    {
                        bi.Status      = "Failed";
                        bi.StatusImage = "Graphics/Failed.png";
                        bi.Message     = "File not found";
                    }
                    else
                    {
                        ExportedBuildDefinition exdef = JsonConvert.DeserializeObject <ExportedBuildDefinition>(File.ReadAllText(bi.JsonFile));
                        var newBuildDefinition        = this.buildServer.CreateBuildDefinition(this.lableTeamProject.Content.ToString());
                        newBuildDefinition.Name        = exdef.Name;
                        newBuildDefinition.Description = exdef.Description;
                        newBuildDefinition.ContinuousIntegrationType        = exdef.ContinuousIntegrationType;
                        newBuildDefinition.ContinuousIntegrationQuietPeriod = exdef.ContinuousIntegrationQuietPeriod;

                        newBuildDefinition.QueueStatus = exdef.QueueStatus;
                        if (exdef.SourceProviders.All(s => s.Name != "TFGIT"))
                        {
                            foreach (var mapping in exdef.Mappings)
                            {
                                newBuildDefinition.Workspace.AddMapping(mapping.ServerItem, mapping.LocalItem, mapping.MappingType);
                            }
                        }

                        newBuildDefinition.RetentionPolicyList.Clear();
                        foreach (var ret in exdef.RetentionPolicyList)
                        {
                            newBuildDefinition.AddRetentionPolicy(ret.BuildReason, ret.BuildStatus, ret.NumberToKeep, ret.DeleteOptions);
                        }

                        foreach (var sp in exdef.SourceProviders)
                        {
                            var provider = newBuildDefinition.CreateInitialSourceProvider(sp.Name);
                            if (exdef.SourceProviders.All(s => s.Name == "TFGIT"))
                            {
                                provider.Fields["RepositoryName"] = sp.Fields["RepositoryName"];
                                provider.Fields["DefaultBranch"]  = sp.Fields["DefaultBranch"];
                                provider.Fields["CIBranches"]     = sp.Fields["CIBranches"];
                                provider.Fields["RepositoryUrl"]  = sp.Fields["RepositoryUrl"];
                            }

                            newBuildDefinition.SetSourceProvider(provider);
                        }

                        newBuildDefinition.BuildController = this.buildServer.GetBuildController(exdef.BuildController);
                        var x = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString());
                        if (x.All(p => p.ServerPath != exdef.ProcessTemplate))
                        {
                            bi.Status      = "Failed";
                            bi.StatusImage = "Graphics/Failed.png";
                            bi.Message     = "Process Template not found - " + exdef.ProcessTemplate;
                            continue;
                        }

                        newBuildDefinition.Process             = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString()).First(p => p.ServerPath == exdef.ProcessTemplate);
                        newBuildDefinition.DefaultDropLocation = exdef.DefaultDropLocation;
                        foreach (var sched in exdef.Schedules)
                        {
                            var newSched = newBuildDefinition.AddSchedule();
                            newSched.DaysToBuild = sched.DaysToBuild;
                            newSched.StartTime   = sched.StartTime;
                            newSched.TimeZone    = sched.TimeZone;
                        }

                        var process = WorkflowHelpers.DeserializeProcessParameters(newBuildDefinition.ProcessParameters);

                        foreach (var param in exdef.ProcessParameters)
                        {
                            if (param.Key != "AgentSettings" && param.Key != "BuildSettings" && param.Key != "TestSpecs")
                            {
                                Newtonsoft.Json.Linq.JArray arrayItem = param.Value as Newtonsoft.Json.Linq.JArray;
                                if (arrayItem == null)
                                {
                                    Newtonsoft.Json.Linq.JObject objectItem = param.Value as Newtonsoft.Json.Linq.JObject;
                                    if (objectItem == null)
                                    {
                                        if (param.Key == "CleanWorkspace")
                                        {
                                            process.Add(param.Key, (CleanWorkspaceOption)Enum.Parse(typeof(CleanWorkspaceOption), param.Value.ToString()));
                                        }
                                        else if (param.Key == "RunCodeAnalysis")
                                        {
                                            process.Add(param.Key, (CodeAnalysisOption)Enum.Parse(typeof(CodeAnalysisOption), param.Value.ToString()));
                                        }
                                        else
                                        {
                                            process.Add(param.Key, param.Value);
                                        }
                                    }
                                    else
                                    {
                                        Microsoft.TeamFoundation.Build.Common.BuildParameter paramItem = new Microsoft.TeamFoundation.Build.Common.BuildParameter(param.Value.ToString());
                                        process.Add(param.Key, paramItem);
                                    }
                                }
                                else
                                {
                                    string[] arrayItemList = new string[arrayItem.Count];
                                    for (int i = 0; i < arrayItem.Count; i++)
                                    {
                                        arrayItemList[i] = arrayItem[i].ToString();
                                    }

                                    process.Add(param.Key, arrayItemList);
                                }
                            }
                        }

                        if (exdef.ProjectsToBuild != null)
                        {
                            process.Add("BuildSettings", new BuildSettings {
                                ProjectsToBuild = exdef.ProjectsToBuild, PlatformConfigurations = exdef.ConfigurationsToBuild
                            });
                        }

                        if (exdef.TfvcAgentSettings != null)
                        {
                            process.Add("AgentSettings", new AgentSettings {
                                MaxExecutionTime = exdef.TfvcAgentSettings.MaxExecutionTime, MaxWaitTime = exdef.TfvcAgentSettings.MaxWaitTime, Name = exdef.TfvcAgentSettings.Name, TagComparison = exdef.TfvcAgentSettings.Comparison, Tags = exdef.TfvcAgentSettings.Tags
                            });
                        }
                        else if (exdef.GitAgentSettings != null)
                        {
                            process.Add("AgentSettings", exdef.GitAgentSettings);
                        }

                        if (exdef.AgileTestSpecs != null)
                        {
                            TestSpecList tsl = new TestSpecList();
                            foreach (var aitem in exdef.AgileTestSpecs)
                            {
                                AgileTestPlatformSpec agileSpec = new AgileTestPlatformSpec();
                                agileSpec.AssemblyFileSpec      = aitem.AssemblyFileSpec;
                                agileSpec.ExecutionPlatform     = aitem.ExecutionPlatform;
                                agileSpec.FailBuildOnFailure    = aitem.FailBuildOnFailure;
                                agileSpec.RunName               = aitem.RunName;
                                agileSpec.TestCaseFilter        = aitem.TestCaseFilter;
                                agileSpec.RunSettingsForTestRun = new RunSettings();
                                agileSpec.RunSettingsForTestRun.ServerRunSettingsFile = aitem.RunSettingsFileName;
                                agileSpec.RunSettingsForTestRun.TypeRunSettings       = aitem.TypeRunSettings;
                                tsl.Add(agileSpec);
                            }

                            process.Add("TestSpecs", tsl);
                        }

                        if (exdef.BuildReasons != null)
                        {
                            foreach (var key in exdef.BuildReasons.Keys)
                            {
                                if (process.ContainsKey(key))
                                {
                                    process[key] = exdef.BuildReasons[key];
                                }
                            }
                        }

                        if (exdef.IntegerParameters != null)
                        {
                            foreach (var key in exdef.IntegerParameters.Keys)
                            {
                                if (process.ContainsKey(key))
                                {
                                    process[key] = exdef.IntegerParameters[key];
                                }
                            }
                        }

                        if (exdef.BuildVerbosities != null)
                        {
                            foreach (var key in exdef.BuildVerbosities.Keys)
                            {
                                if (process.ContainsKey(key))
                                {
                                    process[key] = exdef.BuildVerbosities[key];
                                }
                            }
                        }

                        newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
                        newBuildDefinition.Save();
                        bi.Status      = "Succeeded";
                        bi.StatusImage = "Graphics/Succeeded.png";
                        bi.Message     = string.Empty;
                    }
                }
                catch (Exception ex)
                {
                    bi.Status      = "Failed";
                    bi.StatusImage = "Graphics/Failed.png";
                    bi.Message     = ex.Message;
                }
                finally
                {
                    this.DataGridBuildsToImport.ItemsSource = null;
                    this.DataGridBuildsToImport.ItemsSource = this.buildFiles;
                }
            }
        }