private static void ImportPriv(PwGroup pgStorage, Stream s, GxiProfile p,
                                       PwDatabase pdContext, IStatusLogger sl)
        {
            StrEncodingInfo sei = StrUtil.GetEncoding(p.Encoding);
            StreamReader    srRaw;

            if ((sei != null) && (sei.Encoding != null))
            {
                srRaw = new StreamReader(s, sei.Encoding, true);
            }
            else
            {
                srRaw = new StreamReader(s, true);
            }
            string strDoc = srRaw.ReadToEnd();

            srRaw.Close();

            strDoc = Preprocess(strDoc, p);

            StringReader  srDoc = new StringReader(strDoc);
            XPathDocument xd    = new XPathDocument(srDoc);

            GxiContext c = new GxiContext(p, pdContext, pgStorage, null);

            XPathNavigator xpDoc = xd.CreateNavigator();

            ImportObject(xpDoc, p, p.RootXPath, "/*", GxiImporter.ImportRoot, c);

            srDoc.Close();
        }
            public GxiContext ModifyWith(PwGroup pg)
            {
                GxiContext c = (GxiContext)MemberwiseClone();

                Debug.Assert(object.ReferenceEquals(c.m_dStringKeyRepl, m_dStringKeyRepl));

                c.m_pg = pg;
                return(c);
            }
        private static void ImportRoot(XPathNavigator xpBase, GxiProfile p,
                                       GxiContext c)
        {
            ImportObject(xpBase, p, p.GroupXPath, null, GxiImporter.ImportGroup, c);

            if (p.EntriesInRoot)
            {
                ImportObject(xpBase, p, p.EntryXPath, null, GxiImporter.ImportEntry, c);
            }
        }
        // private static string QueryValueSafe(XPathNavigator xpBase, string strXPath,
        //	bool bQueryName)
        // {
        //	return (QueryValue(xpBase, strXPath, bQueryName) ?? string.Empty);
        // }

        private static void ImportObject(XPathNavigator xpBase, GxiProfile p,
                                         string strXPath, string strAltXPath, ImportObjectDelegate f,
                                         GxiContext c)
        {
            if (f == null)
            {
                Debug.Assert(false); return;
            }

            XPathNodeIterator xi = QueryNodes(xpBase, strXPath, strAltXPath);

            if (xi == null)
            {
                return;                        // No assert
            }
            foreach (XPathNavigator xp in xi)
            {
                f(xp, p, c);
            }
        }
        private static void ImportBinaryKvp(XPathNavigator xpBase, GxiProfile p,
                                            GxiContext c)
        {
            string strKey = QueryValue(xpBase, p.BinaryKeyXPath, p.BinaryKeyUseName);

            if (string.IsNullOrEmpty(strKey))
            {
                return;
            }

            strKey = ApplyRepl(strKey, c.BinaryKeyRepl);
            if (strKey.Length == 0)
            {
                return;
            }

            string strValue = QueryValueSafe(xpBase, p.BinaryValueXPath);

            byte[] pbValue = null;
            if (p.BinaryValueEncoding == GxiBinaryEncoding.Base64)
            {
                pbValue = Convert.FromBase64String(strValue);
            }
            else if (p.BinaryValueEncoding == GxiBinaryEncoding.Hex)
            {
                pbValue = MemUtil.HexStringToByteArray(strValue);
            }
            else
            {
                Debug.Assert(false);
            }

            if (pbValue == null)
            {
                return;
            }

            c.Entry.Binaries.Set(strKey, new ProtectedBinary(false, pbValue));
        }
        private static void ImportEntry(XPathNavigator xpBase, GxiProfile p,
                                        GxiContext c)
        {
            PwEntry pe = new PwEntry(true, true);

            PwGroup pg            = c.Group;  // Not the database root group
            string  strGroupPath  = QueryValueSafe(xpBase, p.EntryGroupXPath);
            string  strGroupPath2 = QueryValueSafe(xpBase, p.EntryGroupXPath2);

            if ((strGroupPath.Length > 0) && (strGroupPath2.Length > 0))
            {
                Debug.Assert(p.EntryGroupSep.Length > 0);
                strGroupPath = strGroupPath + p.EntryGroupSep + strGroupPath2;
            }
            if (strGroupPath.Length > 0)
            {
                if (p.EntryGroupSep.Length == 0)
                {
                    pg = pg.FindCreateGroup(strGroupPath, true);
                }
                else
                {
                    pg = pg.FindCreateSubTree(strGroupPath, new string[1] {
                        p.EntryGroupSep
                    }, true);
                }
            }
            pg.AddEntry(pe, true);

            GxiContext cSub = c.ModifyWith(pe);

            ImportObject(xpBase, p, p.StringKvpXPath, null,
                         GxiImporter.ImportStringKvp, cSub);
            ImportObject(xpBase, p, p.StringKvpXPath2, null,
                         GxiImporter.ImportStringKvp2, cSub);
            ImportObject(xpBase, p, p.BinaryKvpXPath, null,
                         GxiImporter.ImportBinaryKvp, cSub);
        }
        private static void ImportStringKvpEx(XPathNavigator xpBase, GxiProfile p,
                                              GxiContext c, bool bFirst)
        {
            string strKey = QueryValue(xpBase, (bFirst ? p.StringKeyXPath :
                                                p.StringKeyXPath2), (bFirst ? p.StringKeyUseName :
                                                                     p.StringKeyUseName2));

            if (string.IsNullOrEmpty(strKey))
            {
                return;
            }

            strKey = ApplyRepl(strKey, (bFirst ? c.StringKeyRepl : c.StringKeyRepl2));
            if (strKey.Length == 0)
            {
                return;
            }

            if (p.StringKeyToStd)
            {
                string strMapped = ImportUtil.MapNameToStandardField(strKey,
                                                                     p.StringKeyToStdFuzzy);
                if (!string.IsNullOrEmpty(strMapped))
                {
                    strKey = strMapped;
                }
            }

            string strValue = QueryValueSafe(xpBase, (bFirst ? p.StringValueXPath :
                                                      p.StringValueXPath2));

            strValue = ApplyRepl(strValue, (bFirst ? c.StringValueRepl :
                                            c.StringValueRepl2));

            ImportUtil.AppendToField(c.Entry, strKey, strValue, c.Database);
        }
        private static void ImportGroup(XPathNavigator xpBase, GxiProfile p,
                                        GxiContext c)
        {
            PwGroup pg = new PwGroup(true, true);

            c.Group.AddGroup(pg, true);

            GxiContext cSub = c.ModifyWith(pg);

            pg.Name = QueryValueSafe(xpBase, p.GroupNameXPath);
            if (pg.Name.Length == 0)
            {
                pg.Name = KPRes.Group;
            }

            if (p.GroupsInGroup)
            {
                ImportObject(xpBase, p, p.GroupXPath, null, GxiImporter.ImportGroup, cSub);
            }
            if (p.EntriesInGroup)
            {
                ImportObject(xpBase, p, p.EntryXPath, null, GxiImporter.ImportEntry, cSub);
            }
        }
