Exemplo n.º 1
0
        private static unsafe ImageStoreContent FromNativeContent(IntPtr nativePtr)
        {
            NativeImageStore.FABRIC_IMAGE_STORE_CONTENT_QUERY_RESULT *casted = (NativeImageStore.FABRIC_IMAGE_STORE_CONTENT_QUERY_RESULT *)nativePtr;
            var managed = new ImageStoreContent();

            managed.CreateFromNative(casted);
            return(managed);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the image store content information including all files and subfolders
        /// </summary>
        /// <param name="storeSource">The relative path to file or folder from image store root</param>
        /// <param name="isRecursive">flag list subhierarchy</param>
        /// <param name="timeout">The timeout for performing the listing operation</param>
        /// <returns>ImageStoreContent object including files and subfolders</returns>
        public ImageStoreContent ListContentWithDetails(string storeSource, bool isRecursive, TimeSpan timeout)
        {
            ImageStoreContent content = null;

            try
            {
                string smbTag = this.ConvertTagToSMBPath(storeSource);
                if (!FabricDirectory.Exists(smbTag))
                {
                    if (FabricFile.Exists(smbTag))
                    {
                        var fullSourcePath = FabricPath.GetFullPath(storeSource);
                        content = new ImageStoreContent()
                        {
                            Files = new List <ImageStoreFile>()
                            {
                                this.ConvertToImageStoreFile(fullSourcePath, storeSource)
                            }
                        };
                    }
                    else
                    {
                        TraceSource.WriteWarning(
                            TraceType,
                            "Directory/File {0} doesn't exist",
                            smbTag);
                    }
                }
                else
                {
                    content = isRecursive
                        ? new ImageStoreContent()
                    {
                        Files = this.GetAllFiles(smbTag, storeSource).ToList()
                    }
                        : this.GetFilesAndSubFolders(smbTag, storeSource, timeout);
                }
            }
            catch (IOException exception)
            {
                if (exception.GetType() == typeof(IOException))
                {
                    throw new FabricImageStoreException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_ImageStoreIOException, exception));
                }
                else
                {
                    throw;
                }
            }

            return(content);
        }
Exemplo n.º 3
0
        private ImageStoreContent GetFilesAndSubFolders(string directory, string storeSource, TimeSpan timeout)
        {
            TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout);

            var directoryFullNames = FabricDirectory.GetDirectories(directory);
            var fileFullNames      = FabricDirectory.GetFiles(directory);

            var content = new ImageStoreContent();

            foreach (var fileFullName in fileFullNames)
            {
                if (content.Files == null)
                {
                    content.Files = new List <ImageStoreFile>();
                }

                content.Files.Add(this.ConvertToImageStoreFile(fileFullName, storeSource));

                if (helper != null)
                {
                    helper.ThrowIfExpired();
                }
            }

            foreach (var directoryFullName in directoryFullNames)
            {
                if (content.Folders == null)
                {
                    content.Folders = new List <ImageStoreFolder>();
                }

                content.Folders.Add(new ImageStoreFolder(
                                        this.GetStoreRelativePathFromFullName(directoryFullName, storeSource),
                                        this.GetFileCount(directoryFullName)));

                if (helper != null)
                {
                    helper.ThrowIfExpired();
                }
            }

            return(content);
        }