Beispiel #1
0
        protected string InvokeWebRequest(JurisdictionListDataItem item)
        {
            WebHeaderCollection headers = new WebHeaderCollection();

            headers.Add("Api-Key", ApiKey);

            var request = WebRequest.CreateHttp($"{Settings.Default.JurisdictionsListURL}/{item.Id}");

            request.CachePolicy = RestApi.CachePolicy;
            request.Headers     = headers;
            Stopwatch stopWatch     = Stopwatch.StartNew();
            var       responseAsync = request.GetResponseAsync();

            while (!responseAsync.IsCompleted)
            {
                WriteProgress(ProgressRecordFactory.Progress($"Waiting for response from {RequestUri}...", $"Time Elapsed: {stopWatch.Elapsed.Seconds}"));
            }
            HttpWebResponse response = (HttpWebResponse)responseAsync.Result;

            if (response.IsFromCache)
            {
                WriteWarning("Respose was received from the cash!");
            }

            using (Stream stream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(stream))
                {
                    return(reader.ReadToEnd());
                }
        }
Beispiel #2
0
 protected override void ProcessRecord()
 {
     using (SqlConnection connection = new SqlConnection(Jurisdictions_DB_Connection))
     {
         connection.Open();
         var count = Jurisdiction.Length;
         for (var i = 0; i < count; i++)
         {
             WriteProgress(ProgressRecordFactory.Progress(
                               1, "Importing jurisdiction", $"Importing {i} of {count} jurisditions", $"Importing {Jurisdiction[i].Data.Title}"));
             ImportJurisdiction(Jurisdiction[i]);
         }
     }
 }
        protected override void ProcessRecord()
        {
            WebHeaderCollection headers = new WebHeaderCollection();

            headers.Add("Api-Key", ApiKey);

            HttpWebRequest request = HttpWebRequest.CreateHttp(RequestUri);

            request.CachePolicy = RestApi.CachePolicy;
            request.Headers     = headers;

            Stopwatch stopWatch     = Stopwatch.StartNew();
            var       responseAsync = GetWebResponseAsync(request);

            while (!responseAsync.IsCompleted)
            {
                WriteProgress(ProgressRecordFactory.Progress($"Waiting for response from {RequestUri}...", $"Time Elapsed: {stopWatch.Elapsed.Seconds}"));
            }

            HttpWebResponse response = (HttpWebResponse)responseAsync.Result;

            if (response.IsFromCache)
            {
                WriteWarning("Respose was received from the cash!");
            }

            using (Stream stream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(stream))
                {
                    string text = reader.ReadToEnd();

                    JObject obj = JObject.Parse(text);


                    if (ReturnJObject)
                    {
                        WriteObject(obj);
                    }
                    else
                    {
                        JurisdictionList list = JsonModelSerializer.DeserializeList(obj.ToString());

                        PagingUtilities.Page(this, list.Data.ToArray());
                    }
                }
        }
            public void Report(IDownloadProgress value)
            {
                IUpdate5 currentUpdate = (IUpdate5)_updateDownloader.Updates[value.CurrentUpdateIndex];

                _cmdlet.WriteProgress(
                    ProgressRecordFactory.Progress(
                        0,
                        "Downloading Update Collection",
                        $"Download Phase {value.CurrentUpdateDownloadPhase}",
                        value.CurrentUpdateIndex / _updateDownloader.Updates.Count));

                _cmdlet.WriteProgress(
                    ProgressRecordFactory.Progress(
                        1,
                        "Dowloading update",
                        $"Downlading {value.CurrentUpdateBytesDownloaded} of {value.CurrentUpdateBytesToDownload}",
                        $"Downlading {value.CurrentUpdateIndex} of {_updateDownloader.Updates.Count}",
                        value.CurrentUpdatePercentComplete));
            }
