AlexS
AlexS
Reputation Top 10%
AlexS shtuka+trado
1 Snippet  (635th place)
Published
1 Channel
Created
1 Channel
Following
Apr 21, 2017
Last Visit
Apr 21, 2017
Registered
29 points  (989th place)
Reputation
Junior Code Generator
Junior Popular Coder
Junior Autobiographer
Senior Autobiographer

Recent Snippets See all snippets by AlexS

public by AlexS created Apr 21, 2017  540  7  4  0

esp

public OperationResult UploadRelease(Release release, byte[] resourceBytes, string cookieid)
{
    ESPUploadSites uploadsite = ESPUploadSites.USWest;
    ESPBatch batch = lastbatch;
    OperationError error = null;
    OperationResult opresult = null;
    int partno = 1;
    string csrftoken = "";
    string fname = GetESPReleaseFileName(release.Name);
    string time = Tools.GetJavaScriptTime(DateTime.Now).ToString();
    string date = "";
    string auth = "";
    string uploadid = "";
    string data = "";
    string rid = "";
    TimeSpan zero1 = TimeSpan.Zero;
    List<string> etags = new List<string>();
    HTTPRequest r = GetMainPageRequest(cookieid);
    opresult = AuthenticatedRequest(r, Authorize, CheckAuthNotLost, null);
    if (!opresult.Success)
        return opresult;
    if (!ParseMainPage(r, ref csrftoken, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadInitRequest(batch.ID, time, fname, uploadsite, cookieid);
    HTTPRequestResult result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!ParseReleaseUploadInitResponse(r, ref date, ref auth, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadStartOptionsRequest(batch.ID, time, fname, uploadsite, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!CheckReleaseUploadStartOptionsResponse(r, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadStartRequest(batch.ID, time, fname, uploadsite, date, auth, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!ParseReleaseUploadStartRequest(r, ref uploadid, ref error))
        return new OperationResult(error);

    long length = resourceBytes.Length;
    string chunkhash = Tools.GetSHA256(resourceBytes);
    TimeSpan zero2 = TimeSpan.Zero;
    r = GetReleaseUploadChunkInitRequest(batch.ID, time, fname, chunkhash, partno, uploadid, uploadsite, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!ParseReleaseUploadChunkInitResponse(r, ref date, ref auth, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadChunkOptionsRequest(batch.ID, time, fname, uploadid, partno, uploadsite, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!CheckReleaseUploadChunkOptionsResponse(r, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadChunkRequest(batch.ID, time, fname, uploadid, partno, uploadsite, resourceBytes, chunkhash, date, auth, cookieid);
    //Is long
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!CheckReleaseUploadChunkResponse(r, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadChunksListInitRequest(batch.ID, time, fname, uploadid, uploadsite, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!ParseReleaseUploadChunksListInitResponse(r, ref date, ref auth, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadChunksListOptionsRequest(batch.ID, time, fname, uploadid, uploadsite, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!CheckUploadChunkOptionsResponse(r, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadChunksListRequest(batch.ID, time, fname, uploadid, uploadsite, date, auth, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!ParseReleaseUploadChunksListResponse(r, etags, ref error))
        return new OperationResult(error);
    data = GetUploadCompleteData(etags.ToArray());
    chunkhash = Tools.GetSHA256(Encoding.ASCII.GetBytes(data));
    r = GetReleaseUploadCompleteInitRequest(batch.ID, time, fname, uploadid, uploadsite, chunkhash, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!ParseReleaseUploadCompleteInitResponse(r, ref date, ref auth, ref error))
        return new OperationResult(error);
    r = GetReleaseUploadCompleteRequest(batch.ID, time, fname, uploadid, uploadsite, date, auth, data, chunkhash, cookieid);
    result = HTTP.ExecSync(r);
    if (result != HTTPRequestResult.Success)
        return new OperationResult(result, r, StockId);
    if (!CheckReleaseUploadCompleteResponse(r, batch.ID, time, fname, ref error))
        return new OperationResult(error);
    r = GetReleaseCreateRequest(batch, release, time, fname, csrftoken, cookieid);
    result = HTTP.ExecSync(r);
    return result == HTTPRequestResult.Success ? (ParseReleaseCreateResponse(r, release, ref rid, ref error) ? new OperationResult(false) : new OperationResult(error)) : new OperationResult(result, r, StockId);
}

;