/// <summary> /// Initializes a new instance of the <see cref="CodeExpression"/> class. /// </summary> /// <param name="codeSpan">The literal code to be contained by this expression.</param> /// <param name="codeType">The semantic usage of this expression.</param> public CodeExpression(CodeSpan codeSpan, CodeType codeType) { if (codeSpan == null) { throw new ArgumentNullException("codeSpan"); } this.codeSpan = codeSpan; this.codeType = codeType; }
public async Task<IHttpActionResult> GetSmsCode(string phoneNo, CodeType codeType = CodeType.用户注册) { if (!phoneNo.IsMobileNumber(true)) return Json(new ApiResult(OperationResultType.ValidError, "请输入正确的手机号")); var result = await UserContract.GetSmsValidateCode(phoneNo, codeType); return Json(result.ToApiResult()); }
// Generates all of the Web Forms Pages (Default Insert, Edit, Delete), private void AddStorageContexts( Project project, string selectionRelativePath, string dbContextNamespace, string dbContextTypeName, CodeType modelType, bool useMasterPage, string masterPage = null, bool overwriteViews = true ) { if (modelType == null) { throw new ArgumentNullException("modelType"); } var webForms = new[] { "StorageContext", "StorageContext.KeyHelpers" }; // Now add each view foreach (string webForm in webForms) { AddStorageContextTemplates( selectionRelativePath: selectionRelativePath, modelType: modelType, dbContextNamespace: dbContextNamespace, dbContextTypeName: dbContextTypeName, webFormsName: webForm, overwrite: overwriteViews); } }
public static TestableWasteCodeInfo Create(CodeType codeType, string code = null, string description = null, bool isNotApplicable = false) { if (isNotApplicable) { return new TestableWasteCodeInfo { CodeType = codeType, IsNotApplicable = true }; } return new TestableWasteCodeInfo { CodeType = codeType, WasteCode = new TestableWasteCode { CodeType = codeType, Code = code, Description = description } }; }
public StringBuilder GetExecutionCode( IEnumerable<string> usingNamespaces, string namespaceName, string baseClassName, string className, CodeType codeType, string execCode ) { string code = PrepareCode(codeType, execCode); string endCode = (code ?? "").TrimEnd().ToLower().EndsWith("end sub") ? code.ToLower().Contains("class") ? Environment.NewLine : Environment.NewLine + "End Sub" : Environment.NewLine + "End Sub"; StringBuilder usingNs = new StringBuilder(); foreach (string uns in usingNamespaces) usingNs.AppendFormat("Imports {0}{1}", uns, Environment.NewLine); StringBuilder source = new StringBuilder(); source.AppendFormat(@" Imports System Imports System.IO Imports System.Collections.Generic Imports System.Text.RegularExpressions Imports System.Linq Imports it.jodan.SpoolPad.DataContext Imports it.jodan.SpoolPad.Extensions {0} namespace {1} Public Class {2} Inherits {3} Protected Overrides Sub InternalRun() {4}{5} End Class End namespace ", usingNs, namespaceName, className, baseClassName, code, endCode); return source; }
private void btnGenerate_Click(object sender, EventArgs e) { lbOutputs.Items.Clear(); ListItem[] items = new ListItem[clbTables.CheckedItems.Count + clbViews.CheckedItems.Count]; int itemIndex = 0; foreach (object item in clbTables.CheckedItems) { items[itemIndex] = item as ListItem; itemIndex++; } foreach (object item in clbViews.CheckedItems) { items[itemIndex] = item as ListItem; itemIndex++; } _SelectedItems = items; _CodeType = rbEntities.Checked ? CodeType.Entities : CodeType.DbContext; _DbContextName = tbDbContextName.Text; _DefaultNamespace = tbDefaultNamespace.Text; _OutputPath = tbPath.Text.EndsWith("\\") ? tbPath.Text : tbPath.Text + "\\"; if (Directory.Exists(_OutputPath) == false) Directory.CreateDirectory(_OutputPath); Task.Factory.StartNew(StartToGenerate); }
public void GenerateCode(string modelName, CodeType baseClassType, Dictionary<string, string> propertiesCollection, bool overwriteViews = true) { Project project = Project; string modelNamespace = baseClassType == null ? project.Name + ".Models" : baseClassType.Namespace.FullName; List<string> properties = propertiesCollection.Keys.ToList<string>(); List<string> propertyTypes = propertiesCollection.Values.ToList<string>(); string outputPath = Path.Combine("Models", "MyModel"); AddProjectItemViaTemplate(outputPath, templateName: "MyModel", templateModel: new Hashtable() { {"ModelName" , modelName}, {"Namespace" , modelNamespace}, {"BaseClassTypeName", baseClassType == null ? "" : baseClassType.Name}, {"PropertiesCollection",properties}, {"PropertiesTypeCollection",propertyTypes} }, overwrite: false); }
private static bool CanHaveCustomCode(CodeType codeType) { return codeType == CodeType.CustomsCode || codeType == CodeType.ExportCode || codeType == CodeType.ImportCode || codeType == CodeType.OtherCode; }
private void btnOK_Click(object sender, EventArgs e) { switch (cbxCodeType.Text) { case "拼音": SelectedCodeType = CodeType.Pinyin; break; case "五笔": SelectedCodeType = CodeType.Wubi; break; case "注音": SelectedCodeType = CodeType.TerraPinyin; break; case "仓颉": SelectedCodeType = CodeType.Cangjie; break; case "其他": SelectedCodeType = CodeType.Unknown; break; default: SelectedCodeType = CodeType.Unknown; break; } DialogResult = DialogResult.OK; }
// Generates all of the Web Forms Pages (Default Insert, Edit, Delete), private void AddWebFormsPages( Project project, string selectionRelativePath, string dbContextNamespace, string dbContextTypeName, CodeType modelType, bool overwriteViews = true ) { if (modelType == null) { throw new ArgumentNullException("modelType"); } var webForms = new[] { "Index", "Create", "Edit", "Delete", "Details", "Resources" }; // Now add each view foreach (string webForm in webForms) { AddWebFormsViewTemplates( selectionRelativePath: selectionRelativePath, modelType: modelType, dbContextNamespace: dbContextNamespace, dbContextTypeName: dbContextTypeName, webFormsName: webForm, overwrite: overwriteViews); } }
private void btnOK_Click(object sender, EventArgs e) { switch (cbxCodeType.Text) { case "拼音": SelectedCodeType = CodeType.Pinyin; break; case "五笔": SelectedCodeType = CodeType.Wubi; break; case "二笔": SelectedCodeType = CodeType.Erbi; break; case "英语": SelectedCodeType = CodeType.English; break; case "永码": SelectedCodeType = CodeType.Yong; break; case "郑码": SelectedCodeType = CodeType.Zhengma; break; case "内码": SelectedCodeType = CodeType.InnerCode; break; case "其他": SelectedCodeType = CodeType.Unknown; break; default: SelectedCodeType = CodeType.Unknown; break; } DialogResult = DialogResult.OK; }
public static IWordCodeGenerater GetGenerater(CodeType codeType) { switch (codeType) { case CodeType.Pinyin: return new PinyinGenerater(); case CodeType.Wubi: return new Wubi86Generater(); case CodeType.QingsongErbi: return new QingsongErbiGenerater(); case CodeType.ChaoqiangErbi: return new ChaoqiangErbiGenerater(); case CodeType.XiandaiErbi: return new XiandaiErbiGenerater(); case CodeType.ChaoqingYinxin: return new YingxinErbiGenerater(); case CodeType.English: return new PinyinGenerater(); case CodeType.Yong: return new PinyinGenerater(); case CodeType.Zhengma: return new ZhengmaGenerater(); case CodeType.TerraPinyin: return new TerraPinyinGenerater(); case CodeType.Cangjie: return new Cangjie5Generater(); case CodeType.UserDefine: { return SelfDefiningCodeGenerater(); } default: return new SelfDefiningCodeGenerater(); } }
public CodeFile(CodeType type, string path, byte[] data, bool missingHeader = false) { Type = type; Path = path; Data = data; MissingHeader = missingHeader; }
private void SetCodes(IEnumerable<WasteCodeInfo> codes, CodeType codeType) { var newCodes = codes as WasteCodeInfo[] ?? codes.ToArray(); if (codeType != CodeType.CustomsCode && !newCodes.Any(c => c.IsNotApplicable) && newCodes.Select(p => p.WasteCode.Id).Distinct().Count() != newCodes.Count()) { throw new InvalidOperationException( string.Format("The same code cannot be entered twice for notification {0}", Id)); } if (newCodes.Any(p => p.CodeType != codeType)) { throw new InvalidOperationException(string.Format("All codes must be of type {0} for notification {1}", codeType, Id)); } var existingCodes = GetWasteCodes(codeType).ToArray(); foreach (var code in existingCodes) { WasteCodeInfoCollection.Remove(code); } foreach (var code in newCodes) { WasteCodeInfoCollection.Add(code); } }
protected CodeDomTypeMetadata(CodeType codeType, bool isNullable, bool isTask, CodeDomFileMetadata file) { this.codeType = codeType; this.isNullable = isNullable; this.isTask = isTask; this.file = file; }
/// <summary> /// This function is used to verify if the specified <see cref="CodeType"/> is a valid class and if the class /// contains an import statement for the specified namespace. /// </summary> /// <param name="codeType">The specified <see cref="CodeType"/>.</param> /// <param name="productNamespace">The specified namespace value.</param> /// <returns><see langword="true" /> if the <see cref="CodeType"/> contains the specified namespace import statement; /// otherwise, <see langword="false" /> /// </returns> /// <remarks> // The function will not identify imports using the type aliases. For example, the function would return false for "System.Web.Mvc" // if the imports are used as below: // using A1 = System; // using A1.Web.Mvc; /// </remarks> public static bool IsProductNamespaceImported(CodeType codeType, string productNamespace) { if (codeType == null) { throw new ArgumentNullException("codeType"); } if (productNamespace == null) { throw new ArgumentNullException("productNamespace"); } FileCodeModel codeModel = codeType.ProjectItem.FileCodeModel; if (codeModel != null) { foreach (CodeElement codeElement in codeModel.CodeElements) { // This is needed to verify if the namespace import is present at the file level. if (IsNamespaceImportPresent(codeElement, productNamespace)) { return true; } // This is needed to verify if the import is present at the namespace level. if (codeElement.Kind.Equals(vsCMElement.vsCMElementNamespace) && IsImportPresentUnderNamespace(codeElement, productNamespace)) { return true; } } } return false; }
public StringBuilder GetExecutionCode( IEnumerable<string> usingNamespaces, string namespaceName, string baseClassName, string className, CodeType codeType, string execCode ) { string code = PrepareCode(codeType, execCode); string endCode = (code ?? "").TrimEnd().EndsWith("}") ? code.Contains("class") ? ";" : ";}" : ";}"; StringBuilder usingNs = new StringBuilder(); foreach (string uns in usingNamespaces) usingNs.AppendFormat("using {0};", uns); StringBuilder source = new StringBuilder(); source.AppendFormat(@" using System; using System.IO; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Linq; using it.jodan.SpoolPad.DataContext; using it.jodan.SpoolPad.Extensions; {0} namespace {1}{{ public class {2} : {3} {{ protected override void InternalRun(){{ {4}{5} }} }} ", usingNs, namespaceName, className, baseClassName, code, endCode); return source; }
private string PrepareCode( CodeType codeType, string source ) { if (CommonHelper.IsNullOrEmptyOrBlank(source)) return null; string ret = string.Empty; string[] lines = source.Trim().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string temp = line.Trim(); if (temp.StartsWith("//")) continue; ret += temp + "\n"; } switch (codeType) { case CodeType.CSharpFastCode:{ if (CommonHelper.IsNullOrEmptyOrBlank(ret)) return string.Empty; if (!ret.EndsWith("/")) { if (ret.StartsWith("from") && !ret.EndsWith(")")) ret = "(" + ret + ")"; if (!ret.Contains(".Spool(")) ret += ".Spool();"; } break; } } return ret; }
private string PrepareCode( CodeType codeType, string source ) { if (CommonHelper.IsNullOrEmptyOrBlank(source)) return null; string ret = string.Empty; string[] lines = source.Trim().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string temp = line.Trim(); if (temp.StartsWith("'")) continue; ret += temp + Environment.NewLine; } switch (codeType) { case CodeType.VBasicCodeBlock: { break; } } return ret; }
// Generates all of the Web Forms Pages (Default Insert, Edit, Delete), private void AddControllers( Project project, string selectionRelativePath, string dbContextNamespace, string dbContextTypeName, CodeType modelType, bool overwriteViews = true ) { if (modelType == null) { throw new ArgumentNullException("modelType"); } var webForms = new[] { "Controller" }; // Now add each view foreach (string webForm in webForms) { AddControllerTemplates( selectionRelativePath: selectionRelativePath, modelType: modelType, dbContextNamespace: dbContextNamespace, dbContextTypeName: dbContextTypeName, webFormsName: webForm, overwrite: overwriteViews); } }
/// <summary> /// Initializes a new instance of the <see cref="Token"/> class. /// </summary> /// <param name="line">Line number where the token was found (beginning with line 0).</param> /// <param name="position">Position of the token in the line (starting with 0).</param> /// <param name="length">The length of the text.</param> /// <param name="text">Found text.</param> /// <param name="codeType">The type of the token.</param> public Token(int line, int position, int length, string text, CodeType codeType) { Line = line; Position = position; Length = length; Text = text; CodeType = codeType; }
public static WasteCodeInfo CreateNotApplicableCodeInfo(CodeType codeType) { return new WasteCodeInfo { CodeType = codeType, IsNotApplicable = true, }; }
/// <summary> /// /// </summary> /// <param name="tableName"></param> /// <param name="language"></param> /// <param name="memberPrefix"></param> /// <param name="includeWCFTags"></param> /// <param name="buildOutProperties"></param> public static void Execute(string tableName, CodeType language, string memberPrefix, bool includeWCFTags, bool buildOutProperties) { string className = tableName; string sqlQuery = "SELECT TOP 1 * FROM " + tableName; Execute(sqlQuery, className, language, memberPrefix, includeWCFTags, buildOutProperties, tableName); }
public ScanSuccessfulEventArgs(CodeType scanType, string rawScanResult, object scanResult, bool isScanTimeCalculated, TimeSpan scanTime) { this.ScanType = scanType; this.RawScanResult = rawScanResult; this.ScanResult = scanResult; this.IsScanTimeCalculated = isScanTimeCalculated; this.ScanTime = scanTime; }
public Code(CodeType codeType, object[] args,string codeStr,string machineCode) { this.codeType = codeType; this.args = args; this.codeStr = codeStr; this.machineCode = machineCode; this.index =0; this.address = 0; }
public string GenerateCodeByStoreProcedure(CodeType codeType, string objName, string spName, string sql, string returnObjMapping) { if (codeType == CodeType.BLL) return GetTogether.Studio.Database.StoreProcedure.GetBLL(Parameter, objName, spName); else { return GetTogether.Studio.Database.StoreProcedure.GetDAL(Parameter, objName, spName, sql, returnObjMapping); } }
public SelfDefining() { CodeType=CodeType.Unknown; exportForm=new SelfDefiningConfigForm(); importForm = new SelfDefiningConfigForm(); exportForm.IsImport = false; exportForm.Closed += new EventHandler(exportForm_Closed); importForm.IsImport = true; importForm.Closed += new EventHandler(importForm_Closed); }
protected virtual EnterWasteCodesViewModel MapCodes(WasteCodeDataAndNotificationData source, CodeType codeType) { return new EnterWasteCodesViewModel { IsNotApplicable = source.NotApplicableCodes.Any(nac => nac == codeType), SelectedWasteCodes = source.NotificationWasteCodeData[codeType].Where(wc => wc.Id != Guid.Empty).Select(wc => wc.Id).ToList(), WasteCodes = mapper.Map(source.LookupWasteCodeData[codeType]) }; }
public CodeModelModelMetadata(CodeType model) { if (model == null) { throw new ArgumentNullException("model"); } Properties = GetModelProperties(model).ToArray(); PrimaryKeys = GetModelProperties(model).Where(mp => mp.IsPrimaryKey).ToArray(); }
private void AddControllerTemplates( string selectionRelativePath, CodeType modelType, string dbContextNamespace, string dbContextTypeName, string webFormsName, bool overwrite = false ) { if (modelType == null) { throw new ArgumentNullException("modelType"); } if (String.IsNullOrEmpty(webFormsName)) { throw new ArgumentException(Resources.WebFormsViewScaffolder_EmptyActionName, "webFormsName"); } // Add folder for views. This is necessary to display an error when the folder already exists but // the folder is excluded in Visual Studio: see https://github.com/Superexpert/WebFormsScaffolding/issues/18 string outputFolderPath = Path.Combine("Controllers"); AddFolder(Context.ActiveProject, outputFolderPath); string modelNameSpace = modelType.Namespace != null ? modelType.Namespace.FullName : String.Empty; string relativePath = outputFolderPath.Replace(@"\", @"/"); List<string> webFormsTemplates = new List<string>(); webFormsTemplates.AddRange(new string[] { webFormsName }); // Scaffold aspx page and code behind foreach (string webForm in webFormsTemplates) { Project project = Context.ActiveProject; var templatePath = Path.Combine(webForm); string outputPath = Path.Combine(outputFolderPath, modelType.Name + webForm); var defaultNamespace = GetDefaultNamespace(); AddFileFromTemplate(project, outputPath, templateName: templatePath, templateParameters: new Dictionary<string, object>() { {"RelativePath", relativePath}, {"DefaultNamespace", defaultNamespace}, {"Namespace", modelNameSpace}, {"ViewDataType", modelType}, {"ViewDataTypeName", modelType.Name}, {"PluralizedName", GetPluralizedName(modelType.Name)}, {"DbContextNamespace", dbContextNamespace}, {"DbContextTypeName", dbContextTypeName} }, skipIfExists: !overwrite); } }
public int VisitCode(CodeType c) { writer.Write("new CodeType()", c.Size); return(0); }
public IterativeCoder(CodeType codeType) { CodeType = codeType; }
public IEnumerable <WorkItem> VisitCode(CodeType c) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="WrongCodeTypeException"/> class. /// </summary> /// <param name="codeType">The code type.</param> /// <param name="argumentName">Name of the argument.</param> /// <param name="expectedText">The expected text.</param> public WrongCodeTypeException(CodeType codeType, string argumentName, string expectedText) : base(string.Format("Wrong code type [{0}] of passed parameter '{1}'. Expected {2}.", codeType.Name, argumentName, expectedText)) { }
public void VisitCode(CodeType c) { throw new NotImplementedException(); }
// Collects the common data needed by all of the scaffolded output and generates: // 1) Dynamic Data Field Templates // 2) Web Forms Pages private void GenerateCode(Project project, string selectionRelativePath, WebFormsCodeGeneratorViewModel codeGeneratorViewModel) { foreach (var codeType in codeGeneratorViewModel.ModelTypeCollection.Where(m => m.Selected)) { // Get Model Type var modelType = codeType.CodeType; // Get the dbContext string dbContextTypeName = codeGeneratorViewModel.DbContextModelType.TypeName; ICodeTypeService codeTypeService = GetService <ICodeTypeService>(); CodeType dbContext = codeTypeService.GetCodeType(project, dbContextTypeName); // Get the dbContext namespace string dbContextNamespace = dbContext.Namespace != null ? dbContext.Namespace.FullName : String.Empty; if (codeGeneratorViewModel.GenerateViews) { // Add Web Forms Pages from Templates AddWebFormsPages( project, selectionRelativePath, dbContextNamespace, dbContextTypeName, modelType, codeGeneratorViewModel.Overwrite ); } if (codeGeneratorViewModel.GenerateController) { // Add Controllers from Templates AddControllers( project, selectionRelativePath, dbContextNamespace, dbContextTypeName, modelType, codeGeneratorViewModel.Overwrite ); } if (codeGeneratorViewModel.GenerateApiController) { // Add Controllers from Templates AddApiControllers( project, selectionRelativePath, dbContextNamespace, dbContextTypeName, modelType, codeGeneratorViewModel.Overwrite ); } if (codeGeneratorViewModel.GenerateStorageContext) { // Add Storage Contexts from Templates AddStorageContexts( project, selectionRelativePath, dbContextNamespace, dbContextTypeName, modelType, codeGeneratorViewModel.Overwrite ); } if (codeGeneratorViewModel.GenerateScripts) { // Add Storage Contexts from Templates AddScripts( project, selectionRelativePath, dbContextNamespace, dbContextTypeName, modelType, codeGeneratorViewModel.Overwrite ); } } }
/// <summary> /// Verifies if the specified code type is correct for this class. /// </summary> /// <param name="codeType">The code type.</param> /// <returns>Extracted data object or <c>null</c> if fails.</returns> internal static object VerifyCodeType(CodeType codeType) { // We want to have this kind of hierarchy // __tree_ // | __begin_node_ // | __left_ // | __is_black_ // | __left_ // | __parent_ // | __right_ // | __pair1_ // | __value_ (same type as __begin_node_) // | __left_ // | __is_black_ // | __left_ // | __parent_ // | __right_ // | __pair3_ // | __value_ CodeType __tree_, __begin_node_, __left_, __is_black_, __left_2, __parent_, __right_, __pair1_, __value_, __pair3_, __value_2; if (!codeType.GetFieldTypes().TryGetValue("__tree_", out __tree_)) { return(null); } if (!__tree_.GetFieldTypes().TryGetValue("__begin_node_", out __begin_node_) || !__tree_.GetFieldTypes().TryGetValue("__pair1_", out __pair1_) || !__tree_.GetFieldTypes().TryGetValue("__pair3_", out __pair3_)) { return(null); } if (!__begin_node_.GetFieldTypes().TryGetValue("__left_", out __left_)) { return(null); } if (!__left_.GetFieldTypes().TryGetValue("__is_black_", out __is_black_) || !__left_.GetFieldTypes().TryGetValue("__left_", out __left_2) || !__left_.GetFieldTypes().TryGetValue("__parent_", out __parent_) || !__left_.GetFieldTypes().TryGetValue("__right_", out __right_)) { return(null); } if (!__pair1_.GetFieldTypes().TryGetValue("__value_", out __value_) || __value_ != __begin_node_.ElementType) { return(null); } if (!__pair3_.GetFieldTypes().TryGetValue("__value_", out __value_2)) { return(null); } CodeType pairCodeType, treeNodeCodeType; string pairFieldName; try { CodeType valueCodeType = (CodeType)__tree_.TemplateArguments[0]; pairFieldName = valueCodeType.GetFieldTypes().ContainsKey("__nc") ? "__nc" : "__cc"; pairCodeType = valueCodeType.GetFieldType(pairFieldName); CodeType treeNodeBaseCodeType = __left_.ElementType; const string treeNodeBaseNameStart = "std::__1::__tree_node_base<"; const string treeNodeNameStart = "std::__1::__tree_node<"; string treeNodeName = treeNodeNameStart + valueCodeType.Name + ", " + treeNodeBaseCodeType.Name.Substring(treeNodeBaseNameStart.Length); treeNodeCodeType = CodeType.Create(treeNodeName, valueCodeType.Module); } catch { return(null); } if (!pair <TKey, TValue> .VerifyCodeType(pairCodeType)) { return(null); } return(new ExtractedData { ReadSize = codeType.Module.Process.GetReadInt(codeType, "__tree_.__pair3_.__value_"), HeadIsPointer = true, HeadIsAtParent = false, HeadOffset = codeType.GetFieldOffset("__tree_") + __tree_.GetFieldOffset("__pair1_") + __pair1_.GetFieldOffset("__value_") + __value_.GetFieldOffset("__left_"), ItemLeftOffset = treeNodeCodeType.GetFieldOffset("__left_"), ItemParentOffset = treeNodeCodeType.GetFieldOffset("__parent_"), ItemRightOffset = treeNodeCodeType.GetFieldOffset("__right_"), ItemValueOffset = treeNodeCodeType.GetFieldOffset("__value_") + treeNodeCodeType.GetFieldType("__value_").GetFieldOffset(pairFieldName), ItemValueCodeType = pairCodeType, ReadItemIsNil = null, CodeType = codeType, Process = codeType.Module.Process, }); }
public static CustomAttributeData GetCustomAttribute(this CodeType ct, Type attrType) { return(ct.GetCustomAttributes().FirstOrDefault(x => x.AttributeType == attrType)); }
private bool IsReallyValidWebProjectEntityType(CodeType codeType) { return(!IsAbstract(codeType)); }
/// <summary> /// Verifies if the specified code type is correct for this class. /// </summary> /// <param name="codeType">The code type.</param> /// <returns>Extracted data object or <c>null</c> if fails.</returns> internal static object VerifyCodeType(CodeType codeType) { // We want to have this kind of hierarchy // __r_ // | __value_ // | __l // | __cap_ // | __data_ // | __size_ // | __r // | __words // | __s // | __data_ // | __lx // | __size_ CodeType __r_, __value_, __l, __cap_, __data_, __size_, __r, __words, __s, __data_2, __lx, __size_2; if (!codeType.GetFieldTypes().TryGetValue("__r_", out __r_)) { return(null); } if (!__r_.GetFieldTypes().TryGetValue("__value_", out __value_)) { return(null); } if (!__value_.GetFieldTypes().TryGetValue("__l", out __l)) { return(null); } if (!__l.GetFieldTypes().TryGetValue("__cap_", out __cap_) || !__l.GetFieldTypes().TryGetValue("__data_", out __data_) || !__l.GetFieldTypes().TryGetValue("__size_", out __size_)) { return(null); } if (!__value_.GetFieldTypes().TryGetValue("__r", out __r)) { return(null); } if (!__r.GetFieldTypes().TryGetValue("__words", out __words)) { return(null); } if (!__value_.GetFieldTypes().TryGetValue("__s", out __s)) { return(null); } if (!__s.GetFieldTypes().TryGetValue("__data_", out __data_2) || !__s.GetFieldTypes().TryGetValue("__lx", out __lx) || !__s.GetFieldTypes().TryGetValue("__size_", out __size_2)) { return(null); } return(new ExtractedData { BufferLength = (int)(__data_2.Size / __data_2.ElementType.Size), BufferOffset = codeType.GetFieldOffset("__r_") + __r_.GetFieldOffset("__value_") + __value_.GetFieldOffset("__s") + __s.GetFieldOffset("__data_"), CharSize = (int)__data_2.ElementType.Size, PointerOffset = codeType.GetFieldOffset("__r_") + __r_.GetFieldOffset("__value_") + __value_.GetFieldOffset("__l") + __l.GetFieldOffset("__data_"), ReadCapacity = codeType.Module.Process.GetReadInt(codeType, "__r_.__value_.__l.__cap_"), ReadLongDataLength = codeType.Module.Process.GetReadInt(codeType, "__r_.__value_.__l.__size_"), ReadShortDataLength = codeType.Module.Process.GetReadInt(codeType, "__r_.__value_.__s.__size_"), CodeType = codeType, Process = codeType.Module.Process, }); }
/// <summary> /// public constructors /// </summary> /// <param name="len"> 验证码长度 </param> /// <param name="ctype"> 验证码类型:字母、数字、字母+ 数字 </param> public ValidCode(int len, CodeType ctype) { this._len = len; this._codetype = ctype; }
private void _LoadDSNHom() { DataTable list = CodeType.GetByGroup(_group); gridControl1.DataSource = list; }
/// <summary> /// Called when the Generate Migrations command is run /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void MigrationsCallback(object sender, EventArgs e) { IntPtr hierarchyPtr, selectionContainerPtr; uint projectItemId; IVsMultiItemSelect mis; IVsMonitorSelection monitorSelection = (IVsMonitorSelection)GetGlobalService(typeof(SVsShellMonitorSelection)); monitorSelection.GetCurrentSelection(out hierarchyPtr, out projectItemId, out mis, out selectionContainerPtr); IVsHierarchy hierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)) as IVsHierarchy; if (hierarchy == null) { FireError("F**k knows why but it is broken, sorry"); return; } object projObj; hierarchy.GetProperty(projectItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out projObj); ProjectItem projItem = projObj as ProjectItem; if (projItem == null) { FireError("The item you have selected is not playing nicely. Apologies"); return; } var project = projItem.ContainingProject; var migrations = new List <Migration>(); var allClasses = GetProjectItems(project.ProjectItems).Where(v => v.Name.Contains(".cs")); // check for .cs extension on each, foreach (var c in allClasses) { var eles = c.FileCodeModel; if (eles == null) { continue; } foreach (var ele in eles.CodeElements) { if (ele is EnvDTE.CodeNamespace) { var ns = ele as EnvDTE.CodeNamespace; // run through classes foreach (var property in ns.Members) { var member = property as CodeType; if (member == null) { continue; } // check all classes they derive from to see if any of them are migration classes, add them if so migrations.AddRange(from object b in member.Bases select b as CodeClass into bClass where bClass != null && bClass.Name == "DataMigrationImpl" select new Migration(member)); } } } } var model = projItem.FileCodeModel; if (model == null) { FireError("This class you have selected is weird and broken. Choose another one"); return; } var elements = model.CodeElements; var classes = new List <Model>(); // run through elements (they are done in a hierachy, so first we have using statements and the namespace) to find namespace foreach (var ele in elements) { if (ele is EnvDTE.CodeNamespace) { var ns = ele as EnvDTE.CodeNamespace; // run through classes foreach (var c in ns.Members) { var member = c as CodeType; if (member == null) { continue; } classes.Add(new Model() { Class = member, Name = member.Name }); } } } if (!classes.Any()) { FireError("No classes in the selected file!"); return; } var vm = new MigrationsViewModel(migrations, classes); var window = new MigrationsWindow(vm); var success = window.ShowDialog(); if (!success.GetValueOrDefault()) { return; } CodeType selectedClass = vm.SelectedClass.Class; if (selectedClass == null) { FireError("No class to generate migrations from!"); return; } // name of class var modelName = selectedClass.Name; // get code class var cc = selectedClass as CodeClass; // get all members of the class var members = cc.Members; bool contentPartRecord = false; foreach (var d in cc.Bases) { var dClass = d as CodeClass; if (dClass != null && dClass.Name == "ContentPartRecord") { contentPartRecord = true; } } var props = new List <MigrationItem>(); //iterate through to find properties foreach (var member in members) { var prop = member as CodeProperty; if (prop == null) { continue; } if (prop.Access != vsCMAccess.vsCMAccessPublic) { continue; } var type = prop.Type; var name = prop.Name; var fullName = type.AsFullName; var nullable = fullName.Contains(".Nullable<"); var sType = type.AsString.Replace("?", ""); var sName = name; // if model, add _Id for nhibernate if (fullName.Contains(".Models.") || fullName.Contains(".Records.")) { sName += "_Id"; sType = "int"; } var mi = new MigrationItem() { Name = name, SuggestedName = sName, Type = fullName, SuggestedType = sType, Nullable = nullable, Create = true, }; props.Add(mi); } var createMigrationFile = !String.IsNullOrEmpty(vm.NewMigration); if (!createMigrationFile) { if (vm.SelectedMigration == null) { FireError("Select a migration or choose a new one!"); return; } var mig = vm.SelectedMigration.CodeType; string path = (string)mig.ProjectItem.Properties.Item("FullPath").Value; string text = File.ReadAllText(path); var noTimesCreated = Regex.Matches(text, @"SchemaBuilder.Create\(""" + modelName + @""",").Count; var noTimesDropped = Regex.Matches(text, @"SchemaBuilder.DropTable\(""" + modelName + @"""\)").Count; bool created = noTimesCreated > noTimesDropped; if (noTimesCreated == 1 && noTimesDropped == 0) { foreach (var p in props.Where(p => text.Contains(p.Name))) { p.Create = false; } } if (created) { foreach (var p in props) { var name = p.Name; var noDrops = Regex.Matches(text, @".DropColumn\(""" + name).Count; var noOccurences = Regex.Matches(text, name).Count; if ((noOccurences - noDrops) > noDrops) { p.Create = false; } } } } // if a collection ignore foreach (var p in props) { if (p.Type.Contains("System.Collection")) { p.Create = false; } } var bmvm = new BuildMigrationsViewModel(props); var bmWindow = new BuildMigrationsWindow(bmvm); var bmSuccess = bmWindow.ShowDialog(); if (!bmSuccess.GetValueOrDefault()) { return; } var sb = new StringBuilder(); var createTable = "SchemaBuilder.CreateTable(\"" + modelName + "\", t => t"; sb.AppendLine(createTable); if (contentPartRecord) { sb.AppendLine("\t.ContentPartRecord()"); } foreach (var p in bmvm.Migrations.Where(z => z.Create)) { sb.AppendLine("\t" + ParseMigrationItem(p)); } sb.AppendLine(");"); var editViewModel = new EditMigrationsViewModel() { Migrations = sb.ToString() }; var editWindow = new EditMigrationsWindow(editViewModel); var emSuccess = editWindow.ShowDialog(); if (!emSuccess.GetValueOrDefault()) { return; } var migrationsCode = new StringBuilder(); using (StringReader reader = new StringReader(editViewModel.Migrations)) { string line; while ((line = reader.ReadLine()) != null) { migrationsCode.AppendLine(line.Insert(0, "\t\t\t")); } } if (!createMigrationFile) { EditMigrations(vm.SelectedMigration.CodeType, migrationsCode.ToString()); } else { var templates = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "OrchardTemplates"); var newMigration = project.ProjectItems.AddFromFileCopy(templates + "\\Migrationsxxx.cs"); Insert(newMigration.Properties.Item("FullPath").Value.ToString(), new[] { new KeyValuePair <string, string>("$module$", project.Name), new KeyValuePair <string, string>("$migrationName$", vm.NewMigration), new KeyValuePair <string, string>("$code$", migrationsCode.ToString()) }); var cs = vm.NewMigration.EndsWith(".cs") ? "" : ".cs"; newMigration.Name = vm.NewMigration + cs; } }
public DataType VisitCode(CodeType c) { return(c); }
public static bool HasAttribute(this CodeType ct, Type attrType) { return(ct.GetCustomAttribute(attrType) != null); }
public Constructor GetInstance(CodeType initializedType, InstanceAnonymousTypeLinker genericsLinker) => new Constructor(initializedType, _definedAt, AccessLevel.Public);
/// <summary> /// Verifies that type user type can work with the specified code type. /// </summary> /// <param name="codeType">The code type.</param> /// <returns><c>true</c> if user type can work with the specified code type; <c>false</c> otherwise</returns> public static bool VerifyCodeType(CodeType codeType) { return(typeSelector.VerifyCodeType(codeType)); }
/// <summary> /// Verifies if the specified code type is correct for this class. /// </summary> /// <param name="codeType">The code type.</param> /// <returns>Extracted data object or <c>null</c> if fails.</returns> internal static object VerifyCodeType(CodeType codeType) { // We want to have this kind of hierarchy // _M_t // | _M_impl // | _M_header // | _M_color // | _M_left // | _M_parent // | _M_right // | ?_M_storage // | first // | second // | _M_node_count // | _M_key_compare CodeType _M_t, _M_impl, _M_header, _M_color, _M_left, _M_parent, _M_right, _M_node_count, _M_key_compare; if (!codeType.GetFieldTypes().TryGetValue("_M_t", out _M_t)) { return(null); } if (!_M_t.GetFieldTypes().TryGetValue("_M_impl", out _M_impl)) { return(null); } var _M_implFields = _M_impl.GetFieldTypes(); if (!_M_implFields.TryGetValue("_M_header", out _M_header) || !_M_implFields.TryGetValue("_M_node_count", out _M_node_count) || !_M_implFields.TryGetValue("_M_key_compare", out _M_key_compare)) { return(null); } var _M_headerFields = _M_header.GetFieldTypes(); if (!_M_headerFields.TryGetValue("_M_color", out _M_color) || !_M_headerFields.TryGetValue("_M_left", out _M_left) || !_M_headerFields.TryGetValue("_M_parent", out _M_parent) || !_M_headerFields.TryGetValue("_M_right", out _M_right)) { return(null); } CodeType pairCodeType; try { pairCodeType = (CodeType)_M_t.TemplateArguments[1]; } catch { return(null); } if (!pair <TKey, TValue> .VerifyCodeType(pairCodeType)) { return(null); } return(new ExtractedData { ReadSize = codeType.Module.Process.GetReadInt(codeType, "_M_t._M_impl._M_node_count"), HeadIsPointer = false, HeadIsAtParent = true, HeadOffset = codeType.GetFieldOffset("_M_t") + _M_t.GetFieldOffset("_M_impl") + _M_impl.GetFieldOffset("_M_header"), ItemLeftOffset = _M_header.GetFieldOffset("_M_left"), ItemParentOffset = _M_header.GetFieldOffset("_M_parent"), ItemRightOffset = _M_header.GetFieldOffset("_M_right"), ItemValueOffset = (int)_M_header.ElementType.Size, ItemValueCodeType = pairCodeType, ReadItemIsNil = null, CodeType = codeType, Process = codeType.Module.Process, }); }
private string getSample(CodeType codetype) { string sample = ""; if (codetype == Sites.Models.CodeType.Api) { sample = @"// sample code.. //var obj = {}; //obj.name = ""myname""; //obj.fieldtwo = ""value of field two""; //k.response.setHeader(""Access-Control-Allow-Origin"", ""*""); //k.response.json(obj); "; } else if (codetype == Sites.Models.CodeType.Datasource) { sample = @"//sample code, use the k.export to return datasource. //var list = []; //var obj = {name: ""myname"", fieldtwo: ""field two value""}; //list.push(obj); //var obj2 = {name: ""myname2"", fieldtwo: ""field two value2""}; //list.push(obj2); //k.export(list); "; } else if (codetype == Sites.Models.CodeType.Diagnosis) { sample = @"// sample code. //var allpages = k.siteDb.pages.all(); //var page = allpages[0]; //if (page.body.length> 200) //{ // var error = ""Page too long: "" + page.name; // k.diagnosis.error(error); //}"; } else if (codetype == Sites.Models.CodeType.Event) { sample = @"//common event varilables: k.event.url, k.event.userAgent, k.event.culture; //variables per event. k.event.page, k.event.view, k.event.route; // Finding=before object found. Found = object founded. //example, url redirect. only valid on RouteFinding event. //if (k.event.url.indexOf(""pagetwo"")>-1) //{ // k.event.url = ""/pageone""; //}"; } else if (codetype == Sites.Models.CodeType.PageScript) { sample = @"// kscript that can be inserted to page position. //k.cookie.set(""key"", ""value""); //k.response.write(""Hello world"");"; } else if (codetype == Sites.Models.CodeType.Job) { sample = @"//Schedule task"; } else if (codetype == Sites.Models.CodeType.PaymentCallBack) { sample = @"// kscript that can be inserted to page position. //k.cookie.set(""key"", ""value""); //k.response.write(""Hello world"");"; } else if (codetype == Sites.Models.CodeType.Job) { sample = @"//Schedule task"; } return(sample); }
/// <summary> /// Verifies that type selector can work with the specified code type. /// </summary> /// <param name="codeType">The code type.</param> /// <returns><c>true</c> if type selector can work with the specified code type; <c>false</c> otherwise</returns> public bool VerifyCodeType(CodeType codeType) { return(verifiedTypes[codeType] != null); }
public abstract string TranslateType(CodeType type);
protected void btnCTSave_Click(object sender, ImageClickEventArgs e) { try { var obj = new CodeType(); var isEdit = false; int pk = 0; if (CTID.Text != "") { pk = int.Parse(CTID.Text); obj.Fetch(pk); isEdit = true; } if (!isEdit) { obj.isSystem = false; } obj.Description = CodeTypeDesc.Text; obj.CodeTypeName = CodeTypeValue.Text; if (isEdit) { if (obj.IsValid(BusinessRulesValidationMode.UPDATE)) { obj.Update(); LoadData(); ShowDD(); var masterPage = (IControlRoomMaster)Master; masterPage.PageMessage = SRPResources.SaveOK; } else { var masterPage = (IControlRoomMaster)Master; string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in obj.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } } else { if (obj.IsValid(BusinessRulesValidationMode.INSERT)) { pk = obj.Insert(); LoadData(); ddlCodeTypes.SelectedValue = pk.ToString(); ShowDD(); var masterPage = (IControlRoomMaster)Master; masterPage.PageMessage = SRPResources.AddedOK; } else { var masterPage = (IControlRoomMaster)Master; string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in obj.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } } } catch (Exception ex) { var masterPage = (IControlRoomMaster)Master; masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message); } }
public SerializedType VisitCode(CodeType c) { return(new CodeType_v1()); }
/// <summary> /// public constructors /// </summary> /// <param name="len"> 验证码长度 </param> /// <param name="ctype"> 验证码类型:字母、数字、字母+ 数字 </param> public VerificationCode(int len, CodeType ctype) { this._len = len; this._codetype = ctype; }
public FairaCoder(CodeType codeType) { CodeType = codeType; _jsonParser = new JsonParser <QuestionEntity>(); }
/// <summary> /// Verifies if the specified code type is correct for this class. /// </summary> /// <param name="codeType">The code type.</param> /// <returns>Extracted data object or <c>null</c> if fails.</returns> internal static object VerifyCodeType(CodeType codeType) { // We want to have this kind of hierarchy // _Mypair // | _Myval2 // | _Myval2 // | _Myhead // | _Parent // | _Left // | _Right // | _Isnil // | _Myval // | first // | second // | _Mysize CodeType _Mypair, _Myval2, _Myval22, _Myhead, _Parent, _Left, _Right, _Myval, _Mysize, _Isnil; if (!codeType.GetFieldTypes().TryGetValue("_Mypair", out _Mypair)) { return(null); } if (!_Mypair.GetFieldTypes().TryGetValue("_Myval2", out _Myval2)) { return(null); } if (!_Myval2.GetFieldTypes().TryGetValue("_Myval2", out _Myval22)) { return(null); } var _Myval2Fields = _Myval22.GetFieldTypes(); if (!_Myval2Fields.TryGetValue("_Myhead", out _Myhead) || !_Myval2Fields.TryGetValue("_Mysize", out _Mysize)) { return(null); } var _MyheadFields = _Myhead.GetFieldTypes(); if (!_MyheadFields.TryGetValue("_Parent", out _Parent) || !_MyheadFields.TryGetValue("_Left", out _Left) || !_MyheadFields.TryGetValue("_Right", out _Right) || !_MyheadFields.TryGetValue("_Myval", out _Myval) || !_MyheadFields.TryGetValue("_Isnil", out _Isnil)) { return(null); } if (!pair <TKey, TValue> .VerifyCodeType(_Myval)) { return(null); } return(new ExtractedData { ReadSize = codeType.Module.Process.GetReadInt(codeType, "_Mypair._Myval2._Myval2._Mysize"), HeadIsPointer = true, HeadIsAtParent = true, HeadOffset = codeType.GetFieldOffset("_Mypair") + _Mypair.GetFieldOffset("_Myval2") + _Myval2.GetFieldOffset("_Myval2") + _Myval22.GetFieldOffset("_Myhead"), ItemLeftOffset = _Myhead.GetFieldOffset("_Left"), ItemParentOffset = _Myhead.GetFieldOffset("_Parent"), ItemRightOffset = _Myhead.GetFieldOffset("_Right"), ItemValueOffset = _Myhead.GetFieldOffset("_Myval"), ItemValueCodeType = _Myval, ReadItemIsNil = codeType.Module.Process.GetReadInt(_Myhead, "_Isnil"), CodeType = codeType, Process = codeType.Module.Process, }); }
public async Task <string> Generate(CodeType type) { return(await _codeService.GenerateCode(type)); }
/// <summary> /// Verifies if the specified code type is correct for this class. /// </summary> /// <param name="codeType">The code type.</param> private static bool VerifyCodeType(CodeType codeType) { return(codeType.IsFunction); }
public async Task <IList <Code> > List(CodeType type) { return(await _codeService.List(type)); }
public Expression VisitCode(CodeType c) { throw new NotImplementedException(); }