Beispiel #9
0
        private static void ImportBinaryKvp(XPathNavigator xpBase, GxiProfile p,
            GxiContext c)
        {
            string strKey = QueryValue(xpBase, p.BinaryKeyXPath, p.BinaryKeyUseName);
            if(string.IsNullOrEmpty(strKey)) return;

            strKey = ApplyRepl(strKey, c.BinaryKeyRepl);
            if(strKey.Length == 0) return;

            string strValue = QueryValueSafe(xpBase, p.BinaryValueXPath);

            byte[] pbValue = null;
            if(p.BinaryValueEncoding == GxiBinaryEncoding.Base64)
                pbValue = Convert.FromBase64String(strValue);
            else if(p.BinaryValueEncoding == GxiBinaryEncoding.Hex)
                pbValue = MemUtil.HexStringToByteArray(strValue);
            else { Debug.Assert(false); }

            if(pbValue == null) return;

            c.Entry.Binaries.Set(strKey, new ProtectedBinary(false, pbValue));
        }
 private static void ImportStringKvp2(XPathNavigator xpBase, GxiProfile p,
                                      GxiContext c)
 {
     ImportStringKvpEx(xpBase, p, c, false);
 }
Beispiel #11
0
        private static void ImportStringKvpEx(XPathNavigator xpBase, GxiProfile p,
            GxiContext c, bool bFirst)
        {
            string strKey = QueryValue(xpBase, (bFirst ? p.StringKeyXPath :
                p.StringKeyXPath2), (bFirst ? p.StringKeyUseName :
                p.StringKeyUseName2));
            if(string.IsNullOrEmpty(strKey)) return;

            strKey = ApplyRepl(strKey, (bFirst ? c.StringKeyRepl : c.StringKeyRepl2));
            if(strKey.Length == 0) return;

            if(p.StringKeyToStd)
            {
                string strMapped = ImportUtil.MapNameToStandardField(strKey,
                    p.StringKeyToStdFuzzy);
                if(!string.IsNullOrEmpty(strMapped)) strKey = strMapped;
            }

            string strValue = QueryValueSafe(xpBase, (bFirst ? p.StringValueXPath :
                p.StringValueXPath2));
            strValue = ApplyRepl(strValue, (bFirst ? c.StringValueRepl :
                c.StringValueRepl2));

            ImportUtil.AppendToField(c.Entry, strKey, strValue, c.Database);
        }
