示例#1
0
        /// <summary>
        ///  get all files under module folder
        /// </summary>
        /// <param name="token"></param>
        /// <param name="subdomain"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static JArray GetAllModuleFolderFiles(string token, string subdomain, string id)
        {
            string hosturl = string.Format("{0}.sf-api.com", subdomain);

            String uri = string.Format("https://{0}/sf/v3/Items({1})/Children?$select=Id&includeDeleted=false", hosturl, id);

            //Console.WriteLine(uri);

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            DimensionalControlHelper.addAuthorizationHeader(request, token);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //Console.WriteLine(response.StatusCode);
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                String body = reader.ReadToEnd();

                JObject folder = JObject.Parse(body);
                // only Id and Name are available because we specifically selected only those two Properties

                JArray children = (JArray)folder["Children"];
                return(children);
            }
        }
示例#2
0
        /// <summary>
        /// Get a folder using some of the common query parameters that are available. This will
        /// add the expand, select parameters. The following are used:
        /// expand=Children to get any Children of the folder
        /// select=Id,Name,Children/Id,Children/Name,Children/CreationDate to get the Id, Name of the folder and the Id, Name, CreationDate of any Children
        /// </summary>
        /// <param name="token">the OAuth2Token returned from Authenticate</param>
        /// <param name="id">a folder id</param>
        public static void GetFolderWithQueryParameters(string token, string subdomain, string id)
        {
            string hosturl = string.Format("{0}.sf-api.com", subdomain);

            String uri = string.Format("https://{0}/sf/v3/Items({1})?$expand=Children&$select=Id,Name,Children/Id,Children/Name,Children/CreationDate", hosturl, id);

            // String uri = string.Format("https://stw.sf-api.com/sf/v3/Items({1})?$expand=Children&$select=Id,Name,Children/Id,Children/Name,Children/CreationDate", DimensionalControlHelper.GetHostname(token), id);
            Console.WriteLine(uri);

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            DimensionalControlHelper.addAuthorizationHeader(request, token);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Console.WriteLine(response.StatusCode);
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                String body = reader.ReadToEnd();

                JObject folder = JObject.Parse(body);
                // only Id and Name are available because we specifically selected only those two Properties
                Console.WriteLine(folder["Id"] + " " + folder["Name"]);
                JArray children = (JArray)folder["Children"];
                if (children != null)
                {
                    foreach (JObject child in children)
                    {
                        // CreationDate is also available on Children because we specifically selected that property in addition to Id, Name
                        Console.WriteLine(child["Id"] + " " + child["CreationDate"] + " " + child["Name"]);
                    }
                }
            }
        }
示例#3
0
        public static JObject GetTreeView(string token, string subdomain, string id)
        {
            string hosturl = string.Format("{0}.sf-api.com", subdomain);
            //String uri = string.Format("https://{0}/sf/v3/Items", hosturl);

            // https://account.sf-api.com/sf/v3/Items(id)/Children?includeDeleted=false
            String uri = string.Format("https://{0}/sf/v3/Items({1})?includeDeleted=false&treemode=mode&sourceId=id&canCreateRootFolder=false", hosturl, id);

            //String uri = string.Format("https://{0}/sf/v3/Items({1})/Children?includeDeleted=false", hosturl,"fohfbffd-bb1a-4ad8-a1de-aa5ec1b4e450");

            //String uri = "https://STWServicesLLP.sf-api.com/sf/v3/Items(allshared)/Children";

            Console.WriteLine(uri);

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            DimensionalControlHelper.addAuthorizationHeader(request, token);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Console.WriteLine(response.StatusCode);
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                String body = reader.ReadToEnd();

                JObject root = JObject.Parse(body);

                return(root);
            }
        }
示例#4
0
        /// <summary>
        /// Get a single Item by Id.
        /// </summary>
        /// <param name="token">the OAuth2Token returned from Authenticate</param>
        /// <param name="id">an item id</param>
        public static JObject GetItemById(string token, string subdomain, string id)
        {
            string hosturl = string.Format("{0}.sf-api.com", subdomain);

            String uri = string.Format("https://{0}/sf/v3/Items({1})", hosturl, id);

            Console.WriteLine(uri);

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            DimensionalControlHelper.addAuthorizationHeader(request, token);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Console.WriteLine(response.StatusCode);
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                String body = reader.ReadToEnd();

                JObject item = JObject.Parse(body);
                //Console.WriteLine(item["Id"] + " " + item["CreationDate"] + " " + item["Name"]);

                return(item);
            }
        }
示例#5
0
        /// <summary>
        /// Get the root level Item for the provided user. To retrieve Children the $expand=Children
        /// parameter can be added.
        /// </summary>
        /// <param name="token">the OAuth2Token returned from Authenticate</param>
        /// <param name="getChildren">retrieve Children Items if true, default is false</param>
        public static JObject GetRoot(string token, string id, string subdomain, bool getChildren = true)
        {
            string hosturl = string.Format("{0}.sf-api.com", subdomain);
            //String uri = string.Format("https://{0}/sf/v3/Items", hosturl);

            // https://account.sf-api.com/sf/v3/Items(id)/Children?includeDeleted=false
            String uri = string.Format("https://{0}/sf/v3/Items({1})/Children?$select=FileName,Id,odata.type&$filter=ItemType eq Folder&includeDeleted=false", hosturl, id);

            //String uri = string.Format("https://{0}/sf/v3/Items({1})/Children?includeDeleted=false", hosturl,"fohfbffd-bb1a-4ad8-a1de-aa5ec1b4e450");

            //String uri = "https://STWServicesLLP.sf-api.com/sf/v3/Items(allshared)/Children";
            if (getChildren)
            {
                uri += "?$expand=Children";
            }
            Console.WriteLine(uri);

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            DimensionalControlHelper.addAuthorizationHeader(request, token);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Console.WriteLine(response.StatusCode);
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                String body = reader.ReadToEnd();

                JObject root = JObject.Parse(body);

                return(root);

                // just print Id, CreationDate, Name of each element

                /* Console.WriteLine(root["Id"] + " " + root["CreationDate"] + " " + root["Name"]);
                 * JArray children = (JArray)root["Children"];
                 * if (children != null)
                 * {
                 *   foreach (JObject child in children)
                 *   {
                 *       Console.WriteLine(child["Id"] + " " + child["CreationDate"] + " " + child["Name"]);
                 *   }
                 * }*/
            }
        }