C# examples

API calls examples

Receive all the available releases

Receive current release data

```csharp
//Receive current active release data for a game
        //gameId:       Game id in IDCGames admin panel, provided by IDCGames
        //gameSecret:   Game keyword in IDCGames admin panel, provided by IDCGames
        private void getActiveRelease(string gameId, string gameSecret)
        {
            WebClient wc = new WebClient();
            wc.Headers.Add("GameID", gameId);
            wc.Headers.Add("GameSecret", gameSecret);
            try
            {
                string releasesJsonString = wc.DownloadString("https://admin.idcgames.com/api/release/active");
                parseReleasesJson(releasesJsonString);
            }
            catch (WebException wex)
            {
                string response = "";
                string statusCode = wex.Status.ToString();
                if (wex.Response != null)
                {
                    using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
                    {
                        response = r.ReadToEnd();
                    }

                }
                if (response != "")
                {
                    MessageBox.Show("Error downloading active release from IDC Games panel" + Environment.NewLine + response);
                }
                else
                {
                    MessageBox.Show("Error downloading active release from IDC Games panel" + Environment.NewLine + wex.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error downloading active release from IDC Games panel");
            }
        }
```

Create a copy of a release

Modify an existing release

```csharp
//Modify an existing release
        //gameId:           Game id in IDCGames admin panel, provided by IDCGames
        //gameSecret:       Game keyword in IDCGames admin panel, provided by IDCGames
        //releaseID:        Release id (received in createRelease, getActiveRelease or listExistingReleases)
        //releaseName:      Release Name or version
        private void modifyRelease(string gameId, string gameSecret, int releaseId, string releaseName)
        {
            WebClient wc = new WebClient();
            wc.Headers.Add("GameID", gameId);
            wc.Headers.Add("GameSecret", gameSecret);
            //Required in order to post parameters
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            releaseName = System.Web.HttpUtility.UrlPathEncode(releaseName);
            string parameters = $"rel_name={releaseName}";
            try
            {
                string modifyReleaseApiUrl = $"https://admin.idcgames.com/api/release/update/{releaseId}";
                string releasesJsonString = wc.UploadString(modifyReleaseApiUrl, parameters);
                parseCreateOrModifyReleaseJson(releasesJsonString);
            }
            catch (WebException wex)
            {
                string response = "";
                string statusCode = wex.Status.ToString();
                if (wex.Response != null)
                {
                    using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
                    {
                        response = r.ReadToEnd();
                    }

                }
                if (response != "")
                {
                    MessageBox.Show("Error creating game release in IDC Games panel" + Environment.NewLine + response);
                }
                else
                {
                    MessageBox.Show("Error creating game releases¡ in IDC Games panel" + Environment.NewLine + wex.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error creating game releases¡ in IDC Games panel" + Environment.NewLine + ex.ToString());
            }
        }
```

Upload release files into an fp account

==

Publish a relesease

```csharp
//Pusblish a release and start synchronizing files
        //gameId:           Game id in IDCGames admin panel, provided by IDCGames
        //gameSecret:       Game keyword in IDCGames admin panel, provided by IDCGames
        //releaseID:        Release id (received in createRelease, getActiveRelease or listExistingReleases)
        void publishRelease(string gameId, string gameSecret, int releaseID)
        {
            WebClient wc = new WebClient();
            wc.Headers.Add("GameID", gameId);
            wc.Headers.Add("GameSecret", gameSecret);
            //Required in order to post parameters
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string ipParam = "";
            try
            {
                string publishReleaseApiUrl = $"https://admin.idcgames.com/api/release/publish/{releaseID}";
                string publishReleaseJsonString = wc.UploadString(publishReleaseApiUrl, ipParam);
                parsePublishReleaseJson(publishReleaseJsonString);
            }
            catch (WebException wex)
            {
                string response = "";
                string statusCode = wex.Status.ToString();
                if (wex.Response != null)
                {
                    using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
                    {
                        response = r.ReadToEnd();
                    }

                }
                if (response != "")
                {
                    MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + response);
                }
                else
                {
                    MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + wex.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + ex.ToString());
            }

        }
        
```

Check synchronization status for a published release

=

Activate a release

