Exemple #1
0
        public ClassDecl(Cursor c, ISymbolTable table)
            : base(c, table)
        {
            Debug.Assert(CursorKinds.IsClassStructEtc(c.Kind));
    
            _templateKind = Symbols.TemplateKind.NonTemplate;
            if (c.Kind == CursorKind.ClassTemplate)
                _templateKind = Symbols.TemplateKind.Template;
            else if (c.Kind == CursorKind.ClassTemplatePartialSpecialization)
                _templateKind = Symbols.TemplateKind.TemplatePartialSpecialization;
            else if (c.TemplateSpecialisedCursorTemplate != null)
                _templateKind = Symbols.TemplateKind.TemplateSpecialization;

            if(c.SemanticParentCurosr.Kind == CursorKind.Namespace)
            {
                _parent = table.FindNamespaceDeclaration(c.SemanticParentCurosr.Usr);
                Debug.Assert(_parent != null);
            }
            else if (c.SemanticParentCurosr.Kind == CursorKind.TranslationUnit ||
                c.SemanticParentCurosr.Kind == CursorKind.UnexposedDecl)
            {
                _parent = null;
            }
            else if(CursorKinds.IsClassStructEtc(c.SemanticParentCurosr.Kind))
            {
                _parent = table.FindClassDeclaration(c.SemanticParentCurosr.Usr);
                Debug.Assert(_parent != null);
            }
            else
            {
                Debug.Assert(false);
            }
        }
        public async Task Create(TemplateKind templateKind, CancellationToken cancellationToken)
        {
            Check.NotEmpty(templateKind.TemplateKindKey, nameof(templateKind.TemplateKindKey));
            await ValidateUniqueness(templateKind.TemplateKindKey, cancellationToken);

            await _templateKindsRepository.AddTemplateKind(templateKind, cancellationToken);
        }
Exemple #3
0
        public void Throws_ArgumentException_When_Invalid_TemplateKindKey(string key)
        {
            var templateKind = new TemplateKind()
            {
                TemplateKindKey = key
            };
            var ct = CancellationToken.None;

            Assert.ThrowsAsync <ArgumentException>(async() => await _manager.Create(templateKind, ct));
        }
Exemple #4
0
        public void RegisterTemplate(string file, string name, TemplateKind kind)
        {
            if (_templates.ContainsKey(name))
            {
                throw RuntimeException.InvalidArgumentValue(name);
            }

            var template = _factory.CreateTemplate(file, kind);

            _templates.Add(name, template);
        }
        public async Task Will_Insert_TemplateKind_To_Collection()
        {
            var templateKind = new TemplateKind()
            {
                TemplateKindKey = "tk-3"
            };
            await _repository.AddTemplateKind(templateKind, CancellationToken.None);

            var filter = Builders <TemplateKind> .Filter.Eq(x => x.TemplateKindKey, templateKind.TemplateKindKey);

            (await _collection.Find(filter).FirstAsync()).Should().BeEquivalentTo(templateKind);
        }
Exemple #6
0
        public async Task Will_Remove_TemplateKindAsync()
        {
            Authorize(Guid.NewGuid(), Guid.NewGuid(), Array.Empty <string>(), new[] { Permissions.SystemManage });

            var expectedTemplateKind = new TemplateKind()
            {
                TemplateKindKey = _templateKindKey
            };
            await _client.CreateTemplateKind(expectedTemplateKind.TemplateKindKey);

            await _client.RemoveTemplateKind(_templateKindKey);

            Assert.ThrowsAsync <HttpResponseNotFoundException>(async() => await _client.GetTemplateKind(_templateKindKey));
        }
        public async Task Will_Create_New_TemplateKind()
        {
            Authorize(Guid.NewGuid(), Guid.NewGuid(), Array.Empty <string>(), new[] { Permissions.SystemManage });

            var expectedTemplateKind = new TemplateKind()
            {
                TemplateKindKey = Guid.NewGuid().ToString()
            };
            await _client.CreateTemplateKind(expectedTemplateKind.TemplateKindKey);

            var receivedTemplateKind = await _client.GetTemplateKind(expectedTemplateKind.TemplateKindKey);

            receivedTemplateKind.Should().BeEquivalentTo(expectedTemplateKind);
        }
        private IReadOnlyList <ITemplate> ListTemplates(string language, TemplateKind kind)
        {
            var templateList = TemplateListResolver.GetTemplateResolutionResult(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage);

            if (templateList.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousTemplateGroupForDetailDisplay))
            {
                return(unambiguousTemplateGroupForDetailDisplay.Where(t => t.IsMatch).Select(ti => new DotNetTemplateAdaptor(ti, kind)).ToList().AsReadOnly());
            }

            var ambiguous = templateList.GetBestTemplateMatchList(true);

            var groups = HelpForTemplateResolution.GetLanguagesForTemplateInfoGroups(ambiguous, language, "C#");

            return(groups.Keys.Where(t => t.IsMatch).Select(ti => new DotNetTemplateAdaptor(ti, kind)).ToList().AsReadOnly());
        }
