コード例 #1
0
        public async Task <T> GetFromStoreAsync <T>(string tag, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Downloading {0} from store async.",
                tag);

            string tempFileName = ImageBuilderUtility.GetTempFileName(this.localImageBuilderRoot);

            try
            {
                bool doesExist = await this.ImageStore.DoesContentExistAsync(tag, timeoutHelper.GetRemainingTime());

                if (doesExist)
                {
                    await this.ImageStore.DownloadContentAsync(tag, tempFileName, timeoutHelper.GetRemainingTime(), CopyFlag.AtomicCopy);

                    ImageBuilderUtility.RemoveReadOnlyFlag(tempFileName);
                    return(ImageBuilderUtility.ReadXml <T>(tempFileName));
                }
                else
                {
                    throw new FileNotFoundException(
                              string.Format(CultureInfo.CurrentCulture, StringResources.ImageStoreError_FileNotFound, tag));
                }
            }
            finally
            {
                ImageBuilderUtility.DeleteTempLocation(tempFileName);
            }
        }
コード例 #2
0
        private void WriteProgressStatus(string status)
        {
            lock (this.updateLock)
            {
                if (this.isUpdating)
                {
                    return;
                }
                else
                {
                    this.isUpdating = true;
                }
            }

            // Only write out new progress information after
            // CM has consumed the previous progress information file
            //
            if (!File.Exists(this.progressFileName))
            {
                var tmpFileName = string.Format("{0}.tmp", this.progressFileName);

                ImageBuilderUtility.WriteStringToFile(tmpFileName, status, false, Encoding.Unicode);

                File.Move(tmpFileName, this.progressFileName);
            }

            lock (this.updateLock)
            {
                this.isUpdating = false;
            }
        }
コード例 #3
0
        public async Task SetToStoreAsync <T>(string tag, T value, TimeSpan timeout, bool shouldOverwrite = true)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Uploading {0} to store. ShouldOverwrite: {1}.",
                tag,
                shouldOverwrite);

            if (!shouldOverwrite &&
                await this.ImageStore.DoesContentExistAsync(tag, timeoutHelper.GetRemainingTime()))
            {
                return;
            }

            string tempFileName = ImageBuilderUtility.GetTempFileName(this.localImageBuilderRoot);

            try
            {
                ImageBuilderUtility.WriteXml <T>(tempFileName, value);
                await this.ImageStore.UploadContentAsync(tag, tempFileName, timeoutHelper.GetRemainingTime(), CopyFlag.AtomicCopy, false /*acquireSourceLock*/);
            }
            finally
            {
                ImageBuilderUtility.DeleteTempLocation(tempFileName);
            }
        }
コード例 #4
0
        private static string GetProductVersionFromFilename(string codePath, string expectedFileSuffix)
        {
            string fileName = Path.GetFileName(codePath);

            string[] firstTokens = fileName.Split('_');
            if (firstTokens.Length != 2 || !ImageBuilderUtility.Equals(firstTokens[0], StringConstants.ServiceFabric))
            {
                ThrowInvalidCodeUpgradeFileName(fileName);
            }

            string[] secondTokens = firstTokens[1].Split('.');
            if (secondTokens.Length != 5 || !ImageBuilderUtility.Equals(secondTokens[4], expectedFileSuffix))
            {
                ThrowInvalidCodeUpgradeFileName(fileName);
            }

            for (int i = 0; i < secondTokens.Length - 1; i++)
            {
                int value;
                if (!int.TryParse(secondTokens[i], out value))
                {
                    ThrowInvalidCodeUpgradeFileName(fileName);
                }
            }

            return(string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", secondTokens[0], secondTokens[1], secondTokens[2], secondTokens[3]));
        }
コード例 #5
0
 private void ValidateFileStorePath(FileStoreType fileStore, string source)
 {
     if (!this.ShouldValidate(fileStore.Path))
     {
         return;
     }
     if (String.IsNullOrEmpty(fileStore.Path))
     {
         ImageBuilderUtility.TraceAndThrowValidationError(
             TraceType,
             StringResources.ImageBuilderError_DiagnosticValidator_EmptyFilePathNotAllowed,
             source,
             FileStore,
             FileStorePath);
     }
     try
     {
         Uri uri = new Uri(fileStore.Path);
     }
     catch (Exception e)
     {
         ImageBuilderUtility.TraceAndThrowValidationError(
             TraceType,
             StringResources.ImageBuilderError_DiagnosticValidator_PathNotValidUri,
             fileStore.Path,
             source,
             FileStore,
             FileStorePath,
             e);
     }
 }
コード例 #6
0
        private void ValidateAccountName(string value, string source, string destination, string elementName)
        {
            if (value == null)
            {
                return;
            }

            if (!this.ShouldValidate(value))
            {
                return;
            }

            if (!ImageBuilderUtility.IsValidAccountName(value))
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_DiagnosticValidator_InvalidAccountNameFormat,
                    value,
                    source,
                    (destination != null) ?
                    destination :
                    String.Empty,
                    elementName);
            }
        }
