protected void FetchGitSourceLocally(TemplateSource source, string destFolder)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (string.IsNullOrEmpty(destFolder))
            {
                throw new ArgumentNullException("destFolder");
            }

            // TODO: these methods should be renamed since fetch means something in git

            try {
                var destDirInfo = new DirectoryInfo(destFolder);
                if (destDirInfo.Exists)
                {
                    ResetDirectoryAttributes(destDirInfo);
                    // TODO: if the folder exists and there is a .git folder then we should do a fetch/merge or pull
                    destDirInfo.Delete(true);
                }

                // clone it
                var    repoPath = Repository.Clone(source.Location.AbsoluteUri, destFolder);
                var    repo     = new Repository(repoPath);
                Branch branch   = repo.Checkout(source.Branch);
                branch.Checkout();
            }
            catch (Exception ex) {
                UpdateStatusBar("There was an error check the activity log");
                // TODO: we should log this error
                string msg = ex.ToString();
                System.Windows.Forms.MessageBox.Show(msg);
            }
        }
        protected void FetchSourceLocally(TemplateSource source, string destFolder)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (string.IsNullOrEmpty(destFolder))
            {
                throw new ArgumentNullException("destFolder");
            }

            if (string.Compare("file", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                // do a recursive copy of the folder to the dest
                new DirectoryHelper().DirectoryCopy(source.Location.LocalPath, destFolder, true, true);
            }
            else if (
                string.Compare("git", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase) == 0 ||
                string.Compare("http", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase) == 0 ||
                string.Compare("https", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                FetchGitSourceLocally(source, destFolder);
            }
            else
            {
                throw new ApplicationException(
                          string.Format(
                              "Unsupported scheme [{0}] in template source Uri [{1}]",
                              source.Location.Scheme,
                              source.Location.AbsoluteUri));
            }
        }
Пример #3
0
        private async void OkBtn_Click(object sender, EventArgs e)
        {
            DisableControls();
            LoadingImage.Enabled = true;
            LoadingLabel.Enabled = true;
            LoadingImage.Visible = true;
            LoadingLabel.Visible = true;

            List <TemplateSource> sources = new List <TemplateSource>();

            foreach (ListViewItem row in remoteSourceListView.Items)
            {
                TemplateSource source = new TemplateSource
                {
                    Enabled = row.Checked,
                    Name    = row.SubItems[1].Text
                };


                Uri uri = new Uri(row.SubItems[2].Text);
                Uri url = uri;
                if (uri.IsFile)
                {
                    url = new Uri(uri.AbsoluteUri);
                }

                source.Location = url;

                if (row.SubItems[3].Text != "")
                {
                    source.Branch = row.SubItems[3].Text;
                }

                sources.Add(source);
            }

            templateSettings.Sources = sources;

            // Save the configuration schedule
            var checkbox = scheduleGroupBox.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

            templateSettings.UpdateInterval = (UpdateFrequency)checkbox.Tag;

            // Here is where the .json file needs to be saved before calling ProcessTemplates
            templateBuilder.WriteJsonTemplateSettings(templateSettings);

            // Rebuild all templates before notifying the user
            await startRebuildingTemplates();

            // If a new source was added notify the user to restart Visual Studio
            if (templateSourcesChanged || newSourceAdded)
            {
                var dte = Package.GetGlobalService(typeof(DTE)) as DTE;
                dte.StatusBar.Text = @"Your template(s) have been installed. Please restart Visual Studio.";
            }

            templateSourcesChanged = false;
            newSourceAdded         = false;
            this.Close();
        }
Пример #4
0
        public bool AddConfiguredSource(string alias, string sourceName, string location)
        {
            Load();
            ITemplateSource component;

            if (!ComponentRegistry.TryGetNamedComponent(sourceName, out component))
            {
                return(false);
            }

            _configuredSources[alias] = new TemplateSource
            {
                Alias    = alias,
                Location = location.ProcessPath(),
                Source   = component
            };

            JObject result = new JObject();

            foreach (KeyValuePair <string, TemplateSource> entry in _configuredSources)
            {
                result[entry.Key] = new JObject
                {
                    { "location", entry.Value.Location },
                    { "source", entry.Value.Source.Name }
                };
            }

            File.WriteAllText(Paths.TemplateSourcesFile, result.ToString());
            return(true);
        }
Пример #5
0
        private async void LoadSettingsReboot()
        {
            TemplateSource menu       = new TemplateSource();
            var            items_menu = await menu.getMenuItems();

            this.DefaultViewModel["MenuItems"] = items_menu;
            isLoaded = true;
        }
 public TemplateLocalInfo(TemplateSource source, string templateSourceRoot)
     : this(
         source,
         templateSourceRoot,
         Path.Combine(templateSourceRoot, @"project-templates\"),
         Path.Combine(templateSourceRoot, @"project-templates-v0\"),
         Path.Combine(templateSourceRoot, @"item-Templates\"))
 {
 }
Пример #7
0
        public void Test_template_rendering_with_escaped_characters()
        {
            var instance = Handlebars.Create(new HandlebarsConfiguration
            {
                TextEncoder = new NoopTextEncoder()
            });
            var template = new Template("test", instance, TemplateSource.CreateForText("|{{name}}|"));

            template.Name.Should().Be("test");
            template.RenderIntoString(new { name = "< > / \\ & $ # @" }).Should().Be("|< > / \\ & $ # @|");
        }
Пример #8
0
        public void Test_template_rendering()
        {
            var instance = Handlebars.Create(new HandlebarsConfiguration
            {
                TextEncoder = new NoopTextEncoder()
            });
            var template = new Template("test", instance, TemplateSource.CreateForText("Hello {{name}}"));

            template.Name.Should().Be("test");
            template.RenderIntoString(new { name = "Test123" }).Should().Be("Hello Test123");
        }
        private TemplateSource GetTempType(string data)
        {
            TemplateSource t    = TemplateSource.online;
            XMLDataManager mgr  = new XMLDataManager(data);
            string         type = mgr.GetPropVal("TemplateSource");

            if (!string.IsNullOrEmpty(type))
            {
                t = (TemplateSource)Enum.Parse(typeof(TemplateSource), type);
            }
            return(t);
        }
        public TemplateLocalInfo(TemplateSource source, string templateSourceRoot, string templateReferenceSourceRoot, string projectTemplateSourceRoot, string itemTemplateSourceRoot)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (string.IsNullOrEmpty(templateSourceRoot))
            {
                throw new ArgumentNullException("templateSourceRoot");
            }

            this.Source                      = source;
            this.TemplateSourceRoot          = templateSourceRoot;
            this.TemplateReferenceSourceRoot = templateReferenceSourceRoot;
            this.ProjectTemplateSourceRoot   = projectTemplateSourceRoot;
            this.ItemTemplateSourceRoot      = itemTemplateSourceRoot;
        }
Пример #11
0
 public static string Process(string template, params TokensSet[] tokens)
 {
     var index = 0;
     var token_index = FindFirstToken(template);
     if (!TokenFound(token_index)) return template;
     var source = new TemplateSource(template);
     var rez = new TemplateRezult(template.Length);
     while (TokenFound(token_index))
     {
         rez.Append(source.Substring(from: index, to: token_index - 1));
         var token = ReadTokenAt(source, token_index);
         var token_value = CalculateToken(token, tokens);
         source.Replace(from: token.StartsAt, to: token.EndsAt, value: token_value);
         index = token.StartsAt;
         token_index = FindNextToken(in_template: source, starting_on: index);
     }
     rez.Append(source.Substring(from: index));
     return rez.ToString();
 }
Пример #12
0
        public void WriteSchemaObjects(IDocumentSchema schema, StringWriter writer)
        {
            var table = ToTable(schema);

            table.Write(writer);
            writer.WriteLine();
            writer.WriteLine();

            var pgIdType = TypeMappings.PgTypes[IdMember.GetMemberType()];

            var sql = TemplateSource.UpsertDocument()
                      .Replace("%TABLE_NAME%", TableName)
                      .Replace("%SPROC_NAME%", UpsertName)
                      .Replace("%ID_TYPE%", pgIdType);

            writer.WriteLine(sql);

            writer.WriteLine();
            writer.WriteLine();
        }
        private WorkspaceFactory GetFactory(string data)
        {
            WorkspaceFactory factory = null;
            TemplateSource   tType   = GetTempType(data);

            switch (tType)
            {
            case TemplateSource.online:
                factory = new OnlineTempWorkspaceFactory(data);
                break;

            case TemplateSource.downloaded:
                factory = new DownloadedTempWorkspaceFactory(data);
                break;

            default:
                break;
            }

            return(factory);
        }
        public void Generate_CSharp_from_output_model()
        {
            var ns      = new Namespace("MyApp.MyTest", null);
            var builder = new ClassOutputModelBuilder("test", null, new TestClassNamingConvention());

            builder.CreateClass("MyClass", ns);
            builder.CreateProperty("Name", "string");

            var outputModel = builder.Build();
            var instance    = Handlebars.Create(new HandlebarsConfiguration
            {
                TextEncoder = new NoopTextEncoder()
            });
            var template = new Template("test", instance, TemplateSource.CreateForText(@"
namespace {{Model.ClassNamespace}}
public class {{Model.ClassName}}
{
{{#each Model.Properties}}
    public {{Type.TypeName}} {{Name}} { get; set; }
{{/each}}
}
"));
            var renderer = new ClassOutputModelRenderer(template);
            var actual   = default(string);
            var expected = @"
namespace MyApp.MyTest
public class MyClass
{
    public string Name { get; set; }
}
";

            using (var writer = new StringWriter())
            {
                renderer.Render(outputModel, writer);
                actual = writer.ToString();
            }

            actual.Should().Be(expected);
        }
Пример #15
0
 public void can_read_upsert_document()
 {
     TemplateSource.UpsertDocument().ShouldContain("INSERT INTO %TABLE_NAME%");
 }
Пример #16
0
 private static int FindNextToken(TemplateSource in_template, int starting_on)
 {
     return in_template.IndexOf("{{", starting_on, StringComparison.Ordinal);
 }
Пример #17
0
        private static TokenEntry ReadTokenAt(TemplateSource source, int token_index)
        {
            var char_index = token_index + 1;
            var brackets_count = 1;
            var state = ReaderStates.Name;
            var prev_state = state;
            var last_index = source.Length - 1;

            var name = "";
            var body = "";

            while (state != ReaderStates.Done && last_index > char_index)
            {
                char_index++;
                var ch = source[char_index];

                switch (state)
                {
                    case ReaderStates.Name:
                        if (ch == ':') state = ReaderStates.Splitter;
                        else if (ch == '}') state = ReaderStates.CloseBracket;
                        else name += ch;
                        break;
                    case ReaderStates.Splitter:
                        prev_state = state = ReaderStates.Body;
                        if (ch == '{') state = ReaderStates.OpenBracket;
                        else if (ch == '}') state = ReaderStates.CloseBracket;
                        else body += ch;
                        break;
                    case ReaderStates.Body:
                        if (ch == '{') state = ReaderStates.OpenBracket;
                        else if (ch == '}') state = ReaderStates.CloseBracket;
                        else body += ch;
                        break;
                    case ReaderStates.OpenBracket:
                        if (ch == '{') brackets_count++;
                        state = prev_state;
                        if (state == ReaderStates.Body) body = string.Concat(body, '{', ch);
                        else if (state == ReaderStates.Name) name = string.Concat(name, '{', ch);
                        break;
                    case ReaderStates.CloseBracket:
                        if (ch == '}')
                        {
                            brackets_count--;
                            if(brackets_count==0)state = ReaderStates.Done;
                        }
                        if (state != ReaderStates.Done)
                        {
                            state = prev_state;
                            if (state == ReaderStates.Body) body = string.Concat(body, '}', ch);
                            else if (state == ReaderStates.Name) name = string.Concat(name, '}', ch);
                        }
                        break;
                    case ReaderStates.Done:
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            if(state!=ReaderStates.Done)
                throw new Exception("Can't read token: "+source.ToString());

            return new TokenEntry
                {
                    Name = name,
                    Body = body,
                    StartsAt = token_index,
                    EndsAt = char_index
                };
        }