Exemplo n.º 1
0
 public OsbideLoginViewModel()
 {
     _serviceClient                 = new OsbideWebServiceClient(ServiceBindings.OsbideServiceBinding, ServiceBindings.OsbideServiceEndpoint);
     LoginCommand                   = new DelegateCommand(Login, CanIssueCommand);
     LogoutCommand                  = new DelegateCommand(Logout, CanIssueCommand);
     CancelCommand                  = new DelegateCommand(Cancel, CanIssueCommand);
     CreateAccountCommand           = new DelegateCommand(CreateAccount, CanIssueCommand);
     _serviceClient.LoginCompleted += LoginCompleted;
     _buttonsEnabled                = true;
     _loadingIconVisible            = false;
 }
Exemplo n.º 2
0
        private ServiceClient(EventHandlerBase dteEventHandler, ILogger logger)
        {
            _events = dteEventHandler;
            this._logger = logger;
            _webServiceClient = new OsbideWebServiceClient(ServiceBindings.OsbideServiceBinding, ServiceBindings.OsbideServiceEndpoint);

            //AC: "events" ends up being null during unit testing.  Otherwise, it should never happen.
            if (_events != null)
            {
                _events.EventCreated += new EventHandler<EventCreatedArgs>(OsbideEventCreated);
            }

            //if we don't have a cache record of pending logs when we start, create a dummy list
            if (!_cache.Contains(_cacheKey, _cacheRegion))
            {
                SaveLogsToCache(new List<EventLog>());
            }
            
        }
Exemplo n.º 3
0
        public SubmitAssignmentViewModel(string userName, string authToken, SubmitEvent submitEvent)
        {
            UserName        = userName;
            _authToken      = authToken;
            _submitEvent    = submitEvent;
            SolutionName    = Path.GetFileNameWithoutExtension(submitEvent.SolutionName);
            _client         = new OsbideWebServiceClient(ServiceBindings.OsbideServiceBinding, ServiceBindings.OsbideServiceEndpoint);
            ContinueCommand = new DelegateCommand(Continue, CanIssueCommand);
            CancelCommand   = new DelegateCommand(Cancel, CanIssueCommand);
            Assignments     = new ObservableCollection <Assignment>();
            Courses         = new ObservableCollection <Course>();
            LastSubmitted   = "N/A";

            //set up event listeners
            _client.GetCoursesForUserCompleted           += _client_GetCoursesForUserCompleted;
            _client.GetAssignmentsForCourseCompleted     += _client_GetAssignmentsForCourseCompleted;
            _client.SubmitAssignmentCompleted            += _client_SubmitAssignmentCompleted;
            _client.GetLastAssignmentSubmitDateCompleted += _client_GetLastAssignmentSubmitDateCompleted;

            //load courses
            IsLoading = true;
            _client.GetCoursesForUserAsync(authToken);
        }
Exemplo n.º 4
0
        /////////////////////////////////////////////////////////////////////////////
        // 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;
                }
            }
        }