示例#1
0
        // 重新用不同详细级别获取事项内容
        // parameters:
        //      item    要被重新获取内容的对象
        //      nLevel  内容详细级别。0/1/2。0 为最详细级
        public OperLogItem LoadOperLogItem(OperLogItem item, int nLevel)
        {
            OperLogItemLoader loader = new OperLogItemLoader();

            loader.Stop            = this.Stop;
            loader.Channel         = this.Channel;
            loader.estimate        = null;//
            loader.FileName        = item.Date + ".log";
            loader.Level           = nLevel;
            loader.lServerFileSize = -1;
            loader.Range           = item.Index.ToString() + "-" + item.Index.ToString();
            loader.AutoCache       = this.AutoCache;
            loader.lProgressValue  = 0;
            loader.lSize           = 0;
            loader.Filter          = this.Filter;
            loader.LogType         = this.LogType;

#if NO
            loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
            loader.Prompt += new MessagePromptEventHandler(loader_Prompt);
#endif
            foreach (OperLogItem new_item in loader)
            {
                return(new_item);
            }

            return(null);
        }
示例#2
0
        // 重新用不同详细级别获取事项内容
        // parameters:
        //      item    要被重新获取内容的对象
        //      nLevel  内容详细级别。0/1/2。0 为最详细级
        public OperLogItem LoadOperLogItem(OperLogItem item, int nLevel)
        {
            OperLogItemLoader loader = new OperLogItemLoader();
            loader.Stop = this.Stop;
            loader.Channel = this.Channel;
            loader.estimate = null;//
            loader.FileName = item.Date + ".log";
            loader.Level = nLevel;
            loader.lServerFileSize = -1;
            loader.Range = item.Index.ToString() + "-" + item.Index.ToString();
            loader.AutoCache = this.AutoCache;
            loader.lProgressValue = 0;
            loader.lSize = 0;
            loader.Filter = this.Filter;
            loader.LogType = this.LogType;

#if NO
                    loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                    loader.Prompt += new MessagePromptEventHandler(loader_Prompt);
#endif
            foreach (OperLogItem new_item in loader)
            {
                return new_item;
            }

            return null;
        }
