Beispiel #1
0
        public void ReadInbox(NanoDB to)
        {
            if (_isReading)
            {
                return;
            }
            _isReading = true;

            if (Directory.Exists(Strings.Download))
            {
                string[] files = Directory.GetFiles(Strings.Download);

                foreach (string f in files)
                {
                    string pathToPng = f;
                    byte[] packed    = null;

                    try
                    {
                        packed = new PngStegoUtil().ReadHiddenBytesFromPng(pathToPng);
                        GC.Collect();
                    }
                    catch
                    {
                        // invalid container
                    }

                    NanoPost[] posts = null;

                    try
                    {
                        posts = NanoPostPackUtil.Unpack(packed);
                    }
                    catch
                    {
                        // inavlid container
                    }

                    bool any = false;

                    if (posts != null)
                    {
                        foreach (var p in posts)
                        {
                            any |= to.AddPost(p);
                        }
                    }

                    if (any)
                    {
                        NotificationHandler.Instance.AddNotification("Извлечены новые сообщения.");
                        to.WriteNewPosts(false);
                    }
                }

                try
                {
                    foreach (string f in files)
                    {
                        File.Delete(f);
                    }
                }
                catch
                {
                }
            }

            _isReading = false;
        }
Beispiel #2
0
        public void ReadInbox(NanoDB to)
        {
            if (_isReading) return;
            _isReading = true;

            if (Directory.Exists(Strings.Download))
            {
                string[] files = Directory.GetFiles(Strings.Download);

                foreach (string f in files)
                {
                    string pathToPng = f;
                    byte[] packed = null;

                    try
                    {
                        packed = new PngStegoUtil().ReadHiddenBytesFromPng(pathToPng);
                        GC.Collect();
                    }
                    catch
                    {
                        // invalid container
                    }

                    NanoPost[] posts = null;

                    try
                    {
                        posts = NanoPostPackUtil.Unpack(packed);
                    }
                    catch
                    {
                        // inavlid container
                    }

                    bool any = false;

                    if (posts != null)
                    {
                        foreach (var p in posts)
                        {
                            any |= to.AddPost(p);
                        }
                    }

                    if (any)
                    {
                        NotificationHandler.Instance.AddNotification("Извлечены новые сообщения.");
                        to.WriteNewPosts(false);
                    }
                }

                try
                {
                    foreach (string f in files)
                    {
                        File.Delete(f);
                    }
                }
                catch
                {
                }
            }

            _isReading = false;
        }