コード例 #7
0
 private void ValidateManagedServiceAccount(FileStoreType fileStore, string source)
 {
     if ((this.ShouldValidate(fileStore.Password)) &&
         (!String.IsNullOrEmpty(fileStore.Password)))
     {
         ImageBuilderUtility.TraceAndThrowValidationError(
             TraceType,
             StringResources.ImageBuilderError_DiagnosticValidator_PasswordAttributeInvalid,
             Password,
             AccountType,
             FileStoreAccessAccountType.ManagedServiceAccount,
             source,
             FileStore);
     }
     if ((this.ShouldValidate(fileStore.PasswordEncrypted)) &&
         (!String.IsNullOrEmpty(fileStore.PasswordEncrypted)))
     {
         ImageBuilderUtility.TraceAndThrowValidationError(
             TraceType,
             StringResources.ImageBuilderError_DiagnosticValidator_PasswordAttributeInvalid,
             PasswordEncrypted,
             AccountType,
             FileStoreAccessAccountType.ManagedServiceAccount,
             source,
             FileStore);
     }
     ValidateAccountName(fileStore.AccountName, source, FileStore, AccountName);
 }
コード例 #8
0
        private void ValidateLevelFilter(string value, string source, string destination, string elementName)
        {
            if (value == null)
            {
                return;
            }

            if (!this.ShouldValidate(value))
            {
                return;
            }

            ETWTraceLevel etwTraceLevel;

            if (!Enum.TryParse(value, true, out etwTraceLevel))
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_DiagnosticValidator_InvalidETWLevel,
                    value,
                    ETWTraceLevel.Error,
                    ETWTraceLevel.Warning,
                    ETWTraceLevel.Informational,
                    ETWTraceLevel.Verbose,
                    source,
                    (destination != null) ?
                    destination :
                    String.Empty,
                    elementName);
            }
        }
コード例 #9
0
        public void Add(string name)
        {
            if (this.hashSet.Contains(name))
            {
                if (string.IsNullOrEmpty(this.fileName))
                {
                    ImageBuilderUtility.TraceAndThrowValidationError(
                        TraceType,
                        StringResources.ImageBuilderError_DuplicateElementFound,
                        this.elementName,
                        this.propertyName,
                        name);
                }
                else
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        this.fileName,
                        StringResources.ImageBuilderError_DuplicateElementFound,
                        this.elementName,
                        this.propertyName,
                        name);
                }
            }

            this.hashSet.Add(name);
        }
