Files
duplicati/Duplicati/GUI/DuplicityOutputParser.cs
T
kenneth.skovhede@gmail.com 135caf4164 All projects are now signed.
Updated to the newest version of LightDataModel.
Switched from duplicity to duplicati, this runs a bit faster.
Now supports authentication on network shares (windows only).

git-svn-id: https://duplicati.googlecode.com/svn/trunk@66 59da171f-624f-0410-aa54-27559c288bec
2009-01-15 19:42:14 +00:00

71 lines
2.4 KiB
C#

#region Disclaimer / License
// Copyright (C) 2008, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Datamodel;
namespace Duplicati.GUI
{
public class DuplicityOutputParser
{
private const string OK_INDICATOR = "--------------[ Backup Statistics ]--------------";
private const string WARNING_INDICATOR = "Errors ";
private const string SIZE_INDICATOR = "TotalDestinationSizeChange ";
public static void ParseData(Log log)
{
string text = log.Blob.StringData;
log.ParsedStatus = "Error";
if (text.IndexOf(OK_INDICATOR) >= 0)
log.ParsedStatus = "OK";
long c = ExtractNumber(text, WARNING_INDICATOR, -1);
if (c != 0)
log.ParsedStatus = "Warning";
c = ExtractNumber(text, SIZE_INDICATOR, 0);
if (c <= 0)
log.ParsedStatus = "Warning";
log.Transfersize = c;
}
private static long ExtractNumber(string output, string key, long @default)
{
long count = @default;
if (output.IndexOf(key) >= 0)
{
int pos = output.IndexOf(key) + key.Length;
int p2 = output.IndexOfAny(new char[] {' ', '\r', '\n', '\t'}, pos);
string number = output.Substring(pos, p2 - pos).Trim();
if (!long.TryParse(number, out count))
count = @default;
}
return count;
}
}
}