예제 #1
0
 public override void SerializeToXml(AuthRoot root, StringBuilder sb, Func <Guid, byte[]> files)
 {
     foreach (var item in Children)
     {
         item.SerializeToXml(root, sb, files);
     }
 }
예제 #2
0
        public override void SerializeToXml(AuthRoot root, StringBuilder sb, Func <Guid, byte[]> withoutFiles)
        {
            sb.Append("<pwentry>\n");
            var groupTreePath = BuildGroup();
            var group         = Parent.Title;

            if (!String.IsNullOrWhiteSpace(groupTreePath))
            {
                sb.AppendFormat("<group tree=\"{0}\">{1}</group>\n", groupTreePath, group);
            }
            else
            {
                sb.AppendFormat("<group>{0}</group>\n", group);
            }
            sb.AppendFormat("<title>{0}</title>\n", WebUtility.HtmlEncode(this.Title));
            sb.AppendFormat("<username>{0}</username>\n", WebUtility.HtmlEncode(this.UserName));
            sb.AppendFormat("<url>{0}</url>\n", WebUtility.HtmlEncode(this.Url));
            sb.AppendFormat("<password>{0}</password>\n", WebUtility.HtmlEncode(this.Password));
            sb.AppendFormat("<notes>{0}</notes>\n", WebUtility.HtmlEncode(this.Notes));
            sb.AppendFormat("<uuid>{0}</uuid>\n", WebUtility.HtmlEncode(this.Id.ToString()));
            sb.AppendFormat("<image>{0}</image>\n", WebUtility.HtmlEncode("0"));
            sb.AppendFormat("<creationtime>{0}</creationtime>\n", (this.CreationTime.ToString("yyyy-MM-ddTHH:mm:ss")));
            sb.AppendFormat("<lastmodtime>{0}</lastmodtime>\n", (this.LastModifiedTime.ToString("yyyy-MM-ddTHH:mm:ss")));
            sb.AppendFormat("<lastaccesstime>{0}</lastaccesstime>\n", (this.LastAccessTime.ToString("yyyy-MM-ddTHH:mm:ss")));
            sb.AppendFormat("<expiretime expires=\"true\">{0}</expiretime>\n", (this.ExpireTime.ToString("yyyy-MM-ddTHH:mm:ss")));
            if (withoutFiles == null && !string.IsNullOrWhiteSpace(this.HasAttachment))
            {
                sb.AppendFormat("<files>{0}</files>\n", WebUtility.HtmlEncode(this.HasAttachment));
            }
            else if (!string.IsNullOrWhiteSpace(this.HasAttachment))
            {
                var data = withoutFiles(Guid.Parse(this.Id));


                if (data != null)
                {
                    sb.AppendFormat("<attachdesc>{0}</attachdesc>\n", WebUtility.HtmlEncode(HasAttachment));
                    var encodedData = Convert.ToBase64String(data);
                    sb.AppendFormat("<attachment>{0}</attachment>\n", WebUtility.HtmlEncode(encodedData));
                }
            }
            sb.Append("</pwentry>\n");
        }
예제 #3
0
 public abstract void SerializeToXml(AuthRoot root, StringBuilder sb, Func <Guid, byte[]> withoutFiles);
예제 #4
0
        /*
         * <pwentry>
         * <group>WebSites</group>
         * <title>CeframeworkDrupal</title>
         * <username>edaros</username>
         * <url>http://www.ceframework.com/?q=admin</url>
         * <password>XXX</password>
         * <notes>4+4 :P</notes>
         * <uuid>f9717bd74c7c4fbc8de394bffe02b7ab</uuid>
         * <image>0</image>
         * <creationtime>2999-12-28T23:59:59</creationtime>
         * <lastmodtime>2999-12-28T23:59:59</lastmodtime>
         * <lastaccesstime>2999-12-28T23:59:59</lastaccesstime>
         * <expiretime expires="false">2999-12-28T23:59:59</expiretime>
         * </pwentry>*/

        public AuthRoot Initialize(String content)
        {
            var start = content.IndexOf("<");

            if (start > 0)
            {
                content = content.Substring(start);
            }
            items.Clear();
            root       = new AuthRoot();
            root.Id    = Guid.Empty.ToString();
            root.Title = "root";
            items.Add(root.Id, root);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(content);
            XmlNodeList nodes = doc.SelectNodes("//pwentry");

            foreach (XmlNode node in nodes)
            {
                String group      = LoadNode(node, "group");
                String groupTree  = LoadNodeAttr(node, "group", "tree");
                String title      = LoadNode(node, "title");
                String username   = LoadNode(node, "username");
                String url        = LoadNode(node, "url");
                String password   = LoadNode(node, "password");
                String uuid       = LoadNode(node, "uuid");
                String notes      = LoadNode(node, "notes");
                String expiretime = LoadNode(node, "expiretime");
                String expireStr  = LoadNodeAttr(node, "expiretime", "expire");
                if (String.IsNullOrWhiteSpace(expireStr))
                {
                    expireStr = "false";
                }

                String files = LoadNode(node, "files");


                bool     expire = bool.Parse(expireStr);
                AuthLeaf leaf   = new AuthLeaf();

                String attachdesc = LoadNode(node, "attachdesc");
                if (!String.IsNullOrWhiteSpace(attachdesc))
                {
                    leaf.HasAttachment = attachdesc;
                    String encodedString = LoadNode(node, "attachment");
                    var    attach        = new Attachment
                    {
                        Id   = uuid,
                        Data = Convert.FromBase64String(encodedString),
                        Name = attachdesc
                    };
                    root.Attachments.Add(attach);
                }
                else if (!String.IsNullOrWhiteSpace(files))
                {
                    leaf.HasAttachment = files;
                }

                leaf.Id       = uuid;
                leaf.Notes    = notes;
                leaf.Url      = url;
                leaf.UserName = username;
                leaf.Title    = title;
                leaf.Password = password;

                items.Add(leaf.Id, leaf);

                leaf.CreationTime     = DateTime.Parse(LoadNode(node, "creationtime"));
                leaf.LastAccessTime   = DateTime.Parse(LoadNode(node, "lastaccesstime"));
                leaf.LastModifiedTime = DateTime.Parse(LoadNode(node, "lastmodtime"));
                leaf.ExpireTime       = DateTime.MaxValue;
                if (!expire)
                {
                    leaf.ExpireTime = DateTime.Parse(expiretime);
                }
                var strs = new List <string>();
                if (groupTree != null && groupTree != String.Empty)
                {
                    var exp = groupTree.Split(new[] { '/', '\\' });
                    foreach (var exps in exp)
                    {
                        strs.Add(exps);
                    }
                }
                if (group != null && group != String.Empty)
                {
                    strs.Add(group);
                }

                AddToRoot(root, strs, leaf);
            }
            return(root);
        }