예제 #1
0
        private void _ic_Notified(CVResult r, object o)
        {
            if (r == CVResult.TableQueryReceived)
            {
                if (o is QueryResultPt)
                {
                    QueryResultPt qrp = o as QueryResultPt;
                    if (qrp.token == _token)
                    {
                        if (qrp.success == 0)
                        {
                            TableXmlWrapper txw = new TableXmlWrapper(qrp);

                            _curNum    = txw.Count;
                            _curIndex  = 0;
                            _pageCount = txw.Count / _pageSize + (txw.Count % _pageSize == 0 ? 0 : 1);

                            foreach (XmlNode xn in txw.Nodes)
                            {
                                ResXmlNodeParser rxnp     = new ResXmlNodeParser(xn);
                                string           pathfile = rxnp.Pathfile.Remove(0, 1);
                                string           file     = pathfile.Replace(_dc.RemoteDirectory + @"/", "");

                                string source = @"ftp://" + _dc.Ip + @"/" + pathfile;
                                string target = Path.Combine(_dc.LocalDirectory, file).Replace("/", @"\");

                                DateTime tdt = File.Exists(target) ? File.GetLastWriteTime(target) : DateTime.MinValue;
                                if (!Kits.DateTimeEqual(rxnp.Lastwrite, tdt))
                                {
                                    if (UseMemory)
                                    {
                                        DownloadMemoryItem dmi = new DownloadMemoryItem
                                        {
                                            Id     = rxnp.Id,
                                            Source = source,
                                            Target = target,
                                            Crc    = rxnp.Crc,
                                            Tag    = rxnp.Name
                                        };
                                        _dc.Add(dmi);
                                    }
                                    else
                                    {
                                        DownloadDataItem ddi = new DownloadDataItem
                                        {
                                            Id     = rxnp.Id,
                                            Source = source,
                                            Target = target,
                                            Crc    = rxnp.Crc,
                                            Tag    = rxnp.Name
                                        };
                                        _dc.Add(ddi);
                                    }
                                }
                                else
                                {
                                    Notified?.Invoke(CVResDownloadResult.ExistedTarget, target);
                                    if (++_curIndex >= _curNum)
                                    {
                                        if (++_pageNo >= _pageCount)
                                        {
                                            Completed?.Invoke();
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Notified?.Invoke(CVResDownloadResult.RequestResourceFailed, qrp.msg);
                        }
                    }
                }
            }
        }