private void ModelColumnNameChanged(object sender, NameChangedEventArgs e) { foreach (var nextField in ResultFields.Where(x => (((x.ColumnName ?? string.Empty).Equals(e.NewName ?? string.Empty, StringComparison.InvariantCultureIgnoreCase)) || ((x.ColumnName ?? string.Empty).Equals(e.OldName ?? string.Empty, StringComparison.InvariantCultureIgnoreCase))) && !x.IsDefault)) { ValidateColumnName(nextField); } }
private void ModelNameChanged(object sender, NameChangedEventArgs e) { foreach (var nextField in ResultFields.Where(f => (((f.Name ?? string.Empty) == (e.NewName ?? string.Empty)) || ((f.Name ?? string.Empty) == (e.OldName ?? string.Empty))) && !f.IsDefault)) { ValidateName(nextField); } }
private void ExecuteSave() { string validationMessage; if (!ValidateFields(out validationMessage)) { MessageBox.Show(validationMessage, "Save result set", MessageBoxButton.OK, MessageBoxImage.Error); return; } var models = ResultFields.Where(f => (!f.IsDefault) && (!string.IsNullOrWhiteSpace(f.ColumnName))).ToList(); var newResultType = new ResultType(); models.ForEach(m => newResultType.Fields.Add(m.Save())); newResultType.CustomType = selectedCustomType; this.executeSQLDesigner.Context.TransactionManager.StartTransaction("Change result type"); try { this.executeSQLDesigner.ResultTypeValue = newResultType; this.executeSQLDesigner.Context.TransactionManager.StopTransaction(); } catch { this.executeSQLDesigner.Context.TransactionManager.RollbackTransaction(); throw; } if (PostSave != null) { PostSave(); } }
public MultiTableUpdateScript GetLinkedDataScript(NameWithSchema basetable) { var res = new MultiTableUpdateScript(); if (ResultFields == null || !ResultFields.IsMultiTable()) { return(res); } var pks = new Dictionary <DmlfSource, List <DmlfColumnRef> >(); foreach (var row in Rows) { if (row.RowState != CdlRowState.Modified) { continue; } var changed = row.GetChangedColumnRefs(); if (changed.Length == 0) { continue; } var tbls = new List <DmlfSource>(); foreach (var ch in changed) { if (!tbls.Contains(ch.Source)) { tbls.Add(ch.Source); } } foreach (var src in tbls) { if (pks.ContainsKey(src)) { continue; } pks[src] = ResultFields.GetPrimaryKey(src); } foreach (var src in tbls) { var cols = new List <DmlfColumnRef>(); foreach (var ch in changed) { if (ch.Source != src) { continue; } cols.Add(ch); } var pk = pks[src]; res.Update(src == DmlfSource.BaseTable ? basetable : src.TableOrView, (from c in pk select c.ColumnName).ToArray(), row.Original.GetValuesByCols(pk.ToArray(), ResultFields), (from c in cols select c.ColumnName).ToArray(), row.GetValuesByCols(cols.ToArray())); } } return(res); }
private void AddDefaultChild() { var defaultModel = new ResultFieldModel(this); defaultModel.ColumnNameChanged += DefaultModelChanged; defaultModel.NameChanged += DefaultModelChanged; ResultFields.Add(defaultModel); }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { var allErrors = new ErrorResultTO(); InitializeDebug(dataObject); if (Result == null) { Result = string.Empty; } var toresultfields = Result.Split(','); var fromFields = InFields.Split(','); var fromResultFieldresultfields = ResultFields.Split(','); try { PreExecution(dataObject, fromFields, update); if (String.IsNullOrEmpty(InFields)) { throw new Exception(string.Format(ErrorResource.Invalid, "In fields")); } if (String.IsNullOrEmpty(ResultFields)) { throw new Exception(string.Format(ErrorResource.Invalid, "from fields")); } if (toresultfields.Any(ExecutionEnvironment.IsScalar)) { throw new Exception(string.Format(ErrorResource.ScalarsNotAllowed, "'Result'")); } dataObject.Environment.AssignUnique(fromFields, fromResultFieldresultfields, toresultfields, update); } catch (Exception e) { Dev2Logger.Error("DSFUnique", e, GlobalConstants.WarewolfError); allErrors.AddError(e.Message); } finally { PostExecute(dataObject, toresultfields, allErrors.HasErrors(), update); // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfUniqueActivity", allErrors); foreach (var error in allErrors.FetchErrors()) { dataObject.Environment.AddError(error); } } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (InFields != null ? InFields.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ResultFields != null ? ResultFields.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// Get associates fields to a given Ob /// </summary> /// <param name="logJobName"></param> /// <param name="jobID"></param> /// <returns></returns> public static ResultFields GetFieldsByJobID(string logJobName, int jobID) { ResultFields resultFields = new ResultFields(); resultFields.ReturnCode = 0; resultFields.Message = ""; resultFields.RecordsCount = 0; try { lock (lockObj) { LogManager.Configuration.Variables["JobName"] = logJobName; string urlParameters = ""; string URL = ""; string returnMessage = ""; HttpResponseMessage response = new HttpResponseMessage(); HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMinutes(15); URL = VFRDuplicateRemoverService.BaseURL + "Fields/GetFieldsByJobID?jobID=" + jobID; urlParameters = ""; client.BaseAddress = new Uri(URL); response = client.GetAsync(urlParameters).Result; using (HttpContent content = response.Content) { Task <string> resultTemp = content.ReadAsStringAsync(); returnMessage = resultTemp.Result; resultFields = JsonConvert.DeserializeObject <ResultFields>(returnMessage); } if (!response.IsSuccessStatusCode) { nlogger.Error("Error:" + "\r\n" + response.ReasonPhrase + "\r\n" + response.RequestMessage); Console.WriteLine("Error:" + "\r\n" + response.ReasonPhrase + "\r\n" + response.RequestMessage); } } } catch (Exception ex) { lock (lockObj) { LogManager.Configuration.Variables["JobName"] = logJobName; nlogger.Fatal(General.ErrorMessage(ex)); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(General.ErrorMessage(ex)); Console.ForegroundColor = ConsoleColor.White; resultFields.ReturnCode = -2; resultFields.Message = ex.Message; } } return(resultFields); }
private DmlfColumnRef[] GetBaseWhereCols() { if (ResultFields != null) { return(ResultFields.GetPrimaryKey(DmlfSource.BaseTable).ToArray()); } else { var pk = Structure.PrimaryKey; return(DmlfColumnRef.BuildFromArray(pk != null ? pk.Columns.GetNames() : Structure.Columns.GetNames(), null)); } }
public FieldForm() { string URL = ""; string urlParameters = ""; string returnMessage = ""; HttpResponseMessage response = new HttpResponseMessage(); InitializeComponent(); newFieldsList.Clear(); CustomerNameTextBox.Text = Data.GlovalVariables.currentCustomerName; ProjectNameTextBox.Text = Data.GlovalVariables.currentProjectName; JobNameTextBox.Text = Data.GlovalVariables.currentJobName; if (Data.GlovalVariables.transactionType == "Update") { CPFieldNameTextBox.Text = Data.GlovalVariables.currentFieldName; originalField.CPFieldName = Data.GlovalVariables.currentFieldName; HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMinutes(15); // Get Field Information URL = BaseURL + "Fields/GetFieldByID"; urlParameters = "?fieldID=" + Data.GlovalVariables.currentFieldID; client.BaseAddress = new Uri(URL); response = client.GetAsync(urlParameters).Result; if (response.IsSuccessStatusCode) { using (HttpContent content = response.Content) { Task <string> resultTemp = content.ReadAsStringAsync(); returnMessage = resultTemp.Result; ResultFields resultFields = JsonConvert.DeserializeObject <ResultFields>(returnMessage); if (resultFields.ReturnCode == 0) { VFRFieldNameTextBox.Text = resultFields.ReturnValue[0].VFRFieldName; originalField.VFRFieldName = resultFields.ReturnValue[0].VFRFieldName; ExcludeKeystrokeCheckBox.Checked = resultFields.ReturnValue[0].ExcludeFromKeystrokesCount; originalField.ExcludeFromKeystrokesCount = resultFields.ReturnValue[0].ExcludeFromKeystrokesCount; } } } else { MessageBox.Show("Error:" + "\r\n" + response.ReasonPhrase + "\r\n" + response.RequestMessage, "Transaction Error...", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.ControlBox = false; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; }
private void CreateFromSQL() { try { var connectionType = executeSQLDesigner.ResolvedConnectionType; string connectionString = executeSQLDesigner.ResolvedConnectionString; DataTable schemaTable = DatabaseHelpers.RetrieveSchema(connectionType, connectionString, SqlStringHandler.GetSqlStringHandler(this.executeSQLDesigner.ResolvedSqlStatementValue ?? string.Empty).GetExecutableDesignTimeSql()); var newResults = new List <ResultFieldModel>(); foreach (DataColumn dataColumn in schemaTable.Columns) { var oldModel = ResultFields.FirstOrDefault(x => x.ColumnName == dataColumn.ColumnName); if (oldModel != null) { newResults.Add(oldModel); continue; } ResultFieldModel newModel = new ResultFieldModel(this); newModel.IsDefault = false; newModel.ColumnName = dataColumn.ColumnName; newModel.Name = DatabaseHelpers.GetValidName(dataColumn.ColumnName); newModel.SetTypeReferenceValues(dataColumn.DataType); newModel.NameChanged += ModelNameChanged; newModel.ColumnNameChanged += ModelColumnNameChanged; newResults.Add(newModel); } ResultFields.Where(x => !newResults.Contains(x)).ToList().ForEach(x => { x.NameChanged -= ModelNameChanged; x.ColumnNameChanged -= ModelColumnNameChanged; }); ResultFields.Clear(); newResults.ForEach(x => ResultFields.Add(x)); AddDefaultChild(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public ResultTypeViewModel(ExecuteSQLDesigner executeSQLDesigner) { this.executeSQLDesigner = executeSQLDesigner; CreateDataFromSql = new DelegateCommand(CreateFromSQL, CanCreateFromSQL); Save = new DelegateCommand(ExecuteSave); selectedCustomType = executeSQLDesigner.ResultTypeValue.CustomType; foreach (var resultType in executeSQLDesigner.ResultTypeValue.Fields) { var model = new ResultFieldModel(this, resultType); model.ColumnNameChanged += ModelColumnNameChanged; model.NameChanged += ModelNameChanged; ResultFields.Add(model); } AddDefaultChild(); }
private bool ValidateFields(out string message) { foreach (ResultFieldModel nextField in ResultFields.Where(f => (!f.IsDefault) && (!string.IsNullOrWhiteSpace(f.ColumnName)))) { if (nextField.SelectedType == null) { message = "Please select a type for each field."; return(false); } if ((!string.IsNullOrWhiteSpace(nextField.Name)) && (ResultFields.Any(f => (f != nextField) && (f.Name == nextField.Name)))) { message = string.Format("Duplicate output name: {0}.", nextField.Name); return(false); } if (IsMappingCustomType) { if (!nextField.NameIsValid) { message = string.Format("Invalid field name: {0}.", nextField.Name); return(false); } } else { if (string.IsNullOrWhiteSpace(nextField.Name)) { message = "Please enter an output name for each column."; return(false); } if (!nextField.NameIsValid) { message = string.Format("Invalid output name {0}.", nextField.Name); return(false); } } } message = null; return(true); }
public SingleTableDataScript GetBaseModifyScript() { SingleTableDataScript res = new SingleTableDataScript(); DmlfColumnRef[] wherecols = GetBaseWhereCols(); foreach (var row in Rows) { if (row.RowState == CdlRowState.Unchanged) { continue; } // modified rows in multitable views are solved in GetLinkedDataScript() if (row.RowState == CdlRowState.Modified && ResultFields != null && ResultFields.IsMultiTable()) { continue; } string[] changed = row.GetChangedColumns(false); string[] changedNotNull = row.GetChangedColumns(true); if (changed.Length == 0 && row.RowState != CdlRowState.Deleted) { continue; } switch (row.RowState) { case CdlRowState.Added: res.Insert(changedNotNull, row.GetValuesByCols(changedNotNull)); break; case CdlRowState.Modified: res.Update(wherecols.GetNames(), row.Original.GetValuesByCols(wherecols, ResultFields), changed, row[changed]); break; case CdlRowState.Deleted: res.Delete(wherecols.GetNames(), row.Original.GetValuesByCols(wherecols, ResultFields)); break; } } return(res); }
public IEnumerable <string> GetResultList(ResultFields field) { string f = ""; switch (field) { case ResultFields.Team: f = "team"; break; case ResultFields.Driver: f = "driver"; break; case ResultFields.Race: f = "race"; break; default: break; } HttpWebRequest apiRequest = WebRequest.Create($"https://localhost:44329/api/result/{f}") as HttpWebRequest; try { using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string apiResponse = reader.ReadToEnd(); return(Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(apiResponse)); } } } catch (WebException ex) { Console.WriteLine(ex.Message); throw; } }
private void ValidateName(ResultFieldModel field) { var sameNameFields = ResultFields.Where(f => (f.Name ?? string.Empty) == (field.Name ?? string.Empty) && !f.IsDefault); field.NameIsValid = string.IsNullOrWhiteSpace(field.Name) || (sameNameFields.Count() == 1 && Names.IsNameValid(field.Name) && (!IsMappingCustomType || CustomTypeProperties.Contains(field.Name))); }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); var allErrors = new ErrorResultTO(); InitializeDebug(dataObject); var toresultfields = Result.Split(','); var fromFields = InFields.Split(','); var fromResultFieldresultfields = ResultFields.Split(','); try { PreExecution(dataObject, fromFields); if (String.IsNullOrEmpty(InFields)) { throw new Exception("Invalid In fields"); } if (String.IsNullOrEmpty(ResultFields)) { throw new Exception("Invalid from fields"); } if (toresultfields.Any(a => !ExecutionEnvironment.IsValidRecordSetIndex(a))) { throw new Exception("invalid result"); } if (fromFields.Any(a => !ExecutionEnvironment.IsValidRecordSetIndex(a))) { throw new Exception("invalid from"); } if (fromResultFieldresultfields.Any(a => !ExecutionEnvironment.IsValidRecordSetIndex(a))) { throw new Exception("invalid selected fields"); } dataObject.Environment.AssignUnique(fromFields, fromResultFieldresultfields, toresultfields); } catch (Exception e) { Dev2Logger.Log.Error("DSFUnique", e); allErrors.AddError(e.Message); } finally { PostExecute(dataObject, toresultfields, allErrors.HasErrors()); // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfUniqueActivity", allErrors); foreach (var error in allErrors.FetchErrors()) { dataObject.Environment.AddError(error); } } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, StateType.After); } } }
private void ValidateColumnName(ResultFieldModel field) { var sameNameFields = ResultFields.Where(x => (x.ColumnName ?? string.Empty).Equals(field.ColumnName ?? string.Empty, StringComparison.InvariantCultureIgnoreCase) && !x.IsDefault); field.ColumnNameIsValid = string.IsNullOrWhiteSpace(field.ColumnName) || sameNameFields.Count() == 1; }
internal void MoveTo(ResultFieldModel toMove, int destinationIndex) { ResultFields.Move(ResultFields.IndexOf(toMove), destinationIndex); }
private void Save(string action) { Boolean continueTransaction = true; HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMinutes(15); string URL = ""; string bodyString = ""; string fieldJS = ""; string returnMessage = ""; Field field = new Field(); ResultFields resultFields = new ResultFields(); // Build the Field Object field.JobID = Data.GlovalVariables.currentJobID; field.FieldID = Data.GlovalVariables.currentFieldID; field.CPFieldName = CPFieldNameTextBox.Text; field.VFRFieldName = VFRFieldNameTextBox.Text; field.ExcludeFromKeystrokesCount = ExcludeKeystrokeCheckBox.Checked; Data.GlovalVariables.currentFieldName = ""; Data.GlovalVariables.currentVFRFieldName = VFRFieldNameTextBox.Text; switch (Data.GlovalVariables.transactionType) { case "New": // Validation rules if (CPFieldNameTextBox.Text.Length == 0) { MessageBox.Show("Warning:" + "\r\n" + "You must provide values for the Capture Pro Field Name.", "Update Field Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Warning); continueTransaction = false; } if (continueTransaction) { fieldJS = JsonConvert.SerializeObject(field, Newtonsoft.Json.Formatting.Indented); URL = BaseURL + "Fields/NewField"; bodyString = "'" + fieldJS + "'"; HttpContent body_for_new = new StringContent(bodyString); body_for_new.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response_for_new = client.PostAsync(URL, body_for_new).Result; using (HttpContent content = response_for_new.Content) { Task <string> resultTemp = content.ReadAsStringAsync(); returnMessage = resultTemp.Result; resultFields = JsonConvert.DeserializeObject <ResultFields>(returnMessage); } if (response_for_new.IsSuccessStatusCode) { // Set the value of the new Field to a gloval variable if (resultFields.ReturnCode == -1) { MessageBox.Show("Warning:" + "\r\n" + resultFields.Message.Replace(". ", "\r\n"), "New Field Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Data.GlovalVariables.newFieldsList.Add(CPFieldNameTextBox.Text); if (action == "SaveAndExit") { this.Close(); } else { CPFieldNameTextBox.Text = ""; VFRFieldNameTextBox.Text = ""; ExcludeKeystrokeCheckBox.Checked = false; } } } else { MessageBox.Show("Error:" + "\r\n" + resultFields.Message.Replace(". ", "\r\n") + resultFields.Exception, "New Field Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Error); } } break; case "Update": fieldJS = JsonConvert.SerializeObject(field, Newtonsoft.Json.Formatting.Indented); //jobJS = Regex.Escape(jobJS); URL = BaseURL + "Fields/UpdateField"; bodyString = "'" + fieldJS + "'"; HttpContent body_for_update = new StringContent(bodyString); body_for_update.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response_for_update = client.PostAsync(URL, body_for_update).Result; using (HttpContent content = response_for_update.Content) { Task <string> resultTemp = content.ReadAsStringAsync(); returnMessage = resultTemp.Result; resultFields = JsonConvert.DeserializeObject <ResultFields>(returnMessage); } if (response_for_update.IsSuccessStatusCode) { // Set the value of the new Field to a gloval variable if (resultFields.ReturnCode == -1) { MessageBox.Show("Warning:" + "\r\n" + resultFields.Message.Replace(". ", "\r\n"), "Update Field Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Data.GlovalVariables.currentFieldName = CPFieldNameTextBox.Text; if (action == "SaveAndExit") { this.Close(); } else { CPFieldNameTextBox.Focus(); } } } else { MessageBox.Show("Error:" + "\r\n" + resultFields.Message.Replace(". ", "\r\n"), "Update Field Transaction ...", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; } }