Пример #1
0
        private void StartDirectoryWatch()
        {
            exportFolderWatcherTimer = new System.Threading.Timer(o =>
            {
                lock (tempLockObject)
                {
                    try
                    {
                        if (!ExchangeServiceProvider.CookieExist())
                        {
                            return;
                        }

                        var newFiles = new DirectoryInfo(directoryPath).GetFiles("*").Where(p => !p.Extension.Contains(".tmp")).ToList();

                        if (newFiles.Any())
                        {
                            var infos = newFiles.Select(p => new FileInformation()
                            {
                                FullName = p.FullName,
                                Name     = p.Name,
                                Content  = File.ReadAllBytes(p.FullName),
                                TempPath = Path.ChangeExtension(p.FullName, $"{p.Extension}.{Guid.NewGuid().ToString().Replace("-", string.Empty)}.tmp")
                            }).ToList();

                            while (infos.Sum(p => p.Content.Length) > 25165824)
                            {
                                infos = infos.OrderByDescending(p => p.Content.Length).Skip(1).ToList();
                            }

                            infos.ForEach(file =>
                            {
                                try
                                {
                                    File.Move(file.FullName, file.TempPath);
                                }
                                catch (Exception ex)
                                { }
                            });

                            ExportFilesOnCreated(infos);
                        }
                    }
                    catch (Exception ex)
                    { }
                }
            }, null, 0, 100);

            cookieTimer = new System.Threading.Timer(o =>
            {
                if (!ExchangeServiceProvider.CookieExist() || ExchangeServiceProvider.IsInProgress())
                {
                    return;
                }

                ExchangeServiceProvider.ConnectionTest();
            }, null, 0, 5 * 60 * 1000);
        }
Пример #2
0
 public IHttpActionResult Progress(LoginModel model)
 {
     return(Ok(ExchangeServiceProvider.IsInProgress()));
 }