예제 #1
0
파일: User.cs 프로젝트: Zefek/WLiveFW
        /// <summary>
        /// Create new contact for current user. At least one parameter must be filled.
        /// </summary>
        /// <param name="firstname">Contact firstname</param>
        /// <param name="lastname">Contact lastname</param>
        /// <param name="emails">Contact emails</param>
        /// <param name="works">Contact works</param>
        public void CreateContact(Contact contact, Email emails, Work[] work)
        {
            UserContact uc = new UserContact {
                ContactInfo = contact, Emails = emails, Works = work
            };

            /*
             * StringBuilder sb = new StringBuilder();
             * sb.Append("{");
             * if (contact != null)
             * {
             *  if (!string.IsNullOrEmpty(contact.FirstName))
             *      sb.Append("\"first_name\": \"" + contact.FirstName + "\"\r\n");
             *  if(!string.IsNullOrEmpty(contact.LastName))
             *      sb.Append("\"last_name\": \"" + contact.LastName + "\"\r\n");
             * }
             * string email = "";
             * if (emails != null)
             *  email = "\"emails\": " + JSONDataBuilder.Build(emails);
             * if (!string.IsNullOrEmpty(email))
             *  sb.Append(email);
             * string wrk = "";
             * if (work!=null && work.Length > 0)
             * {
             *  wrk = "\"work\": [ { ";
             *  for (int i = 0; i < work.Length; i++)
             *  {
             *      wrk += "\"employer\": " + JSONDataBuilder.Build(work[i].Employer);
             *  }
             *  wrk += "} ]";
             * }
             * if (!string.IsNullOrEmpty(wrk))
             *  sb.Append(wrk);
             * sb.Append("}");
             */
            string data = Newtonsoft.Json.JsonConvert.SerializeObject(uc, AGetOpConverter <UserContact> .Settings);

            try
            {
                RequestObject ro = new RequestObject();
                ro.Method = WebRequestMethods.Http.Post;
                ro.SetData(data);
                ro.Url = UrlBuilder1.Build(Id + "/contacts");
                Requester.Request <Contact>(ro);
            }
            catch
            { throw; }
        }
예제 #2
0
 public void CreateTag(Tag tag)
 {
     try
     {
         string        data = Newtonsoft.Json.JsonConvert.SerializeObject(tag, AGetOpConverter <T> .Settings);
         RequestObject ro   = new RequestObject {
             Url = UrlBuilder1.Build(Id + "/tags"), Method = WebRequestMethods.Http.Post, ContentType = ContentType.ApplicationJson
         };
         ro.SetData(data);
         Requester.Request <T>(ro);
     }
     catch
     {
         throw;
     }
 }
예제 #3
0
 /// <summary>
 /// Update properties of object. Use this method when you want to rename object
 /// </summary>
 public virtual void Update()
 {
     try
     {
         string        data = Newtonsoft.Json.JsonConvert.SerializeObject(this, AGetOpConverter <T> .Settings);
         RequestObject ro   = new RequestObject {
             Url = UrlBuilder1.Build(Id.ToString()), Method = WebRequestMethods.Http.Put, ContentType = ContentType.ApplicationJson
         };
         ro.SetData(data);
         Requester.Request <T>(ro);
     }
     catch
     {
         throw;
     }
 }
예제 #4
0
        /// <summary>
        /// Update properties of calendar
        /// </summary>
        public void Update()
        {
            string data = "{\"name\": \"" + Name + "\"}";

            try
            {
                RequestObject ro = new RequestObject {
                    Url = UrlBuilder1.Build(Id), Method = WebRequestMethods.Http.Put, ContentType = ContentType.ApplicationJson
                };
                ro.SetData(data);
                Requester.Request <Calendar>(ro).ElementAt(0);
            }
            catch
            {
                throw;
            }
        }
