Пример #1
0
        /// <summary>
        /// Process OutputDataReceived event handler
        /// </summary>
        private void OnOutputDataReceived(object sender, DataReceivedEventArgs args)
        {
            // I know, I know
            // parsing output from a program which wasn't made for it it ''bad''
            // however, this is the only thing that works for me(I've tried a few extraction libraries)
            // :)

            string line = args.Data;

            // add to stdout to StandardOut :)
            StandardOutput.Add(line);

            if (line == null)
            {
                return;
            }

            // we need to parse something like:
            // '  4% - ...'

            // when the line is 'Everything is Ok', it's done :)
            // so fire 'OnProgressChange' with 100%
            if (line == "Everything is Ok")
            {
                OnProgressChange?.Invoke(this, 100);
                return;
            }

            // ignore data if it's useless for us
            if (!line.Contains("%") || !line.Contains("-"))
            {
                return;
            }

            // extract percentage from line
            string percentageString = null;

            for (int i = 0; i < 3; i++)
            {
                // if the line is empty, skip it
                if (String.IsNullOrEmpty(line[i].ToString()))
                {
                    continue;
                }

                percentageString += line[i];
            }

            // if we can't parse the string, just return
            if (!Int32.TryParse(percentageString, out int percentage))
            {
                return;
            }

            OnProgressChange?.Invoke(this, percentage);
        }
Пример #2
0
        public void CreateNodeIndex()
        {
            logger.Info("Creating_node_index");

            if (RootSchemaNode.ChildNodes.Count < 1)
            {
                logger.Error("RootSchemaNode does not have child nodes");
                return;
            }

            //  string data = "<" + RootSchemaNode.ChildNodes[0].Name + ">";


            m_nodeMap.Clear();

            try
            {
                logger.Info("Starting_node_indexing file {0}", DataFile);

                foreach (var ff in RootSchemaNode.ChildNodes)
                {
                    // Due to performance issues
                    //logger.Info("Creating_nodeIndex for node {0}", ff.ToString());

                    string indexNodeName = ff.Name;
                    SortedList <long, NodeInfo> nodeMap = new SortedList <long, NodeInfo>();
                    m_nodeMap.Add(indexNodeName, nodeMap);

                    CreateNodeIndex(DataFile, indexNodeName, nodeMap);
                }

                logger.Info("Indexing_completed_successfully file {0}", DataFile);
            }
            catch (Exception ex)
            {
                string errorStr = "IndexingProcessError: " + ex.Message;
                ErrorList.Add(errorStr);
                logger.Error(ex, "XMLFile_node_indexing_error {0}", DataFile);
                OnError?.Invoke(errorStr);
            }
            finally
            {
                OnIndexingCompleted?.Invoke(this, new EventArgs());
                if (!StopIndexing)
                {
                    // NodeParsed?.Invoke(this, new NodeIndexEventArgs() { NodeIndexer = this, ItemCount = NodeMap.Count });
                    OnProgressChange?.Invoke(this, ProgressPercent);
                }
            }

            logger.Trace("Leaving_method");
        }
Пример #3
0
    /// <summary>
    /// 计算刮卡进度
    /// </summary>
    public void CalcProgress()
    {
        var texture2D  = RenderTexture2Texture2D(_texture);
        var colorArray = texture2D.GetPixels(texture2D.mipmapCount - 1);

        if (colorArray.Length == 1)
        {
            _progress = 1 - colorArray[0].a;
        }
        else
        {
            _progress = 1;
        }
        Destroy(texture2D);
        OnProgressChange?.Invoke(_progress);
    }
Пример #4
0
 private void SetProgress(float p)
 {
     p        = Mathf.Clamp(p, 0f, 1f);
     Progress = p;
     OnProgressChange?.Invoke();
 }
Пример #5
0
        private void CreateNodeIndex(string xmlFile, string indexNodeName, SortedList <long, NodeInfo> nodeMap)
        {
            logger.Info("Creating_node_index");
            ProgressPercent = 0;
            indexNodeName   = "<" + indexNodeName;


            int dataLen = indexNodeName.Length;

            int  MB10     = 1024 * 1024 * 10;
            int  recordId = 0;
            long offset   = 0;

            nodeMap.Clear();

            NodeInfo last         = null;
            long     streamLength = 0;

            using (var localFileStream = File.OpenRead(xmlFile))
            {
                streamLength = localFileStream.Length;
                float lastReported = 0;
                do
                {
                    offset = FileUtils.Seek(localFileStream, indexNodeName, MB10);
                    if (offset == -1 || localFileStream.Position >= localFileStream.Length)
                    {
                        break;
                    }

                    if (last != null)
                    {
                        last.Length = (int)(offset - last.Offset);
                    }

                    NodeInfo info = new NodeInfo();
                    info.Id     = ++recordId;
                    info.Offset = offset;
                    last        = info;
                    nodeMap.Add(info.Id, info);

                    // Due to performance issues
                    //logger.Trace("Found_node {0}=>{1}", indexNodeName, info.ToString());

                    OnNodeParsed?.Invoke(this, new NodeIndexEventArgs(indexNodeName)
                    {
                        NodeIndexer = this, ItemCount = nodeMap.Count, CurrentNode = info
                    });
                    if (StopIndexing)
                    {
                        goto lbl_end;
                    }
                    ProgressPercent = 100 * offset / streamLength;

                    if (recordId % 5 == 0 && (ProgressPercent - lastReported >= 2))
                    {
                        OnProgressChange?.Invoke(this, ProgressPercent);
                        lastReported = ProgressPercent;
                    }

                    localFileStream.Seek(dataLen * 2, SeekOrigin.Current);
                } while (offset > 0);

                localFileStream.Close();
            }

lbl_end:
            logger.Trace("Leaving_method");
        }//end of CreateNodeIndex