Beispiel #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);
             }
         }
     }
 }
Beispiel #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);
        }
        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);
        }
Beispiel #4
0
 public static void Clear()
 {
     Files.Clear();
     FailedFiles.Clear();
     Folders.Clear();
 }
Beispiel #5
0
        /// <summary>
        /// Match source and destination files than copy.
        /// </summary>
        /// <param name="source">Source path</param>
        /// <param name="destination">Destination path</param>
        /// <param name="delay">Synchronization speed</param>
        /// <returns></returns>
        public static bool SynchronizeFiles(string source, string destination, int delay)
        {
            try
            {
                #region DEBUGMESSAGE
#if DEBUG
                Tools.LogWriter("Preparing files.", Tools.CreateFolderName(source));
#endif
                #endregion
                destination = CreateDestinationFolder(source, destination);

                FoldersAndFiles sFoldersAndFiles = new FoldersAndFiles();
                FoldersAndFiles dFoldersAndFiles = new FoldersAndFiles();

                if (!ListEveryFileForEachFolder(source, ref sFoldersAndFiles, delay))
                {
                    #region DEBUG  //Write fail
#if DEBUG
                    Tools.LogWriter("List source folders/files method fail.", Tools.CreateFolderName(source));
                    Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
                    #endregion
                    return(false);
                }
                if (!ListEveryFileForEachFolder(destination, ref dFoldersAndFiles, delay))
                {
                    #region DEBUG  //Write fail
#if DEBUG
                    Tools.LogWriter("List destination folders/files method fail.", Tools.CreateFolderName(source));
                    Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
                    #endregion
                    return(false);
                }

                #region DEBUG  //Write folder and files count
#if DEBUG
                Tools.LogWriter("source : " + sFoldersAndFiles.FolderCount + " folder\t" + sFoldersAndFiles.FileCount + " files", Tools.CreateFolderName(source));
                Tools.LogWriter("destin : " + dFoldersAndFiles.FolderCount + " folder\t" + dFoldersAndFiles.FileCount + " files", Tools.CreateFolderName(source));
#endif
                #endregion

                if (!CompareSourceAndDestination(ref sFoldersAndFiles, ref dFoldersAndFiles, source, destination, delay))
                {
                    #region DEBUG  //Write fail
#if DEBUG
                    Tools.LogWriter("CompareSourceAndDestination method fail.", Tools.CreateFolderName(source));
                    Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
                    #endregion
                    return(false);
                }
                dFoldersAndFiles.Dispose();

                #region DEBUG  //Write matched and Unmatched files list
#if DEBUG
                if (sFoldersAndFiles.FileCount > 0 || sFoldersAndFiles.FolderCount > 0)
                {
                    Tools.LogWriter("***************   Folders were not matched   *************", Tools.CreateFolderName(source));
                    Tools.LogWriter("This files will change :  ***", Tools.CreateFolderName(source));
                    foreach (var folder in sFoldersAndFiles.Key)
                    {
                        Tools.LogWriter("\t" + folder, Tools.CreateFolderName(source));
                        foreach (var file in sFoldersAndFiles.GetValue(folder))
                        {
                            Tools.LogWriter("\t\t" + file, Tools.CreateFolderName(source));
                        }
                    }
                    Tools.LogWriter("***********************   END   ***********************", Tools.CreateFolderName(source));
                }
                else
                {
                    Tools.LogWriter("***************   Folders were matched   *************", Tools.CreateFolderName(source));
                }
#endif
                #endregion

                if (!CreateFolders(sFoldersAndFiles.GetKeys(), source, destination))
                {
                    #region DEBUG  //Write fail
#if DEBUG
                    Tools.LogWriter("Create folders method fail.", Tools.CreateFolderName(source));
                    Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
                    #endregion
                    return(false);
                }

                if (!CopyFiles(ref sFoldersAndFiles, source, destination))
                {
                    #region DEBUG  //Write fail
#if DEBUG
                    Tools.LogWriter("CreateFiles method fail.", Tools.CreateFolderName(source));
                    Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
                    #endregion
                    return(false);
                }

                #region DEBUG   //Write list of file that can not be copied
#if DEBUG
                if (sFoldersAndFiles.Key.Count > 0)
                {
                    foreach (var folder in sFoldersAndFiles.Key)
                    {
                        Tools.LogWriter("\t" + folder, Tools.CreateFolderName(source));
                        foreach (var file in sFoldersAndFiles.GetValue(folder))
                        {
                            Tools.LogWriter("\t\t" + file, Tools.CreateFolderName(source));
                        }
                    }
                }
#endif
                #endregion

                FailedFiles ffiles = new FailedFiles(sFoldersAndFiles.Value);
                sFoldersAndFiles.Dispose();
                #region DEBUG  //Write successful
#if DEBUG
                Tools.LogWriter("Synchronization completed successfully.", Tools.CreateFolderName(source));
                Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
                #endregion
                pBar.ProgressbarText  = "Synchronization completed successfully";
                pBar.ProgressbarValue = 100;
                return(true);
            }
            catch (Exception ex)
            {
                Tools.ErrorWriter(ex);
            }

            #region DEBUG  //Write fail
#if DEBUG
            Tools.LogWriter("SynchronizeFiles method fail.", Tools.CreateFolderName(source));
            Tools.LogWriter("************************************************************************************************************", Tools.CreateFolderName(source));
#endif
            #endregion
            return(false);
        }
        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);
        }