示例#1
0
        public override string Execute(StringTemplateItem template)
        {
            string file = PathUtility.ParseSpecialFoldersNames(this.File, ParseSpecialFolderOption.WildCardToRealPath);

            string[]      values = new string[0];
            StringBuilder sb     = new StringBuilder();

            if (Utils.IsFileOrDirectory(file) == Utils.FileOrDirectory.File)
            {
                using (CsvStreamReader reader = new CsvStreamReader(file))
                {
                    reader.Separator = ',';

                    while (!reader.EndOfCsvStream) // Do not use EndOfStream
                    {
                        string line = reader.ReadLine();
                        values = Utils.SplitEscaped(line, reader.Separator, '"');

                        template.IsLastCommand = (reader.EndOfCsvStream && this.IsLastCommand);
                        sb.Append(template.Format(line, this.Data, values));
                    }
                    reader.Close();
                }
            }
            return(sb.ToString());
        }
示例#2
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            StreamReader sr      = new StreamReader(sInput, Encoding.Default);
            string       strData = sr.ReadToEnd();

            sr.Close();
            sInput.Close();

            // Fix broken newlines
            strData = strData.Replace("\r\r\n", "\r\n");

            CsvStreamReader csv = new CsvStreamReader(strData, false);

            while (true)
            {
                string[] v = csv.ReadLine();
                if (v == null)
                {
                    break;
                }
                if (v.Length == 0)
                {
                    continue;
                }

                PwEntry pe = new PwEntry(true, true);
                pwStorage.RootGroup.AddEntry(pe, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
                                   pwStorage.MemoryProtection.ProtectTitle, v[0]));

                int p = 1;
                while ((p + 1) < v.Length)
                {
                    string strMapped = ImportUtil.MapNameToStandardField(v[p], true);
                    string strKey    = (string.IsNullOrEmpty(strMapped) ? v[p] : strMapped);
                    string strValue  = v[p + 1];

                    p += 2;

                    if ((strKey.Length == 0) && (strValue.Length == 0))
                    {
                        continue;
                    }

                    AppendToString(pe, strKey, strValue);
                }

                if ((p < v.Length) && !string.IsNullOrEmpty(v[p]))
                {
                    AppendToString(pe, PwDefs.NotesField, v[p]);
                }
            }
        }
示例#3
0
		public override void Import(PwDatabase pwStorage, Stream sInput,
			IStatusLogger slLogger)
		{
			StreamReader sr = new StreamReader(sInput, Encoding.Default);
			string strData = sr.ReadToEnd();
			sr.Close();

			// Fix broken newlines
			strData = strData.Replace("\r\r\n", "\r\n");

			CsvStreamReader csv = new CsvStreamReader(strData, false);
			while(true)
			{
				string[] v = csv.ReadLine();
				if(v == null) break;
				if(v.Length == 0) continue;

				PwEntry pe = new PwEntry(true, true);
				pwStorage.RootGroup.AddEntry(pe, true);

				pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
					pwStorage.MemoryProtection.ProtectTitle, v[0]));

				int p = 1;
				while((p + 1) < v.Length)
				{
					string strMapped = ImportUtil.MapNameToStandardField(v[p], true);
					string strKey = (string.IsNullOrEmpty(strMapped) ? v[p] : strMapped);
					string strValue = v[p + 1];

					p += 2;

					if((strKey.Length == 0) && (strValue.Length == 0)) continue;

					AppendToString(pe, strKey, strValue);
				}

				if((p < v.Length) && !string.IsNullOrEmpty(v[p]))
					AppendToString(pe, PwDefs.NotesField, v[p]);
			}
		}
示例#4
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            StreamReader sr      = new StreamReader(sInput, Encoding.Default);
            string       strData = sr.ReadToEnd();

            sr.Close();

            CsvStreamReader csv = new CsvStreamReader(strData, true);
            Dictionary <string, PwGroup> dictGroups = new Dictionary <string, PwGroup>();

            while (true)
            {
                string[] vLine = csv.ReadLine();
                if (vLine == null)
                {
                    break;
                }
                if (vLine.Length == 0)
                {
                    continue;                                   // Skip empty line
                }
                if (vLine.Length == 5)
                {
                    continue;                                   // Skip header line
                }
                if (vLine.Length != 34)
                {
                    Debug.Assert(false); continue;
                }

                string strType = vLine[0].Trim();
                if (strType.Equals("Is Template", StrUtil.CaseIgnoreCmp))
                {
                    continue;
                }
                if (strType.Equals("1"))
                {
                    continue;                                     // Skip template
                }
                string  strGroup = vLine[2].Trim();
                PwGroup pg;
                if (strGroup.Length == 0)
                {
                    pg = pwStorage.RootGroup;
                }
                else
                {
                    if (dictGroups.ContainsKey(strGroup))
                    {
                        pg = dictGroups[strGroup];
                    }
                    else
                    {
                        pg = new PwGroup(true, true, strGroup, PwIcon.Folder);
                        pwStorage.RootGroup.AddGroup(pg, true);
                        dictGroups[strGroup] = pg;
                    }
                }

                PwEntry pe = new PwEntry(true, true);
                pg.AddEntry(pe, true);

                string strTitle = vLine[1].Trim();
                if (strTitle.Length > 0)
                {
                    ImportUtil.AppendToField(pe, PwDefs.TitleField, strTitle, pwStorage);
                }

                for (int i = 0; i < 10; ++i)
                {
                    string strKey   = vLine[(i * 3) + 3].Trim();
                    string strValue = vLine[(i * 3) + 4].Trim();
                    if ((strKey.Length == 0) || (strValue.Length == 0))
                    {
                        continue;
                    }

                    string strMapped = ImportUtil.MapNameToStandardField(strKey, true);
                    if (string.IsNullOrEmpty(strMapped))
                    {
                        strMapped = strKey;
                    }
                    ImportUtil.AppendToField(pe, strMapped, strValue, pwStorage);
                }

                string strNotesPre = pe.Strings.ReadSafe(PwDefs.NotesField);
                string strNotes    = vLine[33].Trim();
                if (strNotes.Length > 0)
                {
                    if (strNotesPre.Length == 0)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pwStorage);
                    }
                    else
                    {
                        pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                                           ((pwStorage == null) ? false :
                                            pwStorage.MemoryProtection.ProtectNotes), strNotesPre +
                                           Environment.NewLine + Environment.NewLine + strNotes));
                    }
                }
            }
        }