Exemple #9
0
        public async Task Produces_200OK()
        {
            var templateKindKey         = "tk-1";
            var templateKindFromManager = new TemplateKind()
            {
                TemplateKindKey = templateKindKey
            };

            _templateKindManager.Setup(x => x.Get(templateKindKey, CancellationToken.None))
            .ReturnsAsync(templateKindFromManager)
            .Verifiable();

            var result = await _controller.Get(templateKindKey, CancellationToken.None) as ObjectResult;

            result.StatusCode.Should().Be(StatusCodes.Status200OK);
            result.Value.Should().BeEquivalentTo(templateKindFromManager);

            _templateKindManager.Verify();
        }
        public async Task Will_Return_TemplateKind()
        {
            var templateKindKey = "tk-1";
            var templateKind    = new TemplateKind()
            {
                TemplateKindKey = templateKindKey
            };
            var ct = CancellationToken.None;

            _templateKindsRepositoryMock.Setup(x => x.GetTemplateKind(templateKindKey, ct))
            .ReturnsAsync(templateKind)
            .Verifiable();

            var returnedTemplateKind = await _manager.Get(templateKindKey, ct);

            returnedTemplateKind.Should().BeEquivalentTo(templateKind);

            _templateKindsRepositoryMock.Verify();
        }
Exemple #11
0
        public async Task Stores_Template_Kind_In_Repository()
        {
            var templateKind = new TemplateKind()
            {
                TemplateKindKey = "tk-1"
            };
            var ct = CancellationToken.None;

            _templateKindsRepositoryMock.Setup(x => x.GetTemplateKind(templateKind.TemplateKindKey, ct))
            .ReturnsAsync(default(TemplateKind))
            .Verifiable();

            _templateKindsRepositoryMock.Setup(x => x.AddTemplateKind(templateKind, ct))
            .Verifiable();

            await _manager.Create(templateKind, ct);

            _templateKindsRepositoryMock.Verify();
        }
Exemple #12
0
        public void Throws_TemplateKindKeyAlreadyTakenException_When_Already_Exists()
        {
            var templateKind = new TemplateKind()
            {
                TemplateKindKey = "tk-1"
            };
            var ct = CancellationToken.None;

            _templateKindsRepositoryMock.Setup(x => x.GetTemplateKind(templateKind.TemplateKindKey, ct))
            .ReturnsAsync(templateKind)
            .Verifiable();

            Assert.ThrowsAsync <TemplateKindKeyAlreadyTakenException>(async() => await _manager.Create(templateKind, ct));

            _templateKindsRepositoryMock.Verify();
            _templateKindsRepositoryMock.Verify(x =>
                                                x.AddTemplateKind(
                                                    It.IsAny <TemplateKind>(),
                                                    It.IsAny <CancellationToken>()), Times.Never);
        }