コード例 #10
0
        public static void CompareAndFixTargetManifestVersionsForUpgrade(
            ApplicationManifestType currentApplicationManifest,
            ApplicationManifestType targetApplicationManifest,
            IList <ServiceManifestType> currentServiceManifests,
            ref IList <ServiceManifestType> targetServiceManifests)
        {
            // Service manifest imports that exist in both current and target.
            var targetServiceManifestImports = targetApplicationManifest.ServiceManifestImport;
            var commonServiceManifestImports = currentApplicationManifest.ServiceManifestImport.Where(
                ci => targetServiceManifestImports.Any(ti => ti.ServiceManifestRef.ServiceManifestName == ci.ServiceManifestRef.ServiceManifestName));

            List <ServiceManifestType> unchangedServiceManifests = new List <ServiceManifestType>();

            foreach (ApplicationManifestTypeServiceManifestImport currentManifestImport in commonServiceManifestImports)
            {
                var currentManifest = currentServiceManifests.FirstOrDefault(item => item.Name == currentManifestImport.ServiceManifestRef.ServiceManifestName);
                var targetManifest  = targetServiceManifests.FirstOrDefault(item => item.Name == currentManifestImport.ServiceManifestRef.ServiceManifestName);
                // TODO: would codepackage versions be different than manifest version?
                var currentManifestVersion = currentManifest.Version;
                var targetManifestVersion  = targetManifest.Version;

                var equal = ImageBuilderUtility.IsEqual <ServiceManifestType>(
                    ReplaceVersion(currentManifest, "0"), ReplaceVersion(targetManifest, "0"));

                ReplaceVersion(currentManifest, currentManifestVersion);
                ReplaceVersion(targetManifest, targetManifestVersion);
                if (equal)
                {
                    unchangedServiceManifests.Add(currentManifest);
                }
            }

            // Use the unchanged manifests.
            if (unchangedServiceManifests.Count() != 0)
            {
                List <ServiceManifestType> updatedTargetServiceManifests = new List <ServiceManifestType>();
                foreach (var manifest in targetServiceManifests)
                {
                    var unchangedManifest = unchangedServiceManifests.FirstOrDefault(item => item.Name == manifest.Name);
                    if (unchangedManifest != default(ServiceManifestType))
                    {
                        updatedTargetServiceManifests.Add(unchangedManifest);
                        for (int i = 0; i < targetApplicationManifest.ServiceManifestImport.Count(); ++i)
                        {
                            if (targetApplicationManifest.ServiceManifestImport[i].ServiceManifestRef.ServiceManifestName == manifest.Name)
                            {
                                targetApplicationManifest.ServiceManifestImport[i].ServiceManifestRef.ServiceManifestVersion = unchangedManifest.Version;
                                break;
                            }
                        }
                    }
                    else
                    {
                        updatedTargetServiceManifests.Add(manifest);
                    }
                }

                targetServiceManifests = updatedTargetServiceManifests;
            }
        }
コード例 #11
0
        private T ValidateType <T>(string value, string source, string destination, string elementName)
        {
            if (value == null)
            {
                return(default(T));
            }

            if (!this.ShouldValidate(value))
            {
                return(default(T));
            }

            T convertedValue = default(T);

            try
            {
                convertedValue = ImageBuilderUtility.ConvertString <T>(value);
            }
            catch (Exception)
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_DiagnosticValidator_ValueCannotBeConverted,
                    value,
                    typeof(T),
                    source,
                    (destination != null) ?
                    destination :
                    String.Empty,
                    elementName);
            }

            return(convertedValue);
        }
コード例 #12
0
        private void ValidatePositiveInteger(string value, string source, string destination, string elementName)
        {
            if (value == null)
            {
                return;
            }

            if (!this.ShouldValidate(value))
            {
                return;
            }

            int convertedValue = ValidateType <int>(value, source, destination, elementName);

            if (convertedValue <= 0)
            {
                ImageBuilderUtility.TraceAndThrowValidationError(
                    TraceType,
                    StringResources.ImageBuilderError_DiagnosticValidator_ValueMustBeGreaterThanZero,
                    value,
                    source,
                    (destination != null) ?
                    destination :
                    String.Empty,
                    elementName);
            }
        }
コード例 #13
0
        private void ValidateManageAssembly(string serviceManifestFileName, FileLocator fileLocator, string entryPointValue)
        {
            AssemblyName assemblyName = null;

            try
            {
                assemblyName = new AssemblyName(entryPointValue);
            }
            catch (Exception exception)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    exception,
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_InvalidValue,
                    "EntryPoint",
                    entryPointValue);
            }

            if (!fileLocator.AssemblyExists(assemblyName))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_EntryPointInvalidOrNotFound,
                    entryPointValue,
                    fileLocator.DirectoryOrArchivePath);
            }
        }
コード例 #14
0
        private void ValidateEntryPoint(string serviceManifestFileName, FileLocator fileLocator, DllHostEntryPointType entryPoint)
        {
            bool hasNative = false;

            foreach (var item in entryPoint.Items)
            {
                ManagedAssemblyType managedAssembly = item as ManagedAssemblyType;
                UnmanagedDllType    unmanagedDll    = item as UnmanagedDllType;

                hasNative = hasNative || unmanagedDll != null;

                if (unmanagedDll != null)
                {
                    this.ValidateEntryPointPath(serviceManifestFileName, fileLocator, unmanagedDll.Value.Trim());
                }
                else
                {
                    this.ValidateManageAssembly(serviceManifestFileName, fileLocator, managedAssembly.Value.Trim());
                }
            }

            if (hasNative && entryPoint.IsolationPolicy != DllHostEntryPointTypeIsolationPolicy.DedicatedProcess)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_InvalidIsolationPolicyForNativeDll);
            }
        }
