Пример #1
0
        public WitsInfo getWitInfo(String witId)
        {
            AccessTokenDao accesstokenDao = new AccessTokenDao();
            String token = accesstokenDao.getAccessToken(Common.userName);

            String url = Resource.endpoint + "wittyparrot/api/wits/" + witId + "";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            String content = response.Content;

            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            WitsInfo info = JsonConvert.DeserializeObject<WitsInfo>(content);
            if (info != null){return info;} return null;
        }
Пример #2
0
        public List<Wits> getFolderWits(String parentFolderId)
        {
            AccessTokenDao accesstokenDao = new AccessTokenDao();
            String token = accesstokenDao.getAccessToken(Common.userName);

            String url = Resource.endpoint + "wittyparrot/api/wits/folder/" + parentFolderId + "/children";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

           
            IRestResponse response = client.Execute(request);
            String content = response.Content;

            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            List<Wits> childWits = new List<Wits>();
            childWits = JsonConvert.DeserializeObject<List<Wits>>(content);

            // loop through the wits and create wits 
            if (childWits.Count > 0)
            {
                foreach (var wit in childWits)
                {
                    String witContent = getWitContent(wit.id);
                    if (witContent != null)
                    {
                        wit.content = witContent;
                    }
                }
            }

            return childWits;
        }
        // download all the attachments of a wit to the local folders
        public void getAttachment(String witId, String fileAssociationId, String fileName, String userProfilepath)
        {
            AccessTokenDao accesstokenDao = new AccessTokenDao();
            String token = accesstokenDao.getAccessToken(Common.userName);

            String url = Resource.endpoint + "wittyparrot/api/attachments/associationId/" + fileAssociationId + "";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            byte[] r = client.DownloadData(request);
            String fullPath = userProfilepath + "//files//attachments//";
            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }
            // save the file details to docs table
            Docs doc = new Docs();
            doc.docId = fileName.GetHashCode().ToString();
            doc.localPath = fullPath;
            doc.fileName = fileName;
            doc.witId = witId;


            AttachmentDao attachmentDao = new AttachmentDao();
            attachmentDao.saveDocs(doc);

            File.WriteAllBytes(fullPath + fileName, r);
        }
Пример #4
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());
            }

        }
Пример #5
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);
               
            }

        }
Пример #6
0
        // We are tackling the combowits
        public String getWitContent(string witId)
        {

            AccessTokenDao accesstokenDao = new AccessTokenDao();
            String token = accesstokenDao.getAccessToken(Common.userName);

            String url = Resource.endpoint + "wittyparrot/api/wits/" + witId + "";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            String content = response.Content;

            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }


            WitsInfo witInfo = JsonConvert.DeserializeObject<WitsInfo>(content);
            if (witInfo != null)
            {

                String witContent = witInfo.content;
                if (witContent != null)
                {
                    return witContent;
                }

                String witType = witInfo.witType;
                // check the type of the wit if its combo then we need to call the associated wits
                // get the content of associated wits to merge it and then return the content 

                if (witType == WitType.COMBO.Value)
                {
                    return getCombowitContent(witInfo); // return the combined wit contents of all the associated wits
                }
            }

            return null;

        }
Пример #7
0
        // not implemented/used
        public List<Folder> getChildFolders(String parentFolderId)
        {

            AccessTokenDao accesstokenDao = new AccessTokenDao();
            String token = accesstokenDao.getAccessToken(Common.userName);

            String url = Resource.endpoint + "wittyparrot/api/folders/" + parentFolderId + "/children";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            String content = response.Content;

            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            List<Folder> childFolders = new List<Folder>();
            childFolders = JsonConvert.DeserializeObject<List<Folder>>(content);
            if (childFolders != null && childFolders.Count > 0)
            {
                // all the code comes under this code
            }
                return childFolders;
        }