private void Download(object param) { var save = new SaveFileDialog { Filter = "zip|*.zip", Title = "Download Submission" }; save.ShowDialog(); if (save.FileName == "") { return; } using (var stream = (FileStream)save.OpenFile()) { using (var writer = new BinaryWriter(stream)) { writer.Write(Submission.SolutionData); } } //Notify that a submission has been downloaded var generator = EventGenerator.GetInstance(); generator.NotifySolutionDownloaded(Submission); }
private void SetupServiceClient() { _eventHandler = new VsEventHandler(this, EventGenerator.GetInstance()); //need the toolManager to open the intervention window _eventHandler.InterventionUpdate += InterventionReceivedUpdate; _client = ServiceClient.GetInstance(_eventHandler, _errorLogger); _client.PropertyChanged += ServiceClientPropertyChanged; _client.ReceivedNewSocialActivity += ServiceClientReceivedSocialUpdate; }
private void Download(object param) { var save = new FolderBrowserDialog(); var result = save.ShowDialog(); if (result != DialogResult.OK) { return; } var directory = save.SelectedPath; foreach (var vm in SubmissionEntries) { var unpackDir = Path.Combine(directory, vm.Submission.Sender.FullName); using (var zipStream = new MemoryStream()) { zipStream.Write(vm.Submission.SolutionData, 0, vm.Submission.SolutionData.Length); zipStream.Position = 0; try { using (var zip = ZipFile.Read(zipStream)) { foreach (var entry in zip) { try { entry.Extract(unpackDir, ExtractExistingFileAction.OverwriteSilently); } catch (BadReadException ex) { ErrorMessage = ex.Message; } catch (Exception ex) { ErrorMessage = ex.Message; } } } } catch (ZipException ex) { ErrorMessage = ex.Message; MessageBox.Show(string.Format("extract failed for {0}", vm.Submission.Sender.FullName)); } catch (Exception ex) { ErrorMessage = ex.Message; } } //notify that someone has downloaded a submission var generator = EventGenerator.GetInstance(); generator.NotifySolutionDownloaded(vm.Submission); } }
public void ShowAskForHelp(object sender, EventArgs e) { var cacheItem = _cache[StringConstants.AuthenticationCacheKey]; if (cacheItem != null && string.IsNullOrEmpty(cacheItem.ToString())) { MessageBox.Show("You must be logged into OSBLE+ in order to access this window."); return; } var vm = new AskForHelpViewModel(); //find current text selection var dte = (DTE2)GetService(typeof(SDTE)); if (dte != null) { dynamic selection = dte.ActiveDocument.Selection; if (selection != null) { try { vm.Code = selection.Text; } catch (Exception) { // ignored } } } //AC: Restrict "ask for help" to approx 20 lines if (vm.Code.Length > 750) { vm.Code = vm.Code.Substring(0, 750); } //show message dialog var result = AskForHelpForm.ShowModalDialog(vm); if (result == MessageBoxResult.OK) { var generator = EventGenerator.GetInstance(); var evt = new AskForHelpEvent { Code = vm.Code, UserComment = vm.UserText }; generator.SubmitEvent(evt); MessageBox.Show("Your question has been logged and will show up in the activity stream shortly."); } }
private void Download(object param) { FolderBrowserDialog save = new FolderBrowserDialog(); DialogResult result = save.ShowDialog(); if (result == DialogResult.OK) { string directory = save.SelectedPath; foreach (SubmissionEntryViewModel vm in SubmissionEntries) { string unpackDir = Path.Combine(directory, vm.SubmissionLog.Sender.FullName); using (MemoryStream zipStream = new MemoryStream()) { zipStream.Write(vm.Submission.SolutionData, 0, vm.Submission.SolutionData.Length); zipStream.Position = 0; try { using (ZipFile zip = ZipFile.Read(zipStream)) { foreach (ZipEntry entry in zip) { try { entry.Extract(unpackDir, ExtractExistingFileAction.OverwriteSilently); } catch (BadReadException) { } catch (Exception) { } } } } catch (ZipException) { MessageBox.Show("extract failed for " + vm.SubmissionLog.Sender.FullName); } catch (Exception) { } } //notify OSBIDE that someone has downloaded a submission EventGenerator generator = EventGenerator.GetInstance(); throw new NotImplementedException("This code needs to be updated."); //generator.NotifySolutionDownloaded(OsbideUser.CurrentUser, vm.Submission); } } }
private void Download(object param) { SaveFileDialog save = new SaveFileDialog(); save.Filter = "zip|*.zip"; save.Title = "Download Submission"; save.ShowDialog(); if (save.FileName != "") { using (FileStream stream = (FileStream)save.OpenFile()) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(Submission.SolutionData); } } //Notify OSBIDE that a submission has been downloaded EventGenerator generator = EventGenerator.GetInstance(); throw new NotImplementedException("This code needs to be updated."); //generator.NotifySolutionDownloaded(OsbideUser.CurrentUser, Submission); } }
///////////////////////////////////////////////////////////////////////////// // Overridden Package Implementation #region Package Members /// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); //AC: Explicity load in assemblies. Necessary for serialization (why?) Assembly.Load("OSBIDE.Library"); Assembly.Load("OSBIDE.Controls"); //force load awesomium dlls /* * try * { * Assembly.Load("Awesomium.Core, Version=1.7.1.0, Culture=neutral, PublicKeyToken=e1a0d7c8071a5214"); * Assembly.Load("Awesomium.Windows.Controls, Version=1.7.1.0, Culture=neutral, PublicKeyToken=7a34e179b8b61c39"); * } * catch (Exception ex) * { * _errorLogger.WriteToLog("Error loading awesomium DLLs: " + ex.Message, LogPriority.HighPriority); * } * */ // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { //login toolbar item. CommandID menuCommandID = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideCommand); MenuCommand menuItem = new MenuCommand(OpenLoginScreen, menuCommandID); mcs.AddCommand(menuItem); //login toolbar menu option. CommandID loginMenuOption = new CommandID(CommonGuidList.guidOSBIDE_OsbideToolsMenuCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideLoginToolWin); MenuCommand menuLoginMenuOption = new MenuCommand(OpenLoginScreen, loginMenuOption); mcs.AddCommand(menuLoginMenuOption); //activity feed CommandID activityFeedId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideActivityFeedTool); MenuCommand menuActivityWin = new MenuCommand(ShowActivityFeedTool, activityFeedId); mcs.AddCommand(menuActivityWin); //activity feed details CommandID activityFeedDetailsId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideActivityFeedDetailsTool); MenuCommand menuActivityDetailsWin = new MenuCommand(ShowActivityFeedDetailsTool, activityFeedDetailsId); mcs.AddCommand(menuActivityDetailsWin); //chat window CommandID chatWindowId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideChatTool); MenuCommand menuChatWin = new MenuCommand(ShowChatTool, chatWindowId); mcs.AddCommand(menuChatWin); //profile page CommandID profileWindowId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideUserProfileTool); MenuCommand menuProfileWin = new MenuCommand(ShowProfileTool, profileWindowId); mcs.AddCommand(menuProfileWin); //"ask for help context" menu CommandID askForHelpId = new CommandID(CommonGuidList.guidOSBIDE_ContextMenuCmdSet, (int)CommonPkgCmdIDList.cmdOsbideAskForHelp); OleMenuCommand askForHelpWin = new OleMenuCommand(ShowAskForHelp, askForHelpId); askForHelpWin.BeforeQueryStatus += AskForHelpCheckActive; mcs.AddCommand(askForHelpWin); //create account window CommandID createAccountWindowId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideCreateAccountTool); MenuCommand menuAccountWin = new MenuCommand(ShowCreateAccountTool, createAccountWindowId); mcs.AddCommand(menuAccountWin); //OSBIDE documentation link CommandID documentationId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideDocumentationTool); MenuCommand documentationWin = new MenuCommand(OpenDocumentation, documentationId); mcs.AddCommand(documentationWin); //OSBIDE web link CommandID webLinkId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideWebLinkTool); MenuCommand webLinkWin = new MenuCommand(OpenOsbideWebLink, webLinkId); mcs.AddCommand(webLinkWin); //generic OSBIDE window CommandID genericId = new CommandID(CommonGuidList.guidOSBIDE_VSPackageCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideGenericToolWindow); MenuCommand genericWindow = new MenuCommand(ShowGenericToolWindow, genericId); mcs.AddCommand(genericWindow); //submit assignment command CommandID submitCommand = new CommandID(CommonGuidList.guidOSBIDE_OsbideToolsMenuCmdSet, (int)CommonPkgCmdIDList.cmdidOsbideSubmitAssignmentCommand); MenuCommand submitMenuItem = new MenuCommand(SubmitAssignmentCallback, submitCommand); mcs.AddCommand(submitMenuItem); //ask the professor window //(commented out for Fall 2013 release at instructor request) /* * CommandID askProfessorWindowId = new CommandID(GuidList.guidOSBIDE_VSPackageCmdSet, (int)PkgCmdIDList.cmdidOsbideAskTheProfessor); * MenuCommand menuAskProfessorWin = new MenuCommand(ShowAskProfessorTool, askProfessorWindowId); * mcs.AddCommand(menuAskProfessorWin); * */ // -- Set an event listener for shell property changes var shellService = GetService(typeof(SVsShell)) as IVsShell; if (shellService != null) { ErrorHandler.ThrowOnFailure(shellService. AdviseShellPropertyChanges(this, out _EventSinkCookie)); } } //add right-click context menu to the VS Error List DTE2 dte = (DTE2)this.GetService(typeof(SDTE)); if (dte != null) { CommandBars cmdBars = (CommandBars)dte.CommandBars; CommandBar errorListBar = cmdBars[10]; CommandBarControl osbideControl = errorListBar.Controls.Add(MsoControlType.msoControlButton, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true); // Set the caption of the submenuitem osbideControl.Caption = "View Error in OSBIDE"; _osbideErrorListEvent = (EnvDTE.CommandBarEvents)dte.Events.get_CommandBarEvents(osbideControl); _osbideErrorListEvent.Click += osbideCommandBarEvent_Click; } //create our web service _webServiceClient = new OsbideWebServiceClient(ServiceBindings.OsbideServiceBinding, ServiceBindings.OsbideServiceEndpoint); _webServiceClient.LibraryVersionNumberCompleted += InitStepThree_CheckServiceVersionComplete; _webServiceClient.LoginCompleted += InitStepTwo_LoginCompleted; _webServiceClient.GetMostRecentWhatsNewItemCompleted += GetRecentNewsItemDateComplete; //set up local encryption if (_cache.Contains(StringConstants.AesKeyCacheKey) == false) { _encoder.GenerateKey(); _encoder.GenerateIV(); _cache[StringConstants.AesKeyCacheKey] = _encoder.Key; _cache[StringConstants.AesVectorCacheKey] = _encoder.IV; } else { _encoder.Key = _cache[StringConstants.AesKeyCacheKey] as byte[]; _encoder.IV = _cache[StringConstants.AesVectorCacheKey] as byte[]; } //set up user name and password _userName = _cache[StringConstants.UserNameCacheKey] as string; byte[] passwordBytes = _cache[StringConstants.PasswordCacheKey] as byte[]; try { _userPassword = AesEncryption.DecryptStringFromBytes_Aes(passwordBytes, _encoder.Key, _encoder.IV); } catch (Exception) { } //set up tool window manager _manager = new OsbideToolWindowManager(_cache as FileCache, this); //set up service logger _eventHandler = new OsbideEventHandler(this as System.IServiceProvider, EventGenerator.GetInstance()); _client = ServiceClient.GetInstance(_eventHandler, _errorLogger); _client.PropertyChanged += ServiceClientPropertyChanged; _client.ReceivedNewSocialActivity += ServiceClientReceivedSocialUpdate; UpdateSendStatus(); //display a user notification if we don't have any user on file if (_userName == null || _userPassword == null) { _hasStartupErrors = true; MessageBoxResult result = MessageBox.Show("Thank you for installing OSBIDE. To complete the installation, you must enter your user information, which can be done by clicking on the \"Tools\" menu and selecting \"Log into OSBIDE\".", "Welcome to OSBIDE", MessageBoxButton.OK); } else { //step #1: attempt login string hashedPassword = UserPassword.EncryptPassword(_userPassword, _userName); try { _webServiceClient.LoginAsync(_userName, hashedPassword); } catch (Exception ex) { _errorLogger.WriteToLog("Web service error: " + ex.Message, LogPriority.HighPriority); _hasStartupErrors = true; } } }