コード例 #15
0
        public async Task <Tuple <T, bool> > TryGetFromStoreAsync <T>(string tag, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Downloading {0} from store.",
                tag);

            bool exists = false;
            T    value  = default(T);

            string tempFileName = ImageBuilderUtility.GetTempFileName(this.localImageBuilderRoot);

            try
            {
                if (await this.ImageStore.DoesContentExistAsync(tag, timeoutHelper.GetRemainingTime()))
                {
                    await this.ImageStore.DownloadContentAsync(tag, tempFileName, timeoutHelper.GetRemainingTime(), CopyFlag.AtomicCopy);

                    ImageBuilderUtility.RemoveReadOnlyFlag(tempFileName);
                    value  = ImageBuilderUtility.ReadXml <T>(tempFileName);
                    exists = true;
                }
            }
            finally
            {
                ImageBuilderUtility.DeleteTempLocation(tempFileName);
            }

            return(new Tuple <T, bool>(value, exists));
        }
コード例 #16
0
        public string TryGetFromStore(string tag, out bool exists, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            ImageBuilder.TraceSource.WriteInfo(
                TraceType,
                "Downloading {0} from store.",
                tag);

            exists = false;
            string value = null;

            string tempFileName = ImageBuilderUtility.GetTempFileName(this.localImageBuilderRoot);

            try
            {
                if (this.ImageStore.DoesContentExist(tag, timeoutHelper.GetRemainingTime()))
                {
                    this.ImageStore.DownloadContent(tag, tempFileName, timeoutHelper.GetRemainingTime(), CopyFlag.AtomicCopy);

                    ImageBuilderUtility.RemoveReadOnlyFlag(tempFileName);
                    value  = ImageBuilderUtility.ReadStringFromFile(tempFileName);
                    exists = true;
                }
            }
            finally
            {
                ImageBuilderUtility.DeleteTempLocation(tempFileName);
            }

            return(value);
        }
コード例 #17
0
        public static int?ValidateAsPositiveInteger(string value, string propertyName, IDictionary <string, string> parameters, string fileName)
        {
            int convertedValue;

            if (!IsValidParameter(value, propertyName, parameters, fileName))
            {
                convertedValue = ConvertProperty <int>(value, propertyName, fileName);
                if (convertedValue < 1)
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        fileName,
                        StringResources.ImageBuilderError_ValueMustBePositiveInt,
                        convertedValue,
                        propertyName);
                }
            }
            else
            {
                // Resource is specified as a parameter
                // Parse it from parameter list and get the value for the specified key
                string parameterName = value.Substring(1, value.Length - 2);
                convertedValue = ConvertProperty <int>(parameters[parameterName], propertyName, fileName);
                // Do not check and throw if convertedValue is less than 1 as application should be provisioned with default params
                // We shouldn't allow creation with incorect params
            }
            return(convertedValue);
        }
コード例 #18
0
        public static bool IsValidName(string name, bool isComposeDeployment = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            //When deployment type is not composed type but the name starts with "Compose_"
            if (!isComposeDeployment && name.StartsWith(StringConstants.ComposeDeploymentTypePrefix))
            {
                return(false);
            }

            if (name.Contains(StringConstants.DoubleDot))
            {
                return(false);
            }

            if (!ImageBuilderUtility.IsValidFileName(name))
            {
                return(false);
            }

            return(true);
        }
コード例 #19
0
        public static bool IsEqual <T>(T param1, T param2)
            where T : class
        {
            if (param1 == null && param2 == null)
            {
                return(true);
            }

            if (param1 == null || param2 == null)
            {
                return(false);
            }

            var serializer = new XmlSerializer(typeof(T));

            using (MemoryStream stream1 = new MemoryStream(), stream2 = new MemoryStream())
            {
                serializer.Serialize(stream1, param1);
                serializer.Serialize(stream2, param2);

                stream1.Seek(0, SeekOrigin.Begin);
                stream2.Seek(0, SeekOrigin.Begin);

                return(ImageBuilderUtility.Equals(new StreamReader(stream1).ReadToEnd(), new StreamReader(stream2).ReadToEnd()));
            }
        }
