예제 #1
0
        public static async Task <bool> CopyResourceToPackageAsync(
            ContentURI uri, string resourceRelFilePaths,
            int arrayPos, string rootDirectory, string newDirectory,
            string parentFileName, IDictionary <string, string> zipArgs)
        {
            bool bHasCopied = false;

            string[] arrResourceParams = resourceRelFilePaths.Split(GeneralHelpers.PARAMETER_DELIMITERS);
            string   sResourceParams   = string.Empty;
            string   sResourceRelURI   = string.Empty;
            string   sResourceFullURI  = string.Empty;

            //refactor: parallel didn't work with this loop - keep testing
            //Parallel.For(0, arrResourceParams.Length, i =>
            for (int i = 0; i < arrResourceParams.Length; i++)
            {
                sResourceParams = arrResourceParams[i];
                if (string.IsNullOrEmpty(sResourceParams) == false)
                {
                    //the array holds relative paths; convert to full path for file.copy and package
                    sResourceRelURI = GeneralHelpers.GetDelimitedSubstring(sResourceParams,
                                                                           GeneralHelpers.STRING_DELIMITERS, arrayPos);
                    //remove the rel directories
                    string sBaseResourceURI = sResourceRelURI.Replace("../", string.Empty);
                    if ((!sBaseResourceURI.StartsWith(GeneralHelpers.WEBFILE_PATH_DELIMITER)) &&
                        (!rootDirectory.EndsWith(GeneralHelpers.FILE_PATH_DELIMITER)))
                    {
                        sBaseResourceURI = string.Concat(GeneralHelpers.WEBFILE_PATH_DELIMITER,
                                                         sBaseResourceURI);
                    }
                    FileStorageIO.PLATFORM_TYPES ePlatform
                        = uri.URIDataManager.PlatformType;
                    if (ePlatform == FileStorageIO.PLATFORM_TYPES.webserver)
                    {
                        bHasCopied = await CopyWebServerResourceToPackageAsync(
                            uri, rootDirectory, newDirectory,
                            parentFileName, zipArgs, sBaseResourceURI);
                    }
                    else if (ePlatform == FileStorageIO.PLATFORM_TYPES.azure)
                    {
                        bHasCopied = await CopyAzureResourceToPackageAsync(
                            uri, rootDirectory, newDirectory,
                            parentFileName, zipArgs, sBaseResourceURI);
                    }
                }
            }
            return(bHasCopied);
        }