```csharp
//Activate a release
        //gameId:           Game id in IDCGames admin panel, provided by IDCGames
        //gameSecret:       Game keyword in IDCGames admin panel, provided by IDCGames
        //releaseID:        Release id (received in createRelease, getActiveRelease or listExistingReleases)
        void activateRelease(string gameId, string gameSecret, int releaseID)
        {
            WebClient wc = new WebClient();
            wc.Headers.Add("GameID", gameId);
            wc.Headers.Add("GameSecret", gameSecret);
            //Required in order to post parameters
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string ipParam = "";
            try
            {
                string activateReleaseApiUrl = $"https://admin.idcgames.com/api/release/activate/{releaseID}";
                string activateReleaseJsonString = wc.UploadString(activateReleaseApiUrl, ipParam);
                parseReleaseActivationJson(activateReleaseJsonString);
            }
            catch (WebException wex)
            {
                string response = "";
                string statusCode = wex.Status.ToString();
                if (wex.Response != null)
                {
                    using (StreamReader r = new StreamReader(wex.Response.GetResponseStream()))
                    {
                        response = r.ReadToEnd();
                    }

                }
                if (response != "")
                {
                    MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + response);
                }
                else
                {
                    MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + wex.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error publishing release in idc panel" + Environment.NewLine + ex.ToString());
            }

        }
```

Deactivate a release

=

Classes used in parsing code

```csharp
public class CommonResponseClass {
        public string success { get; set; }
        public string message { get; set; }
    }
```
==

```csharp
public class ReleasesClass {
        public List<ReleaseClass> data { get; set; }
    }
```

```csharp
public class FtpAccountClass
    {
        public int id { get; set; }
        public int user { get; set; }
        public int rel { get; set; }
        public string rel_dir { get; set; }
        public int hours { get; set; }
        public string ip { get; set; }
        public string requested_at { get; set; }
        public string accepted_at { get; set; }
        public bool notified { get; set; }
        public string ftp_username { get; set; }
        public string ftp_password { get; set; }
        public string expire_at { get; set; }
        public int status { get; set; }
        public string rel_dlc { get; set; }
        public string created_at { get; set; }
        public string updated_at { get; set; }
```
=

```csharp
public class CheckSynchronizationResponseClass{
        public int status { get; set; }
        public List<SyncrhonizationProgressClass> progress { get; set; }
    }
```

```csharp
public class ReleaseActivationResponseClass
    {
        public string success { get; set; }
    }
```

Parse JSON Examples (Using newtonsoft)

```csharp
private void parseCreateOrModifyReleaseJson(string releasesJsonString)
        {
            CreateOrModifyReleaseClass release;
            try
            {
                release = JsonConvert.DeserializeObject<CreateOrModifyReleaseClass>(releasesJsonString);
                showCreatedOrModifiedRelease(release);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Invalid create release json data received from IDC Games panel:{Environment.NewLine}{releasesJsonString}");
            }
        }
```

```csharp
private void parseCreateFtpAccountJson(string createFtpAccountJson)
        {
            CommonResponseClass createFtpAccountsResponse;
            try
            {
                createFtpAccountsResponse = JsonConvert.DeserializeObject<CommonResponseClass>(createFtpAccountJson);
                if (createFtpAccountsResponse.success != "false")
                {
                    MessageBox.Show("FTP account created");
                }
                else
                {
                    MessageBox.Show("Error creating FTP Account: " + createFtpAccountsResponse.message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Invalid create ftp account json data received from IDC Games panel:{Environment.NewLine}{createFtpAccountJson}");
            }
        }
```
==

```csharp
private void parseCheckSynchronizationJson(string checkSynchronizationJson)
        {
            CheckSynchronizationResponseClass checkSynchronizationResponse;
            try
            {
                checkSynchronizationResponse = JsonConvert.DeserializeObject<CheckSynchronizationResponseClass>(checkSynchronizationJson);
                if (checkSynchronizationResponse.status == 1)
                {
                    synchronizationFinished();
                }
                else
                {
                    showSynchronizationStatus(checkSynchronizationResponse);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Invalid check synchronization json data received from IDC Games panel:{Environment.NewLine}{checkSynchronizationJson}");
            }
        }
```

```csharp
 private void parseReleaseActivationJson(string releaseActivationJson)
        {
            ReleaseActivationResponseClass releaseActivationResponse;
            try
            {
                releaseActivationResponse = JsonConvert.DeserializeObject<ReleaseActivationResponseClass>(releaseActivationJson);
                if (releaseActivationResponse.success != "false")
                {
                    //activation/deactivation success true, add your code here
                    showReleaseActivationResponse(releaseActivationResponse);
                }
                else
                {
                    MessageBox.Show("Error activating release.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Invalid release activation json data received from IDC Games panel:{Environment.NewLine}{releaseActivationJson}");
            }
        }
```