示例#3
0
        public IEnumerator GetEnumerator()
        {
            string strError = "";
            int nRet = 0;

            if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0
    && (this.LogType & dp2Circulation.LogType.OperLog) != 0)
                throw new ArgumentException("OperLogLoader 的 LogType 只能使用一种类型");

            if (string.IsNullOrEmpty(this.CacheDir) == false)
                PathUtil.CreateDirIfNeed(this.CacheDir);

            // ProgressEstimate estimate = new ProgressEstimate();
            bool bAutoCache = this.AutoCache;

            if (bAutoCache == true)
            {
                long lServerFileSize = 0;
                long lCacheFileSize = 0;
                // 象征性获得一个日志文件的尺寸,主要目的是为了触发一次通道登录
                // return:
                //      -2  此类型的日志尚未启用
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    "20121001.log",
                    this.LogType,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                    throw new Exception(strError);
                // 2015/11/25
                if (nRet == -2)
                    yield break;    // 此类型的日志尚未启用

                // 检查日志文件缓存目录的版本是否和当前用户的信息一致
                // return:
                //      -1  出错
                //      0   一致
                //      1   不一致
                nRet = DetectCacheVersionFile(
                    this.CacheDir,
                    "version.xml",
                    this.Channel.LibraryCodeList,
                    this.Channel.Url,
                    out strError);
                if (nRet == -1)
                    throw new Exception(strError);
                if (nRet == 1)
                {
                REDO:
                    // 清空当前缓存目录
                    nRet = Global.DeleteDataDir(
                        null, // owner,
                        this.CacheDir,
                        out strError);
                    if (nRet == -1)
                    {
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "清空当前缓存目录时发生错误: " + strError;
                            e.Actions = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                                throw new Exception(strError);
                            else if (e.ResultAction == "yes")
                                goto REDO;
                            else
                            {
                            }
                        }
                        else
                            throw new Exception(strError);
                    }
#if NO
                    if (nRet == -1)
                        throw new Exception(strError);
#endif

                    PathUtil.CreateDirIfNeed(this.CacheDir);  // 重新创建目录

                    // 创建版本文件
                    nRet = CreateCacheVersionFile(
                        this.CacheDir,
                        "version.xml",
                        this.Channel.LibraryCodeList,
                        this.Channel.Url,
                        out strError);
                    if (nRet == -1)
                        throw new Exception(strError);
                }
            }

            long lTotalSize = 0;
            List<string> lines = new List<string>();    // 经过处理后排除了不存在的文件名
            List<string> ranges = new List<string>();
            List<long> sizes = new List<long>();

            this.Stop.SetMessage("正在准备获得日志文件尺寸 ...");
            foreach (string strLine in this.FileNames)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                if (String.IsNullOrEmpty(strLine) == true)
                    continue;

                string strFilename = strLine.Trim();
                // 去掉注释
                nRet = strFilename.IndexOf("#");
                if (nRet != -1)
                    strFilename = strFilename.Substring(0, nRet).Trim();

                if (String.IsNullOrEmpty(strFilename) == true)
                    continue;

                string strLogFilename = "";
                string strRange = "";

                nRet = strFilename.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strFilename.Substring(0, nRet).Trim();
                    strRange = strFilename.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strFilename.Trim();
                    strRange = "";
                }

                if (strLogFilename.Length == 8)
                    strLogFilename += ".log";
            REDO_GETSIZE:
                long lServerFileSize = 0;
                long lCacheFileSize = 0;
                // 获得一个日志文件的尺寸
                //      -2  此类型的日志尚未启用
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    strLogFilename,
                    this.LogType,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                {
                    // throw new Exception(strError);

                    if (this.Prompt != null)
                    {
                        MessagePromptEventArgs e = new MessagePromptEventArgs();
                        e.MessageText = "获取日志文件 " + strLogFilename + " 尺寸的操作发生错误: " + strError;
                        e.Actions = "yes,no,cancel";
                        this.Prompt(this, e);
                        if (e.ResultAction == "cancel")
                            throw new Exception(strError);
                        else if (e.ResultAction == "yes")
                        {
                            if (this.Stop != null)
                                this.Stop.Continue();
                            goto REDO_GETSIZE;
                        }
                        else
                        {
                            // ??
                            continue;
                        }
                    }
                    else
                        throw new Exception(strError);
                }

                if (nRet == 0)
                    continue;

                if (lServerFileSize == 0)
                    continue;   // 0字节的文件当作不存在处理
                // 2015/11/25
                if (lServerFileSize == -1)
                    yield break;    // 此类型的日志尚未启用

                Debug.Assert(lServerFileSize >= 0, "");

                if (bAutoCache == true)
                {
                    if (lCacheFileSize > 0)
                        lTotalSize += lCacheFileSize;
                    else
                        lTotalSize += lServerFileSize;
                }
                else
                {
                    lTotalSize += lServerFileSize;
                }

                // lines.Add(strFilename);
                lines.Add(strLogFilename);
                ranges.Add(strRange);

                // 记忆每个文件的尺寸,后面就不用获取了?
                sizes.Add(lServerFileSize);
            }

            long lDoneSize = 0;

            if (this.ProgressStart == -1)
                lDoneSize = lTotalSize;
            else
                lDoneSize = this.ProgressStart;

            lTotalSize += lDoneSize;

            if (this.Stop != null)
            {
                this.Stop.SetProgressRange(0, lTotalSize);
            }

            estimate.SetRange(lDoneSize, lTotalSize);
            estimate.StartEstimate();

            for (int i = 0; i < lines.Count; i++)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                string strLine = lines[i];
                string strRange = ranges[i];

                string strLogFilename = strLine;
#if NO
                string strLogFilename = "";
                string strRange = "";

                nRet = strLine.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strLine.Substring(0, nRet).Trim();
                    strRange = strLine.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strLine.Trim();
                    strRange = "";
                }
