public async Task <IActionResult> Edit(string id) { KBHelper kBHelper = new KBHelper(_appSettings); Knowledgebase knowledgebase = await kBHelper.GetKB(id); return(View(knowledgebase)); }
public static void Main(string[] args) { File.WriteAllText(AppProperties.ServerLogPath, ""); // Erase server log file. // Set console window position on desktop. //try //{ // //Console.SetWindowPosition(0, 100); // Console.WindowLeft = 0; // Console.WindowTop = 0; //} //catch (Exception error) //{ // Console.WriteLine("Error: " + error.Message); // File.AppendAllText(AppProperties.ServerLogPath, "Error: " + // error.Message + Environment.NewLine); //} ServerTCPConnection.Start(); //ServerTCPConnection.GetConnection(); Knowledgebase.Connect(); Knowledgebase.LoadLang(); File.AppendAllText(AppProperties.ServerLogPath, "Entering server loop." + Environment.NewLine); bool continueRunning = true; // For writing to the console only after a number of passes through the server loop. int cycleCount = 0; while (continueRunning) { if (cycleCount == 0) { Console.Write(DateTime.Now.ToLongTimeString() + "\r\nServer running...\n"); } if (cycleCount == 0 || cycleCount == 10) { Console.Write("Getting commands...\r\n"); } Thread.Sleep(50); string commands = ServerTCPConnection.HandleConnection(); if (!string.IsNullOrEmpty(commands)) { continueRunning = ProcessCommands(commands); } cycleCount++; if (cycleCount == 20) { cycleCount = 0; } } Console.WriteLine("Closing Server..."); File.AppendAllText(AppProperties.ServerLogPath, "Closing server." + Environment.NewLine); Thread.Sleep(300); //return 0; }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { EndpointSettings = new EndpointSettings(this); EndpointKeys = new EndpointKeys(this); Alterations = new Alterations(this); Knowledgebase = new Knowledgebase(this); Operations = new Operations(this); BaseUri = "{Endpoint}/qnamaker/v4.0"; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); }
public void LoadKnowledgebase(Knowledgebase Knowledgebase) { foreach (Dictionary dictionary in Knowledgebase.Dictionaries) { LoadDictionary(dictionary); } foreach (Intent intent in Knowledgebase.Intents) { LoadIntent(intent); } }
public async void SourceFailsThrowsKnowledgebaseException() { var knowledgebase = new Knowledgebase( new FileSource(TestFiles.TocFileOnly, Substitute.For <ILogger>()), Substitute.For <ILogger>()); var ex = await Assert.ThrowsAsync <KnowledgebaseException>( () => knowledgebase.GetSubjectAsync <Incidents>(KnowedgebaseSubjects.Incidents, CancellationToken.None)); Assert.Equal("Incidents file not configured", ex.Message); }
public void SaveJSON(string filePath, Knowledgebase data) { if (File.Exists(filePath)) { File.Delete(filePath); } string jsonString = JsonConvert.SerializeObject(data); File.WriteAllText(filePath, jsonString); }
public void LoadKnowledgebase(string KnowledgebasePath) { if (!File.Exists(KnowledgebasePath)) { throw new FileNotFoundException(); } string rawData = File.ReadAllText(KnowledgebasePath); Knowledgebase knowledgebase = JsonConvert.DeserializeObject <Knowledgebase>(rawData); LoadKnowledgebase(knowledgebase); }
public void SaveBinary(string filePath, Knowledgebase data) { if (File.Exists(filePath)) { File.Delete(filePath); } BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream fileStream = File.Open(filePath, FileMode.CreateNew); binaryFormatter.Serialize(fileStream, data); fileStream.Close(); }
public async void GetTocs() { var logger = Substitute.For <ILogger>(); using (var source = new NationalRailEnquiriesSource(new HttpClient(), logger)) { await source.Initiate(user, password, CancellationToken.None); var knowledgebase = new Knowledgebase(source, logger); var tocs = await knowledgebase.GetTocs(CancellationToken.None); Assert.NotEmpty(tocs.TrainOperatingCompany); } }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { // Inputs var portaldt = PortalDT.Get(context); var knowledgebase = Knowledgebase.Get(context); var knowledgebasename = KnowledgebaseName.Get(context); var JsonObjectUpdateKbOperationDTO = KnowledgebaseUtility.CreateKnowledgebaseUpdate(portaldt, knowledgebase, knowledgebasename); // Outputs return((ctx) => { UpdateKbJson.Set(ctx, JsonObjectUpdateKbOperationDTO); }); }
public void CreateFile(string filePath, string fileType) { try { FileType = fileType; FilePath = filePath; Data = new Knowledgebase(); if (File.Exists(filePath)) { File.Delete(filePath); } switch (fileType.ToUpper()) { case "BIN": BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream binaryFileStream = File.Create(filePath); binaryFormatter.Serialize(binaryFileStream, Data); binaryFileStream.Close(); break; case "JSON": string jsonString = JsonConvert.SerializeObject(Data); File.WriteAllText(filePath, jsonString); break; case "EIC": FileType = "BIN"; goto case "BIN"; default: FileType = "JSON"; goto case "JSON"; } UpdateTitle(); UpdateDictionaries(); UpdateIntents(); } catch { FileType = ""; FilePath = ""; UpdateTitle(); UpdateDictionaries(); UpdateIntents(); } }
public void OpenFile(string filePath) { if (!File.Exists(filePath)) { MessageBox.Show("Error!", "The specified file does not exist. :("); return; } bool recognised = false; string[] extensionSplitString = filePath.Split('.'); string extensionString = extensionSplitString[extensionSplitString.Length - 1]; if (extensionString.ToUpper() == "JSON") { recognised = true; FileType = "JSON"; string jsonString = File.ReadAllText(filePath); Knowledgebase fileData = JsonConvert.DeserializeObject <Knowledgebase>(jsonString); Data = fileData; } if (extensionString.ToUpper() == "BIN" || extensionString.ToUpper() == "EIC") { recognised = true; FileType = "BIN"; FileStream binaryFileStream = File.Open(filePath, FileMode.Open); BinaryFormatter binaryFormatter = new BinaryFormatter(); Object binaryData = binaryFormatter.Deserialize(binaryFileStream); Data = (Knowledgebase)binaryData; } if (recognised) { FilePath = filePath; } if (!recognised) { FileType = ""; FilePath = ""; } UpdateTitle(); UpdateDictionaries(); UpdateIntents(); }
public QnABot( IConfiguration configuration, ILogger <QnABot> logger, IHttpClientFactory httpClientFactory, Knowledgebase knowledgebase, Operations operations, QnAMakerEndpoint qnAMakerEndpoint, QnAModel model) { _configuration = configuration; _logger = logger; _httpClientFactory = httpClientFactory; _knowledgebase = knowledgebase; _operations = operations; _qnAMakerEndpoint = qnAMakerEndpoint; _model = model; }
void AddKnowledgeBaseIfDoesntExist() { GameObject knowledgebaseGameObject = Instantiate(_KnowledgeBase) as GameObject; knowledgebase = knowledgebaseGameObject.GetComponent <Knowledgebase>(); GameObject skillAtomGO = new GameObject(); skillAtomGO.transform.SetParent(knowledgebaseGameObject.transform); skillAtomGO.name = skillAtom.name; SkillAtom newSA = skillAtomGO.AddComponent <SkillAtom>(); newSA.skillAtomName = skillAtom.name; newSA.initialMastery = skillAtom.GetMastery(); skillAtom = newSA; }
// Use this for initialization void Awake() { knowledgebase = FindObjectOfType <Knowledgebase>() as Knowledgebase; if (knowledgebase == null) { AddKnowledgeBaseIfDoesntExist(); Debug.LogWarning("No skill atom knowledgebase found by detector, tried to automatically add the requirements. Please add a knowledgebase to your scene to ensure there is no unexpected behavior.", transform); } // TODO: Create some way of having these be ordered by priority. hints.AddRange(transform.GetComponents <Hint>()); if (!skillAtom.gameObject.activeInHierarchy) { SkillAtom[] allSkillAtoms; allSkillAtoms = FindObjectsOfType <SkillAtom>(); foreach (SkillAtom skill in allSkillAtoms) { if (skill.name == skillAtom.name) { skillAtom = skill; } } } }
public ActionResult Edit(EditKnowledgebaseViewModel editKnowledgebaseViewModel) { try { // ReSharper disable once JoinDeclarationAndInitializer // ReSharper disable once CollectionNeverQueried.Local var knowledgebaselist = new List <KnowledgebaseAttachments>(); var knowledgebase = new Knowledgebase(); var knowledgebaseDetails = new KnowledgebaseDetails(); var knowledgebaseAttachmentsDetails = new KnowledgebaseAttachmentsDetails(); var knowledgebaseAttachmentsDetailsList = new List <KnowledgebaseAttachmentsDetails>(); if (ModelState.IsValid) { knowledgebase.Subject = editKnowledgebaseViewModel.Subject; knowledgebase.Status = editKnowledgebaseViewModel.Status; knowledgebase.KnowledgebaseTypeId = editKnowledgebaseViewModel.KnowledgebaseTypeId; knowledgebase.CreateDate = DateTime.Now; knowledgebase.UserId = Convert.ToInt32(_sessionHandler.UserId); knowledgebase.CategoryId = editKnowledgebaseViewModel.CategoryId; knowledgebase.KnowledgebaseId = Convert.ToInt64(editKnowledgebaseViewModel.KnowledgebaseId); knowledgebaseDetails.Contents = editKnowledgebaseViewModel.Contents; knowledgebaseDetails.Keywords = editKnowledgebaseViewModel.Keywords; if (Request != null && (_knowledgebase.GetKnowledgebaseAttachmentsCount(editKnowledgebaseViewModel.KnowledgebaseId) > 0 && Request.Files["fileupload_1"].ContentLength != 0 && Request.Files["fileupload_2"].ContentLength != 0 && Request.Files["fileupload_3"].ContentLength != 0)) { ModelState.AddModelError("", "Delete Pervious uploaded Attachments for Uploading New Attachments"); editKnowledgebaseViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory(); editKnowledgebaseViewModel.ListofKnowledgebaseType = _knowledgebase.KnowledgebaseTypeList(); return(View(editKnowledgebaseViewModel)); } else { if ((_knowledgebase.GetKnowledgebaseAttachmentsCount(editKnowledgebaseViewModel.KnowledgebaseId) == 0)) { for (int i = 1; i <= 3; i++) { var filename = "fileupload_" + Convert.ToString(i); var file = Request?.Files[filename]; if (file != null && file.ContentLength > 0) { var knowledgebaseAttachments1 = new KnowledgebaseAttachments(); string extension = Path.GetExtension(file.FileName); var myUniqueFileName = String.Concat(Guid.NewGuid(), extension); knowledgebaseAttachments1.AttachmentsName = myUniqueFileName; knowledgebaseAttachments1.AttachmentsType = extension; using (var binaryReader = new BinaryReader(file.InputStream)) { byte[] fileSize = binaryReader.ReadBytes(file.ContentLength); knowledgebaseAttachmentsDetails.AttachmentBytes = fileSize; } knowledgebaselist.Add(knowledgebaseAttachments1); knowledgebaseAttachmentsDetailsList.Add(knowledgebaseAttachmentsDetails); } } _knowledgebase.UpdateKnowledgebase(knowledgebase, knowledgebaseDetails, knowledgebaselist, knowledgebaseAttachmentsDetailsList); TempData["KnowledgebaseMessage"] = "Your Article Updated Successfully"; return(RedirectToAction("Edit", "Knowledgebase")); } _knowledgebase.UpdateKnowledgebase(knowledgebase, knowledgebaseDetails, null, null); TempData["KnowledgebaseMessage"] = "Your Article Updated Successfully"; return(RedirectToAction("Edit", "Knowledgebase", new { id = editKnowledgebaseViewModel.KnowledgebaseId })); } } editKnowledgebaseViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory(); editKnowledgebaseViewModel.ListofKnowledgebaseType = _knowledgebase.KnowledgebaseTypeList(); editKnowledgebaseViewModel.ListofAttachments = _knowledgebase.GetKnowledgebaseAttachments(editKnowledgebaseViewModel.KnowledgebaseId); return(View(editKnowledgebaseViewModel)); } catch (Exception) { throw; } }
public void LoadKnowledgebase(Knowledgebase Knowledgebase) { throw new NotImplementedException(); }
public int UpdateKnowledgebase( Knowledgebase knowledgebase, KnowledgebaseDetails knowledgebaseDetails, List <KnowledgebaseAttachments> listknowledgebaseAttachments, List <KnowledgebaseAttachmentsDetails> knowledgebaseAttachmentsDetails ) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString)) { con.Open(); SqlTransaction transaction = con.BeginTransaction(); try { var param = new DynamicParameters(); param.Add("@KnowledgebaseTypeId", knowledgebase.KnowledgebaseTypeId); param.Add("@Subject", knowledgebase.Subject); param.Add("@Status", knowledgebase.Status); param.Add("@UserId", knowledgebase.UserId); param.Add("@CategoryId", knowledgebase.CategoryId); param.Add("@KnowledgebaseId", knowledgebase.KnowledgebaseId); var resultknowledgebase = con.Execute("Usp_UpdateKnowledgebase", param, transaction, 0, CommandType.StoredProcedure); var paramknowledgebaseDetails = new DynamicParameters(); paramknowledgebaseDetails.Add("@Contents", knowledgebaseDetails.Contents); paramknowledgebaseDetails.Add("@Keywords", knowledgebaseDetails.Keywords); paramknowledgebaseDetails.Add("@KnowledgebaseId", knowledgebase.KnowledgebaseId); var resultknowledgebaseDetails = con.Execute("Usp_UpdateKnowledgebaseDetails", paramknowledgebaseDetails, transaction, 0, CommandType.StoredProcedure); if (listknowledgebaseAttachments != null) { for (var index = 0; index < listknowledgebaseAttachments.Count; index++) { var listkb = listknowledgebaseAttachments[index]; var paramknowledgebaseAttachment = new DynamicParameters(); paramknowledgebaseAttachment.Add("@AttachmentsName", listkb.AttachmentsName); paramknowledgebaseAttachment.Add("@AttachmentsType", listkb.AttachmentsType); paramknowledgebaseAttachment.Add("@KnowledgebaseId", knowledgebase.KnowledgebaseId); paramknowledgebaseAttachment.Add("@KnowledgebaseAttachmentsId", dbType: DbType.Int64, direction: ParameterDirection.Output); con.Execute("Usp_InsertKnowledgebaseAttachments", paramknowledgebaseAttachment, transaction, 0, CommandType.StoredProcedure); long knowledgebaseAttachmentsId = paramknowledgebaseAttachment.Get <Int64>("@KnowledgebaseAttachmentsId"); var listofattachmentbytes = knowledgebaseAttachmentsDetails[index]; var paramKnowledgebaseAttachmentsDetails = new DynamicParameters(); paramKnowledgebaseAttachmentsDetails.Add("@AttachmentBytes", listofattachmentbytes.AttachmentBytes); paramKnowledgebaseAttachmentsDetails.Add("@KnowledgebaseId", knowledgebase.KnowledgebaseId); paramKnowledgebaseAttachmentsDetails.Add("@KnowledgebaseAttachmentsId", knowledgebaseAttachmentsId); var resultKnowledgebaseAttachmentsDetails = con.Execute("Usp_InsertKnowledgebaseAttachmentsDetails", paramKnowledgebaseAttachmentsDetails, transaction, 0, CommandType.StoredProcedure); } } if (resultknowledgebase > 0 && resultknowledgebaseDetails > 0) { transaction.Commit(); return(1); } else { transaction.Rollback(); return(0); } } catch (Exception) { transaction.Rollback(); throw; } } }
public ActionResult Add(KnowledgebaseViewModel knowledgebaseViewModel) { try { // ReSharper disable once JoinDeclarationAndInitializer // ReSharper disable once CollectionNeverQueried.Local var knowledgebaselist = new List <KnowledgebaseAttachments>(); var knowledgebase = new Knowledgebase(); var knowledgebaseDetails = new KnowledgebaseDetails(); var knowledgebaseAttachmentsDetails = new KnowledgebaseAttachmentsDetails(); var knowledgebaseAttachmentsDetailsList = new List <KnowledgebaseAttachmentsDetails>(); if (ModelState.IsValid) { knowledgebase.Subject = knowledgebaseViewModel.Subject; knowledgebase.Status = knowledgebaseViewModel.Status; knowledgebase.KnowledgebaseTypeId = knowledgebaseViewModel.KnowledgebaseTypeId; knowledgebase.CreateDate = DateTime.Now; knowledgebase.KnowledgebaseId = 0; knowledgebase.UserId = Convert.ToInt32(_sessionHandler.UserId); knowledgebase.CategoryId = knowledgebaseViewModel.CategoryId; knowledgebaseDetails.Contents = knowledgebaseViewModel.Contents; knowledgebaseDetails.Keywords = knowledgebaseViewModel.Keywords; knowledgebaseDetails.KnowledgebaseDetailsId = 0; for (int i = 1; i <= 3; i++) { var filename = "fileupload_" + Convert.ToString(i); var file = Request.Files[filename]; if (file != null && file.ContentLength > 0) { var knowledgebaseAttachments1 = new KnowledgebaseAttachments(); string extension = Path.GetExtension(file.FileName); var myUniqueFileName = String.Concat(Guid.NewGuid(), extension); knowledgebaseAttachments1.AttachmentsName = myUniqueFileName; knowledgebaseAttachments1.AttachmentsType = extension; using (var binaryReader = new BinaryReader(file.InputStream)) { byte[] fileSize = binaryReader.ReadBytes(file.ContentLength); knowledgebaseAttachmentsDetails.AttachmentBytes = fileSize; } knowledgebaselist.Add(knowledgebaseAttachments1); knowledgebaseAttachmentsDetailsList.Add(knowledgebaseAttachmentsDetails); } } _knowledgebase.AddKnowledgebase(knowledgebase, knowledgebaselist, knowledgebaseDetails, knowledgebaseAttachmentsDetailsList); TempData["KnowledgebaseMessage"] = "Your Article Added Successfully"; } knowledgebaseViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory(); knowledgebaseViewModel.ListofKnowledgebaseType = _knowledgebase.KnowledgebaseTypeList(); return(View(knowledgebaseViewModel)); } catch (Exception) { throw; } }
private static bool ProcessCommands(string commands) { bool continueRunning = true; if (commands != null) { Console.WriteLine("Commands received [" + commands + "]"); string response = ""; //commands = commands.ToLower(); if (commands == "clearstream") { // For clearing the client/network stream. ServerTCPConnection.ReturnResponse("stream cleared"); } else if (commands == "closeserver") { ServerTCPConnection.ReturnResponse("closing server"); Console.WriteLine("Closing server..."); ServerTCPConnection.connected = false; continueRunning = false; } //else if (commands == "serverconnect") //{ // ServerTCPConnection.ReturnResponse("server connected"); //} else if (commands == "disconnect") { ServerTCPConnection.ReturnResponse("server disconnected"); Console.WriteLine("Closing connection..."); ServerTCPConnection.connected = false; } else if (commands == "writetolog") { response = Knowledgebase.WriteToLog(); ServerTCPConnection.ReturnResponse(response); } else if (commands == "clearlog") { response = Knowledgebase.ClearLog(); ServerTCPConnection.ReturnResponse(response); } else if (commands == "runcode") { response = RunCode(); ServerTCPConnection.ReturnResponse(response); } else if (commands == "runsql") { response = Knowledgebase.RunSQL(); ServerTCPConnection.ReturnResponse(response); } else if (commands == "getnets") { string netsData; netsData = Knowledgebase.GetNetsData(); ServerTCPConnection.ReturnResponse(netsData); } else if (commands == "python") { //commands = @"print('Hello world!')"; response = Knowledgebase.StartPython(); ServerTCPConnection.ReturnResponse(response); } else if (commands.StartsWith("[py]")) { if (commands[4..] == "exit()")