コード例 #1
0
 internal static bool IsZipArchive(Uri location)
 {
     if (!location.IsFile)
     {
         return(false);
     }
     return(TemplateBase.IsZipArchive(location.LocalPath));
 }
コード例 #2
0
        protected Stream OpenRead(string file, Uri root)
        {
            if (TemplateBase.IsZipArchive(root))
            {
                return(this.ZipArchive.OpenRead(file));
            }
            Uri uri = this.ResolveFileUri(file, root);

            if (!uri.IsFile || !File.Exists(uri.LocalPath))
            {
                return(null);
            }
            return(File.OpenRead(uri.LocalPath));
        }
コード例 #3
0
ファイル: TemplateManager.cs プロジェクト: radtek/Shopdrawing
        public bool ShouldUseTemplate(Microsoft.Expression.Project.IProject project, ITemplate templateToTest)
        {
            bool flag;

            Microsoft.Expression.Project.Templates.VSTemplate template;
            if (this.TemplateFilters != null)
            {
                Microsoft.Expression.Extensibility.Project.IProject project1 = null;
                TemplateBase templateBase = templateToTest as TemplateBase;
                if (templateBase != null)
                {
                    template = templateBase.Template;
                }
                else
                {
                    template = null;
                }
                Microsoft.Expression.Project.Templates.VSTemplate vSTemplate = template;
                if (vSTemplate != null)
                {
                    using (IEnumerator <ITemplateFilter> enumerator = this.TemplateFilters.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ITemplateFilter current = enumerator.Current;
                            try
                            {
                                if (project1 == null)
                                {
                                    project1 = new Microsoft.Expression.Extensibility.Project.Project(project);
                                }
                                if (!current.ShouldUseTemplate(project1, vSTemplate.TemplateExtensibilityWrapper))
                                {
                                    flag = false;
                                    return(flag);
                                }
                            }
                            catch (Exception exception)
                            {
                            }
                        }
                        return(true);
                    }
                    return(flag);
                }
            }
            return(true);
        }
コード例 #4
0
        public string ParseTemplate(string templateName, ICollection <TemplateArgument> arguments)
        {
            string end;

            if (!TemplateBase.IsZipArchive(this.templateLocation))
            {
                using (StreamReader streamReader = new StreamReader(Path.Combine(this.templateLocation, templateName)))
                {
                    end = streamReader.ReadToEnd();
                }
            }
            else
            {
                using (StreamReader streamReader1 = ZipHelper.CreateZipArchive(this.templateLocation).OpenText(templateName))
                {
                    end = streamReader1.ReadToEnd();
                }
            }
            return(TemplateParser.EvaluateTemplate(TemplateParser.ReplaceTemplateArguments(end, arguments)));
        }
コード例 #5
0
        protected StreamReader OpenText(string file, Uri root)
        {
            if (!TemplateBase.IsZipArchive(root))
            {
                return(new StreamReader(this.ResolveFileUri(file, root).LocalPath));
            }
            Microsoft.Expression.SubsetFontTask.Zip.ZipArchive zipArchive = this.ZipArchive;
            if (zipArchive[file] != null)
            {
                return(zipArchive.OpenText(file));
            }
            string str = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

            if (zipArchive[str] == null)
            {
                CultureInfo currentCulture   = CultureInfo.CurrentCulture;
                string      couldNotFindFile = ExceptionStringTable.CouldNotFindFile;
                object[]    objArray         = new object[] { string.Concat(this.TemplateLocation.LocalPath, "[", file, "]") };
                throw new FileNotFoundException(string.Format(currentCulture, couldNotFindFile, objArray));
            }
            return(zipArchive.OpenText(str));
        }
コード例 #6
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);
        }