예제 #1
0
        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair <string, string> entry in expected)
            {
                Assert.IsTrue(actual.Contains(entry));
            }
        }
예제 #2
0
 public void Interpret(PropertySet properties)
 {
     if (properties.Contains("throw"))
     {
         throw new Exception();
     }
     else
     {
         DidInterpret = true;
     }
 }
예제 #3
0
        public void ModifyDeleteAddPropertyTest()
        {
            using (PropertySets propertySets = new PropertySets(s_testFile, false))
            {
                Console.WriteLine("Before:");
                DumpPropertySets(propertySets);

                PropertySet projectInfo = null;
                if (propertySets.Contains(PropertySetIds.ProjectInformation))
                {
                    projectInfo = propertySets[PropertySetIds.ProjectInformation];
                }
                else
                {
                    projectInfo = propertySets.Add(PropertySetIds.ProjectInformation, false);
                }

                Property docNumber = null;
                if (projectInfo.Contains(ProjectInfoIds.DocumentNumber))
                {
                    docNumber = projectInfo[ProjectInfoIds.DocumentNumber];
                }
                else
                {
                    docNumber = projectInfo.Add(ProjectInfoIds.DocumentNumber, string.Empty);
                }
                docNumber.Value = "Testing";
                Console.WriteLine();
                Console.WriteLine("After modification:");
                DumpPropertySets(propertySets);

                docNumber.Delete();
                Console.WriteLine();
                Console.WriteLine("After deletion:");
                DumpPropertySets(propertySets);

                docNumber = projectInfo.Add(ProjectInfoIds.DocumentNumber, "New property");
                Console.WriteLine();
                Console.WriteLine("After adding:");
                DumpPropertySets(propertySets);
            }
        }
        private void LinkControlToProperty()
        {
            string pn = "DEPARTMENT";

            if (!Properties.Settings.Default.Testing)
            {
                pn = "DEPTID";
            }

            string dept;

            if (PropertySet.Contains(pn))
            {
                PropertySet.GetProperty(pn).Ctl = cbDepartment;
                dept = PropertySet.GetProperty(pn).Value;
                int tp = 1;

                if (int.TryParse(dept, out tp))
                {
                    OpType = tp;
                }
                else
                {
                    OpType = PropertySet.cutlistData.GetOpTypeIDByName(dept);
                }
                dept = tp.ToString();
            }
            else
            {
                SolidWorks.Interop.swconst.swCustomInfoType_e t = SolidWorks.Interop.swconst.swCustomInfoType_e.swCustomInfoNumber;
                SwProperty p = new SwProperty(pn, t, "1", true);
                p.SwApp = SwApp;
                p.Ctl   = cbDepartment;
                PropertySet.Add(p);
                OpType = 1;
            }
        }
예제 #5
0
        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair<string, string> entry in expected)
                Assert.IsTrue(actual.Contains(entry));
        }
