예제 #1
0
        internal void OutputStoreFolderInfo(ImageStoreFolder folderInfo)
        {
            var folderPSObj = new PSObject();

            folderPSObj.Properties.Add(new PSNoteProperty(Constants.StoreRelativePathPropertyName, folderInfo.StoreRelativePath));
            folderPSObj.Properties.Add(new PSNoteProperty("Type", string.Format("Folder [{0} files]", folderInfo.FileCount.ToString())));
            this.OutputVersionInfo(folderInfo.VersionInfo, folderPSObj);
            this.WriteObject(folderPSObj, true);
        }
예제 #2
0
 public void SetData(ImageStoreFile file, ImageStoreFolder folder, string extensionName)
 {
     FileId         = file.Id;
     ExtensionName  = extensionName;
     FolderName     = folder.Name;
     FolderIsSealed = folder.IsSealed;
     if (extensionName == "")
     {
         FileNameWithExtension = file.FileName;
     }
     else
     {
         FileNameWithExtension = file.FileName + "." + extensionName;
     }
     if (file.Path == "")
     {
         PathToDirectory = folder.Path;
         if (folder.Path.EndsWith(DirectorySeparatorString.Value))
         {
             FilePath = folder.Path + FileNameWithExtension;
         }
         else
         {
             FilePath = folder.Path + DirectorySeparatorString.Value + FileNameWithExtension;
         }
     }
     else
     {
         if (folder.Path.EndsWith(DirectorySeparatorString.Value))
         {
             PathToDirectory = folder.Path + file.Path;
         }
         else
         {
             PathToDirectory = folder.Path + DirectorySeparatorString.Value + file.Path;
         }
         FilePath = PathToDirectory + DirectorySeparatorString.Value + FileNameWithExtension;
     }
     FileSize = file.FileSize;
 }
예제 #3
0
        int Compute(ImageStoreFolder folder, int?limit, bool remeasuringDisabled, bool remeasuringComputed, bool remeasuringNotImage, bool remeasuringNotReadable, bool remeasuringSizeZero)
        {
            WriteInformation("Measuring folder: " + folder.Name, new string[] { "MeasureFiles", "MeasureFolder" });

            //get records from database
            //path, isImage, id, isNew
            files = new List <Tuple <string, bool, Guid, bool> >();
            string baseFolder = folder.Path;

            if (!baseFolder.EndsWith(DirectorySeparatorString.Value))
            {
                baseFolder += DirectorySeparatorString.Value;
            }

            WriteVerbose("Reading records from database...");

            foreach (var file in FileHelper.GetAllFilesWithoutData(folder.Id, limit,
                                                                   remeasuringDisabled,
                                                                   remeasuringComputed,
                                                                   remeasuringNotImage,
                                                                   remeasuringNotReadable,
                                                                   remeasuringSizeZero))
            {
                var extension = extensionsById[file.ExtensionId];
                if (extension.Ignored)
                {
                    continue;
                }

                string fullPath = FileHelper.GetFullFilePath(baseFolder, file.Path, file.FileName, extension.Extension);

                files.Add(new Tuple <string, bool, Guid, bool>(fullPath, extension.IsImage, file.Id, file.FileState == FileState.New));
            }

            filesCount       = files.Count;
            filesCountSingle = filesCount;
            filesCountText   = files.Count.ToString();
            if (filesCount == 0)
            {
                files = null;
                WriteVerbose("Nothing to be measuring in this folder.");
                return(0);
            }
            else if (filesCount == 1)
            {
                WriteVerbose("One record is read from database.");
            }
            else
            {
                WriteVerbose(filesCountText + " records are read from database.");
            }

            WriteVerbose("Starting measuring...");

            outputs = new BlockingCollection <Tuple <int, string> >();

            finishedCount = 0;

            Thread writing = new Thread(WriteDatabase);

            using (var measuring = new Task(ComputeAll, TaskCreationOptions.LongRunning))
                using (toWrite = new BlockingCollection <Tuple <Guid, byte[], byte[], int, FileState, bool> >())
                {
                    writing.Start();
                    measuring.Start();

                    while (true)
                    {
                        try
                        {
                            var itemToDisplay = outputs.Take();
                            if (itemToDisplay.Item1 == 2)
                            {
                                //Other exception
                                WriteWarning(itemToDisplay.Item2);
                            }
                            else
                            {
                                if (itemToDisplay.Item1 == 0)
                                {
                                    //file finished
                                    WriteVerbose(itemToDisplay.Item2);
                                }
                                else //1
                                {
                                    //file failed
                                    WriteWarning(itemToDisplay.Item2);
                                }
                            }
                        }
                        catch (InvalidOperationException) { break; }
                    }

                    measuring.Wait();
                    writing.Join();
                }
            toWrite.Dispose();
            toWrite = null;
            outputs.Dispose();
            outputs = null;
            files   = null;

            return(filesCount);
        }