//Receive all the releases available in the panel for a game//gameId: Game id in IDCGames admin panel, provided by IDCGames//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGamesprivate void listExistingReleases(stringgameId, stringgameSecret)
{
WebClient wc = newWebClient();
wc.Headers.Add("GameID", gameId);
wc.Headers.Add("GameSecret", gameSecret);
try
{
string releasesJsonString = wc.DownloadString("https://admin.idcgames.com/api/release");
parseReleasesJson(releasesJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = newStreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error downloading game releases from IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error downloading game releases from IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error downloading game releases from IDC Games panel");
}
}
//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 IDCGamesprivate void getActiveRelease(stringgameId, stringgameSecret)
{
WebClient wc = newWebClient();
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 = newStreamReader(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 new release (a copy of the last release)//gameId: Game id in IDCGames admin panel, provided by IDCGames//gameSecret: Game keyword in IDCGames admin panel, provided by IDCGames//releaseName: Release Name or versionprivate void createRelease(stringgameId, stringgameSecret, stringreleaseName)
{
WebClient wc = newWebClient();
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 releasesJsonString = wc.UploadString("https://admin.idcgames.com/api/release", parameters);
parseCreateOrModifyReleaseJson(releasesJsonString);
}
catch (WebException wex) {
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = newStreamReader(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());
}
}
//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 versionprivate void modifyRelease(stringgameId, stringgameSecret, intreleaseId, stringreleaseName)
{
WebClient wc = newWebClient();
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 = newStreamReader(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());
}
}
//Create a ftp account to upload release files. Once the accounts are created, ftp data can be received calling getReleaseFtpAccounts//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)//ftpType: 0 for release// 1 for DLC//ftpFolderType: redist for redistribuible files// common for files with the same format in x86 and x6 systems// uncommon for files for x86 systems, wich should be included in x86 folder and files for x64 systems, wich should be included in x64 folder//sourcePublicIp: public source ip for uploading files with ftp. Leave blank if api is called from the same ip as ftp upload//hours: ftp account lifetime in hours
void createReleaseFtpAccount(stringgameId, stringgameSecret, intreleaseID, intftpType, stringftpFolderType, stringsourcePublicIp, inthours)
{
WebClient wc = newWebClient();
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 = "";
if (sourcePublicIp != "")
{
ipParam = $"&ip={sourcePublicIp}";
}
string parameters = $"rel_dlc={ftpType}&rel_dir={ftpFolderType}&hours={hours}{ipParam}";
try
{
string ftpApiUrl = $"https://admin.idcgames.com/api/release/ftp/{releaseID}";
string createFtpAccountJsonString = wc.UploadString(ftpApiUrl, parameters);
parseCreateFtpAccountJson(createFtpAccountJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = newStreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error creating ftp account in IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error creating ftp account in IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error creating ftp account in IDC Games panel" + Environment.NewLine + ex.ToString());
}
}
//Get available ftp accounts for 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 getReleaseFtpAccounts(stringgameId, stringgameSecret, intreleaseID)
{
WebClient wc = newWebClient();
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 ftpApiUrl = $"https://admin.idcgames.com/api/release/ftp/{releaseID}";
string ftpAccountsJsonString = wc.DownloadString(ftpApiUrl);
parseGetReleaseFTPAccountsJson(ftpAccountsJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = newStreamReader(wex.Response.GetResponseStream()))
{
response = r.ReadToEnd();
}
}
if (response != "")
{
MessageBox.Show("Error downloading release ftp accounts from IDC Games panel" + Environment.NewLine + response);
}
else
{
MessageBox.Show("Error downloading release ftp accounts from IDC Games panel" + Environment.NewLine + wex.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error downloading release ftp accounts from IDC Games panel" + Environment.NewLine + ex.ToString());
}
}
//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(stringgameId, stringgameSecret, intreleaseID)
{
WebClient wc = newWebClient();
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 = newStreamReader(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//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 checkSynchronization(stringgameId, stringgameSecret, intreleaseID)
{
WebClient wc = newWebClient();
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 checSynchronizationApiUrl = $"https://admin.idcgames.com/api/release/check_sync/{releaseID}";
string checSynchronizationJsonString = wc.DownloadString(checSynchronizationApiUrl);
parseCheckSynchronizationJson(checSynchronizationJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = newStreamReader(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());
}
}
//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(stringgameId, stringgameSecret, intreleaseID)
{
WebClient wc = newWebClient();
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 = newStreamReader(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//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 deactivateRelease(stringgameId, stringgameSecret)
{
WebClient wc = newWebClient();
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 deactivateReleaseApiUrl = "https://admin.idcgames.com/api/release/remove_active/";
string deactivateReleaseJsonString = wc.UploadString(deactivateReleaseApiUrl, ipParam);
parseReleaseActivationJson(deactivateReleaseJsonString);
}
catch (WebException wex)
{
string response = "";
string statusCode = wex.Status.ToString();
if (wex.Response != null)
{
using (StreamReader r = newStreamReader(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());
}
}
privatevoidparseReleasesJson(string releasesJsonString)
{
ReleasesClass releases;
try
{
releases = JsonConvert.DeserializeObject<ReleasesClass>(releasesJsonString);
showReleases(releases);
}
catch (Exception ex)
{
MessageBox.Show($"Invalid releases json data received from IDC Games panel:{Environment.NewLine}{releasesJsonString}");
}
}
privatevoidparseCreateOrModifyReleaseJson(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}");
}
}
privatevoidparseGetReleaseFTPAccountsJson(string ftpAccountsJsonString)
{
List<FtpAccountClass> ftpAccountsList;
try
{
ftpAccountsList = JsonConvert.DeserializeObject<List<FtpAccountClass>>(ftpAccountsJsonString);
showFtpAccounts(ftpAccountsList);
}
catch (Exception ex)
{
MessageBox.Show($"Invalid get release ftp accounts json data received from IDC Games panel:{Environment.NewLine}{ftpAccountsJsonString}");
private void parseCreateFtpAccountJson(stringcreateFtpAccountJson)
{
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}");
}
}
private void parsePublishReleaseJson(stringpublishReleaseJson)
{
PublishReleaseResponseClass publishReleaseResponse;
try
{
publishReleaseResponse = JsonConvert.DeserializeObject<PublishReleaseResponseClass>(publishReleaseJson);
if (publishReleaseResponse.success != "false")
{
//Synchronization status true, add your code here
synchronizationStarted(publishReleaseResponse);
}
else
{
//Convert errors list to comma separated string to show the message with the errors
IList<string> errors = publishReleaseResponse.errors;
MessageBox.Show("Error publishing Release: " + string.Join(",", errors));
}
}
catch (Exception ex)
{
MessageBox.Show($"Invalid publish release json data received from IDC Games panel:{Environment.NewLine}{publishReleaseJson}");
}
}
private void parseCheckSynchronizationJson(stringcheckSynchronizationJson)
{
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}");
}
}
private void parseReleaseActivationJson(stringreleaseActivationJson)
{
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}");
}
}