示例#1
0
        public static async Task <Rootobject> GetFoldersAsync()
        { /////////////////////////////////////SF REST API and .net//////////////////////Get method////
            //QUERY: Retrieve records of type "Folder"
            //string restQuery = serviceUrl + "/services/data/v47.0/folders";
            //QUERY: retrieve a specific Folder with "shares" component
            //string restQuery = serviceUrl + "/services/data/v47.0/folders/00l0d0000028qGDAAY/shares/0AF0d000000LbYuGAK";

            SaleForceConnect sfc = new SaleForceConnect();
            await sfc.RestConectionAsync();

            string restQuery = sfc.serviceUrl + "/services/data/v47.0/query/?q=SELECT+AccessType,Type,Name,id+from+folder+where+Type%3D%27report%27%20or%20Type%3D%27dashboard%27";//"/services/data/v47.0/folders";

            //String restQuery = serviceUrl + "/services/data/v47.0/folder/00l0d0000028qGDAAY/share-recipients?shareType=User"; //Not working, check with Salesforce

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, restQuery);

            //add token to header
            request.Headers.Add("Authorization", "Bearer " + sfc.OauthToken);

            //return XML to the caller
            //request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

            //return JSON to the caller
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));



            //call endpoint async

            HttpResponseMessage response = await SalesforceWindowsForms.DAL.SaleForceConnect.authClient.SendAsync(request);

            string result = await response.Content.ReadAsStringAsync();

            Rootobject Folders = JsonConvert.DeserializeObject <Rootobject>(result, new JsonSerializerSettings
            {
                ObjectCreationHandling = ObjectCreationHandling.Replace //set to Replace so that collection values aren't duplicated.
            });

            /*foreach (Folder office in Folders)
             * {
             *  Console.WriteLine(office);
             * }*/



            return(Folders);
        }
 public static SaleForceConnect getInstance(String username, String password, String serverUrl)
 {
     try
     {
         if (instance == null)
         {
             sfService = new SforceService();
             instance  = new SaleForceConnect(username, password, serverUrl);
             return(instance);
         }
         else
         {
             return(instance);
         }
     }
     catch (System.Web.Services.Protocols.SoapException e)
     {
         // This is likley to be caused by bad username or password
         throw (e);
     }
 }
示例#3
0
        public async Task <IDictionary <String, List <FolderShare> > > GetFolderShareListAsync(List <String> folderId)
        { /////////////////////////////////////SF REST API and .net//////////////////////Get method////
            //QUERY: Retrieve records of type "Folder"
            //string restQuery = serviceUrl + "/services/data/v47.0/folders";
            //QUERY: retrieve a specific Folder with "shares" component
            //string restQuery = serviceUrl + "/services/data/v47.0/folders/00l0d0000028qGDAAY/shares/0AF0d000000LbYuGAK";

            IDictionary <String, List <FolderShare> > mapFolderShare = new Dictionary <String, List <FolderShare> >();
            SaleForceConnect sfc     = new SaleForceConnect();
            RootobjectShares folderS = new RootobjectShares();
            await sfc.RestConectionAsync();

            foreach (String id in folderId)
            {
                string restQuery = sfc.serviceUrl + "/services/data/v47.0/folders/" + id + "/shares";

                //String restQuery = serviceUrl + "/services/data/v47.0/folder/00l0d0000028qGDAAY/share-recipients?shareType=User"; //Not working, check with Salesforce

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, restQuery);

                //add token to header

                request.Headers.Add("Authorization", "Bearer " + sfc.OauthToken);

                //return XML to the caller

                //request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                //return JSON to the caller

                request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //call endpoint async

                //call endpoint async
                try
                {
                    HttpResponseMessage response = await SalesforceWindowsForms.DAL.SaleForceConnect.authClient.SendAsync(request);

                    string result = await response.Content.ReadAsStringAsync();


                    folderS = JsonConvert.DeserializeObject <RootobjectShares>(result, new JsonSerializerSettings
                    {
                        ObjectCreationHandling = ObjectCreationHandling.Replace //set to Replace so that collection values aren't duplicated.
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unable to deserialize object" + ex.Message);
                }
                List <FolderShare> fs = new List <FolderShare>();

                foreach (FolderShare x in folderS.shares)
                {
                    x.folderId = id;
                    fs.Add(x);
                }


                mapFolderShare.Add(id, fs);

                /*foreach (FolderShare office in folderS.shares)
                 * {
                 *  Console.WriteLine(office);
                 * }*/
            }

            return(mapFolderShare);
        }