#endif

                {
                    OperLogItemLoader loader = new OperLogItemLoader();
                    loader.Stop = this.Stop;
                    loader.Channel = this.Channel;
                    // loader.owner = this.owner;
                    loader.estimate = this.estimate;
                    loader.FileName = strLogFilename;
                    loader.Level = this.Level;
                    loader.lServerFileSize = sizes[i];
                    loader.Range = strRange;
                    loader.AutoCache = this.AutoCache;
                    loader.lProgressValue = lDoneSize;
                    loader.lSize = lTotalSize;
                    loader.Filter = this.Filter;
                    loader.LogType = this.LogType;

                    loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                    loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                    foreach (OperLogItem item in loader)
                    {
                        yield return item;
                    }

                    lDoneSize = loader.lProgressValue;
                    lTotalSize = loader.lSize;
                }
            }
        }
示例#4
0
        public IEnumerator GetEnumerator()
        {
            string strError = "";
            int    nRet     = 0;

            if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0 &&
                (this.LogType & dp2Circulation.LogType.OperLog) != 0)
            {
                throw new ArgumentException("OperLogLoader 的 LogType 只能使用一种类型");
            }

            if (string.IsNullOrEmpty(this.CacheDir) == false)
            {
                PathUtil.CreateDirIfNeed(this.CacheDir);
            }

            // ProgressEstimate estimate = new ProgressEstimate();
            bool bAutoCache = this.AutoCache;

            if (bAutoCache == true)
            {
                long lServerFileSize = 0;
                long lCacheFileSize  = 0;
                // 象征性获得一个日志文件的尺寸,主要目的是为了触发一次通道登录
                // return:
                //      -2  此类型的日志尚未启用
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    "20121001.log",
                    this.LogType,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }
                // 2015/11/25
                if (nRet == -2)
                {
                    yield break;    // 此类型的日志尚未启用
                }
                // 检查日志文件缓存目录的版本是否和当前用户的信息一致
                // return:
                //      -1  出错
                //      0   一致
                //      1   不一致
                nRet = DetectCacheVersionFile(
                    this.CacheDir,
                    "version.xml",
                    this.Channel.LibraryCodeList,
                    this.Channel.Url,
                    out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }
                if (nRet == 1)
                {
REDO:
                    // 清空当前缓存目录
                    nRet = Global.DeleteDataDir(
                        null, // owner,
                        this.CacheDir,
                        out strError);
                    if (nRet == -1)
                    {
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "清空当前缓存目录时发生错误: " + strError;
                            e.Actions     = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                            {
                                throw new Exception(strError);
                            }
                            else if (e.ResultAction == "yes")
                            {
                                goto REDO;
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            throw new Exception(strError);
                        }
                    }
#if NO
                    if (nRet == -1)
                    {
                        throw new Exception(strError);
                    }
#endif

                    PathUtil.CreateDirIfNeed(this.CacheDir);  // 重新创建目录

                    // 创建版本文件
                    nRet = CreateCacheVersionFile(
                        this.CacheDir,
                        "version.xml",
                        this.Channel.LibraryCodeList,
                        this.Channel.Url,
                        out strError);
                    if (nRet == -1)
                    {
                        throw new Exception(strError);
                    }
                }
            }

            long          lTotalSize = 0;
            List <string> lines      = new List <string>(); // 经过处理后排除了不存在的文件名
            List <string> ranges     = new List <string>();
            List <long>   sizes      = new List <long>();

            this.Stop.SetMessage("正在准备获得日志文件尺寸 ...");
            foreach (string strLine in this.FileNames)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                if (String.IsNullOrEmpty(strLine) == true)
                {
                    continue;
                }

                string strFilename = strLine.Trim();
                // 去掉注释
                nRet = strFilename.IndexOf("#");
                if (nRet != -1)
                {
                    strFilename = strFilename.Substring(0, nRet).Trim();
                }

                if (String.IsNullOrEmpty(strFilename) == true)
                {
                    continue;
                }

                string strLogFilename = "";
                string strRange       = "";

                nRet = strFilename.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strFilename.Substring(0, nRet).Trim();
                    strRange       = strFilename.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strFilename.Trim();
                    strRange       = "";
                }

                if (strLogFilename.Length == 8)
                {
                    strLogFilename += ".log";
                }
