Beispiel #1
0
        void BindRTB(HttpResponseMessage response, int fileorfolder)
        {
            if (!response.IsSuccessStatusCode)
            {
                Message = "The GitHub Module Name/Path provided is invalid. Error :" + response.ReasonPhrase + ".";
                Console.WriteLine("The GitHub Module Name/Path provided is invalid. Error :" + response.ReasonPhrase + ".");
            }
            else
            {
                var     dataObjects = response.Content.ReadAsStringAsync();
                dynamic srcData     = Json.Decode(dataObjects.Result);

                if (fileorfolder == 0)
                {
                    foreach (var item in srcData)
                    {
                        string itemext = string.Empty;
                        int    index   = item.name.IndexOf(".");
                        if (index == -1)
                        {
                        }
                        else
                        {
                            itemext = item.name.Substring(index);
                        }
                        if (!ExtList.Contains(itemext) || string.IsNullOrEmpty(itemext))
                        {
                            //do nothing
                        }
                        else
                        {
                            foreach (var item1 in ExcludeFiles)
                            {
                                if (item.name == item1)
                                {
                                    flag    = true;
                                    Message = "Successful Message : File:" + item.name + " : has been successfully excluded.";
                                    Console.WriteLine("Successful Message : File:" + item.name + " : has been successfully excluded.");
                                    break;
                                }
                                else
                                {
                                    flag = false;
                                }
                            }

                            if (!flag)
                            {
                                try
                                {
                                    string Filepath = ModulePath + "\\" + item.name;
                                    using (var client = new System.Net.Http.HttpClient())
                                    {
                                        var credentials = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:", sToken);
                                        credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
                                        client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
                                        var contents = client.GetByteArrayAsync(item.download_url).Result;
                                        System.IO.File.WriteAllBytes(Filepath, contents);
                                    }

                                    Message = "Successful Message : File:" + item.name + " : has been successfully downloaded.";
                                    Console.WriteLine("Successful Message : File:" + item.name + " : has been successfully downloaded.");
                                }
                                catch (System.Exception e)
                                {
                                    Message = "Error while getting the File:" + item.name + "(" + e.Message + ")";
                                    Console.WriteLine(Message);
                                    FileErr = true;
                                }
                            }
                            flag = false;
                        }
                    }
                }
                else
                {
                    //Do nothing;
                }
            }
        }