コード例 #1
0
        public void Start()
        {
            var jsonProjects = Phase1();

            foreach (var projItem in jsonProjects)
            {
                WorkerPayload wp = (WorkerPayload)projItem;
                //SmallProject sp = new SmallProject() { Key = wp["key"], ProjectID = wp["id"] };
                SmallProject sp = new SmallProject(wp.ProjectData.ToString());
                //SmallProject sp = (SmallProject)projItem;
                Phase2(sp);
            }
        }
コード例 #2
0
        private void Phase2(SmallProject sp)
        {
            var jiraService = new JiraService();

            ManualResetEvent[] events  = Enumerable.Range(1, 10).Select(e => new ManualResetEvent(true)).ToArray();
            ImportWorker[]     workers = new ImportWorker[10];
            Thread[]           threads = new Thread[10];

            // Get All Issues for project.
            //var itemDataJson = jiraService.GetIssueList(sp.ProjectID);
            var     itemDataJson  = jiraService.GetIssueList(sp.Key);
            dynamic obj           = JsonConvert.DeserializeObject(itemDataJson);
            int     current       = 0;
            int     total         = obj.issues.Count;
            var     countToAssign = total > MaxPool ? MaxPool : total;

            // if there are no issues, just skip through.
            if (obj.issues.Count > 0)
            {
                for (int i = 0; i < total; i++)
                {
                    dynamic jsonProject = JsonConvert.DeserializeObject(jiraService.GetSelfResults(obj.issues[i].self.Value));
                    var     itemService = new ItemService();
                    itemService.Save(jsonProject, int.Parse(sp.ProjectID));
                }



                //List<object> jsonProjects = new List<object>();

                //// Return specific details for each issue
                //for (int i = 0; i < countToAssign; i++) {
                //    StartIssueWorker(events, workers, threads, i, obj.issues[i].id.Value, sp.ProjectID, obj.issues[i].self.Value);
                //    current++;
                //}

                //while (current < total) {
                //    int index = WaitHandle.WaitAny(events);
                //    jsonProjects.Add(workers[index].Payload);
                //    StartIssueWorker(events, workers, threads, index, obj.issues[index].id.Value, sp.ProjectID, obj.issues[index].self.Value);
                //    current++;
                //}
                //WaitHandle.WaitAll(events);
                //for (var i = 0; i < workers.Length; i++) {
                //    if (workers[i] != null && workers[i].Payload != null) {
                //        jsonProjects.Add(workers[i].Payload);
                //    }
                //}
            }
        }