REDO_GETSIZE:
                long lServerFileSize = 0;
                long lCacheFileSize = 0;
                // 获得一个日志文件的尺寸
                //      -2  此类型的日志尚未启用
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    strLogFilename,
                    this.LogType,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                {
                    // throw new Exception(strError);

                    if (this.Prompt != null)
                    {
                        MessagePromptEventArgs e = new MessagePromptEventArgs();
                        e.MessageText = "获取日志文件 " + strLogFilename + " 尺寸的操作发生错误: " + strError;
                        e.Actions     = "yes,no,cancel";
                        this.Prompt(this, e);
                        if (e.ResultAction == "cancel")
                        {
                            throw new Exception(strError);
                        }
                        else if (e.ResultAction == "yes")
                        {
                            if (this.Stop != null)
                            {
                                this.Stop.Continue();
                            }
                            goto REDO_GETSIZE;
                        }
                        else
                        {
                            // ??
                            continue;
                        }
                    }
                    else
                    {
                        throw new Exception(strError);
                    }
                }

                if (nRet == 0)
                {
                    continue;
                }

                if (lServerFileSize == 0)
                {
                    continue;   // 0字节的文件当作不存在处理
                }
                // 2015/11/25
                if (lServerFileSize == -1)
                {
                    yield break;    // 此类型的日志尚未启用
                }
                Debug.Assert(lServerFileSize >= 0, "");

                if (bAutoCache == true)
                {
                    if (lCacheFileSize > 0)
                    {
                        lTotalSize += lCacheFileSize;
                    }
                    else
                    {
                        lTotalSize += lServerFileSize;
                    }
                }
                else
                {
                    lTotalSize += lServerFileSize;
                }

                // lines.Add(strFilename);
                lines.Add(strLogFilename);
                ranges.Add(strRange);

                // 记忆每个文件的尺寸,后面就不用获取了?
                sizes.Add(lServerFileSize);
            }

            long lDoneSize = 0;

            if (this.ProgressStart == -1)
            {
                lDoneSize = lTotalSize;
            }
            else
            {
                lDoneSize = this.ProgressStart;
            }

            lTotalSize += lDoneSize;

            if (this.Stop != null)
            {
                this.Stop.SetProgressRange(0, lTotalSize);
            }

            estimate.SetRange(lDoneSize, lTotalSize);
            estimate.StartEstimate();

            for (int i = 0; i < lines.Count; i++)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                string strLine  = lines[i];
                string strRange = ranges[i];

                string strLogFilename = strLine;
#if NO
                string strLogFilename = "";
                string strRange       = "";

                nRet = strLine.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strLine.Substring(0, nRet).Trim();
                    strRange       = strLine.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strLine.Trim();
                    strRange       = "";
                }
#endif

                {
                    OperLogItemLoader loader = new OperLogItemLoader();
                    loader.Stop    = this.Stop;
                    loader.Channel = this.Channel;
                    // loader.owner = this.owner;
                    loader.estimate        = this.estimate;
                    loader.FileName        = strLogFilename;
                    loader.Level           = this.Level;
                    loader.lServerFileSize = sizes[i];
                    loader.Range           = strRange;
                    loader.AutoCache       = this.AutoCache;
                    loader.lProgressValue  = lDoneSize;
                    loader.lSize           = lTotalSize;
                    loader.Filter          = this.Filter;
                    loader.LogType         = this.LogType;

                    loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                    loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                    foreach (OperLogItem item in loader)
                    {
                        yield return(item);
                    }

                    lDoneSize  = loader.lProgressValue;
                    lTotalSize = loader.lSize;
                }
            }
        }