Beispiel #12
0
        private static void ImportEntry(XPathNavigator xpBase, GxiProfile p,
            GxiContext c)
        {
            PwEntry pe = new PwEntry(true, true);

            PwGroup pg = c.Group; // Not the database root group
            string strGroupPath = QueryValueSafe(xpBase, p.EntryGroupXPath);
            string strGroupPath2 = QueryValueSafe(xpBase, p.EntryGroupXPath2);
            if((strGroupPath.Length > 0) && (strGroupPath2.Length > 0))
            {
                Debug.Assert(p.EntryGroupSep.Length > 0);
                strGroupPath = strGroupPath + p.EntryGroupSep + strGroupPath2;
            }
            if(strGroupPath.Length > 0)
            {
                if(p.EntryGroupSep.Length == 0)
                    pg = pg.FindCreateGroup(strGroupPath, true);
                else
                    pg = pg.FindCreateSubTree(strGroupPath, new string[1]{
                        p.EntryGroupSep }, true);
            }
            pg.AddEntry(pe, true);

            GxiContext cSub = c.ModifyWith(pe);

            ImportObject(xpBase, p, p.StringKvpXPath, null,
                GxiImporter.ImportStringKvp, cSub);
            ImportObject(xpBase, p, p.StringKvpXPath2, null,
                GxiImporter.ImportStringKvp2, cSub);
            ImportObject(xpBase, p, p.BinaryKvpXPath, null,
                GxiImporter.ImportBinaryKvp, cSub);
        }
Beispiel #13
0
 private static void ImportStringKvp2(XPathNavigator xpBase, GxiProfile p,
     GxiContext c)
 {
     ImportStringKvpEx(xpBase, p, c, false);
 }
Beispiel #14
0
        private static void ImportRoot(XPathNavigator xpBase, GxiProfile p,
            GxiContext c)
        {
            ImportObject(xpBase, p, p.GroupXPath, null, GxiImporter.ImportGroup, c);

            if(p.EntriesInRoot)
                ImportObject(xpBase, p, p.EntryXPath, null, GxiImporter.ImportEntry, c);
        }
Beispiel #15
0
        private static void ImportPriv(PwGroup pgStorage, Stream s, GxiProfile p,
            PwDatabase pdContext, IStatusLogger sl)
        {
            StrEncodingInfo sei = StrUtil.GetEncoding(p.Encoding);
            StreamReader srRaw;
            if((sei != null) && (sei.Encoding != null))
                srRaw = new StreamReader(s, sei.Encoding, true);
            else srRaw = new StreamReader(s, true);
            string strDoc = srRaw.ReadToEnd();
            srRaw.Close();

            strDoc = Preprocess(strDoc, p);

            StringReader srDoc = new StringReader(strDoc);
            XPathDocument xd = new XPathDocument(srDoc);

            GxiContext c = new GxiContext(p, pdContext, pgStorage, null);

            XPathNavigator xpDoc = xd.CreateNavigator();
            ImportObject(xpDoc, p, p.RootXPath, "/*", GxiImporter.ImportRoot, c);

            srDoc.Close();
        }
Beispiel #16
0
        // private static string QueryValueSafe(XPathNavigator xpBase, string strXPath,
        //    bool bQueryName)
        // {
        //    return (QueryValue(xpBase, strXPath, bQueryName) ?? string.Empty);
        // }
        private static void ImportObject(XPathNavigator xpBase, GxiProfile p,
            string strXPath, string strAltXPath, ImportObjectDelegate f,
            GxiContext c)
        {
            if(f == null) { Debug.Assert(false); return; }

            XPathNodeIterator xi = QueryNodes(xpBase, strXPath, strAltXPath);
            if(xi == null) return; // No assert
            foreach(XPathNavigator xp in xi) { f(xp, p, c); }
        }
Beispiel #17
0
        private static void ImportGroup(XPathNavigator xpBase, GxiProfile p,
            GxiContext c)
        {
            PwGroup pg = new PwGroup(true, true);
            c.Group.AddGroup(pg, true);

            GxiContext cSub = c.ModifyWith(pg);

            pg.Name = QueryValueSafe(xpBase, p.GroupNameXPath);
            if(pg.Name.Length == 0) pg.Name = KPRes.Group;

            if(p.GroupsInGroup)
                ImportObject(xpBase, p, p.GroupXPath, null, GxiImporter.ImportGroup, cSub);
            if(p.EntriesInGroup)
                ImportObject(xpBase, p, p.EntryXPath, null, GxiImporter.ImportEntry, cSub);
        }