public static WordModel ConvertEntityToModel(Word source) { var wordModel = new WordModel { Name = source.Name, Level = source.Level, Definitions = new List <DefinitionModel>() }; if (source.Meanings != null) { foreach (var meaningEntity in source.Meanings) { var definitionModel = new DefinitionModel { PartOfSpeech = meaningEntity.PartOfSpeech }; if (meaningEntity.Definitions != null) { foreach (var definitionEntity in meaningEntity.Definitions.Where(d => d.Language == Language.English)) { definitionModel.Define = definitionEntity.Define; definitionModel.Example = definitionEntity.Example; definitionModel.Antonyms = definitionEntity.Antonyms?.AsString(); definitionModel.Synonyms = definitionEntity.Synonyms?.AsString(); } } wordModel.Definitions.Add(definitionModel); } } return(wordModel); }
private async Task OnSearchWordAsync(string wordToSearch) { await spinner.ShowAsync(async() => { var wordResult = await dictionaryService.FindAsync(wordToSearch); if (wordResult.IsFound) { wordModel.Name = wordResult.Word; wordModel.Definitions.Clear(); foreach (var meaning in wordResult.Meanings) { var definitionModel = new DefinitionModel { PartOfSpeech = meaning.PartOfSpeech }; foreach (var definition in meaning.Definitions) { definitionModel.Antonyms = string.Join(",", definition.Antonyms); definitionModel.Synonyms = string.Join(",", definition.Synonyms); definitionModel.Define = definition.Define; definitionModel.Example = definition.Example; } wordModel.Definitions.Add(definitionModel); } } }); }
public async Task <DefinitionModel> GetDefinitions(string word) { string requestString = $"{word}/definitions"; DefinitionModel result = RequestWordsApi(requestString); return(await Task.FromResult(result)); }
public static DefinitionModel MapDefinition( CoreModel designer, DefinitionModel model, LookupValues lookupValues) { model.Keys = lookupValues.DefinitionValues .Where(dv => dv.Id == model.Id) .ToDictionary(kvp => kvp.Key, kvp => kvp); model.Tags = lookupValues.DefinitionTags .Where(dt => dt.DefinitionId == model.Id); model.Settings = lookupValues.DefinitionSettings .Where(ds => ds.DefinitionId == model.Id); model.Settings.ToList().ForEach(s => { // Get all values for DefinitionSettings s.Keys = lookupValues.DefinitionSettingsValues .Where(dsv => dsv.Id == s.Id) .ToDictionary(kvp => kvp.Key, kvp => kvp); }); return(model); }
public async Task <ActionResult> Create([Bind(Include = "DefinitionId,Term,TermDefinition")] DefinitionModel model) { try { if (ModelState.IsValid) { var def = (from d in db.Definitions where d.Term == model.Term select d).FirstOrDefault(); if (def != null) { //def.TermDefinition = model.TermDefinition; ModelState.AddModelError("Term", "A definition already exists for this Term"); return(View(model)); } else { var definition = new Definition { Term = model.Term, TermDefinition = model.TermDefinition }; db.Definitions.Add(definition); } await db.SaveChangesAsync(); return(RedirectToAction("List")); } return(View(model)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(RedirectToActionPermanent("Index", "Error")); } }
public void Init() { IsEnter = false; IsShow = false; CurDefinitionModel = DefinitionModel.UNKOWN; AutoDefinitionModel = DefinitionModel.UNKOWN; OldDefnBtn = AutoBtn; CurrentDefnList = new List <MifengPlayer.DefnInfo>(); EventTriggerListener.Get(this.gameObject).OnPtEnter = OnPointerEnterPanel; EventTriggerListener.Get(this.gameObject).OnPtExit = OnPointerExitPanel; EventTriggerListener.Get(FourKBtn.gameObject).OnPtEnter = OnPointerEnterBtn; EventTriggerListener.Get(FourKBtn.gameObject).OnPtExit = OnPointerExitBtn; EventTriggerListener.Get(FHDBtn.gameObject).OnPtEnter = OnPointerEnterBtn; EventTriggerListener.Get(FHDBtn.gameObject).OnPtExit = OnPointerExitBtn; EventTriggerListener.Get(SHDBtn.gameObject).OnPtEnter = OnPointerEnterBtn; EventTriggerListener.Get(SHDBtn.gameObject).OnPtExit = OnPointerExitBtn; EventTriggerListener.Get(AutoBtn.gameObject).OnPtEnter = OnPointerEnterBtn; EventTriggerListener.Get(AutoBtn.gameObject).OnPtExit = OnPointerExitBtn; FourKBtn.SelectBtnCallback = SelectFourKBtn; FHDBtn.SelectBtnCallback = SelectFHDBtn; SHDBtn.SelectBtnCallback = SelectSHDBtn; AutoBtn.SelectBtnCallback = SelectAutoBtn; }
public void SetDefnList(List <MifengPlayer.DefnInfo> list, MifengPlayer.DefnInfo current) { SHDBtnIsDisable = true; FHDBtnIsDisable = true; FourKBtnIsDisable = true; CurrentDefnList.Clear(); CurrentDefnList.AddRange(list); for (int i = 0; i < list.Count; i++) { DefinitionModel defn = list[i].defn; if (defn.Equals(DefinitionModel.DEFINITION_720P) && list[i].benefitType == 0) { SHDBtnIsDisable = false; } if (defn.Equals(DefinitionModel.DEFINITION_1080P) && list[i].benefitType == 0) { FHDBtnIsDisable = false; } if (defn.Equals(DefinitionModel.DEFINITION_4K) && list[i].benefitType == 0) { FourKBtnIsDisable = false; } } //if (current.defn != null || current.name != null) { AutoBtnIsDisable = false; if (AutoDefinitionModel != DefinitionModel.UNKOWN) { return; //说明选择过自动 } switch (current.defn) { case DefinitionModel.DEFINITION_720P: AutoDefinitionModel = DefinitionModel.DEFINITION_720P; break; case DefinitionModel.DEFINITION_1080P: AutoDefinitionModel = DefinitionModel.DEFINITION_1080P; break; case DefinitionModel.DEFINITION_4K: AutoDefinitionModel = DefinitionModel.DEFINITION_4K; break; default: AutoDefinitionModel = DefinitionModel.DEFINITION_720P; break; } } SetUIState(); if (ChangeDefinitionModelCallback != null) { ChangeDefinitionModelCallback(AutoDefinitionModel, false, true); } }
public DefnInfo() { this.defn = DefinitionModel.DEFINITION_720P; this.audioType = 0; this.codecType = 0; this.dynamicRangeType = 0; this.ctrlType = 0; this.benefitType = 0; this.obj = null; }
/// <summary> /// Create a Definition record in the database. /// </summary> /// <param name="Model">A model of the Definition properties.</param> /// <returns>The newly created Definition model.</returns> public long Create(DefinitionModel Model, long UserId) { var spr_name = "[Verspyre].[Insert_Definition]"; var spr_prms = new { Model.GameId, UserId }; return(_cnx.Query <long>(spr_name, spr_prms, commandType: CommandType.StoredProcedure).Single()); }
public IActionResult Index() { Attempt = new AttemptModel(); List <DefinitionModel> Definitions = _db.Definitions.ToList(); Random random = new Random(); int randomIndex = random.Next(Definitions.Count); DefinitionModel definition = Definitions[randomIndex]; Attempt.Definition = definition; return(View(Attempt)); }
public IActionResult Upsert(int?id) { Definition = new DefinitionModel(); if (id == null) { return(View(Definition)); } Definition = _db.Definitions.FirstOrDefault(u => u.Id == id); if (id == null) { return(NotFound()); } return(View(Definition)); }
void SelectAutoBtn(MixedButton stb, bool isSelect) { if (AutoBtnIsDisable || OldDefnBtn == stb) { return; } OldDefnBtn.SetSelected(false); OldDefnBtn = stb; stb.SetSelected(true); CurDefinitionModel = DefinitionModel.UNKOWN; if (ChangeDefinitionModelCallback != null) { ChangeDefinitionModelCallback(AutoDefinitionModel, true, true); } }
void SelectSHDBtn(MixedButton stb, bool isSelect) { if (SHDBtnIsDisable || OldDefnBtn == stb) { return; } OldDefnBtn.SetSelected(false); OldDefnBtn = stb; stb.SetSelected(true); CurDefinitionModel = DefinitionModel.DEFINITION_720P; if (ChangeDefinitionModelCallback != null) { ChangeDefinitionModelCallback(DefinitionModel.DEFINITION_720P, true, true); } }
public long SaveDefinition(DefinitionModel Model) { if (Model.Id == 0) { // INSERT return(_context.Definitions.Create(Model, User.Id)); } else { // UPDATE _context.Definitions.Update(Model, User.Id); } return(Model.Id); }
public IActionResult Upsert(DefinitionModel definition) { if (ModelState.IsValid) { if (Definition.Id == 0) { _db.Definitions.Add(Definition); } else { _db.Definitions.Update(Definition); } _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(Definition)); }
public MifengPlayer.DefnInfo GetDefnInfoWithModel(DefinitionModel model) { if (model == DefinitionModel.UNKOWN) { return(null); } foreach (MifengPlayer.DefnInfo info in CurrentDefnList) { if (info.defn == model) { return(info); } } return(null); }
public async Task <ActionResult> Edit([Bind(Include = "DefinitionId,Term,TermDefinition")] DefinitionModel definition) { try { if (ModelState.IsValid) { var def = (from d in db.Definitions where d.Term == definition.Term select d).FirstOrDefault(); if (def != null) { if (def.DefinitionId != definition.DefinitionId) { // Validation error - there is an existing definition for that term ModelState.AddModelError("Term", "A definition already exists for this Term"); return(View(definition)); } else { def.Term = definition.Term; def.TermDefinition = definition.TermDefinition; db.Entry(def).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("List")); } } else { // Re-defining current term (Term does not conflict with existing) var rename = (from d in db.Definitions where d.DefinitionId == definition.DefinitionId select d).FirstOrDefault(); rename.Term = definition.Term; rename.TermDefinition = definition.TermDefinition; db.Entry(rename).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("List")); } } return(View(definition)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(RedirectToActionPermanent("Index", "Error")); } }
/// <summary> /// Read one Definition record from the database by Id. /// </summary> /// <returns>The Definition model that matches the given Id's.</returns> public void Update(DefinitionModel Definition, long UserId) { var spr_name = "[Verspyre].[Update_Definition]"; var settings = Definition.Settings?.Select(s => (TableDefinitionSettingModel)s); var definitionSettings = Definition.GetSettingsValues(); var spr_prms = new { Id = Definition.Id, Name = Definition.Name, ControlId = Definition.ControlId, GroupId = Definition.GroupId, UserId, Tags = Definition.Tags.ToDataTable(), Settings = settings.ToDataTable(), SettingsValues = definitionSettings.ToDataTable() }; _cnx.Execute(spr_name, spr_prms, commandType: CommandType.StoredProcedure); }
void ChangeDefinitionModel(DefinitionModel definitionModel, bool IsChangeSDK, bool IsNeedToast = true) { //switch (definitionModel) //{ // case DefinitionModel.DEFINITION_4K: // DefinitionBtn.GetComponentInChildren<Text>().SetTextByKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.AutoBtn.Text", "4K"); // break; // case DefinitionModel.DEFINITION_1080P: // DefinitionBtn.GetComponentInChildren<Text>().SetTextByKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.AutoBtn.Text", "1080P"); // break; // case DefinitionModel.DEFINITION_720P: // DefinitionBtn.GetComponentInChildren<Text>().SetTextByKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.AutoBtn.Text", "720P"); // break; // case DefinitionModel.UNKOWN: // DefinitionBtn.GetComponentInChildren<Text>().SetTextByKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.Title.Text"); // break; // default: // DefinitionBtn.GetComponentInChildren<Text>().SetTextByKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.AutoBtn.Text", "720P"); // break; //} }
/// <summary> /// Home page /// </summary> public ActionResult Index() { try { // Random 'term of the day' DefinitionModel model = null; var defs = (from d in db.Definitions select d).ToArray(); if (defs.Length > 0) { var r = new Random().Next(defs.Length); model = new DefinitionModel { Term = defs[r].Term, TermDefinition = defs[r].TermDefinition }; } return(View(model)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(RedirectToActionPermanent("Index", "Error")); } }
private void ChangeDefinitionModel(DefinitionModel definitionModel, bool IsChangeSDK, bool IsNeedToast = true) { //切换中 if (CurDefn == definitionModel) { return; } CurDefn = definitionModel; if (IsChangeSDK) { if (IsNeedToast) { ChooseCinemaCnvasTrans(); switch (definitionModel) { case DefinitionModel.DEFINITION_4K: CinemaTipsCanvasControl.GetInstance().GlobalToast.ShowToastByXMLLanguageKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.StartChangeDefinition", "4K"); break; case DefinitionModel.DEFINITION_1080P: CinemaTipsCanvasControl.GetInstance().GlobalToast.ShowToastByXMLLanguageKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.StartChangeDefinition", "1080P"); break; case DefinitionModel.DEFINITION_720P: CinemaTipsCanvasControl.GetInstance().GlobalToast.ShowToastByXMLLanguageKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.StartChangeDefinition", "720P"); break; default: CinemaTipsCanvasControl.GetInstance().GlobalToast.ShowToastByXMLLanguageKey("Cinema.VideoPlayerPanel.VariablePanel.DefinitionPanel.StartChangeDefinition", "720P"); break; } IsChangeDefinitionModel = true; } Cinema.VideoPlayer.SetDefinitionModel(VideoPlayerPanel.VideoCtrlPanel.SettingsPanel.DefinitionPanel.GetDefnInfoWithModel(definitionModel)); } }
private static string DefinitionToJson(Dictionary <string, DefinitionModel> definitions, DefinitionModel model) { if (model.Type == "object") { return(GenerateObject(definitions, model.Properties)); } if (model.Type == "array") { return(GenerateArray(definitions, model.Properties)); } throw new Exception($"Definition type {model.Type.ToUpper()} is not found"); }
private void OnDeleteDefinition(DefinitionModel definition) => wordModel.Definitions.Remove(definition);
public DefinitionPage() { ViewModel = new DefinitionModel(); InitializeComponent(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var pathInput = Path.Combine(AppContext.BaseDirectory, "swagger.json"); var json = File.ReadAllText(pathInput); json = json.Replace("$ref", "ref"); var document = JsonConvert.DeserializeObject <DocumentModel>(json); var pathOutput = Path.Combine(AppContext.BaseDirectory, "document.xlsx"); if (File.Exists(pathOutput)) { File.Delete(pathOutput); } using (var package = new ExcelPackage(new FileInfo(pathOutput))) { var workSheet = package.Workbook.Worksheets.Add("APIs"); workSheet.PrinterSettings.LeftMargin = (decimal)0.2; workSheet.PrinterSettings.RightMargin = 0; workSheet.View.PageLayoutView = true; workSheet.View.ShowGridLines = false; workSheet.Cells.Style.WrapText = true; workSheet.Cells.Style.Font.Name = "Calibri (Body)"; workSheet.Cells.Style.Font.Size = 10; workSheet.Column(1).Width = 5; workSheet.Column(2).Width = 3; workSheet.Column(3).Width = 13; workSheet.Column(4).Width = 15; workSheet.Column(5).Width = 47.6; workSheet.Column(6).Width = 9; //Title workSheet.Cells[1, 1, 1, 6].Merge = true; workSheet.Row(1).Height = 25; workSheet.Cells[1, 1, 1, 6].Style.Font.Size = 24; workSheet.Cells[1, 1, 1, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[1, 1, 1, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[1, 1, 1, 6].Style.Font.Color.SetColor(1, 48, 84, 150); workSheet.Cells[1, 1, 1, 6].Value = document.Info.Title; //Description workSheet.Cells[2, 1, 2, 6].Merge = true; workSheet.Cells[2, 1, 2, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[2, 1, 2, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[2, 1, 2, 6].Value = document.Info.Description; workSheet.Row(2).CustomHeight = true; //Version workSheet.Cells[3, 1, 3, 6].Merge = true; workSheet.Cells[3, 1, 3, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[3, 1, 3, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[3, 1, 3, 6].Value = $"Version: {document.Info.Version}"; var row = 5; var indexApi = 1; foreach (var path in document.Paths) { var url = path.Key; var methods = path.Value.First(); var method = methods.Key; var api = methods.Value; var summary = api.Summary; var inputType = api.Consumes.FirstOrDefault(); var outputType = api.Produces.FirstOrDefault(); var paramQuery = api.Parameters.Where(x => x.In == "query").ToList(); var paramBody = api.Parameters.FirstOrDefault(x => x.In == "body"); var response = api.Responses.ContainsKey("200") ? api.Responses["200"] : null; //Info workSheet.Cells[row, 1, row, 6].Style.Font.Bold = true; workSheet.Cells[row, 1, row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 1, row, 6].Style.Fill.BackgroundColor.SetColor(1, 180, 198, 231); workSheet.Cells[row, 1].Value = indexApi; workSheet.Cells[row, 2, row, 6].Style.Font.Bold = true; workSheet.Cells[row, 2, row, 6].Merge = true; workSheet.Cells[row, 2, row, 6].Value = url; workSheet.Row(row).CustomHeight = true; row++; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Summary"; workSheet.Cells[row, 4, row, 6].Merge = true; workSheet.Cells[row, 4, row, 6].Value = summary; workSheet.Row(row).CustomHeight = true; row++; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Method"; workSheet.Cells[row, 4, row, 6].Merge = true; workSheet.Cells[row, 4, row, 6].Value = method.ToUpper(); row++; //Parameter if (paramQuery.Count > 0) { row++; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Parameters"; workSheet.Cells[row, 4, row, 6].Merge = true; workSheet.Cells[row, 4, row, 6].Value = "Query string"; row++; workSheet.Cells[row, 1].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 1].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Style.Font.Bold = true; workSheet.Cells[row, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 1].Value = "STT"; workSheet.Cells[row, 2, row, 3].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 2, row, 3].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Style.Font.Bold = true; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 2, row, 3].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 2, row, 3].Value = "Field"; workSheet.Cells[row, 4].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 4].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Style.Font.Bold = true; workSheet.Cells[row, 4].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 4].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 4].Value = "Type"; workSheet.Cells[row, 5].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 5].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 5].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5].Style.Font.Bold = true; workSheet.Cells[row, 5].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 5].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 5].Value = "Description"; workSheet.Cells[row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 6].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 6].Style.Font.Bold = true; workSheet.Cells[row, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 6].Value = "Required"; row++; for (int i = 0; i < paramQuery.Count; i++) { var parameter = paramQuery[i]; workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = i + 1; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = parameter.Name; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(parameter.Format) ? $"{parameter.Type}" : $"{parameter.Type} ({parameter.Format})"; workSheet.Cells[row, 5].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5].Value = parameter.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; if (parameter.Required) { workSheet.Cells[row, 6].Value = "x"; } row++; } } //Body if (paramBody != null) { row++; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Body type"; workSheet.Cells[row, 4, row, 6].Merge = true; workSheet.Cells[row, 4, row, 6].Value = inputType; row++; workSheet.Cells[row, 1].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 1].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Style.Font.Bold = true; workSheet.Cells[row, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 1].Value = "STT"; workSheet.Cells[row, 2, row, 3].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 2, row, 3].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Style.Font.Bold = true; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 2, row, 3].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 2, row, 3].Value = "Field"; workSheet.Cells[row, 4].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 4].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Style.Font.Bold = true; workSheet.Cells[row, 4].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 4].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 4].Value = "Type"; workSheet.Cells[row, 5].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 5].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 5].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5].Style.Font.Bold = true; workSheet.Cells[row, 5].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 5].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 5].Value = "Description"; workSheet.Cells[row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 6].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 6].Style.Font.Bold = true; workSheet.Cells[row, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 6].Value = "Required"; row++; if (paramBody.Schema != null) { var schema = ""; if (paramBody.Schema.ContainsKey("ref")) { schema = (paramBody.Schema["ref"].ToString()).Replace("#/definitions/", ""); } if (paramBody.Schema.ContainsKey("items")) { schema = (JsonConvert.DeserializeObject <Dictionary <string, string> >(paramBody.Schema["items"].ToString())["ref"]).Replace("#/definitions/", ""); } //var schema = paramBody.Schema["ref"].Replace("#/definitions/", ""); if (document.Definitions.ContainsKey(schema)) { var modelInput = document.Definitions[schema]; var indexProperty = 0; foreach (var property in modelInput.Properties) { indexProperty++; workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = indexProperty; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = property.Key; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(property.Value.Format) ? $"{property.Value.Type}" : $"{property.Value.Type} ({property.Value.Format})"; workSheet.Cells[row, 5].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5].Value = property.Value.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 6].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; if (modelInput.Required != null && modelInput.Required.Any(x => x == property.Key)) { workSheet.Cells[row, 6].Value = "x"; } row++; } workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Input example"; row++; workSheet.Cells[row, 3, row, 6].Merge = true; workSheet.Cells[row, 3, row, 6].Style.WrapText = true; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 3, row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 3, row, 6].Style.Fill.BackgroundColor.SetColor(1, 244, 176, 132); workSheet.Cells[row, 3, row, 6].Value = DefinitionToJson(document.Definitions, modelInput); row++; } } } //Response //nếu response là 1 object if (response != null && response.Schema != null) { row++; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Output"; workSheet.Cells[row, 4, row, 6].Merge = true; workSheet.Cells[row, 4, row, 6].Value = outputType; if (response.Schema.ContainsKey("ref")) { row++; workSheet.Cells[row, 1].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 1].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Style.Font.Bold = true; workSheet.Cells[row, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 1].Value = "STT"; workSheet.Cells[row, 2, row, 3].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 2, row, 3].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Style.Font.Bold = true; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 2, row, 3].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 2, row, 3].Value = "Field"; workSheet.Cells[row, 4].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 4].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Style.Font.Bold = true; workSheet.Cells[row, 4].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 4].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 4].Value = "Type"; workSheet.Cells[row, 5, row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 5, row, 6].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Style.Font.Bold = true; workSheet.Cells[row, 5, row, 6].Merge = true; workSheet.Cells[row, 5, row, 5].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 5, row, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 5, row, 6].Value = "Description"; row++; var modelOutput = GetDefinition(document.Definitions, response.Schema["ref"].ToString()); var index = 0; foreach (var item in modelOutput.Properties) { workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = index + 1; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = item.Key; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(item.Value.Format) ? $"{item.Value.Type}" : $"{item.Value.Type} ({item.Value.Format})"; workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Value = item.Value.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 5, row, 6].Merge = true; row++; if (item.Value.Type == "array") { if (item.Value.Items.ContainsKey("ref")) { var model = GetDefinition(document.Definitions, item.Value.Items["ref"]); foreach (var property in model.Properties) { workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = index + 1; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = property.Key; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(property.Value.Format) ? $"{property.Value.Type}" : $"{property.Value.Type} ({property.Value.Format})"; workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Value = property.Value.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 5, row, 6].Merge = true; row++; index++; } } else { //TODO: có trường hợp là error => có item là type } } if (item.Value.Ref != null) { var referenceOutModel = GetDefinition(document.Definitions, item.Value.Ref); modelOutput.Properties[item.Key].Schema = referenceOutModel.Properties.ToDictionary(x => x.Key, x => (object)x.Value); foreach (var property in referenceOutModel.Properties) { workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = index + 1; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = $"{item.Key}.{property.Key}"; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(property.Value.Format) ? $"{property.Value.Type}" : $"{property.Value.Type} ({property.Value.Format})"; workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Value = property.Value.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 5, row, 6].Merge = true; row++; index++; } } else { index++; } } workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Output example"; row++; workSheet.Cells[row, 3, row, 6].Style.WrapText = true; workSheet.Cells[row, 3, row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 3, row, 6].Style.Fill.BackgroundColor.SetColor(1, 244, 176, 132); workSheet.Cells[row, 3, row, 6].Merge = true; workSheet.Row(row).CustomHeight = true; var output = DefinitionToJson(document.Definitions, modelOutput); workSheet.Cells[row, 3, row, 6].Value = output; double totalWidth = 0; for (int i = 3; i <= 6; i++) { totalWidth += workSheet.Column(i).Width; } workSheet.Cells[row, 7].Value = output; workSheet.Column(7).Width = totalWidth; workSheet.Row(row).CustomHeight = true; row++; } //Response //nếu response là 1 mảng else if (response.Schema.ContainsKey("type") && response.Schema["type"].ToString() == "array") { row++; workSheet.Cells[row, 1].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 1].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Style.Font.Bold = true; workSheet.Cells[row, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 1].Value = "STT"; workSheet.Cells[row, 2, row, 3].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 2, row, 3].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Style.Font.Bold = true; workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 2, row, 3].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 2, row, 3].Value = "Field"; workSheet.Cells[row, 4].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 4].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Style.Font.Bold = true; workSheet.Cells[row, 4].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 4].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 4].Value = "Type"; workSheet.Cells[row, 5, row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 5, row, 6].Style.Fill.BackgroundColor.SetColor(1, 169, 208, 142); workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Style.Font.Bold = true; workSheet.Cells[row, 5, row, 6].Merge = true; workSheet.Cells[row, 5, row, 5].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; workSheet.Cells[row, 5, row, 6].Style.VerticalAlignment = ExcelVerticalAlignment.Center; workSheet.Cells[row, 5, row, 6].Value = "Description"; row++; DefinitionModel modelOutput = null; var typeResponse = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Schema["items"].ToString())["ref"]; modelOutput = GetDefinition(document.Definitions, typeResponse); var index = 0; foreach (var item in modelOutput.Properties) { workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = index + 1; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = item.Key; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(item.Value.Format) ? $"{item.Value.Type}" : $"{item.Value.Type} ({item.Value.Format})"; workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Value = item.Value.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 5, row, 6].Merge = true; row++; if (item.Value.Type == "array") { if (item.Value.Items.ContainsKey("ref")) { var model = GetDefinition(document.Definitions, item.Value.Items["ref"]); foreach (var property in model.Properties) { workSheet.Cells[row, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 1].Value = index + 1; workSheet.Cells[row, 2, row, 3].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = property.Key; workSheet.Cells[row, 4].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 4].Value = string.IsNullOrWhiteSpace(property.Value.Format) ? $"{property.Value.Type}" : $"{property.Value.Type} ({property.Value.Format})"; workSheet.Cells[row, 5, row, 6].Style.Border.BorderAround(ExcelBorderStyle.Thin); workSheet.Cells[row, 5, row, 6].Value = property.Value.Description; workSheet.Row(row).CustomHeight = true; workSheet.Cells[row, 5, row, 6].Merge = true; row++; index++; } } //TODO: có trường hợp là error => có item là type } else { index++; } } workSheet.Cells[row, 2, row, 3].Merge = true; workSheet.Cells[row, 2, row, 3].Value = "Output example"; row++; workSheet.Cells[row, 3, row, 6].Style.WrapText = true; workSheet.Cells[row, 3, row, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; workSheet.Cells[row, 3, row, 6].Style.Fill.BackgroundColor.SetColor(1, 244, 176, 132); workSheet.Cells[row, 3, row, 6].Merge = true; workSheet.Row(row).CustomHeight = true; var output = DefinitionToJson(document.Definitions, modelOutput); workSheet.Cells[row, 3, row, 6].Value = output; double totalWidth = 0; for (int i = 3; i <= 6; i++) { totalWidth += workSheet.Column(i).Width; } workSheet.Cells[row, 7].Value = output; workSheet.Column(7).Width = totalWidth; workSheet.Row(row).CustomHeight = true; row++; } } workSheet.Cells[row, 1, row, 6].Style.Border.Bottom.Style = ExcelBorderStyle.Double; row++; row++; indexApi++; } workSheet.Column(7).Hidden = true; package.Save(); } Console.WriteLine("Done"); // Console.ReadLine(); }