예제 #6
0
        private async Task <MailInfo> ConvertToMailInfo(EmailMessage message, PropertySet sets)
        {
            if (message == null || sets == null)
            {
                return(null);
            }
            var mail = new MailInfo();

            mail.Attachments = new List <AttachmentInfo>();
            if (sets.Contains(ItemSchema.Id))
            {
                mail.Id = message.Id.UniqueId;
            }
            if (sets.Contains(ItemSchema.Subject))
            {
                mail.Subject = message.Subject;
            }
            if (sets.Contains(ItemSchema.Body))
            {
                mail.Content = message.Body.ToString();
            }
            if (sets.Contains(ItemSchema.TextBody))
            {
                mail.Description = message.TextBody.ToString();
            }
            if (sets.Contains(ItemSchema.DateTimeReceived))
            {
                mail.RecivedTime = message.DateTimeReceived;
            }
            if (sets.Contains(ItemSchema.DateTimeCreated))
            {
                mail.CreateTime = message.DateTimeCreated;
            }
            if (sets.Contains(ItemSchema.DateTimeSent))
            {
                mail.SentTime = message.DateTimeSent;
            }
            if (sets.Contains(EmailMessageSchema.Sender))
            {
                if (message.Sender != null)
                {
                    mail.Sender     = message.Sender.Address;
                    mail.SenderName = message.Sender.Name;
                }
            }
            //AppointmentSchema.IsMeeting,
            //AppointmentSchema.IsOnlineMeeting,
            //MeetingMessageSchema.AssociatedAppointmentId,
            if (sets.Contains(AppointmentSchema.IsMeeting))
            {
                var request = message as MeetingRequest;
                if (request != null)
                {
                    mail.IsMeeting = request.IsMeeting;
                }
            }

            if (sets.Contains(AppointmentSchema.IsOnlineMeeting))
            {
                var request = message as MeetingRequest;
                if (request != null)
                {
                    mail.IsOnlineMeeting = request.IsOnlineMeeting;
                }
            }

            if (sets.Contains(MeetingMessageSchema.AssociatedAppointmentId))
            {
                var request = message as MeetingRequest;
                if (request != null && mail.IsOnlineMeeting && request.AssociatedAppointmentId != null)
                {
                    mail.AppointMeetingId = request.AssociatedAppointmentId.UniqueId;
                }
            }

            if (sets.Contains(ItemSchema.HasAttachments))
            {
                mail.HasAttachments = message.HasAttachments;
            }
            if (sets.Contains(ItemSchema.Attachments))
            {
                var list            = new List <AttachmentInfo>();
                var fileAttachments = message.Attachments.Where(u => u is FileAttachment);
                foreach (var file in fileAttachments)
                {
                    var item = new AttachmentInfo();
                    if (file.IsInline)
                    {
                        await file.Load();

                        item.Bytes = (file as FileAttachment).Content;
                    }
                    item.ContentId = file.ContentId;
                    item.Name      = file.Name;
                    item.Id        = file.Id;
                    item.MailId    = message.Id.ToString();
                    item.Size      = file.Size;
                    item.IsInline  = file.IsInline;
                    list.Add(item);
                }
                mail.Attachments    = list;
                mail.HasAttachments = mail.Attachments.Count != 0;
            }

            if (sets.Contains(EmailMessageSchema.IsRead))
            {
                mail.Readed = message.IsRead;
            }
            if (sets.Contains(ItemSchema.DisplayTo))
            {
                if (message.DisplayTo == null)
                {
                    mail.Recivers = new List <EmailContact>();
                }
                else
                {
                    var to = message.DisplayTo.Split(";", StringSplitOptions.RemoveEmptyEntries);
                    mail.Recivers = to.Select(u =>
                    {
                        if (true) //是一个人的名字
                        {
                            return new EmailContact()
                            {
                                Name = u, Address = ""
                            }
                        }
                        ;
                        return(new EmailContact()
                        {
                            Name = "", Address = u
                        });
                    }).ToList();
                }
            }

            if (sets.Contains(ItemSchema.DisplayCc))
            {
                if (message.DisplayTo == null)
                {
                    mail.Cc = new List <EmailContact>();
                }
                else
                {
                    var cc = message.DisplayTo.Split(";", StringSplitOptions.RemoveEmptyEntries);
                    mail.Cc = cc.Select(u =>
                    {
                        if (true) //是一个人的名字
                        {
                            return new EmailContact()
                            {
                                Name = u, Address = ""
                            }
                        }
                        ;
                        return(new EmailContact()
                        {
                            Name = "", Address = u
                        });
                    }).ToList();
                }
            }

            //开始设置内敛属性
            var inlineAttachments = mail.Attachments.Where(u => u.IsInline).ToList();

            if (inlineAttachments.Count != 0)
            {
                //开始处理
                foreach (var attachment in inlineAttachments)
                {
                    var cid       = "cid:" + attachment.ContentId;
                    var base64str = Convert.ToBase64String(attachment.Bytes);
                    var imgSrc    = "data:image/jpeg;base64," + base64str;
                    mail.Content = mail.Content.Replace(cid, imgSrc);
                }
            }

            return(mail);
        }
