Esempio n. 1
0
 private static void DeleteByResolution(AppConfig config, FileInfo fi)
 {
     if (Helpers.IsImageFile(fi.FullName) && config.Width > 0 && config.Height > 0)
     {
         using (Image img = ImageHelpers.LoadImage(fi.FullName))
         {
             if (img == null && fi.Length < config.FileSize * 1024 ||
                 img != null && img.Width <= config.Width && img.Height <= config.Height)
             {
                 if (string.IsNullOrEmpty(config.RecycleBinPath))
                 {
                     FileSystem.DeleteFile(fi.FullName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                 }
                 else
                 {
                     FileSystem.MoveFile(fi.FullName, Helpers.GetUniqueFilePath(Path.Combine(config.RecycleBinPath, Path.GetFileName(fi.FullName))));
                 }
             }
             else if (img == null)
             {
                 FailedFiles.Add(fi);
             }
         }
     }
 }
Esempio n. 2
0
        private List <string> GetChangesetFiles(SvnClient svnClient, Changeset changeset)
        {
            List <string> filePaths;

            filePaths = new List <string>();

            foreach (ChangesetFileInfo fileInfo in changeset.Files)
            {
                VSSItem versionItem;
                string  filePath;

                //get version item to get the version of the file
                versionItem = fileInfo.VssFile.get_Version(fileInfo.VssVersion.VersionNumber);

                //get the version of the file in question and saves it to the path
                filePath = fileInfo.FilePath;

                try
                {
                    versionItem.Get(ref filePath, (int)(VSSFlags.VSSFLAG_USERRONO | VSSFlags.VSSFLAG_TIMEMOD));
                }
                catch (COMException ex)
                {
                    // skip if the file couldn't obtained - one of my databases seems to be corrupt and I can't access some files
                    if (!FailedFiles.Contains(fileInfo.FilePath))
                    {
                        FailedFiles.Add(fileInfo.FilePath);
                    }

                    this.OnLog(new LogEventArgs(ex, string.Format("Could not get version {0} of {1}", fileInfo.VssVersion.VersionNumber, fileInfo.VssFile.Spec)));
                }

                if (File.Exists(fileInfo.FilePath))
                {
                    // remove VSS bindings
                    //if (this.RemoveVssBindings) <--- always remove VSS bindings from solution
                    VssBindingRemover.RemoveBindings(fileInfo.FilePath);

                    //add the file to SVN if it's not there yet
                    if (fileInfo.IsAdd || FailedFiles.Contains(fileInfo.FilePath))
                    {
                        try
                        {
                            svnClient.Add(fileInfo.FilePath);
                            this.FailedFiles.Remove(fileInfo.FilePath); // remove from the final failed files collection
                        }
                        catch (SvnEntryException ex)
                        {
                            this.LogException(ex);
                        }
                    }

                    filePaths.Add(fileInfo.FilePath);
                }
            }

            return(filePaths);
        }
Esempio n. 3
0
        private long ProcessFileSize(HttpWebResponse webResp, out string filePath)
        {
            long length = 0;

            filePath = null;
            Stream       receiveStream = webResp.GetResponseStream();
            Encoding     encode        = System.Text.Encoding.GetEncoding("utf-8");
            StreamReader readStream    = new StreamReader(receiveStream, encode);

            Char[] read = new Char[webResp.ContentLength];
            readStream.Read(read, 0, (int)webResp.ContentLength);

            string file = new string(read, 0, (int)webResp.ContentLength);

            if (file.Contains("PATH"))
            {
                file = file.Substring(5, file.Length - 5); //Removing PATH: from the output

                try
                {
                    System.IO.FileInfo fInfo = new System.IO.FileInfo(file);
                    if (fInfo.Exists)
                    {
                        length   = fInfo.Length;
                        filePath = file;
                    }
                }
                catch (Exception ex)
                {
                    WriteToLog(file, ex);
                }
            }
            else
            {
                int    position = webResp.ResponseUri.PathAndQuery.IndexOf(".pdb");
                string fileName = webResp.ResponseUri.PathAndQuery.Substring(1, position + 3);
                if (!FailedFiles.ContainsKey(fileName))
                {
                    FailedFiles.Add(fileName, " - No matching PDBs found - " + file);
                }
            }

            return(length);
        }
Esempio n. 4
0
        private void downloadFile(Int32 fileNr)
        {
            bool headVerb = false;

            m_currentFileSize = 0;
            bool fileptr = false;

            fireEventFromBgw(Event.FileDownloadAttempting);

            FileInfo file = this.Files[fileNr];

            Int64 size = 0;

            Byte[] readBytes = new Byte[this.PackageSize];
            Int32  currentPackageSize;

            System.Diagnostics.Stopwatch speedTimer = new System.Diagnostics.Stopwatch();
            Int32     readings = 0;
            Exception exc      = null;

            FileStream writer;
            string     dirPath     = DownloadLocation + "\\" + file.Name + "\\" + file.PdbGuid;
            string     downloadUrl = this.Files[fileNr].Path;

            HttpWebRequest  webReq;
            HttpWebResponse webResp = null;

            try
            {
                webReq           = (HttpWebRequest)System.Net.WebRequest.Create(downloadUrl);
                webReq.UserAgent = Constants.SymbolServer;
                webResp          = (HttpWebResponse)webReq.GetResponseNoException();
                if (webResp.StatusCode == HttpStatusCode.NotFound)
                {
                    webResp = Retry(fileNr, headVerb);

                    if (webResp.StatusCode == HttpStatusCode.OK)
                    {
                        file.IsCompressed = true;
                        size = webResp.ContentLength;
                    }

                    if (webResp.StatusCode == HttpStatusCode.NotFound)
                    {
                        webResp = RetryFilePointer(fileNr);
                        fileptr = true;
                    }

                    if (webResp.StatusCode != HttpStatusCode.OK)
                    {
                        if (!FailedFiles.ContainsKey(file.Name))
                        {
                            FailedFiles.Add(file.Name, " - " + webResp.StatusCode + "  " + webResp.StatusDescription);
                        }
                    }
                }
                else if (webResp.StatusCode == HttpStatusCode.OK)
                {
                    size = webResp.ContentLength;
                }
            }
            catch (Exception ex)
            {
                exc = ex;
                WriteToLog(file.Name, exc);
            }
            if (webResp.StatusCode == HttpStatusCode.OK)
            {
                Directory.CreateDirectory(dirPath);

                if (fileptr)
                {
                    string filePath = dirPath + "\\" +
                                      file.Name;
                    string     srcFile = null;
                    FileStream reader;
                    size = ProcessFileSize(webResp, out srcFile);
                    m_currentFileSize = size;

                    if (srcFile != null)
                    {
                        reader = new FileStream(srcFile, FileMode.Open, FileAccess.Read);
                        writer = new FileStream(filePath,
                                                System.IO.FileMode.Create);

                        //   DownloadFile(srcFile, filePath);
                        fireEventFromBgw(Event.FileDownloadStarted);
                        m_currentFileProgress = 0;
                        while (m_currentFileProgress < size && !bgwDownloader.CancellationPending)
                        {
                            while (this.IsPaused)
                            {
                                System.Threading.Thread.Sleep(100);
                            }

                            speedTimer.Start();

                            currentPackageSize = reader.Read(readBytes, 0, this.PackageSize);

                            m_currentFileProgress += currentPackageSize;
                            m_totalProgress       += currentPackageSize;
                            fireEventFromBgw(Event.ProgressChanged);

                            writer.Write(readBytes, 0, currentPackageSize);
                            readings += 1;

                            if (readings >= this.StopWatchCyclesAmount)
                            {
                                m_currentSpeed = (Int32)(this.PackageSize * StopWatchCyclesAmount * 1000 / (speedTimer.ElapsedMilliseconds + 1));
                                speedTimer.Reset();
                                readings = 0;
                            }
                        }
                        reader.Close();
                        writer.Close();
                        speedTimer.Stop();
                        //end
                    }
                }
                else
                {
                    m_currentFileSize = size;
                    //string name;
                    if (file.IsCompressed)
                    {
                        file.Name = ProbeWithUnderscore(file.Name);
                    }
                    string filePath = dirPath + "\\" +
                                      file.Name;
                    writer = new FileStream(filePath,
                                            System.IO.FileMode.Create);

                    if (exc != null)
                    {
                        bgwDownloader.ReportProgress((Int32)InvokeType.FileDownloadFailedRaiser, exc);
                    }
                    else
                    {
                        m_currentFileProgress = 0;
                        while (m_currentFileProgress < size && !bgwDownloader.CancellationPending)
                        {
                            while (this.IsPaused)
                            {
                                System.Threading.Thread.Sleep(100);
                            }

                            speedTimer.Start();

                            currentPackageSize = webResp.GetResponseStream().Read(readBytes, 0, this.PackageSize);

                            m_currentFileProgress += currentPackageSize;
                            m_totalProgress       += currentPackageSize;
                            fireEventFromBgw(Event.ProgressChanged);

                            writer.Write(readBytes, 0, currentPackageSize);
                            readings += 1;

                            if (readings >= this.StopWatchCyclesAmount)
                            {
                                m_currentSpeed = (Int32)(this.PackageSize * StopWatchCyclesAmount * 1000 / (speedTimer.ElapsedMilliseconds + 1));
                                speedTimer.Reset();
                                readings = 0;
                            }
                        }

                        speedTimer.Stop();
                        writer.Close();

                        webResp.Close();
                        if (file.IsCompressed)
                        {
                            HandleCompression(filePath);
                        }
                    }
                    if (!bgwDownloader.CancellationPending)
                    {
                        fireEventFromBgw(Event.FileDownloadSucceeded);
                    }
                }
            }
            fireEventFromBgw(Event.FileDownloadStopped);
        }