Example #1
0
        public void CopyExecuted(object sender)
        {
            try
            {
                // for configuration of fields to export from file view
                LogFile.ExportConfigurationInfo config = new LogFile.ExportConfigurationInfo();
                if (sender is LogFile.ExportConfigurationInfo)
                {
                    config = (sender as LogFile.ExportConfigurationInfo);
                }

                HtmlFragment htmlFragment = new HtmlFragment();
                foreach (IFileItem lbi in SelectedContent)
                {
                    // get all cells
                    if (typeof(T) == typeof(LogFileItem))
                    {
                        LogFileItem   item = (LogFileItem)lbi;
                        StringBuilder sb   = new StringBuilder();

                        sb = FormatExportItem(config.Index, config.Separator, config.RemoveEmpty, item.Index.ToString(), sb);
                        sb = FormatExportItem(config.Content, config.Separator, config.RemoveEmpty, item.Content, sb);
                        sb = FormatExportItem(config.Group1, config.Separator, config.RemoveEmpty, item.Group1, sb);
                        sb = FormatExportItem(config.Group2, config.Separator, config.RemoveEmpty, item.Group2, sb);
                        sb = FormatExportItem(config.Group3, config.Separator, config.RemoveEmpty, item.Group3, sb);
                        sb = FormatExportItem(config.Group4, config.Separator, config.RemoveEmpty, item.Group4, sb);

                        htmlFragment.AddClipToList(sb.ToString(), lbi.Background, lbi.Foreground);
                    }
                    else
                    {
                        htmlFragment.AddClipToList(lbi.Content, lbi.Background, lbi.Foreground);
                    }
                }

                htmlFragment.CopyListToClipboard();
            }
            catch (Exception ex)
            {
                SetStatus("Exception:CopyCmdExecute:" + ex.ToString());
            }
        }
Example #2
0
        public void ParallelMMFRead(object taskMMFInfo)
        {
            try
            {
                TaskMMFInfo taskInfo = (TaskMMFInfo)taskMMFInfo;
                Debug.Print(string.Format("ParallelMMFRead:enter : position:{0} length:{1} total:{2}",
                                          taskInfo.position, taskInfo.length, taskInfo.length + taskInfo.position));

                MemoryMappedViewStream viewStream = taskInfo.mmf.CreateViewStream(taskInfo.position, taskInfo.length, MemoryMappedFileAccess.Read);
                byte[] bytes = new byte[taskInfo.length];
                viewStream.Read(bytes, 0, taskInfo.length);

                byte[] newLine        = (taskInfo.logFile.Encoding).GetBytes(Environment.NewLine);
                int    beginningIndex = 0;
                int    indexCount     = 0;
                int    fixUp          = 0;
                int    x    = 0;
                int    step = Math.Max(1, newLine.Length / 2);

                // check first two bytes to make sure not part of crlf
                if (bytes[0] == newLine[0] || bytes[0] == newLine[step])
                {
                    fixUp = step;

                    if (bytes[step] == newLine[step])
                    {
                        fixUp = step * 2;
                    }

                    taskInfo.stringList.Add(new LogFileItem());
                }

                for (x = fixUp; x < bytes.Length; x += step)
                {
                    if (taskInfo.bgWorker.CancellationPending)
                    {
                        taskInfo.completedEvent.Set();
                        Debug.Print("ParallelMMFRead:cancelled");
                        return;
                    }

                    if (bytes[x] == newLine[0])
                    {
                        LogFileItem logFileItem = new LogFileItem()
                        {
                            Content    = (taskInfo.logFile.Encoding).GetString(bytes, beginningIndex, indexCount),
                            Background = Settings.BackgroundColor,
                            Foreground = Settings.ForegroundColor,
                        };

                        taskInfo.stringList.Add(logFileItem);

                        if (x + step <= bytes.Length && bytes[x + step] == newLine[step])
                        {
                            x += step;
                        }

                        beginningIndex = x + step;

                        indexCount = 0;
                    }
                    else
                    {
                        indexCount += step;
                    }
                }

                if (indexCount > 1)
                {
                    // partial string
                    LogFileItem logFileItem = new LogFileItem()
                    {
                        Content    = (taskInfo.logFile.Encoding).GetString(bytes, beginningIndex, bytes.Length - beginningIndex),
                        Background = Settings.BackgroundColor,
                        Foreground = Settings.ForegroundColor,
                        // Index = x
                    };

                    taskInfo.stringList.Add(logFileItem);

                    logFileItem = new LogFileItem()
                    {
                        Content    = _needsPatch,
                        Background = Settings.BackgroundColor,
                        Foreground = Settings.ForegroundColor,
                        // Index = x
                    };

                    taskInfo.stringList.Add(logFileItem);
                }

                taskInfo.completedEvent.Set();
                Debug.Print("ParallelMMFRead:exit");
            }
            catch (Exception e)
            {
                Debug.Print("ParallelMMFRead:exception" + e.ToString());
                return;
            }
        }