示例#5
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
            IStatusLogger slLogger)
        {
            StreamReader sr = new StreamReader(sInput, Encoding.Default);
            string strData = sr.ReadToEnd();
            sr.Close();

            CsvStreamReader csv = new CsvStreamReader(strData, true);
            Dictionary<string, PwGroup> dictGroups = new Dictionary<string, PwGroup>();

            while(true)
            {
                string[] vLine = csv.ReadLine();
                if(vLine == null) break;
                if(vLine.Length == 0) continue; // Skip empty line
                if(vLine.Length == 5) continue; // Skip header line
                if(vLine.Length != 34) { Debug.Assert(false); continue; }

                string strType = vLine[0].Trim();
                if(strType.Equals("Is Template", StrUtil.CaseIgnoreCmp)) continue;
                if(strType.Equals("1")) continue; // Skip template

                string strGroup = vLine[2].Trim();
                PwGroup pg;
                if(strGroup.Length == 0) pg = pwStorage.RootGroup;
                else
                {
                    if(dictGroups.ContainsKey(strGroup)) pg = dictGroups[strGroup];
                    else
                    {
                        pg = new PwGroup(true, true, strGroup, PwIcon.Folder);
                        pwStorage.RootGroup.AddGroup(pg, true);
                        dictGroups[strGroup] = pg;
                    }
                }

                PwEntry pe = new PwEntry(true, true);
                pg.AddEntry(pe, true);

                string strTitle = vLine[1].Trim();
                if(strTitle.Length > 0)
                    ImportUtil.AppendToField(pe, PwDefs.TitleField, strTitle, pwStorage);

                for(int i = 0; i < 10; ++i)
                {
                    string strKey = vLine[(i * 3) + 3].Trim();
                    string strValue = vLine[(i * 3) + 4].Trim();
                    if((strKey.Length == 0) || (strValue.Length == 0)) continue;

                    string strMapped = ImportUtil.MapNameToStandardField(strKey, true);
                    if(string.IsNullOrEmpty(strMapped)) strMapped = strKey;
                    ImportUtil.AppendToField(pe, strMapped, strValue, pwStorage);
                }

                string strNotesPre = pe.Strings.ReadSafe(PwDefs.NotesField);
                string strNotes = vLine[33].Trim();
                if(strNotes.Length > 0)
                {
                    if(strNotesPre.Length == 0)
                        ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pwStorage);
                    else
                        pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                            ((pwStorage == null) ? false :
                            pwStorage.MemoryProtection.ProtectNotes), strNotesPre +
                            Environment.NewLine + Environment.NewLine + strNotes));
                }
            }
        }
示例#6
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            string strData;

            using (StreamReader sr = new StreamReader(sInput, Encoding.Default))
            {
                strData = sr.ReadToEnd();
            }

            // Fix new-line sequences
            strData = strData.Replace("\r\r\n", "\r\n");

            CsvStreamReader csv = new CsvStreamReader(strData, false);

            while (true)
            {
                string[] v = csv.ReadLine();
                if (v == null)
                {
                    break;
                }
                if (v.Length == 0)
                {
                    continue;
                }

                PwEntry pe = new PwEntry(true, true);
                pwStorage.RootGroup.AddEntry(pe, true);

                ImportUtil.AppendToField(pe, PwDefs.TitleField, v[0], pwStorage);

                int p = 1;
                while ((p + 1) < v.Length)
                {
                    string strMapped = ImportUtil.MapNameToStandardField(v[p], true);
                    string strKey    = (string.IsNullOrEmpty(strMapped) ? v[p] : strMapped);
                    string strValue  = v[p + 1];

                    p += 2;

                    if (strKey.Length == 0)
                    {
                        if (strValue.Length == 0)
                        {
                            continue;
                        }

                        Debug.Assert(false);
                        strKey = PwDefs.NotesField;
                    }

                    ImportUtil.AppendToField(pe, strKey, strValue, pwStorage);
                }

                if ((p < v.Length) && !string.IsNullOrEmpty(v[p]))
                {
                    ImportUtil.AppendToField(pe, PwDefs.NotesField, v[p], pwStorage);
                }
            }
        }