Exemple #13
0
        /// <summary>
        /// Async send SMS
        /// 异步发送短信
        /// </summary>
        /// <param name="kind">Template kind</param>
        /// <param name="mobiles">Mobiles</param>
        /// <param name="vars">Variables</param>
        /// <param name="template">Template</param>
        /// <returns>Result</returns>
        public async Task <ActionResult> SendAsync(TemplateKind kind, IEnumerable <AddressRegion.Phone> mobiles, Dictionary <string, string> vars, TemplateItem?template = null)
        {
            // Mobile only and avoid duplicate items
            var validatedMobiles = mobiles.UniquePhones().Where(m => m.IsMobile);

            var count = validatedMobiles.Count();

            if (count == 0)
            {
                return(new ActionResult {
                    Status = -1, Title = "No Valid Item"
                });
            }
            else if (count > 2000)
            {
                return(new ActionResult {
                    Status = -1, Title = "Max 2000 Items"
                });
            }

            // Is international
            bool intl;

            if (template == null)
            {
                // Countries
                var countries = validatedMobiles.GroupBy(m => m.Region).Select(g => g.Key);

                // If more then one country or different with the default country
                var countriesCount = countries.Count();
                var firstCountry   = countries.First();
                intl = countriesCount > 1 || firstCountry != Region.Id;

                // Default template
                template = GetTemplate(kind, region: (countriesCount > 1 ? null : firstCountry));
                if (template == null)
                {
                    throw new ArgumentNullException(nameof(template));
                }
            }
            else if (template.Region == null)
            {
                // No country specified
                intl = mobiles.Any(m => m.Region != Region.Id);
            }
            else
            {
                // Specific country
                intl = template.Region != Region.Id;
            }

            // Is domestic
            var msgType = intl ? 2 : 0;

            // Join all numbers
            var numbers = validatedMobiles.Select(m => intl ? m.ToInternationalFormat(Region.ExitCode) : m.PhoneNumber);

            // Variables to JSON
            var varsJson = JsonSerializer.Serialize(vars, new JsonSerializerOptions {
                WriteIndented = false, AllowTrailingCommas = false
            });

            // Post data
            var data = new SortedDictionary <string, string>
            {
                ["smsUser"]    = smsUser,
                ["templateId"] = template.TemplateId,
                ["phone"]      = string.Join(',', numbers),
                ["msgType"]    = msgType.ToString(),
                ["vars"]       = varsJson
            };

            // Create signature
            await CreateSignatureAsync(data);

            // Endpoint
            var endPoint = template.EndPoint ?? "https://www.sendcloud.net/smsapi/send";

            // Post
            var result = await PostFormAsync <SMSActionResult>(endPoint, data);

            // Data
            var info       = result?.Info;
            var resultData = info == null ? new StringKeyDictionaryObject() : new StringKeyDictionaryObject(info);

            // Return
            return(new ActionResult {
                Ok = result?.Result ?? false, Status = result?.StatusCode, Title = result?.Message, Data = resultData
            });
        }
 public Task AddTemplateKind(TemplateKind templateKind, CancellationToken cancellationToken = default)
 => _collection.InsertOneAsync(templateKind, null, cancellationToken);
 private long GetCountForKind(TemplateKind kind, List <KeyValuePair <string, long> > counters)
 => counters
 .Where(x => x.Key == kind.TemplateKindKey)
 .Select(x => x.Value)
 .DefaultIfEmpty(0)
 .FirstOrDefault();
Exemple #16
0
 public InternalTemplate(byte[] data, TemplateKind kind)
 {
     Kind  = kind;
     _data = new BinaryDataContext(data);
 }
 public ITemplate CreateTemplate(string file, TemplateKind kind)
 {
     return new FileSourceTemplate(file, kind);
 }
Exemple #18
0
        public void AddTemplate(string file, string name, TemplateKind kind = TemplateKind.File)
        {
            var manager = GlobalsManager.GetGlobalContext <TemplateStorage>();

            manager.RegisterTemplate(file, name, kind);
        }
Exemple #19
0
 /// <summary>
 /// Async send SMS with template id
 /// 异步通过模板编号发送短信
 /// </summary>
 /// <param name="kind">Template kind</param>
 /// <param name="mobiles">Mobiles</param>
 /// <param name="vars">Variables</param>
 /// <param name="templateId">Template id</param>
 /// <returns>Result</returns>
 public async Task <ActionResult> SendAsync(TemplateKind kind, IEnumerable <AddressRegion.Phone> mobiles, Dictionary <string, string> vars, string templateId)
 {
     return(await SendAsync(kind, mobiles, vars, GetTemplate(TemplateKind.Code, templateId)));
 }
 public ITemplate CreateTemplate(string file, TemplateKind kind)
 {
     throw new NotImplementedException();
 }
