Beispiel #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CleanRequest request;

            try
            {
                request = new CleanRequest
                {
                    NamespaceName   = NamespaceName,
                    ScheduledTaskId = ScheduledTaskId,
                    TimeStart       = TimeStart,
                    TimeEnd         = TimeEnd,
                    OpcRequestId    = OpcRequestId,
                    OpcRetryToken   = OpcRetryToken
                };

                response = client.Clean(request).GetAwaiter().GetResult();
                WriteOutput(response);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        public async Task <IList <IDadataEntity> > Clean(IEnumerable <StructureType> structure, IEnumerable <string> data)
        {
            var request  = new CleanRequest(structure, data);
            var response = await Execute <CleanResponse>(method : "clean", entity : null, request : request);

            return(response.data[0]);
        }
Beispiel #3
0
        /// <summary>
        /// Выполняет запрос к сервису стандантизации DaData.ru с получением данных типа <typeparamref name="T"/>.
        /// </summary>
        /// <param name="inputs">Массив данных для обработки в сервисе.</param>
        /// <typeparam name="T">Целевой тип данных, который должен стандартизироваться сервисом (IDadataEntity — AddressData, PhoneData и т.д.).</typeparam>
        public Response <IList <T> > Clean <T>(IEnumerable <string> inputs) where T : IDadataEntity
        {
            // infer structure from target entity type
            var structure = new List <StructureType>(
                new StructureType[] { TYPE_TO_STRUCTURE[typeof(T)] }
                );
            // transform enity list to CleanRequest data structure
            var data = new List <List <string> >();

            foreach (string input in inputs)
            {
                data.Add(new List <string>(new string[] { input }));
            }
            var request = new CleanRequest(structure, data);
            // get response and transform it to list of entities
            var response = CleanRequest(request);

            if (!response.IsSuccess)
            {
                return(new Response <IList <T> >(response));
            }
            var outputs = new List <T>();

            foreach (IList <IDadataEntity> row in response.Data.data)
            {
                outputs.Add((T)row[0]);
            }
            return(new Response <IList <T> >(response)
            {
                Data = outputs
            });
        }
        private void ShowNotifications(CleanRequest request)
        {
            string version = Assembly.GetEntryAssembly().GetName().Version.ToString(3);

            this._notificationHelper.WriteMessage($"{TITLE} {version} - {DESCRIPTION}");

            if (request.ZipProject)
            {
                this._notificationHelper.WriteVerboseMessage("Will copy to a temporary directory, clean and zip the project");
            }

            if (request.RemoveSourceControl)
            {
                this._notificationHelper.WriteVerboseMessage("Will remove source control bindings from projects");
            }

            if (!request.QuietMode)
            {
                this._notificationHelper.WriteMessage("Will clean the following directories");
                foreach (var directory in request.Directories)
                {
                    this._notificationHelper.WriteColorMessage(ConsoleColor.Yellow, directory);
                }
            }
        }
        public bool Run(CleanRequest request)
        {
            ShowNotifications(request);

            try
            {
                IEnumerable <SolutionInfo> directories = this._solutionCleaner.GetDirectories(request.Directories, request.ZipProject);
                this._solutionCleaner.CleanDirectories(directories, request.AdditionalOptions, request.RemoveSourceControl,
                                                       request.ShowAllMessages);

                if (request.ZipProject)
                {
                    this._zipHelper.ZipDirectories(directories, request.ZipDirectory);
                }
            }
            catch (ApplicationException exception)
            {
                this._notificationHelper.WriteColorMessage(ConsoleColor.Red, exception.Message);
                return(false);
            }

            this._notificationHelper.WriteColorMessage(ConsoleColor.Green, "Cleaning complete.");

            return(true);
        }
Beispiel #6
0
        private async void Clean_Button_Click(object sender, RoutedEventArgs e)
        {
            string directory       = this.Directory.Text;
            bool   zipProject      = this.ZipProject.IsChecked ?? false;
            bool   sourceControl   = this.SourceControl.IsChecked ?? false;
            bool   showAllMessages = this.ShowAllMessages.IsChecked ?? false;

            var request = new CleanRequest(new[] { directory }, zipProject, sourceControl, showAllMessages, null, null, false);

            bool result = await Task.Run(() =>
            {
                this._notificatior.Clear();
                bool isSuccess = this._service.Run(request);
                return(isSuccess);
            });

            if (result)
            {
                Form.MessageBox.Show("Cleaning complete", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                string message = "Cleaning failed!";
                this._notificatior.WriteColorMessage(ConsoleColor.Red, message);

                Form.MessageBox.Show(message, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error,
                                     MessageBoxDefaultButton.Button1, (Form.MessageBoxOptions) 0x40000);
            }
        }
        public IList <IDadataEntity> Clean(IEnumerable <StructureType> structure, IEnumerable <string> data)
        {
            var request     = new CleanRequest(structure, data);
            var httpRequest = CreateHttpRequest(verb: "POST", url: baseUrl);

            httpRequest = Serialize(httpRequest, request);
            var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            var response     = Deserialize <CleanResponse>(httpResponse);

            return(response.data[0]);
        }
Beispiel #8
0
        public async Task <IList <IDadataEntity> > Clean(IEnumerable <StructureType> structure, IEnumerable <string> data)
        {
            var request     = new CleanRequest(structure, data);
            var httpRequest = CreateHttpRequest();

            httpRequest = Serialize(httpRequest, request);
            var httpResponse = (HttpWebResponse)await httpRequest.GetResponseAsync();

            var response = await Deserialize <CleanResponse>(httpResponse);

            return(response.data[0]);
        }
Beispiel #9
0
        /// <summary>
        /// Выполняет запрос к сервису стандантизации DaData.ru.
        /// </summary>
        private CleanResponseInternal CleanRequest(CleanRequest request)
        {
            var client = new System.Net.Http.HttpClient();

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("Authorization", "Token " + _token);
            if (_secret != null)
            {
                client.DefaultRequestHeaders.Add("X-Secret", _secret);
            }

            var serialized   = JsonConvert.SerializeObject(request, new StringEnumConverter());
            var responseTask = client.PostAsync(_urlClean, new System.Net.Http.StringContent(serialized));

            responseTask.Wait();
            var answerTask = responseTask.Result.Content.ReadAsStringAsync();

            answerTask.Wait();
            if (responseTask.Result.IsSuccessStatusCode)
            {
                var answerObject = JsonConvert.DeserializeObject <CleanResponseInternalData>(answerTask.Result, _converter);
                return(new CleanResponseInternal()
                {
                    IsSuccess = true,
                    Detail = null,
                    Code = (int)responseTask.Result.StatusCode,
                    Data = answerObject
                });
            }
            else
            {
                var answerObject = JsonConvert.DeserializeObject <CleanResponseInternalError>(answerTask.Result, _converter);
                return(new CleanResponseInternal()
                {
                    IsSuccess = false,
                    Detail = answerObject.detail,
                    Code = (int)responseTask.Result.StatusCode,
                    Data = null
                });
            }
        }