示例#1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var str = value as string;
            if (str != null)
            {
                var note = new PNote();
                var values = str.Split(DEL_NOTE);
                if (values.Length == Enum.GetValues(typeof(Fields)).Length)
                {
                    string[] arr;
                    var dtc = new DateTimeConverter();
                    var szc = new SizeConverter();
                    var scd = new System.Drawing.SizeConverter();
                    var ptc = new PointConverter();
                    var scv = new ScheduleConverter();
                    var skc = new SkinlessConverter();

                    note.Changed = Convert.ToBoolean(values[(int)Fields.Changed]);
                    note.Completed = Convert.ToBoolean(values[(int)Fields.Completed]);
                    note.CustomOpacity = Convert.ToBoolean(values[(int)Fields.CustomOpacity]);
                    var dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateCreated]);
                    if (dateFromString != null)
                        note.DateCreated = (DateTime)dateFromString;
                    dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateDeleted]);
                    if (dateFromString != null)
                        note.DateDeleted = (DateTime)dateFromString;
                    dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateReceived]);
                    if (dateFromString != null)
                        note.DateReceived = (DateTime)dateFromString;
                    dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateSaved]);
                    if (dateFromString != null)
                        note.DateSaved = (DateTime)dateFromString;
                    dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.DateSent]);
                    if (dateFromString != null)
                        note.DateSent = (DateTime)dateFromString;
                    note.DockStatus = (DockStatus)Convert.ToInt32(values[(int)Fields.DockStatus]);
                    var sizeFromString = scd.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.EditSize]);
                    if (sizeFromString != null)
                        note.EditSize = (Size)sizeFromString;
                    note.Favorite = Convert.ToBoolean(values[(int)Fields.Favorite]);
                    note.FromDB = Convert.ToBoolean(values[(int)Fields.FromDB]);
                    note.GroupID = Convert.ToInt32(values[(int)Fields.GroupID]);
                    note.ID = values[(int)Fields.ID];
                    var temp = values[(int)Fields.LinkedNotes];
                    if (temp != "")
                    {
                        arr = temp.Split(DEL_INNER);
                        foreach (var s in arr)
                        {
                            note.LinkedNotes.Add(s);
                        }
                    }
                    note.Name = values[(int)Fields.Name];
                    var convertFromString = ptc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.NoteLocation]);
                    if (convertFromString != null)
                        note.NoteLocation = (Point)convertFromString;
                    var fromString = szc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.NoteSize]);
                    if (fromString != null)
                        note.NoteSize = (System.Windows.Size)fromString;
                    note.Opacity = Convert.ToDouble(values[(int)Fields.Opacity], PNStatic.CultureInvariant);
                    note.PasswordString = values[(int)Fields.PasswordString];
                    note.Pinned = Convert.ToBoolean(values[(int)Fields.Pinned]);
                    note.PrevGroupID = Convert.ToInt32(values[(int)Fields.PrevGroupID]);
                    note.Priority = Convert.ToBoolean(values[(int)Fields.Priority]);
                    note.Protected = Convert.ToBoolean(values[(int)Fields.Protected]);
                    note.ReceivedFrom = values[(int)Fields.ReceivedFrom];
                    note.Rolled = Convert.ToBoolean(values[(int)Fields.Rolled]);
                    note.Schedule = (PNNoteSchedule)scv.ConvertFromString(values[(int)Fields.Schedule]);
                    note.SentReceived = (SendReceiveStatus)Convert.ToInt32(values[(int)Fields.SentReceived]);
                    note.SentTo = values[(int)Fields.SentTo];
                    temp = values[(int)Fields.SkinName];
                    if (temp != PNSkinDetails.NO_SKIN && temp != "")
                    {
                        // TODO - get skin properties
                    }
                    note.Skinless = (PNSkinlessDetails)skc.ConvertFromString(values[(int)Fields.Skinless]);
                    temp = values[(int)Fields.Tags];
                    if (temp != "")
                    {
                        arr = temp.Split(DEL_INNER);
                        foreach (var s in arr)
                        {
                            note.Tags.Add(s);
                        }
                    }
                    note.Topmost = Convert.ToBoolean(values[(int)Fields.Topmost]);
                    note.Visible = Convert.ToBoolean(values[(int)Fields.Visible]);
                    note.XFactor = Convert.ToDouble(values[(int)Fields.XFactor], PNStatic.CultureInvariant);
                    note.YFactor = Convert.ToDouble(values[(int)Fields.YFactor], PNStatic.CultureInvariant);
                    note.PinClass = values[(int)Fields.PinClass];
                    note.PinText = values[(int)Fields.PinText];
                }
                return note;
            }
            return base.ConvertFrom(context, culture, value);
        }
