Ejemplo n.º 1
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            // Set cursor as hourglass
            Cursor.Current = Cursors.WaitCursor;

            //obtain basic api information
            BasicTeamInformation teamInformation = dfbBasicTeamInfo();
            //obtain team information
            DfBTeam dfbTeam = dfb_members_list();

            //if we connect to the api successfully:
            if (teamInformation.num_licenced_users >= 0)
            {
                labelTeamName.Text           = "Connected to: " + teamInformation.name;
                pictureBoxConnected.SizeMode = PictureBoxSizeMode.Zoom;
                pictureBoxConnected.Image    = imageList2.Images[1];
                //populate the global object for use throughout the app.
                gbl_TeamObject = dfbTeam;
                populateDfBMembers(gbl_TeamObject);
            }

            // Set cursor as default arrow
            Cursor.Current = Cursors.Default;
        }
Ejemplo n.º 2
0
        private BasicTeamInformation dfbBasicTeamInfo()
        {
            String     page    = "https://api.dropbox.com/1/team/get_info";
            WebRequest request = WebRequest.Create(page);

            request.Method      = "POST";
            request.ContentType = "application/json";
            String authheader = "Authorization:Bearer " + txtToken.Text;

            request.Headers.Add(authheader);

            // Create POST data and convert it to a byte array.
            string postData = "{}";

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            // Get the request stream.
            Stream ds = request.GetRequestStream();

            // Write the data to the request stream.
            ds.Write(byteArray, 0, byteArray.Length);

            // Close the Stream object.
            ds.Close();

            // Get the response.
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();

                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);

                // Read the content.
                string responseFromServer = reader.ReadToEnd();

                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();

                //serialise the json so we can send back a BasicTeamInformation object
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(BasicTeamInformation));
                MemoryStream         stream    = new MemoryStream(Encoding.UTF8.GetBytes(responseFromServer));
                BasicTeamInformation teamObj   = (BasicTeamInformation)ser.ReadObject(stream);

                return(teamObj);
            }

            catch (WebException error)
            {
                BasicTeamInformation failedObj = new BasicTeamInformation();
                failedObj.name = error.Message;
                failedObj.num_licenced_users    = -1;
                failedObj.num_provisioned_users = -1;
                return(failedObj);
            }
        }
Ejemplo n.º 3
0
        private BasicTeamInformation dfbBasicTeamInfo()
        {
            String page = "https://api.dropbox.com/1/team/get_info";
            WebRequest request = WebRequest.Create(page);

            request.Method = "POST";
            request.ContentType = "application/json";
            String authheader = "Authorization:Bearer " + txtToken.Text;
            request.Headers.Add(authheader);

            // Create POST data and convert it to a byte array.
            string postData = "{}";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            // Get the request stream.
            Stream ds = request.GetRequestStream();

            // Write the data to the request stream.
            ds.Write(byteArray, 0, byteArray.Length);

            // Close the Stream object.
            ds.Close();

            // Get the response.
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();

                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);

                // Read the content.
                string responseFromServer = reader.ReadToEnd();

                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();

                //serialise the json so we can send back a BasicTeamInformation object
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(BasicTeamInformation));
                MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(responseFromServer));
                BasicTeamInformation teamObj = (BasicTeamInformation)ser.ReadObject(stream);

                return teamObj;
            }

            catch (WebException error)
            {
                BasicTeamInformation failedObj = new BasicTeamInformation();
                failedObj.name = error.Message;
                failedObj.num_licenced_users = -1;
                failedObj.num_provisioned_users = -1;
                return failedObj;
            }
        }