コード例 #20
0
        private bool IsOnDemandCodePackageActivationImapcted(
            ServicePackageTypeDigestedCodePackage[] currentDigestedCodePackages,
            ServicePackageTypeDigestedCodePackage[] targetDigestedCodePackages)
        {
            var currentHasActivatorCodePackage = this.HasActivatorCodePackage(
                currentDigestedCodePackages, out ServicePackageTypeDigestedCodePackage currentActivatorCodePackage);

            var targetHasActivatorCodePackage = this.HasActivatorCodePackage(
                targetDigestedCodePackages, out ServicePackageTypeDigestedCodePackage targetActivatorCodePackage);

            if (!currentHasActivatorCodePackage && !targetHasActivatorCodePackage)
            {
                return(false);
            }

            if (currentHasActivatorCodePackage != targetHasActivatorCodePackage ||
                ImageBuilderUtility.IsNotEqual(currentActivatorCodePackage, targetActivatorCodePackage) ||
                currentDigestedCodePackages.Length != targetDigestedCodePackages.Length ||
                this.CheckTargetContainsSource(currentDigestedCodePackages, targetDigestedCodePackages) == false ||
                this.CheckTargetContainsSource(targetDigestedCodePackages, currentDigestedCodePackages) == false)
            {
                return(true);
            }

            return(false);
        }
コード例 #21
0
 private static void ThrowInvalidCodeUpgradeFileName(string fileName)
 {
     ImageBuilderUtility.TraceAndThrowValidationError(
         FabricErrorCode.ImageBuilderInvalidMsiFile,
         TraceType,
         StringResources.ImageBuilderError_InvalidMSIFileName,
         fileName);
 }
コード例 #22
0
        private void IntializeTargetPackageWithCurrentRolloutVersion(ServicePackageType currentServicePackage, ServicePackageType targetServicePackage)
        {
            //Set target rolloutversion to current before comparison
            for (int i = 0; i < targetServicePackage.DigestedCodePackage.Length; i++)
            {
                ServicePackageTypeDigestedCodePackage targetDigestedCodePackage = targetServicePackage.DigestedCodePackage[i];

                ServicePackageTypeDigestedCodePackage matchingCurrentDigestedCodePackage = currentServicePackage.DigestedCodePackage.FirstOrDefault(
                    digestedCodePackage => ImageBuilderUtility.Equals(digestedCodePackage.CodePackage.Name, targetDigestedCodePackage.CodePackage.Name));

                if (matchingCurrentDigestedCodePackage != null)
                {
                    targetDigestedCodePackage.RolloutVersion = matchingCurrentDigestedCodePackage.RolloutVersion;
                }
            }

            //Set target rolloutversion for config to current before comparison
            if (targetServicePackage.DigestedConfigPackage != null)
            {
                foreach (ServicePackageTypeDigestedConfigPackage targetDigestedConfigPackage in targetServicePackage.DigestedConfigPackage)
                {
                    ServicePackageTypeDigestedConfigPackage matchingCurrentDigestedConfigPackage = null;
                    if (currentServicePackage.DigestedConfigPackage != null)
                    {
                        matchingCurrentDigestedConfigPackage = currentServicePackage.DigestedConfigPackage.FirstOrDefault(
                            digestedConfigPackage => ImageBuilderUtility.Equals(digestedConfigPackage.ConfigPackage.Name, targetDigestedConfigPackage.ConfigPackage.Name));

                        if (matchingCurrentDigestedConfigPackage != null)
                        {
                            targetDigestedConfigPackage.RolloutVersion = matchingCurrentDigestedConfigPackage.RolloutVersion;
                        }
                    }
                }
            }

            //Set RolloutVersion for matching data packages to be same as current
            if (targetServicePackage.DigestedDataPackage != null)
            {
                foreach (ServicePackageTypeDigestedDataPackage targetDigestedDataPackage in targetServicePackage.DigestedDataPackage)
                {
                    ServicePackageTypeDigestedDataPackage matchingCurrentDigestedDataPackage = null;
                    if (currentServicePackage.DigestedDataPackage != null)
                    {
                        matchingCurrentDigestedDataPackage = currentServicePackage.DigestedDataPackage.FirstOrDefault(
                            digestedDataPackage => ImageBuilderUtility.Equals(digestedDataPackage.DataPackage.Name, targetDigestedDataPackage.DataPackage.Name));

                        if (matchingCurrentDigestedDataPackage != null)
                        {
                            targetDigestedDataPackage.RolloutVersion = matchingCurrentDigestedDataPackage.RolloutVersion;
                        }
                    }
                }
            }
        }