示例#2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != typeof (string)) return base.ConvertTo(context, culture, value, destinationType);
            var note = value as PNote;
            if (note == null) return "";
            var bt = new StringBuilder();
            var dtc = new DateTimeConverter();
            var szc = new SizeConverter();
            var scd = new System.Drawing.SizeConverter();
            var ptc = new PointConverter();
            var scv = new ScheduleConverter();
            var skc = new SkinlessConverter();
            var sb = new StringBuilder();

            sb.Append(note.Changed);
            sb.Append(DEL_NOTE);
            sb.Append(note.Completed);
            sb.Append(DEL_NOTE);
            sb.Append(note.CustomOpacity);
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateCreated));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateDeleted));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateReceived));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateSaved));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateSent));
            sb.Append(DEL_NOTE);
            sb.Append((int)note.DockStatus);
            sb.Append(DEL_NOTE);
            sb.Append(scd.ConvertToString(null, PNStatic.CultureInvariant, note.EditSize));
            sb.Append(DEL_NOTE);
            sb.Append(note.Favorite);
            sb.Append(DEL_NOTE);
            sb.Append(note.FromDB);
            sb.Append(DEL_NOTE);
            sb.Append(note.GroupID);
            sb.Append(DEL_NOTE);
            sb.Append(note.ID);
            sb.Append(DEL_NOTE);
            foreach (var s in note.LinkedNotes)
            {
                bt.Append(s);
                bt.Append(DEL_INNER);
            }
            if (bt.Length > 0)
                bt.Length -= 1;
            sb.Append(bt);
            sb.Append(DEL_NOTE);
            sb.Append(note.Name);
            sb.Append(DEL_NOTE);
            sb.Append(ptc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteLocation));
            sb.Append(DEL_NOTE);
            sb.Append(szc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteSize));
            sb.Append(DEL_NOTE);
            sb.Append(note.Opacity.ToString(PNStatic.CultureInvariant));
            sb.Append(DEL_NOTE);
            sb.Append(note.PasswordString);
            sb.Append(DEL_NOTE);
            sb.Append(note.Pinned);
            sb.Append(DEL_NOTE);
            sb.Append(note.PrevGroupID);
            sb.Append(DEL_NOTE);
            sb.Append(note.Priority);
            sb.Append(DEL_NOTE);
            sb.Append(note.Protected);
            sb.Append(DEL_NOTE);
            sb.Append(note.ReceivedFrom);
            sb.Append(DEL_NOTE);
            sb.Append(note.Rolled);
            sb.Append(DEL_NOTE);
            sb.Append(scv.ConvertToString(note.Schedule));
            sb.Append(DEL_NOTE);
            sb.Append((int)note.SentReceived);
            sb.Append(DEL_NOTE);
            sb.Append(note.SentTo);
            sb.Append(DEL_NOTE);
            sb.Append(note.Skin != null ? note.Skin.SkinName : "");
            sb.Append(DEL_NOTE);
            sb.Append(note.Skinless != null ? skc.ConvertToString(note.Skinless) : "");
            sb.Append(DEL_NOTE);
            bt = new StringBuilder();
            foreach (var s in note.Tags)
            {
                bt.Append(s);
                bt.Append(DEL_INNER);
            }
            if (bt.Length > 0)
                bt.Length -= 1;
            sb.Append(bt);
            sb.Append(DEL_NOTE);
            sb.Append(note.Topmost);
            sb.Append(DEL_NOTE);
            sb.Append(note.Visible);
            sb.Append(DEL_NOTE);
            sb.Append(note.XFactor.ToString(PNStatic.CultureInvariant));
            sb.Append(DEL_NOTE);
            sb.Append(note.YFactor.ToString(PNStatic.CultureInvariant));
            sb.Append(DEL_NOTE);
            sb.Append(note.PinClass);
            sb.Append(DEL_NOTE);
            sb.Append(note.PinText);
            return sb.ToString();
        }