} // EnsureDriveIsRooted

        static private ErrorRecord CreateErrorRecord(string path,
                                              CertificateProviderItem itemType)
        {
            Exception e = null;
            string message = null;

            //
            // first, find the resource-id so that we can display
            // correct message
            //
            switch (itemType)
            {
                case CertificateProviderItem.Certificate:
                    message = CertificateProviderStrings.CertificateNotFound;
                    break;

                case CertificateProviderItem.Store:
                    message = CertificateProviderStrings.CertificateStoreNotFound;
                    break;

                case CertificateProviderItem.StoreLocation:
                    message = CertificateProviderStrings.CertificateStoreLocationNotFound;
                    break;

                default:
                    message = CertificateProviderStrings.InvalidPath;
                    break;
            }

            message = String.Format(
                System.Globalization.CultureInfo.CurrentCulture,
                message, path);
            ErrorDetails ed = new ErrorDetails(message);

            //
            // create appropriate exception type
            //
            switch (itemType)
            {
                case CertificateProviderItem.Certificate:
                    e = new CertificateNotFoundException(message);
                    break;

                case CertificateProviderItem.Store:
                    e = new CertificateStoreNotFoundException(message);
                    break;

                case CertificateProviderItem.StoreLocation:
                    e = new CertificateStoreLocationNotFoundException(message);
                    break;

                default:
                    e = new ArgumentException(message);
                    break;
            }

            ErrorRecord er =
                new ErrorRecord(e,
                                "CertProviderItemNotFound",
                                ErrorCategory.ObjectNotFound,
                                null);

            er.ErrorDetails = ed;

            return er;
        }
Beispiel #2
0
		private static ErrorRecord CreateErrorRecord(string path, CertificateProviderItem itemType)
		{
			Exception certificateNotFoundException = null;
			string certificateNotFound = null;
			CertificateProviderItem certificateProviderItem = itemType;
			switch (certificateProviderItem)
			{
				case CertificateProviderItem.Certificate:
				{
					certificateNotFound = CertificateProviderStrings.CertificateNotFound;
					break;
				}
				case CertificateProviderItem.Store:
				{
					certificateNotFound = CertificateProviderStrings.CertificateStoreNotFound;
					break;
				}
				case CertificateProviderItem.StoreLocation:
				{
					certificateNotFound = CertificateProviderStrings.CertificateStoreLocationNotFound;
					break;
				}
				default:
				{
					certificateNotFound = CertificateProviderStrings.InvalidPath;
					break;
				}
			}
			object[] objArray = new object[1];
			objArray[0] = path;
			certificateNotFound = string.Format(CultureInfo.CurrentCulture, certificateNotFound, objArray);
			ErrorDetails errorDetail = new ErrorDetails(certificateNotFound);
			CertificateProviderItem certificateProviderItem1 = itemType;
			switch (certificateProviderItem1)
			{
				case CertificateProviderItem.Certificate:
				{
					certificateNotFoundException = new CertificateNotFoundException(certificateNotFound);
					break;
				}
				case CertificateProviderItem.Store:
				{
					certificateNotFoundException = new CertificateStoreNotFoundException(certificateNotFound);
					break;
				}
				case CertificateProviderItem.StoreLocation:
				{
					certificateNotFoundException = new CertificateStoreLocationNotFoundException(certificateNotFound);
					break;
				}
				default:
				{
					certificateNotFoundException = new ArgumentException(certificateNotFound);
					break;
				}
			}
			ErrorRecord errorRecord = new ErrorRecord(certificateNotFoundException, "CertProviderItemNotFound", ErrorCategory.ObjectNotFound, null);
			errorRecord.ErrorDetails = errorDetail;
			return errorRecord;
		}