コード例 #1
0
		private void SetConnection()
		{
			if (!_isAuthenticated)
			{
				UserCredentials creds = new UserCredentials(Username, AccessKey);
				_client = new CF_Client();
				_conn = new CF_Connection(creds, _client);
				_conn.Authenticate();
				CheckContainer();
				_isAuthenticated = true;
			}
		}
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rackspace.Cloudfiles.CF_Connection"/> class.
 /// </summary>
 /// <param name='creds'>
 /// An instance of a UserCredentials object
 /// </param>
 /// <param name='client'>
 /// a HTTP client object 
 /// </param>
 public CF_Connection(UserCredentials creds, Client client)
 {
     _client = client;
     _user_creds = creds;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rackspace.Cloudfiles.CF_Connection"/> class.
 /// </summary>
 /// <param name='creds'>
 /// An instance of a UserCredentials object
 /// </param>
 public CF_Connection(UserCredentials creds)
 {
     _client = new CF_Client();
     _user_creds = creds;
 }
コード例 #4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string username = CFUsernameText.Text;
            string api_access_key = CFApiKeyText.Text;
            string ContainerNameText = CFContainerText.Text;
            try
            {
                //Check to make sure a service net value to selected
                if (!SnetFalse.Checked & !SnetTrue.Checked)
                {
                    Error.Text = "Please select true or false for ServiceNet";
                }
                else
                {
                    //Check to make sure a file is selected.
                    if (FileUpload1.HasFile)
                    {
                        //If service net is checked then continue.
                        if (SnetTrue.Checked)
                        {
                            //create the path to save the file to.
                            string fileName = Path.Combine(Server.MapPath("~/temp/"), FileUpload1.FileName);
                            string path = Server.MapPath("~/temp/");
                            //ServiceNet value taken from frontend.
                            bool snet = bool.Parse(SnetTrue.Text);

                            //Save the file to local path.
                            FileUpload1.SaveAs(fileName);

                            //Set CloudFiles credentials
                            var userCredentials = new UserCredentials(username, api_access_key);
                            var client = new CF_Client();
                            Connection conn = new CF_Connection(userCredentials, client);
                            conn.Authenticate(snet);

                            //Set container, and obj values
                            var container = new CF_Container(conn, client, ContainerNameText);
                            var obj = new CF_Object(conn, container, client, FileUpload1.FileName);

                            //CloudFiles binding writing from local object to CloudFiles
                            obj.WriteFromFile(fileName);

                            //Get list of object in container you just uploaded to
                            var list = container.GetObjects(true);

                            CFResultsGrid.DataSource = list;
                            CFResultsGrid.DataBind();

                            Error.Text = FileUpload1.FileName + " Has Been Uploaded Successfully";
                        }
                        else if (SnetFalse.Checked)
                        {
                            //create the path to save the file to.
                            string fileName = Path.Combine(Server.MapPath("~/temp/"), FileUpload1.FileName);
                            string path = Server.MapPath("~/temp/");
                            //ServiceNet value taken from frontend.
                            bool snet = bool.Parse(SnetTrue.Text);

                            //Save the file to local path.
                            FileUpload1.SaveAs(fileName);

                            //Set CloudFiles credentials
                            var userCredentials = new UserCredentials(username, api_access_key);
                            var client = new CF_Client();
                            Connection conn = new CF_Connection(userCredentials, client);
                            conn.Authenticate(snet);

                            //Set container, and obj values
                            var container = new CF_Container(conn, client, ContainerNameText);
                            var obj = new CF_Object(conn, container, client, FileUpload1.FileName);

                            //CloudFiles binding writing from local object to CloudFiles
                            obj.WriteFromFile(fileName);

                            //Get list of object in container you just uploaded to
                            var list = container.GetObjects(true);

                            CFResultsGrid.DataSource = list;
                            CFResultsGrid.DataBind();

                            Error.Text = FileUpload1.FileName + " Has Been Uploaded Successfully";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Error.Text = "Something went terribly wrong! See below for more info. <br /> <br />" + ex.ToString();
            }
        }
コード例 #5
0
        protected void ListContainerContents_Click(object sender, EventArgs e)
        {
            string username = CFUsernameText.Text;
            string api_access_key = CFApiKeyText.Text;
            string ContainerNameText = CFContainerText.Text;

            try
            {
                if (!SnetFalse.Checked & !SnetTrue.Checked)
                {
                    Error.Text = "Please select true or false for ServiceNet";
                }
                else
                {
                    if (SnetTrue.Checked)
                    {
                        if (CFUsernameText.Text != "" & CFApiKeyText.Text != "" & CFContainerText.Text != "")
                        {
                            bool snet = bool.Parse(SnetTrue.Text);

                            var userCredentials = new UserCredentials(username, api_access_key);
                            var client = new CF_Client();
                            Connection conn = new CF_Connection(userCredentials, client);
                            conn.Authenticate(snet);
                            var container = new CF_Container(conn, client, ContainerNameText);
                            if (container.ObjectCount != 0)
                            {
                                var list = container.GetObjects(true);

                                CFResultsGrid.DataSource = list;
                                CFResultsGrid.DataBind();
                            }
                            else
                            {
                                Error.Text = "There is no content within this container.";
                            }

                        }
                        else
                        {
                            Error.Text = "Please be sure to enter Username, APIKey, and Container to upload to! <br /> <br />";
                        }
                    }
                    else if (SnetFalse.Checked)
                    {
                        if (CFUsernameText.Text != "" & CFApiKeyText.Text != "" & CFContainerText.Text != "")
                        {
                            bool snet = bool.Parse(SnetFalse.Text);

                            var userCredentials = new UserCredentials(username, api_access_key);
                            var client = new CF_Client();
                            Connection conn = new CF_Connection(userCredentials, client);
                            conn.Authenticate(snet);
                            var container = new CF_Container(conn, client, ContainerNameText);
                            if (container.ObjectCount != 0)
                            {
                                var list = container.GetObjects(true);

                                CFResultsGrid.DataSource = list;
                                CFResultsGrid.DataBind();
                            }
                            else
                            {
                                Error.Text = "There is no content within this container.";
                            }
                        }
                        else
                        {
                            Error.Text = "Please be sure to enter Username, APIKey, and Container to upload to! <br /> <br />";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Error.Text = "Something went terribly wrong! See below for more info. <br /> <br />" + ex.ToString();
            }
        }