Пример #1
0
        /// <summary>
        /// Initializes a new instance of the FileImageStore class.
        /// </summary>
        /// <param name="uri">The root URI (the root folder) of the image store.</param>
        /// <param name="localRoot">The default path for the file image store root.</param>
        /// <param name="accessDescription">Access rights to specific users or groups.</param>
        public FileImageStore(
            string uri,
            string localRoot = null,
            ImageStoreAccessDescription accessDescription = null)
        {
            if (uri == null)
            {
                throw new ArgumentException(StringResources.ImageStoreError_InvalidParameterSpecified, "uri");
            }

            this.localRoot         = localRoot;
            this.accessDescription = accessDescription;
            this.storeParams       = new FileProviderParameters(uri);

            if (!this.storeParams.RootUri.StartsWith(SchemeTag, StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, StringResources.ImageStoreError_InvalidImageStoreUriScheme, this.storeParams.RootUri));
            }

            this.rootUri = this.storeParams.RootUri.TrimStart().Substring(SchemeTag.Length).Trim();

#if !DotNetCoreClr
            using (WindowsImpersonationContext impersonationContext = this.GetImpersonationContext())
#endif
            {
                if (!FabricDirectory.Exists(this.rootUri))
                {
                    throw new DirectoryNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ImageStoreError_UnaccessibleImageStore, this.rootUri));
                }
            }
        }
Пример #2
0
        internal static IImageStore CreateImageStore(
            string imageStoreUri,
            string localRoot,
            string[] connectionStrings,
            SecurityCredentials credentials,
            string workingDirectory,
            bool isInternal)
        {
            if (imageStoreUri == null)
            {
                throw new ArgumentException(StringResources.Error_InvalidImageStoreConnectionString);
            }

            if (FileImageStore.IsFileStoreUri(imageStoreUri))
            {
                string rootUri;
                string accountName, accountPassword;
                bool   isManagedServiceAccount;

                ImageStoreFactory.ParseFileImageStoreConnectionString(
                    imageStoreUri,
                    out rootUri,
                    out accountName,
                    out accountPassword,
                    out isManagedServiceAccount);

                ImageStoreAccessDescription accessDescription = null;

#if !DotNetCoreClrLinux
                WindowsIdentity windowsIdentity = null;

                windowsIdentity = GetWindowsIdentity(accountName, accountPassword, isManagedServiceAccount);

                if (windowsIdentity != null)
                {
                    accessDescription = new ImageStoreAccessDescription(windowsIdentity, localRoot);
                }
#endif

                return(new FileImageStore(rootUri, localRoot, accessDescription));
            }
            else if (XStoreProxy.IsXStoreUri(imageStoreUri))
            {
                return(new XStoreProxy(imageStoreUri, localRoot));
            }
            else if (NativeImageStoreClient.IsNativeImageStoreUri(imageStoreUri))
            {
                return(new NativeImageStoreClient(connectionStrings, isInternal, workingDirectory, credentials));
            }
            else
            {
                throw new ArgumentException(StringResources.ImageStoreError_InvalidImageStoreUriScheme);
            }
        }