예제 #1
0
        protected bool CreateFile(string source, Uri sourceLocation, Uri destination, bool replaceParameters, IEnumerable <TemplateArgument> templateArguments)
        {
            bool   flag;
            string str           = TemplateParser.ReplaceTemplateArguments(destination.LocalPath, templateArguments);
            string directoryName = Path.GetDirectoryName(str);

            if (!string.IsNullOrEmpty(directoryName) && !Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(directoryName))
            {
                try
                {
                    Directory.CreateDirectory(directoryName);
                }
                catch (IOException oException)
                {
                    flag = false;
                    return(flag);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException)
                {
                    flag = false;
                    return(flag);
                }
            }
            if (!replaceParameters)
            {
                try
                {
                    if (!TemplateBase.IsZipArchive(sourceLocation))
                    {
                        File.Copy(this.ResolveFileUri(source, sourceLocation).LocalPath, str, true);
                    }
                    else if (!this.ZipArchive.Exists(source))
                    {
                        flag = false;
                        return(flag);
                    }
                    else
                    {
                        this.ZipArchive.CopyToFile(source, str);
                    }
                    return(true);
                }
                catch (IOException oException1)
                {
                    flag = false;
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    flag = false;
                }
            }
            else
            {
                StreamReader streamReader = this.OpenText(source, sourceLocation);
                try
                {
                    File.WriteAllText(str, TemplateParser.ParseTemplate(streamReader, templateArguments), Encoding.UTF8);
                    return(true);
                }
                catch (IOException oException2)
                {
                    flag = false;
                }
                catch (UnauthorizedAccessException unauthorizedAccessException2)
                {
                    flag = false;
                }
                catch (SecurityException securityException)
                {
                    flag = false;
                }
            }
            return(flag);
        }