Exemplo n.º 1
0
        public static void GetInfo()
        {
            credentials = Credentials.FromFile(Path.Combine(
                                                   Directory.GetCurrentDirectory(), "token.json"));
            string hub_id       = GetHubs();
            var    projectsInfo = GetProjects(hub_id);

            foreach (var project in projectsInfo)
            {
                var containerId = GetContainerId(hub_id, project.ProjectBIM360ID);
                var issueTypes  = GetIssueTypes(containerId);
                var issues      = GetIssues(containerId, hub_id, project.ProjectBIM360ID);
                var rootCauses  = GetRootCauses(containerId);

                //записыввем дату выгрузки в файл
                DateTime date = DateTime.Now;

                string dateJson     = JsonConvert.SerializeObject(date);
                string dateFilePath = Path.Combine(
                    Directory.GetCurrentDirectory(), "date.json");
                try
                {
                    using (StreamWriter sw = new StreamWriter(dateFilePath,
                                                              false,
                                                              System.Text.Encoding.Default))
                    {
                        sw.WriteLine(dateJson);
                    }
                }
                catch (Exception e)
                {
                    // Console.WriteLine(e.Message);
                }
                using (SoccerContext db = new SoccerContext())
                {
                    foreach (var pr in projectsInfo)
                    {
                        db.Projects.Load();
                        Project projectInDb = db.Projects.Where(p => p.ProjectBIM360ID == project.ProjectBIM360ID).FirstOrDefault();
                        if (db.Projects.Where(p => p.ProjectBIM360ID == pr.ProjectBIM360ID).FirstOrDefault() == null)
                        {
                            db.Projects.Add(pr);
                        }
                    }

                    db.SaveChanges();
                }

                using (SoccerContext db = new SoccerContext())
                {
                    Project projectInDb = db.Projects.Where(p => p.ProjectBIM360ID == project.ProjectBIM360ID).FirstOrDefault();
                    db.Locations.Add(new Location()
                    {
                        ProjectID = projectInDb.ProjectID, LocationDetails = "test"
                    });
                    db.IssuesTemplate.Add(new IssueTemplate()
                    {
                        ProjectID = projectInDb.ProjectID, Description = "test"
                    });
                    db.RootCauses.Load();
                    foreach (var rootcauses in rootCauses)
                    {
                        if (db.RootCauses.Where(p => p.RootCausesBIM360ID == rootcauses.RootCausesBIM360ID).FirstOrDefault() == null)
                        {
                            db.RootCauses.Add(new RootCauses()
                            {
                                ProjectID = projectInDb.ProjectID, Title = rootcauses.Title, RootCausesBIM360ID = rootcauses.RootCausesBIM360ID
                            });
                        }
                    }

                    foreach (var issuesType in issueTypes)
                    {
                        db.IssueTypes.Load();
                        if (db.IssueTypes.Where(p => p.IssueTypeBIM360ID == issuesType.Id).FirstOrDefault() == null)
                        {
                            db.IssueTypes.Add(new IssueType()
                            {
                                Title = issuesType.IssueName, IssueTemplateID = 1, IssueTypeBIM360ID = issuesType.Id
                            });
                        }
                        else
                        {
                            IssueType type = db.IssueTypes.Where(p => p.IssueTypeBIM360ID == issuesType.Id).FirstOrDefault();
                            type.Title             = issuesType.IssueName;
                            type.IssueTypeBIM360ID = issuesType.Id;
                        }
                    }
                    db.SaveChanges();
                }

                using (SoccerContext db = new SoccerContext())
                {
                    foreach (var issuesType in issueTypes)
                    {
                        foreach (var issuesSubType in issuesType.IssueSubtypes)
                        {
                            db.IssueSubTypes.Load();
                            if (db.IssueSubTypes.Where(p => p.IssueSubTypeBIM360ID == issuesSubType.IssueSubTypeBIM360ID).FirstOrDefault() == null)
                            {
                                IssueType itype = db.IssueTypes.Where(p => p.IssueTypeBIM360ID == issuesType.Id).FirstOrDefault();
                                db.IssueSubTypes.Add(new IssueSubType()
                                {
                                    IssueTypeID = itype.IssueTypeID, Title = issuesSubType.Title, IssueSubTypeBIM360ID = issuesSubType.IssueSubTypeBIM360ID, IssueTemplateID = 1
                                });
                            }
                            else
                            {
                                IssueType    itype    = db.IssueTypes.Where(p => p.IssueTypeBIM360ID == issuesType.Id).FirstOrDefault();
                                IssueSubType subtypes = db.IssueSubTypes.Where(p => p.IssueSubTypeBIM360ID == issuesSubType.IssueSubTypeBIM360ID).FirstOrDefault();
                                subtypes.IssueTypeID          = itype.IssueTypeID;
                                subtypes.Title                = issuesSubType.Title;
                                subtypes.IssueSubTypeBIM360ID = issuesSubType.IssueSubTypeBIM360ID;
                            }
                        }
                    }
                    db.SaveChanges();
                }
                using (SoccerContext db = new SoccerContext())
                {
                    db.Projects.Load();
                    db.RootCauses.Load();
                    db.IssueTypes.Load();
                    db.IssueSubTypes.Load();
                    db.Issues.Load();
                    foreach (var issue in issues)
                    {
                        if (db.Issues.Where(p => p.IssueBIM360ID == issue.IssueBIM360ID).FirstOrDefault() == null)
                        {
                            IssueSubType subtype = db.IssueSubTypes.Where(p => p.IssueSubTypeBIM360ID == issue.IssueSubTypesBIM360ID).FirstOrDefault();
                            RootCauses   causes  = db.RootCauses.Where(p => p.RootCausesBIM360ID == issue.RootCausesBIM360ID).FirstOrDefault();

                            db.Issues.Add(new Issues()
                            {
                                IssueTemplateID       = 1,
                                LocationID            = 1,
                                CreatedBy             = issue.CreatedBy,
                                IssueSubTypeID        = subtype.IssueSubTypeID,
                                CreatedOn             = issue.CreatedOn,
                                Status                = issue.Status,
                                IssueNumber           = issue.IssueNumber,
                                Description           = issue.Description,
                                AnsweredOn            = issue.AnsweredOn,
                                CloasedOn             = issue.CloasedOn,
                                UpdatedOn             = issue.UpdatedOn,
                                AssignedTo            = issue.AssignedTo,
                                OwnedBy               = issue.OwnedBy,
                                CloasedBy             = issue.CloasedBy,
                                AnsweredBy            = issue.AnsweredBy,
                                IssueBIM360ID         = issue.IssueBIM360ID,
                                IssueSubTypesBIM360ID = issue.IssueSubTypesBIM360ID,
                                RootCausesBIM360ID    = issue.RootCausesBIM360ID,
                                Title           = issue.Title,
                                DueDate         = issue.DueDate,
                                LocationDetails = issue.LocationDetails,
                            });
                        }
                        else
                        {
                            IssueSubType subtype       = db.IssueSubTypes.Where(p => p.IssueSubTypeBIM360ID == issue.IssueSubTypesBIM360ID).FirstOrDefault();
                            Issues       existingIssue = db.Issues.Where(p => p.IssueBIM360ID == issue.IssueBIM360ID).FirstOrDefault();
                            existingIssue.CreatedBy             = issue.CreatedBy;
                            existingIssue.IssueSubTypeID        = subtype.IssueSubTypeID;
                            existingIssue.CreatedOn             = issue.CreatedOn;
                            existingIssue.Status                = issue.Status;
                            existingIssue.Description           = issue.Description;
                            existingIssue.AnsweredOn            = issue.AnsweredOn;
                            existingIssue.CloasedOn             = issue.CloasedOn;
                            existingIssue.UpdatedOn             = issue.UpdatedOn;
                            existingIssue.AssignedTo            = issue.AssignedTo;
                            existingIssue.OwnedBy               = issue.OwnedBy;
                            existingIssue.CloasedBy             = issue.CloasedBy;
                            existingIssue.AnsweredBy            = issue.AnsweredBy;
                            existingIssue.IssueBIM360ID         = issue.IssueBIM360ID;
                            existingIssue.IssueSubTypesBIM360ID = issue.IssueSubTypesBIM360ID;
                            existingIssue.RootCausesBIM360ID    = issue.RootCausesBIM360ID;
                            existingIssue.Title           = issue.Title;
                            existingIssue.DueDate         = issue.DueDate;
                            existingIssue.IssueNumber     = issue.IssueNumber;
                            existingIssue.LocationDetails = issue.LocationDetails;
                        }
                    }
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        public static List <Issues> GetIssues(string container_id, string account_id, string project_id)
        {
            var           page              = 0;
            int           pageFromRequest   = 0;
            bool          IsLast            = false;
            List <Issues> isssuesCollection = new List <Issues>();
            var           users             = GetUsers(project_id);
            var           roles             = GetRoles(account_id, project_id);
            IRestResponse issuesResponse    = GetIssueResponse(container_id, page);
            dynamic       issuesJson        = JObject.Parse(issuesResponse.Content);

            Int32.TryParse(issuesJson.meta.page.offset.ToString(), out pageFromRequest);
            if (pageFromRequest == page)
            {
                IsLast = true;
            }
            else
            {
                page = pageFromRequest;
            }
            foreach (dynamic issue in issuesJson.data)
            {
                string assignedTo = String.Empty;
                string createdBy  = String.Empty;
                string closedBy   = String.Empty;
                string answeredBy = String.Empty;
                string ownedBy    = String.Empty;
                if (issue.attributes.assigned_to_type.ToString() == "user")
                {
                    if (users != null)
                    {
                        assignedTo = users.Where(v => v.Id == issue.id.ToString()).Select(x => x.Name).FirstOrDefault();
                    }
                }
                else if (issue.attributes.assigned_to_type.ToString() == "role")
                {
                    if (roles != null)
                    {
                        assignedTo = roles.Where(v => v.Id == issue.id.ToString()).Select(x => x.Name).FirstOrDefault();
                    }
                }

                if (users != null)
                {
                    createdBy = users.Where(v => v.Id == issue.attributes.created_by.ToString()).Select(x => x.Name).FirstOrDefault();

                    closedBy   = users.Where(v => v.Id == issue.attributes.closed_by.ToString()).Select(x => x.Name).FirstOrDefault();
                    answeredBy = users.Where(v => v.Id == issue.attributes.closed_by.ToString()).Select(x => x.Name).FirstOrDefault();
                    ownedBy    = users.Where(v => v.Id == issue.attributes.closed_by.ToString()).Select(x => x.Name).FirstOrDefault();
                }

                Issues element = new Issues()
                {
                    IssueBIM360ID         = issue.id.ToString(),
                    Title                 = issue.attributes.title.ToString(),
                    AssignedTo            = assignedTo,
                    CloasedBy             = closedBy,
                    CloasedOn             = issue.attributes.closed_at,
                    Description           = issue.attributes.description.ToString(),
                    CreatedBy             = createdBy,
                    CreatedOn             = issue.attributes.created_at,
                    DueDate               = issue.attributes.due_date,
                    Status                = issue.attributes.status.ToString(),
                    IssueSubTypesBIM360ID = issue.attributes.ng_issue_subtype_id.ToString(),
                    RootCausesBIM360ID    = issue.attributes.root_cause_id.ToString(),
                    OwnedBy               = ownedBy,
                    IssueNumber           = issue.attributes.identifier,
                    AnsweredBy            = answeredBy,
                    LocationDetails       = issue.attributes.location_description.ToString(),
                };
                isssuesCollection.Add(element);
            }

            while (!IsLast)
            {
                dynamic issuesJson1 = JObject.Parse(GetIssueResponse(container_id, page).Content);

                Int32.TryParse(issuesJson1.meta.page.offset.ToString(), out pageFromRequest);
                if (pageFromRequest == page)
                {
                    IsLast = true;
                }
                else
                {
                    page = pageFromRequest;
                }
                foreach (dynamic issue in issuesJson.data)
                {
                    string assignedTo = String.Empty;
                    string createdBy  = String.Empty;
                    string closedBy   = String.Empty;
                    string answeredBy = String.Empty;
                    string ownedBy    = String.Empty;
                    if (issue.attributes.assigned_to_type.ToString() == "user")
                    {
                        if (users != null)
                        {
                            assignedTo = users.Where(v => v.Id == issue.id.ToString()).Select(x => x.Name).FirstOrDefault();
                        }
                    }
                    else if (issue.attributes.assigned_to_type.ToString() == "role")
                    {
                        if (roles != null)
                        {
                            assignedTo = roles.Where(v => v.Id == issue.id.ToString()).Select(x => x.Name).FirstOrDefault();
                        }
                    }

                    if (users != null)
                    {
                        createdBy = users.Where(v => v.Id == issue.attributes.created_by.ToString()).Select(x => x.Name).FirstOrDefault();

                        closedBy   = users.Where(v => v.Id == issue.attributes.closed_by.ToString()).Select(x => x.Name).FirstOrDefault();
                        answeredBy = users.Where(v => v.Id == issue.attributes.closed_by.ToString()).Select(x => x.Name).FirstOrDefault();
                        ownedBy    = users.Where(v => v.Id == issue.attributes.closed_by.ToString()).Select(x => x.Name).FirstOrDefault();
                    }

                    Issues element = new Issues()
                    {
                        IssueBIM360ID         = issue.id.ToString(),
                        Title                 = issue.attributes.title.ToString(),
                        AssignedTo            = assignedTo,
                        CloasedBy             = closedBy,
                        CloasedOn             = issue.attributes.closed_at,
                        Description           = issue.attributes.description.ToString(),
                        CreatedBy             = createdBy,
                        CreatedOn             = issue.attributes.created_at,
                        DueDate               = issue.attributes.due_date,
                        Status                = issue.attributes.status.ToString(),
                        IssueSubTypesBIM360ID = issue.attributes.ng_issue_subtype_id.ToString(),
                        RootCausesBIM360ID    = issue.attributes.root_cause_id.ToString(),
                        OwnedBy               = ownedBy,
                        IssueNumber           = issue.attributes.identifier,
                        AnsweredBy            = answeredBy,
                        LocationDetails       = issue.attributes.location_description.ToString(),
                    };
                    isssuesCollection.Add(element);
                }
            }



            return(isssuesCollection);
        }