Пример #1
0
        // gets invoke when the user logins
        public void login(object sender, EventArgs e)
        {

            try {
                Panel witsPanel = this.witsPanel;
                witsPanel.Visible = false;
               

                Panel panel = this.pnlMenu;
                panel.Visible = true;

                // get the username and pasword from the widget
                var userName = textBox1.Text;
                var password = textBox2.Text;

                // rest api for login
                RestClientLogin clientLogin = new RestClientLogin();
                this.rootObj = clientLogin.login(userName, password);

                // check if the db is already present or not
                UserDBConnector userDBConnector = new UserDBConnector(userName);
                if (!userDBConnector.isDataBaseExists()) {
                    refreshDatabaseThread();
                }

                AccessTokenDao accessTokenDao = new AccessTokenDao();
                accessTokenDao.saveAccessToken(rootObj.accessToken);

                this.userName = userName;
                this.password = password;

                UserWorkspaceDao workspaceDao = null;
                if (rootObj.userProfile.userWorkspaces != null && rootObj.userProfile.userWorkspaces.Count > 0) {

                    workspaceDao = new UserWorkspaceDao();
                    // fetch all the workspaces and show it in the workspace panel

                    if (workspaceDao.getWorkspaceNameList() != null && workspaceDao.getWorkspaceNameList().Count != 0)
                    {
                        List<UserWorkspace> workspaces = workspaceDao.getWorkspaceList();                     
                        panel.Controls.Clear(); // clear the panel before adding the workspace controls

                        // loop through all the workspaces and get the folders of the workspaces
                        foreach (var workspace in workspaces)
                        {

                            CustomWorkspaceButton workspaceButton = new CustomWorkspaceButton();
                            workspaceButton.Text = " " + workspace.Name;

                            var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                            var path = Path.Combine(appDataPath, "wpoutlookwidget" + @"\");

                            workspaceButton.Image = new Bitmap(path + "wpdependencies\\list_icon.ico");
                            workspaceButton.Click += workspaceButtonHandler;

                            CustomWorkspacePanel childPanel = new CustomWorkspacePanel();                          
                            childPanel.Controls.Add(workspaceButton);

                            panel.Controls.Add(childPanel);

                        }
                    }


                    // make the backgroud color WhiteSmoke so that if clicks for wits
                    // backgroud should should not look un even
                    this.BackColor = System.Drawing.Color.WhiteSmoke;

                    // clear all the controls from the widget and show only Workspace panel
                    // workspace panel is the starting point (iniital screen) 
                    afterLogin();
                    mainTabPanel.Visible = true;


                    // save all the images needed to show to the widget
                    ImageList myImageList = new ImageList();
                    myImageList.Images.Add(Resource.grayfolder);
                    myImageList.Images.Add(Resource.grayfolder);
                    myImageList.ColorDepth = ColorDepth.Depth32Bit;

                    // Assign the ImageList to the TreeView.
                    myCustomTreeView.ImageList = myImageList;

                    // Set the TreeView control's default image and selected image indexes.
                    myCustomTreeView.ImageIndex = 0;
                    myCustomTreeView.SelectedImageIndex = 0;

                    // control factory for future use
                    witChildPanels = new List<CustomWitPanel>();
                    ControlFactory controlFactory = new ControlFactory();
                    witChildPanels = controlFactory.getChildWitPanels();

                }
                else {

                    // when there is no folders to show !!!
                    MessageBox.Show("No Workspace to show");
                }
            }
            catch (SQLiteException sqlException)
            {
                MessageBox.Show("Error occured: " + sqlException.ToString());
            }
            catch (System.ApplicationException appException)
            {
                MessageBox.Show("Error occured: "+ appException.ToString());
            }
            catch (Exception ew) {

                MessageBox.Show("Error occured: "+ ew.ToString());
            }

        }
Пример #2
0
        private void refreshDatabase()
        {

            try
            {           

                UserDBConnector userDBConnector = new UserDBConnector(Common.userName);         
                userDBConnector.prepareUserDBSchema(rootObj);
               
                AccessTokenDao accessTokenDao = new AccessTokenDao();
                accessTokenDao.saveAccessToken(rootObj.accessToken);

             
                UserWorkspaceDao workspaceDao = new UserWorkspaceDao();
                workspaceDao.saveWorkspaces(rootObj.userProfile.userWorkspaces);

                if (workspaceDao.getWorkspaceNameList() != null && workspaceDao.getWorkspaceNameList().Count != 0)
                {
                    List<UserWorkspace> workspaces = workspaceDao.getWorkspaceList();
                   
                    foreach (var workspace in workspaces)
                    {
                        RestClientFolder restClientFolder = new RestClientFolder();
                        restClientFolder.getAllFolders(rootObj.accessToken.tokenValue, workspace.WorkspaceId, 0);
                    }

                   // FolderDao folderDao = new FolderDao();
                    //folderDao.saveAllFolders(allFolderList);
                }

            }
            catch (Exception e)
            {
                MessageBox.Show("Error occured while refreshing data:" + e.Message);
               
            }

        }