コード例 #23
0
 public bool FileExists(string filePath)
 {
     if (isArchive)
     {
         return(ImageBuilderUtility.IsInArchive(this.DirectoryOrArchivePath, filePath));
     }
     else
     {
         return(FabricFile.Exists(Path.Combine(this.DirectoryOrArchivePath, filePath)));
     }
 }
コード例 #24
0
        public static bool IsEqual <T>(T[] param1, T[] param2)
            where T : class
        {
            bool isEqual = ImageBuilderUtility.IsArrayItemCountEqual <T>(param1, param2);

            for (int i = 0; isEqual && (param2 != null) && i < param2.Length; i++)
            {
                isEqual = ImageBuilderUtility.IsEqual <T>(param1[i], param2[i]);
            }

            return(isEqual);
        }
コード例 #25
0
        private void ValidateEntryPointPath(string serviceManifestFileName, FileLocator fileLocator, string program, bool isExternalExecutable = false)
        {
            string entryPointPath = this.GetEntryPointPath(program, serviceManifestFileName);

            if (string.IsNullOrEmpty(entryPointPath))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_NullOrEmptyError,
                    "EntryPoint");
            }
            else if (entryPointPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_InvalidValue,
                    "EntryPoint",
                    entryPointPath);
            }
            else if (System.IO.Path.IsPathRooted(entryPointPath))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_RootedEntryPointNotSupported,
                    entryPointPath);
            }

            if (isExternalExecutable)
            {
                ImageBuilder.TraceSource.WriteInfo(
                    TraceType,
                    "EntryPointPath {0} is external executable",
                    entryPointPath);
            }
            else if (!fileLocator.FileExists(entryPointPath))
            {
#if !DotNetCoreClrLinux
                if (string.IsNullOrEmpty(Path.GetExtension(entryPointPath)) && fileLocator.FileExists(entryPointPath + ".exe"))
                {
                    return;
                }
#endif
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_EntryPointNotFound,
                    entryPointPath);
            }
        }
コード例 #26
0
 public static string EnsureHashFile(string resourcePath, string hashFilePath, bool imageStoreServiceEnabled)
 {
     if (!FabricFile.Exists(hashFilePath))
     {
         string checksum = ChecksumUtility.ComputeHash(resourcePath, imageStoreServiceEnabled);
         ImageBuilderUtility.WriteStringToFile(hashFilePath, checksum);
         return(checksum);
     }
     else
     {
         return(ImageBuilderUtility.ReadStringFromFile(hashFilePath));
     }
 }
コード例 #27
0
 void ValidateServiceTypeCombination(
     string serviceManifestFileName,
     int implicitServiceTypeCount,
     int normalServiceTypeCount,
     bool hasServiceGroupTypes)
 {
     if (implicitServiceTypeCount > 0 && (normalServiceTypeCount > 0 || hasServiceGroupTypes))
     {
         ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
             TraceType,
             serviceManifestFileName,
             StringResources.ImageBuilderError_InvalidServiceTypeCombination);
     }
 }
コード例 #28
0
        public bool DownloadIfContentExists(string source, string destination, IImageStoreProgressHandler progressHandler, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            if (this.ImageStore.DoesContentExist(source, timeoutHelper.GetRemainingTime()))
            {
                this.ImageStore.DownloadContent(source, destination, progressHandler, timeoutHelper.GetRemainingTime(), CopyFlag.AtomicCopy);
                ImageBuilderUtility.RemoveReadOnlyFlag(destination);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #29
0
 private void ValidatePlacementConstraints(string fileName, string placementConstraints)
 {
     if (!string.IsNullOrEmpty(placementConstraints))
     {
         if (!InteropHelpers.ExpressionValidatorHelper.IsValidExpression(placementConstraints))
         {
             ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                 TraceType,
                 fileName,
                 StringResources.ImageBuilderError_InvalidValue,
                 "PlacementConstraint",
                 placementConstraints);
         }
     }
 }
コード例 #30
0
        public static double?ValidateAsPositiveZeroIncluded(decimal value, string propertyName, string fileName)
        {
            double convertedValue = (double)value;

            if (convertedValue < 0)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    fileName,
                    StringResources.ImageBuilderError_ValueMustNotBeNegative,
                    convertedValue,
                    propertyName);
            }

            return(convertedValue);
        }