Exemplo n.º 1
0
        public static BH.oM.Adapters.TDRepo.Issue ToTDRepo(this Issue bhomIssue, string resourcesFolder = "")
        {
            BH.oM.Adapters.TDRepo.Issue tdrIssue = new BH.oM.Adapters.TDRepo.Issue();

            // Checks
            if (string.IsNullOrWhiteSpace(bhomIssue.Name))
            {
                BH.Engine.Reflection.Compute.RecordError($"The {nameof(BH.oM.Inspection.Issue)} must be assigned a Name in order for the conversion to be possible.");
                return(null);
            }

            if (bhomIssue.Position == null)
            {
                BH.Engine.Reflection.Compute.RecordError($"The {nameof(BH.oM.Inspection.Issue)} must be assigned a position in order for the conversion to be possible.");
                return(null);
            }

            //TDRepo uses UNIX time, needs converted value from UTC
            DateTimeOffset UTCdt           = bhomIssue.DateCreated;
            long           dateCreatedUNIX = UTCdt.ToUnixTimeMilliseconds();

            // Pick and choose data from the BH.oM.Inspection.Issue
            // to build the BH.oM.Adapters.TDRepo.Issue, which can be then uploaded to 3DRepo.

            tdrIssue.Name    = bhomIssue.Name;
            tdrIssue.Created = dateCreatedUNIX;
            tdrIssue.AssignedRoles.AddRange(bhomIssue.Assign);
            tdrIssue.Status    = bhomIssue.Status;
            tdrIssue.Priority  = bhomIssue.Priority;
            tdrIssue.TopicType = bhomIssue.Type;

            // The first media item is picked as the screenshot.
            string screenshotFilePath = !string.IsNullOrWhiteSpace(bhomIssue?.Media?.FirstOrDefault()) ? System.IO.Path.Combine(resourcesFolder ?? "C:\\temp\\", bhomIssue.Media.FirstOrDefault()) : null;

            tdrIssue.Viewpoint = new oM.Adapters.TDRepo.Viewpoint()
            {
                Position   = new double[] { bhomIssue.Position.X, bhomIssue.Position.Y, bhomIssue.Position.Z }, // TODO: now this is taking the same Position of the issue. Ideally to take the position of the media's viewpoint.
                Screenshot = Compute.ReadToBase64(screenshotFilePath)
                                                                                                                // Note: all other properties of the 3DRepo's Viewpoint object are not currently supported by BHoM, and therefore are not populated.
            };

            tdrIssue.Position = new double[] {
                bhomIssue.Position.X,
                bhomIssue.Position.Y,
                bhomIssue.Position.Z
            };

            tdrIssue.Desc = bhomIssue.Description;

            tdrIssue.Desc += $"\nParentAuditId: {bhomIssue.AuditID}";

            return(tdrIssue);
        }
Exemplo n.º 2
0
        public static BH.oM.Inspection.Issue FromTDRepo(this BH.oM.Adapters.TDRepo.Issue issue, List <string> mediaFileNames = null)
        {
            BH.oM.Inspection.Issue bhomIssue = new BH.oM.Inspection.Issue();

            // Checks
            if (string.IsNullOrWhiteSpace(issue.Name))
            {
                BH.Engine.Reflection.Compute.RecordError($"The {nameof(BH.oM.Inspection.Issue)} must be assigned a Name in order for the conversion to be possible.");
                return(null);
            }

            if (issue.Position == null)
            {
                BH.Engine.Reflection.Compute.RecordError($"The {nameof(BH.oM.Inspection.Issue)} must be assigned a position in order for the conversion to be possible.");
                return(null);
            }

            //TDRepo uses UNIX time, need to convert to UTC
            DateTime issueDtCreated = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            issueDtCreated = issueDtCreated.AddMilliseconds(System.Convert.ToDouble(issue.Created)).ToLocalTime();

            // Pick and choose data from the BH.oM.Adapters.TDRepo.Issue
            // to build the BH.oM.Inspection.Issue.
            bhomIssue.DateCreated = issueDtCreated;
            bhomIssue.Name        = issue.Name;
            bhomIssue.IssueNumber = issue.Name;
            bhomIssue.Assign      = issue.AssignedRoles;
            bhomIssue.Status      = issue.Status;
            bhomIssue.Priority    = issue.Priority;
            bhomIssue.Type        = issue.TopicType;
            bhomIssue.Comments    = issue.Comments?.Select(c =>
                                                           new Comment()
            {
                Message     = string.IsNullOrWhiteSpace(c.comment) ? $"{c.action.property} changed from `{(string.IsNullOrWhiteSpace(c.action.from) ? "<empty>" : c.action.from)}` to `{c.action.to}`." : c.comment,
                Owner       = c.owner,
                CommentDate = new DateTime(long.Parse(c.created.ToString()))
            })
                                    .ToList();

            if (mediaFileNames != null)
            {
                bhomIssue.Media = mediaFileNames;
            }

            if (issue.Position.Length > 0)
            {
                bhomIssue.Position = new oM.Geometry.Point()
                {
                    X = issue.Position[0],
                    Y = issue.Position[1],
                    Z = issue.Position[2]
                };
            }

            string toFind   = "\nParentAuditId: ";
            int    startPos = issue.Desc.Length;
            int    endPos   = issue.Desc.Length;

            if (issue.Desc.IndexOf(toFind) != -1)
            {
                startPos = issue.Desc.IndexOf(toFind);
                endPos   = startPos + toFind.Length;
            }
            bhomIssue.Description = issue.Desc.Substring(0, startPos);
            bhomIssue.AuditID     = issue.Desc.Substring(endPos);

            return(bhomIssue);
        }