예제 #7
0
        /// <summary>
        /// Select known data in fields, and link controls to properties. I think this should be refactored.
        /// </summary>
        private void FillBoxes()
        {
            SwProperty partNo = this.PropertySet.GetProperty("PartNo");
            SwProperty custo  = this.PropertySet.GetProperty("CUSTOMER");
            SwProperty by     = this.PropertySet.GetProperty("DrawnBy");
            SwProperty d      = this.PropertySet.GetProperty("DATE");
            SwProperty rl     = PropertySet.GetProperty("REVISION LEVEL");

            fileTitle = (PropertySet.SwApp.ActiveDoc as ModelDoc2).GetTitle().Replace(@".SLDDRW", string.Empty);
            fileName  = fileTitle.Split(' ')[0].Trim();
            if (fileTitle.ToUpper().Contains(@" REV"))
            {
                fileRev = fileTitle.Split(new string[] { @" REV", @" " }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
            }
            else
            {
                if (rl != null)
                {
                    fileRev = rl.ResValue;
                }
                else
                {
                    fileRev = "100";
                }
            }

            if (partNo != null)
            {
                label4.Text = fileName;
                partNo.Ctl  = tbItemNo;
            }
            else
            {
                partNo       = new SwProperty("PartNo", swCustomInfoType_e.swCustomInfoText, "$PRP:\"SW-File Name\"", true);
                partNo.SwApp = SwApp;
                partNo.Ctl   = tbItemNo;
                this.PropertySet.Add(partNo);
            }

            if (custo != null)
            {
                custo.Ctl = cbCustomer;
            }
            else
            {
                custo       = new SwProperty("CUSTOMER", swCustomInfoType_e.swCustomInfoText, string.Empty, true);
                custo.SwApp = SwApp;
                custo.Ctl   = cbCustomer;
                this.PropertySet.Add(custo);
            }

            if (by != null)
            {
                if (by.Value == string.Empty)
                {
                    by.ID       = PropertySet.CutlistData.GetCurrentAuthor().ToString();
                    by.Value    = PropertySet.CutlistData.GetCurrentAuthorInitial();
                    by.ResValue = by.Value;
                }
                by.Ctl = this.cbAuthor;
            }
            else
            {
                by       = new SwProperty("DrawnBy", swCustomInfoType_e.swCustomInfoText, string.Empty, true);
                by.SwApp = SwApp;
                by.Ctl   = cbAuthor;
                this.PropertySet.Add(by);
            }

            if (d != null)
            {
                d.Ctl = this.dpDate;
            }
            else
            {
                d       = new SwProperty("DATE", swCustomInfoType_e.swCustomInfoDate, string.Empty, true);
                d.SwApp = SwApp;
                d.Ctl   = dpDate;
                this.PropertySet.Add(d);
            }

            if (rl != null)
            {
                rl.Ctl = cbRevision;
            }
            else
            {
                rl       = new SwProperty("REVISION LEVEL", swCustomInfoType_e.swCustomInfoText, "100", true);
                rl.SwApp = SwApp;
                rl.Ctl   = cbRevision;
                PropertySet.Add(rl);
            }

            for (int i = 1; i < 6; i++)
            {
                if (PropertySet.Contains("M" + i.ToString()))
                {
                    foreach (Control c in tableLayoutPanel3.Controls)
                    {
                        if (c.Name.ToUpper().Contains("M" + i.ToString()))
                        {
                            PropertySet.GetProperty("M" + i.ToString()).Ctl = c;
                        }


                        if (c.Name.ToUpper().Contains("FINISH" + i.ToString()))
                        {
                            this.PropertySet.GetProperty("FINISH " + i.ToString()).Ctl = c;
                        }
                    }
                }
                else
                {
                    foreach (Control c in tableLayoutPanel3.Controls)
                    {
                        if (c.Name.ToUpper().Contains("M" + i.ToString()))
                        {
                            SwProperty mx = new SwProperty("M" + i.ToString(), swCustomInfoType_e.swCustomInfoText, string.Empty, true);
                            mx.SwApp = SwApp;
                            mx.Ctl   = c;
                            PropertySet.Add(mx);
                        }

                        if (c.Name.ToUpper().Contains("FINISH" + i.ToString()))
                        {
                            SwProperty fx = new SwProperty("FINISH " + i.ToString(), swCustomInfoType_e.swCustomInfoText, string.Empty, true);
                            fx.SwApp = SwApp;
                            fx.Ctl   = c;
                            PropertySet.Add(fx);
                        }
                    }
                }
            }

            DataSet ds = PropertySet.CutlistData.GetCutlistData(fileName.Trim(),
                                                                PropertySet.GetProperty("REVISION LEVEL").Value.Trim());
            int stat = 0;

            if (ds.Tables[0].Rows.Count > 0 && int.TryParse(ds.Tables[0].Rows[0][(int)CutlistData.CutlistDataFields.STATEID].ToString(), out stat))
            {
                cbStatus.Enabled       = true;
                cbStatus.SelectedValue = stat;
            }
            else
            {
                cbStatus.Enabled = false;
            }

            PropertySet.UpdateFields();
            tbItemNoRes.Text = PropertySet.GetProperty("PartNo").ResValue;
        }