Esempio n. 1
0
 /// <summary>
 /// Delete current calendar
 /// </summary>
 public void Delete()
 {
     try
     {
         Requester.Request <Calendar>(new RequestObject {
             Url = UrlBuilder1.Build(Id), Method = WebRequestMethods.Http.Delete
         });
     }
     catch
     {
         throw;
     }
 }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="objectId">Object ID - FOLDER_ID/FILE_ID/...</param>
 /// <returns>Return object get by their ID</returns>
 public static T Get(string objectId)
 {
     try
     {
         return(Requester.Request <T>(new RequestObject {
             Url = UrlBuilder1.Build(objectId)
         }).ElementAt(0));
     }
     catch
     {
         throw;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Delete current object
 /// </summary>
 public virtual void Delete()
 {
     try
     {
         Requester.Request <T>(new RequestObject {
             Url = UrlBuilder1.Build(Id.ToString()), Method = WebRequestMethods.Http.Delete
         });
     }
     catch
     {
         throw;
     }
 }
Esempio n. 4
0
        /// <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; }
        }
Esempio n. 5
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;
     }
 }
Esempio n. 6
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;
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Gets all events of user
 /// </summary>
 /// <param name="usrid">USER_ID</param>
 /// <returns>Events collection of user</returns>
 public static IEnumerable <WLEvent> GetEvents(string userId)
 {
     if (string.IsNullOrEmpty(userId))
     {
         userId = "me";
     }
     try
     {
         return(Requester.Request <WLEvent>(new RequestObject {
             Url = UrlBuilder1.Build(userId + "/events")
         }).ToList());
     }
     catch
     {
         throw;
     }
 }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="userId">USER_ID</param>
 /// <returns>Returns all calendars of user by user_id when parameter is not empty else returns all calendars of current user</returns>
 public static IEnumerable <Calendar> GetCalendars(string userId)
 {
     if (string.IsNullOrEmpty(userId))
     {
         userId = "me";
     }
     try
     {
         return(Requester.Request <Calendar>(new RequestObject {
             Url = UrlBuilder1.Build(userId + "/calendars")
         }));
     }
     catch
     {
         throw;
     }
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="folderid">FOLDER_ID</param>
 /// <returns>Return files in folder get by folderid</returns>
 public static IEnumerable <File> GetFiles(string folderId)
 {
     try
     {
         if (string.IsNullOrEmpty(folderId))
         {
             folderId = "me/skydrive";
         }
         return(Requester.Request <File>(new RequestObject {
             Url = UrlBuilder1.Build(folderId + "/files")
         }).ToList());
     }
     catch
     {
         throw;
     }
 }
Esempio n. 10
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;
            }
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T">Type of file which you want to return. If you want to return more types, use type File</typeparam>
        /// <param name="folderid">FOLDER_ID</param>
        /// <param name="filter">Types of file which you want to return.</param>
        /// <returns>Return files in folder get by folderid</returns>
        public static IEnumerable <T> GetFiles <T>(string folderId, FilterTypes filter)
        {
            QueryParameters qp = new QueryParameters();
            Filter          f  = new Filter(filter);

            qp.Add("filter", f.GetTypesForQuery);
            try
            {
                if (string.IsNullOrEmpty(folderId))
                {
                    folderId = "me/skydrive";
                }
                return(Requester.Request <T>(new RequestObject {
                    Url = UrlBuilder1.Build(folderId + "/files", qp)
                }).ToList());
            }
            catch
            {
                throw;
            }
        }
Esempio n. 12
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;
            }
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        /// <summary>
        /// Gets folders or subfolders of current user
        /// </summary>
        /// <param name="option">Option if you want to folders with subfolders or not</param>
        /// <returns>List of folders or subfolders of current user</returns>
        public IEnumerable <Folder> GetFolders(System.IO.SearchOption option)
        {
            if (string.IsNullOrEmpty(Id))
            {
                Id = "me";
            }
            Filter          f  = new Filter(FilterTypes.Folder);
            QueryParameters qp = new QueryParameters();

            qp.Add("filter", f.GetTypesForQuery);
            try
            {
                if (option == System.IO.SearchOption.TopDirectoryOnly)
                {
                    return(Requester.Request <Folder>(new RequestObject {
                        Url = UrlBuilder1.Build(Id + "/skydrive/files", qp)
                    }).ToList());
                }
                else
                {
                    List <Folder> k = new List <Folder>();
                    foreach (Folder folder in Requester.Request <Folder>(new RequestObject {
                        Url = UrlBuilder1.Build(Id + "/files", qp)
                    }))
                    {
                        k.Add(folder);
                        k.AddRange(folder.GetFolders(option));
                    }
                    return(k);
                }
            }
            catch
            {
                throw;
            }
        }
Esempio n. 15
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;
            }
        }
Esempio n. 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folderid">FOLDER_ID</param>
        /// <param name="option">Option for search in current folder or is subfolders</param>
        /// <returns>Returns list of folders or subfolders of folder based od location id</returns>
        public static IEnumerable <Folder> GetFolders(string folderId, System.IO.SearchOption searchOption)
        {
            if (string.IsNullOrEmpty(folderId))
            {
                folderId = "me/skydrive";
            }
            Filter          f  = new Filter(FilterTypes.Folder | FilterTypes.Album);
            QueryParameters qp = new QueryParameters();

            qp.Add("filter", f.GetTypesForQuery);
            try
            {
                if (searchOption == System.IO.SearchOption.TopDirectoryOnly)
                {
                    return(Requester.Request <Folder>(new RequestObject {
                        Url = UrlBuilder1.Build(folderId + "/files", qp)
                    }).ToList());
                }
                else
                {
                    List <Folder> ret = new List <Folder>();
                    foreach (Folder folder in Requester.Request <Folder>(new RequestObject {
                        Url = UrlBuilder1.Build(folderId + "/files", qp)
                    }))
                    {
                        ret.Add(folder);
                        ret.AddRange(GetFolders(folder.Id, searchOption));
                    }
                    return(ret);
                }
            }
            catch
            {
                throw;
            }
        }
Esempio n. 17
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;
     }
 }