コード例 #1
0
        public void AddEvents(List <TrackerEvent> items)
        {
            if (items == null || items.Count == 0)
            {
                return;
            }

            FileInfo fi;
            var      teInfos = new List <TrackerEventInfo>();

            foreach (var item in items)
            {
                var teInfo = new TrackerEventInfo {
                    TrackerEvent = item
                };

                switch (item.EventName)
                {
                case TrackerEvents.Changed:
                case TrackerEvents.Created:
                    fi = new FileInfo(item.FullName);
                    if (fi.Length < sizeLimit)
                    {
                        try
                        {
                            GetContentFromFile(fi, item);

                            teInfo.IsContentInTrackerEvent = true;
                        } catch
                        {
                            continue;
                        }
                    }
                    else
                    {
                        var path = ArchivetedFile(item.Name, item.FullName);
                        if (!String.IsNullOrEmpty(path))
                        {
                            teInfo.IsContentInTrackerEvent = false;
                            teInfo.PathToContent           = path;
                        }
                    }
                    break;

                default:
                    teInfo.IsContentInTrackerEvent = true;

                    break;
                }

                teInfos.Add(teInfo);
            }
            lock (objLock) {
                TrackerEventInfo.AddRange(teInfos);
                SaveChanges();
            }
        }
コード例 #2
0
        public void RemoveAll()
        {
            lock (objLock) {
                RemoveRange(TrackerEvent.ToList());
                RemoveRange(TrackerEventInfo.ToList());

                SaveChanges();
            }
        }
コード例 #3
0
        public void AddDirEvent(TrackerEvent trackerEvent)
        {
            TrackerEventInfo dirEvent = new TrackerEventInfo()
            {
                IsContentInTrackerEvent = true,
                TrackerEvent            = trackerEvent,
            };

            lock (objLock)
            {
                TrackerEventInfo.Add(dirEvent);
                SaveChanges();
            }
        }
コード例 #4
0
        public bool SendTrackerEvents(Socket socket, ref bool isConnected)
        {
            List <TrackerEventInfo> teInfos;
            bool isNeedSendAgain = true;

            lock (objLock) {
                teInfos = TrackerEventInfo
                          .Include(te => te.TrackerEvent)
                          .Take(100)
                          .ToList();
            }

            if (teInfos == null || teInfos.Count == 0)
            {
                return(false);
            }
            if (teInfos.Count < 100)
            {
                isNeedSendAgain = false;
            }

            var listToDelete = new List <TrackerEventInfo>();

            foreach (var teInfo in teInfos)
            {
                try {
                    SocketHelper.SendItemToServer(teInfo.TrackerEvent, socket);

                    if (!teInfo.IsContentInTrackerEvent)
                    {
                        SocketHelper.SendZipArchive(socket, teInfo.PathToContent);
                        File.Delete(teInfo.PathToContent);
                    }

                    listToDelete.Add(teInfo);
                } catch {
                    isConnected     = false;
                    isNeedSendAgain = true;
                    break;
                }
            }

            RemoveList(listToDelete);
            return(isNeedSendAgain);
        }