Exemple #21
0
 /// <summary>
 /// Async send SMS
 /// 异步发送短信
 /// </summary>
 /// <param name="kind">Template kind</param>
 /// <param name="mobiles">Mobiles</param>
 /// <param name="vars">Variables</param>
 /// <param name="template">Template</param>
 /// <returns>Result</returns>
 public async Task <ActionResult> SendAsync(TemplateKind kind, IEnumerable <string> mobiles, Dictionary <string, string> vars, TemplateItem?template = null)
 {
     return(await SendAsync(kind, AddressRegion.CreatePhones(mobiles, Region.Id), vars, template));
 }
Exemple #22
0
        private void ReadTemplate()
        {
            try
            {
                #region Start reading Xml .vstemplate file
                XmlDocument templateDoc = new XmlDocument();
                templateDoc.Load(templateFileName);
                XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(templateDoc.NameTable);
                xmlNamespaceManager.AddNamespace("vstemplns", "http://schemas.microsoft.com/developer/vstemplate/2005");
                #endregion
                #region Set VsTemplate data
                XmlNodeList templateData = templateDoc.SelectNodes("/vstemplns:VSTemplate/vstemplns:TemplateData", xmlNamespaceManager);
                foreach (XmlNode xmlNode in templateData[0].ChildNodes)
                {
                    CommandID    valueAsCommandID = null;
                    string       valueAsString    = null;
                    XmlAttribute xmlPackage       = xmlNode.Attributes["Package"];
                    if (xmlPackage != null)
                    {
                        XmlAttribute xmlId       = xmlNode.Attributes["ID"];
                        Guid         guidPackage = new Guid(xmlPackage.Value);
                        if (xmlId != null)
                        {
                            valueAsCommandID = new CommandID(guidPackage, int.Parse(xmlId.Value));
                        }
                    }
                    else
                    {
                        valueAsString = xmlNode.InnerText;
                    }
                    switch (xmlNode.Name)
                    {
                    case "Name":
                        this.name          = valueAsString;
                        this.commandIdName = valueAsCommandID;
                        break;

                    case "Description":
                        this.description          = valueAsString;
                        this.commandIdDescription = valueAsCommandID;
                        break;

                    case "Icon":
                        this.icon = valueAsCommandID;
                        if (valueAsString != null)
                        {
                            this.iconFileName = valueAsString;
                        }
                        break;

                    case "CreateNewFolder":
                        this.createNewFolder = bool.Parse(valueAsString);
                        break;

                    case "AppendDefaultFileExtension":
                        this.appendDefaultFileExtension = bool.Parse(valueAsString);
                        break;

                    case "SupportsLanguageDropDown":
                        this.supportsLanguageDropDown = bool.Parse(valueAsString);
                        break;

                    case "SupportsMasterPage":
                        this.supportsMasterPage = bool.Parse(valueAsString);
                        break;

                    case "ProvideDefaultName":
                        this.provideDefaultName = bool.Parse(valueAsString);
                        break;

                    case "SortOrder":
                        this.sortPriority = int.Parse(valueAsString);
                        break;

                    case "ProjectType":
                        this.language = valueAsString;
                        break;

                    case "DefaultName":
                        this.suggestedBaseName = valueAsString;
                        break;

                    case "EnableLocationBrowseButton":
                        this.enableLocationBrowseButton = bool.Parse(valueAsString);
                        break;

                    case "EnableEditOfLocationField":
                        this.enableEditOfLocationField = bool.Parse(valueAsString);
                        break;

                    case "LocationField":
                        this.locationField = (LocationField)Enum.Parse(typeof(LocationField), valueAsString);
                        break;

                    default:
                        break;
                    }
                }
                #endregion
                #region Set vsKind
                XmlNode projectTypeNode = templateDoc.SelectSingleNode("/vstemplns:VSTemplate/@Type", xmlNamespaceManager);
                if (projectTypeNode == null)
                {
                    throw new RecipeFrameworkException(Properties.Resources.Templates_MissingType);
                }
                else if (string.Compare(projectTypeNode.InnerText, "Project", true, CultureInfo.InvariantCulture) == 0)
                {
                    this.vsKind = WizardRunKind.AsNewProject;
                }
                else if (string.Compare(projectTypeNode.InnerText, "Item", true, CultureInfo.InvariantCulture) == 0)
                {
                    this.vsKind = WizardRunKind.AsNewItem;
                }
                else if (string.Compare(projectTypeNode.InnerText, "ProjectGroup", true, CultureInfo.InvariantCulture) == 0)
                {
                    this.vsKind = WizardRunKind.AsMultiProject;
                }
                #endregion
                #region Set Kind
                string   folderName   = Path.GetDirectoryName(this.FileName);
                string[] folders      = folderName.Split('\\');
                string[] foldersArray = new string[2] {
                    folders[folders.Length - 1], folders[folders.Length - 2]
                };
                foreach (string folder in foldersArray)
                {
                    if (folder.Equals("Items", StringComparison.InvariantCultureIgnoreCase))
                    {
                        kind = TemplateKind.ProjectItem;
                        break;
                    }
                    else if (folder.Equals("Projects", StringComparison.InvariantCultureIgnoreCase))
                    {
                        kind = TemplateKind.Project;
                        if (folders[0].Equals("Solutions"))
                        {
                        }
                        break;
                    }
                    else if (folder.Equals("Solutions", StringComparison.InvariantCultureIgnoreCase))
                    {
                        kind = TemplateKind.Solution;
                        break;
                    }
                }
                #endregion
                #region Set extension data
                XmlNode wizardData = templateDoc.SelectSingleNode("/vstemplns:VSTemplate/vstemplns:WizardData", xmlNamespaceManager);
                if (wizardData == null)
                {
                    this.extensionData = new VsTemplate.Template();
                }
                else
                {
                    this.extensionData = this.GetWizardData(wizardData.ChildNodes[0]);
                }
                #endregion
                #region Make sure that the there is an custom UI specified:
                try
                {
                    XmlNode wizardUINode = templateDoc.SelectSingleNode(
                        "/vstemplns:VSTemplate/vstemplns:WizardExtension", xmlNamespaceManager);
                    XmlNode wizardAsmNode = wizardUINode.SelectSingleNode(
                        "vstemplns:Assembly", xmlNamespaceManager);
                    XmlNode wizardClassNode = wizardUINode.SelectSingleNode(
                        "vstemplns:FullClassName", xmlNamespaceManager);

                    string extensionFullName = wizardClassNode.InnerText + ", " + wizardAsmNode.InnerText;
                    Type   extensionType     = ReflectionHelper.LoadType(extensionFullName);
                    if (extensionType == null)
                    {
                        throw new TypeLoadException(extensionFullName);
                    }
                    if (!(typeof(UnfoldTemplate).IsAssignableFrom(extensionType)))
                    {
                        throw new ArgumentException(Properties.Resources.Templates_NoExtension);
                    }
                }
                catch
                {
                    throw new ArgumentException(Properties.Resources.Templates_NoExtension);
                }
                #endregion
                #region Additional Checks
                CheckTemplateKinds();
                CheckTemplateReferences();
                #endregion
            }
            catch (Exception e)
            {
                throw new RecipeFrameworkException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Properties.Resources.Templates_InvalidTemplateFile,
                              templateFileName), e);
            }
        }
Exemple #23
0
 public ITemplate CreateTemplate(string file, TemplateKind kind)
 {
     return(new Template(file, kind));
 }
Exemple #24
0
 internal DotNetTemplateAdaptor(ITemplateMatchInfo template, TemplateKind kind)
 {
     _kind     = kind;
     _template = template;
 }
Exemple #25
0
 internal RazorTemplate(TemplateKind kind, string key)
 {
     _kind = kind;
     _key  = key;
 }
 public FileSourceTemplate(string file, TemplateKind kind)
 {
     Kind     = kind;
     Filename = file;
 }