private void client_Disconnected(object sender, EventArgs e) { BattleNetClient client = sender as BattleNetClient; if (client == null) { return; } ProfileDocument profileDoc = this.dock.ActiveDocument as ProfileDocument; if (profileDoc == null) { return; } if (profileDoc.Client == client) { SyncDel go = delegate { this.connectToolStripMenuItem1.Enabled = true; this.disconnectToolStripMenuItem.Enabled = false; }; if (InvokeRequired) { BeginInvoke(go); } else { go(); } } }
private void enableVoidViewToolStripMenuItem_Click(object sender, EventArgs e) { ProfileDocument tab = this.dock.ActiveDocument as ProfileDocument; if (tab != null) { tab.VoidView = enableVoidViewToolStripMenuItem.Checked; } }
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { ProfileDocument pd = this.dock.ActiveDocument as ProfileDocument; if (pd != null) { pd.Disconnect(); this.disconnectToolStripMenuItem.Enabled = false; this.connectToolStripMenuItem1.Enabled = true; } }
public ProfilePluginManager(ClientProfile profile, BattleNetClient client, ProfileDocument view) { m_profile = profile; m_client = client; m_view = view; m_clientPlugins = new List <ISingleClientPlugin>(); m_multiClientPlugins = new List <IMultiClientPlugin>(); m_clientPluginSettings = new Dictionary <ISingleClientPlugin, Dictionary <string, string> >(); EnumeratePlugins(profile.PluginSettings); }
public JinxBotClient(ClientProfile profile) { m_activePlugins = new Dictionary <ProfilePluginConfiguration, IJinxBotPlugin>(); if (profile.SimulateClient) { m_client = new SimulatedBattleNetClient(profile); } else { m_client = new BattleNetClient(profile); } m_profile = profile; m_resourceProvider = ProfileResourceProvider.RegisterProvider(m_client); m_cmdTranslator = new CommandTranslator(this); bool hasSetCommandQueue = false; if (m_database == null) { m_database = new JinxBotDefaultDatabase(); } // finally, initialize ui m_window = new ProfileDocument(this); // initialize plugins m_commandHandlers = new List <ICommandHandler>(); foreach (ProfilePluginConfiguration pluginConfig in profile.PluginSettings) { hasSetCommandQueue = ProcessPlugin(hasSetCommandQueue, pluginConfig); } ProfilePluginConfiguration jsConfig = new ProfilePluginConfiguration { Assembly = "JinxBot.Plugins.Script.dll", Name = "JavaScript Plugin", Settings = new ProfilePluginSettingConfiguration[0], Type = "JinxBot.Plugins.Script.JinxBotJavaScriptPlugin" }; hasSetCommandQueue = ProcessPlugin(hasSetCommandQueue, jsConfig); if (!hasSetCommandQueue) { m_client.CommandQueue = new TimedMessageQueue(); } }
public void LoadProfileTest3() { var document = new ProfileDocument(CreateProfile3(_testProfileName, _testSsidString)); Assert.IsTrue(document.BssType == BssType.Independent, "Failed to get wireless profile BSS type."); Assert.IsTrue(document.Authentication == AuthenticationMethod.Open, "Failed to get wireless profile authentication."); Assert.IsTrue(document.Encryption == EncryptionType.None, "Failed to get wireless profile encryption."); Assert.IsTrue(!document.IsAutoConnectEnabled, "Failed to get wireless profile automatic connection."); Assert.IsTrue(!document.IsAutoSwitchEnabled, "Failed to get wireless profile automatic switch."); document.IsAutoConnectEnabled = true; Assert.IsTrue(!document.IsAutoConnectEnabled, "Failed to interrupt enabling wireless profile automatic connection."); document.IsAutoSwitchEnabled = true; Assert.IsTrue(!document.IsAutoSwitchEnabled, "Failed to interrupt enabling wireless profile automatic switch."); }
private void dock_ActiveDocumentChanged(object sender, EventArgs e) { ProfileDocument profileDoc = this.dock.ActiveDocument as ProfileDocument; if (profileDoc != null) { this.currentProfileNoneToolStripMenuItem.Enabled = true; this.enableVoidViewToolStripMenuItem.Checked = profileDoc.VoidView; this.connectToolStripMenuItem1.Enabled = !profileDoc.Client.IsConnected; this.disconnectToolStripMenuItem.Enabled = !connectToolStripMenuItem1.Enabled; } else { this.currentProfileNoneToolStripMenuItem.Enabled = false; } }
public void LoadProfileTest2() { var document = new ProfileDocument(CreateProfile2(_testProfileName, _testSsidString)); Assert.IsTrue(document.BssType == BssType.Infrastructure, "Failed to get wireless profile BSS type."); Assert.IsTrue(document.Authentication == AuthenticationMethod.WPA2_Personal, "Failed to get wireless profile authentication."); Assert.IsTrue(document.Encryption == EncryptionType.AES, "Failed to get wireless profile encryption."); Assert.IsTrue(document.IsAutoConnectEnabled, "Failed to get wireless profile automatic connection."); Assert.IsTrue(document.IsAutoSwitchEnabled, "Failed to get wireless profile automatic switch."); document.IsAutoConnectEnabled = false; Assert.IsTrue(!document.IsAutoConnectEnabled, "Failed to disable wireless profile automatic connection."); Assert.IsTrue(!document.IsAutoSwitchEnabled, "Failed to disable wireless profile automatic switch."); document.IsAutoSwitchEnabled = true; Assert.IsTrue(!document.IsAutoSwitchEnabled, "Failed to interrupt enabling wireless profile automatic switch."); }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { ProfileDocument pd = this.dock.ActiveDocument as ProfileDocument; if (pd != null) { ClientProfile profile = pd.Client.Settings as ClientProfile; JinxBotClient client = m_activeClients[profile]; client.Client.Disconnected -= client_Disconnected; client.Client.Connected -= client_Connected; client.Close(); pd.Close(); m_activeClients.Remove(profile); } }
public void LoadProfileTest1() { var document = new ProfileDocument(CreateProfile1(_testProfileName, _testSsidString)); Assert.IsTrue(document.Name == _testProfileName, "Failed to get wireless profile name."); Assert.IsTrue(document.Ssid.ToString() == _testSsidString, "Failed to get wireless profile SSID."); Assert.IsTrue(document.BssType == BssType.Infrastructure, "Failed to get wireless profile BSS type."); Assert.IsTrue(document.Authentication == AuthenticationMethod.WPA_Personal, "Failed to get wireless profile authentication."); Assert.IsTrue(document.Encryption == EncryptionType.TKIP, "Failed to get wireless profile encryption."); Assert.IsTrue(!document.IsAutoConnectEnabled, "Failed to get wireless profile automatic connection."); Assert.IsTrue(!document.IsAutoSwitchEnabled, "Failed to get wireless profile automatic switch."); document.IsAutoConnectEnabled = true; Assert.IsTrue(document.IsAutoConnectEnabled, "Failed to enable wireless profile automatic connection."); document.IsAutoSwitchEnabled = true; Assert.IsTrue(document.IsAutoSwitchEnabled, "Failed to enable wireless profile automatic switch."); document.IsAutoSwitchEnabled = false; Assert.IsTrue(!document.IsAutoSwitchEnabled, "Failed to disable wireless profile automatic switch."); }
public HttpResponseMessage GetFile(int candidateId) { //Create HTTP Response. HttpResponseMessage http_Response = Request.CreateResponse(HttpStatusCode.OK); //Get the File data from Database based on File ID. using (var context = new CandidateProfileDBContext()) { ProfileDocument profileDocument = context.ProfileDocuments.Find(candidateId); if (profileDocument != null) { HttpResponseMessage httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK); httpResponseMessage.Content = new ByteArrayContent(profileDocument.DocumentData); httpResponseMessage.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); httpResponseMessage.Content.Headers.ContentDisposition.FileName = profileDocument.DocumentName; httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(profileDocument.DocumentType); return(httpResponseMessage); } return(Request.CreateResponse(HttpStatusCode.NoContent)); } }
public IHttpActionResult Post(string filename, int profileId, int docmentTypeId) { var fileObj = new ProfileDocument(); var thisProfile = db.Profiles.SingleOrDefault(x => x.id == profileId); if (thisProfile == null) { Log.DebugFormat( "Error retrieving Profile. The profile cannot be found"); var myError = new Error { Code = "400", Message = "Error retrieving Profile. The profile cannot be found", Data = null }; return(new ErrorResult(myError, Request)); } // Check for valid file types var extension = Path.GetExtension(filename.Trim()); if (!string.IsNullOrEmpty(extension)) { extension = extension.TrimStart('.'); //remove full stop var tagList = new List <string> { "pdf", "doc", "docx", "txt" }; var exists = tagList.Any(val => val.Contains(extension.ToLower())); if (exists) { fileObj.mimeType = extension.ToLower(); fileObj.originalFileName = filename.ToLower().Trim(); } } else { Log.DebugFormat("Missing or disallowed file extension"); var myError = new Error { Code = "400", Message = "Missing or disallowed file extension", Data = null }; return(new ErrorResult(myError, Request)); } // Read data here var task = Request.Content.ReadAsStreamAsync(); task.Wait(); var requestStream = task.Result; try { var byteArray = ReadFully(requestStream); var compress = Compress(byteArray); fileObj.documentData = compress; fileObj.dateObtained = DateTime.Now; fileObj.profileId = profileId; fileObj.documentTypeId = docmentTypeId; db.ProfileDocuments.Add(fileObj); db.SaveChanges(); } catch (IOException ex) { Log.DebugFormat( $"Error storing ProfileDocument. The reason is as follows: {ex.Message} {ex.StackTrace}"); var myError = new Error { Code = "400", Message = "Error storing ProfileDocument", Data = new object[] { ex.Message, ex.StackTrace } }; return(new ErrorResult(myError, Request)); } return(Ok()); }
public HttpResponseMessage UploadFile() { Dictionary <string, object> dict = new Dictionary <string, object>(); try { //Check if Request contains any File or not if (HttpContext.Current.Request.Files.Count == 0) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } //Read the File data from Request.Form collections. HttpPostedFile uploadedFile = HttpContext.Current.Request.Files[0]; int CandidateId = Convert.ToInt32(HttpContext.Current.Request.Form["id"]); if (uploadedFile != null && uploadedFile.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 2; //Size = 2 MB IList <string> AllowedFileExtensions = new List <string> { ".txt", ".csv", ".doc", ".docx" }; var ext = uploadedFile.FileName.Substring(uploadedFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); if (!AllowedFileExtensions.Contains(extension)) { var message = string.Format("Please Upload file of type .txt,.csv,.doc(x)."); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } else if (uploadedFile.ContentLength > MaxContentLength) { var message = string.Format("Please Upload a file upto 2 mb."); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } else { //Convert the File data to Byte Array which will be store in database byte[] bytes; using (BinaryReader br = new BinaryReader(uploadedFile.InputStream)) { bytes = br.ReadBytes(uploadedFile.ContentLength); } //Insert the File to Database Table - FileInfo. using (var context = new CandidateProfileDBContext()) { //context.Entry(profileDocument).State = profileDocument.CandidateId == 0 ? EntityState.Added : EntityState.Modified; ProfileDocument profileDocument = context.ProfileDocuments.Find(CandidateId); if (profileDocument != null) { profileDocument.DocumentName = Path.GetFileName(uploadedFile.FileName); profileDocument.DocumentData = bytes; profileDocument.DocumentType = uploadedFile.ContentType; context.Entry(profileDocument).State = EntityState.Modified; } else { profileDocument = new ProfileDocument() { DocumentName = Path.GetFileName(uploadedFile.FileName), DocumentData = bytes, DocumentType = uploadedFile.ContentType, CandidateId = CandidateId }; context.Entry(profileDocument).State = EntityState.Added; } context.SaveChanges(); //clear the cache once delete candidate value ObjectCache cache = MemoryCache.Default; if (cache.Contains(Cache_Key_Candidates)) { cache.Remove(Cache_Key_Candidates); } return(Request.CreateResponse(HttpStatusCode.OK, new { id = profileDocument.CandidateId, Name = profileDocument.DocumentName })); } } } } catch (Exception ex) { var res = string.Format("upload failed"); dict.Add("error", res); return(Request.CreateResponse(HttpStatusCode.NotFound, dict)); } return(Request.CreateResponse(HttpStatusCode.NoContent)); }