예제 #5
0
        /// <summary>
        /// Creates new calendar
        /// </summary>
        /// <param name="userId">USER_ID</param>
        /// <param name="name">Name of calendar</param>
        /// <param name="summary">Summary of calendar</param>
        /// <returns>Returns new calendar object</returns>
        public static Calendar Create(string userId, string name, string summary)
        {
            if (string.IsNullOrEmpty(userId))
            {
                userId = "me";
            }
            string data = "{\"name\": \"" + name + "\",\r\n \"summary\": \"" + summary + "\"}";

            try
            {
                RequestObject ro = new RequestObject {
                    Url = UrlBuilder1.Build(userId + "/calendars"), Method = WebRequestMethods.Http.Post, ContentType = ContentType.ApplicationJson
                };
                ro.SetData(data);
                return(Requester.Request <Calendar>(ro).ElementAt(0));
            }
            catch
            {
                throw;
            }
        }
예제 #6
0
        /// <summary>
        /// Create object with content and progress when upload
        /// </summary>
        /// <param name="locationid">Location id where you want to object create</param>
        /// <param name="name">Object name</param>
        /// <param name="file">Object content</param>
        /// <param name="owoption">Overwrite option</param>
        /// <param name="handler">Progress handler for watch progress when uploading</param>
        /// <returns>Returns created object</returns>
        public static T Create(T fileValue, Stream file, OverwriteOption overwriteOption, RequestProgressHandler handler)
        {
            T          obj     = default(T);
            AFiles <T> fileobj = (fileValue as AFiles <T>);

            if (string.IsNullOrEmpty((fileobj as AFiles <T>).ParentId))
            {
                fileobj.ParentId = "me/skydrive";
            }
            try
            {
                QueryParameters qp = new QueryParameters();
                qp.Add("overwrite", GetOverwriteOption(overwriteOption));
                RequestObject ro = new RequestObject {
                    Url = UrlBuilder1.Build(fileobj.ParentId + "/files/" + fileobj.Name, qp), Method = WebRequestMethods.Http.Put, ContentType = ContentType.ApplicationJsonODataVerbose
                };
                ro.SetData(new byte[] { 0 });
                obj       = Requester.Request <T>(ro).ElementAt(0);
                fileValue = Get((obj as AOperational <T>).Id);
            }
            catch
            {
                throw;
            }
            string[] lid   = fileobj.ParentId.Split('.');
            string   usrid = User.Get("").Id;

            try
            {
                UploadContent(file, usrid, fileobj.Name, lid[lid.Length - 1], 0, handler, null, obj);
            }
            catch
            {
                throw;
            }
            return(obj);
        }
예제 #7
0
 /// <summary>
 /// Copy object into location
 /// </summary>
 /// <param name="newLocationId">Location id where you want to copy object</param>
 public virtual void Copy(string newLocationId)
 {
     if (string.IsNullOrEmpty(newLocationId))
     {
         newLocationId = "me/skydrive";
     }
     try
     {
         WLDestination dest = new WLDestination {
             Destination = newLocationId
         };
         string        data = Newtonsoft.Json.JsonConvert.SerializeObject(dest, AGetOpConverter <T> .Settings);
         RequestObject ro   = new RequestObject {
             Url = UrlBuilder1.Build(Id), Method = WebRequestMethods.Http.Copy, ContentType = ContentType.ApplicationJson
         };
         //ro.SetData("{ \"destination\": \"" + newLocationId + "\"}");
         ro.SetData(data);
         Requester.Request <T>(ro);
     }
     catch
     {
         throw;
     }
 }
예제 #8
0
        /// <summary>
        /// Create new object
        /// </summary>
        /// <param name="locationid">Location id where you want object create</param>
        /// <param name="name">Name of object</param>
        /// <param name="description">Description object</param>
        /// <returns>Created object</returns>
        public static T Create(T value)
        {
            AOperational <T> obj = (value as AOperational <T>);

            if (string.IsNullOrEmpty(obj.ParentId))
            {
                obj.ParentId = "me/skydrive";
            }
            //string data = JSONDataBuilder.Build(obj); //"{\"name\": \"" + name + "\",\r\n \"description\": \"" + description + "\"}";
            string data = Newtonsoft.Json.JsonConvert.SerializeObject(obj, AGetOpConverter <T> .Settings);

            try
            {
                RequestObject ro = new RequestObject {
                    Url = UrlBuilder1.Build(obj.ParentId), Method = WebRequestMethods.Http.Post, ContentType = ContentType.ApplicationJson
                };
                ro.SetData(data);
                return(Requester.Request <T>(ro).ElementAt(0));
            }
            catch
            {
                throw;
            }
        }