Beispiel #5
0
        protected override void ProcessRecord()
        {
            UpdateSearcherHelper.SearchSession searchSession = this.BeginSearch(Force, "IsInstalled=0");

            while (searchSession.Searching)
            {
                WriteProgress(ProgressRecordFactory.Progress("Searching for applicable packages"));
            }

            if (searchSession.SearchResult.Updates.Count == 0)
            {
                WriteWarning("There are no applicable updates.");
                return;
            }

            UpdateDownloaderHelper.DownloadSession downloadSession = this.BeginDownload(searchSession.SearchResult);

            while (downloadSession.Downloading)
            {
            }

            WriteObject(downloadSession.Dictionary, true);
        }
Beispiel #6
0
        private void ImportJurisdiction(Jurisdiction jurisdiction)
        {
            Guid tbl_juris_key = Guid.NewGuid();


            WriteProgress(
                ProgressRecordFactory.Progress(2, "Inserting into table tbl_jurisdictions"));

            using (SqlConnection connection = new SqlConnection(Jurisdictions_DB_Connection))
                using (SqlCommand command = new SqlCommand("sp_insert_tbl_jurisdictions", connection))
                {
                    connection.Open();

                    command.CommandType = CommandType.StoredProcedure;
                    SqlParameter retVal = command.Parameters.Add("RetVal", SqlDbType.Int);
                    retVal.Direction = ParameterDirection.ReturnValue;

                    command.Parameters.Add(new SqlParameter("@jurisdictions_key", tbl_juris_key));
                    command.Parameters.Add(new SqlParameter("@jurisdictions_id", Guid.Parse(jurisdiction.Data.Id)));
                    command.Parameters.Add(new SqlParameter("@jurisdictions_title", jurisdiction.Data.Title));
                    command.Parameters.Add(new SqlParameter("@jurisdictions_type", jurisdiction.Data.Type));

                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                    }
                    ;
                    reader.Close();
                }

            WriteProgress(
                ProgressRecordFactory.Progress(3, "Inserting into table tbl_standard_sets"));

            foreach (var standardSet in jurisdiction.Data.StandardSets)
            {
                using (SqlConnection connection = new SqlConnection(Jurisdictions_DB_Connection))
                    using (SqlCommand command = new SqlCommand("sp_insert_tbl_standard_sets", connection))
                    {
                        connection.Open();

                        Guid tbl_ss_key = Guid.NewGuid();

                        command.CommandType = CommandType.StoredProcedure;
                        SqlParameter retVal = command.Parameters.Add("RetVal", SqlDbType.Int);
                        retVal.Direction = ParameterDirection.ReturnValue;

                        command.Parameters.Add(new SqlParameter("@standard_sets_key", tbl_ss_key));
                        command.Parameters.Add(new SqlParameter("@jurisdictions_key", tbl_juris_key));
                        command.Parameters.Add(new SqlParameter("@standard_sets_id", standardSet.Id));
                        command.Parameters.Add(new SqlParameter("@standard_sets_subject", standardSet.Subject));
                        command.Parameters.Add(new SqlParameter("@standard_sets_title", standardSet.Title));
                        command.Parameters.Add(new SqlParameter("@standard_sets_educationLevels", standardSet.GetEducationLevels()));

                        command.Parameters.Add(new SqlParameter("@standard_sets_document_id", standardSet.Document.Id));
                        command.Parameters.Add(new SqlParameter("@standard_sets_document_asnIdentifier", standardSet.Document.AsnIdentifier));
                        command.Parameters.Add(new SqlParameter("@standard_sets_document_publicationStatus", standardSet.Document.PublicationStatus));
                        command.Parameters.Add(new SqlParameter("@standard_sets_document_title", standardSet.Document.Title));
                        command.Parameters.Add(new SqlParameter("@standard_sets_document_valid", standardSet.Document.Valid));
                        command.Parameters.Add(new SqlParameter("@standard_sets_document_sourceURL", standardSet.Document.Id));
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                        }
                        ;
                        reader.Close();
                    }
            }
        }