//Public Class IValidation // <JsonIgnore> Property isValid As Boolean // MustOverride Function Validation(Optional nomeProp As String = "") As ValidationResult //End Class public static bool CtrlValue(Object value, string nomeVar = "value", bool ctrlNothing = true, bool ctrlVoid = true, bool throwEx = true) { if (ctrlNothing == true && value == null) { Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto " + nomeVar + " a nothing")); if (throwEx == true) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType._Nothing, ""))); } return(false); } if (value != null && ctrlVoid == true) { if (value.GetType() == typeof(string)) { if ((string)value == "") { Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto " + nomeVar + " vuoto")); if (throwEx == true) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType._Nothing, ""))); } return(false); } } else { } } return(true); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { //if (value.GetType().BaseType != typeof(BackupBaseM)) //{ Log.main.Add(new Mess(Tipi.ERR, Log.main.errUserText, "E' stato ricevuto un tipo che non eredita da BackupBaseM, val.GetType.BaseType:<" + value.GetType().BaseType.ToString() + ">")); } if (parameter == null) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto parameter a null"))); } if (parameter.GetType().FullName != "System.RuntimeType") { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto parameter di tipo:<" + parameter.GetType().ToString() + ">, deve essere di tipo Type"))); } return(Activator.CreateInstance((Type)parameter, value)); } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Eccezione ex.mess:<" + ex.Message + ">"))); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { var vmBackupTypes = from tmp in Assembly.GetExecutingAssembly().GetTypes() where tmp.IsClass && tmp.BaseType == typeof(BackupBaseVM) select tmp; //List<string> backupsTypeName = (from tmpTypes in vmBackupTypes select tmpTypes.).ToList(); SortedList <int, string> backupsTypeName = new SortedList <int, string>(); foreach (Type type in vmBackupTypes) { PropertyInfo propInfoName = type.GetProperty("BackupTypeName"); PropertyInfo propInfoOrder = type.GetProperty("BackupTypeOrder"); backupsTypeName.Add((int)propInfoOrder.GetValue(null), (string)propInfoName.GetValue(null)); } return(backupsTypeName.Values.ToList()); } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Exception ex.mess:<" + ex.Message + ">"))); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter == null) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto parameter a null"))); } if (parameter.GetType() != typeof(string)) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto parameter di tipo:<" + parameter.GetType().ToString() + ">, deve essere una stringa"))); } try { if (value == null) { return((string)parameter == "null" ? true : false); } if (value.GetType() == typeof(Type).GetType()) //The type of value parameter is Type, in this case compare the property Name { return((value as Type).Name == (string)parameter ? true : false); } return((value.GetType().Name == (string)parameter) ? true : false); } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Eccezione ex.mess:<" + ex.Message + ">"))); } }
public Orario(string strOrario) { Mess logMess = new Mess(LogType._Nothing, Log.main.errUserText); if (ChkSintassiStringa(strOrario, aggiornaProprietà: true, logMess: logMess) == false) { logMess.tipo = LogType.ERR; throw new Exception(Excep.ScriviLogInEx(logMess)); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { return(value != parameter); } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Eccezione ex.mess:<" + ex.Message + ">"))); } }
private void ImpostaStringaDaProprietà() { try { strOrario = Ora + ":" + Minuti + ":" + Secondi + "." + Millesimi; //uso la var strOrarioVM_ e non la prop. poichè non deve andare a risettare le property } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, ex.Message))); } }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Count() < 3) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, "", "values array ha meno di 3 elementi, values.Count:<" + values.Count() + ">"))); } if (values[0].GetType() != typeof(DataOre.WeekDay[])) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, "", "l'elemento 0 dell'array values non è un array di DataOre.WeekDay, values[0].GetType:<" + values[0].GetType().ToString() + ">"))); } if (values[1].GetType() != typeof(SchedulerVM)) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, "", "l'elemento 1 dell'array values non è un SchedulerVM, values[1].GetType:<" + values[1].GetType().ToString() + ">"))); } if (values[2].GetType() != typeof(DataGrid) && !values[2].GetType().IsSubclassOf(typeof(DataGrid))) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, "", "l'elemento 2 dell'array values non è un DataGrid, values[2].GetType:<" + values[2].GetType().ToString() + ">"))); } List <DataOre.WeekDay> availableWeekDays = new List <DataOre.WeekDay>(); availableWeekDays.AddRange((DataOre.WeekDay[])values[0]); SchedulerVM schedulerVm = (SchedulerVM)values[1]; DataGrid dataGrid = (DataGrid)values[2]; foreach (WeekDayObj dayInScheduler in schedulerVm.SchedulerM.WeekDays) { //ogni giorno già presente nello scheduler lo tolgo dalla lista solo se non è il giorno già valorizzato nella combobox if (availableWeekDays.Contains(dayInScheduler.SelectedDay) && (dataGrid.SelectedItem == null || dayInScheduler != (WeekDayObj)dataGrid.SelectedItem)) { availableWeekDays.Remove(dayInScheduler.SelectedDay); } } if ((from tmp in schedulerVm.SchedulerM.WeekDays where tmp.SelectedDay == ((WeekDayObj)dataGrid.SelectedItem).SelectedDay && tmp != (WeekDayObj)dataGrid.SelectedItem select tmp).Count() > 0) { //Nel caso in cui il valore di default dell'enum è già stato preso, cioè presente già nello scheduler e oggetto diverso da quello della cella attuale... if (availableWeekDays.Count > 0) //...allora imposto il primo disponibile { ((WeekDayObj)dataGrid.SelectedItem).SelectedDay = availableWeekDays[0]; } else //...altrimenti cancello l'attuale elemento poichè non si sono più giorni disponibili { WeekDays days = (WeekDays)dataGrid.ItemsSource; days.Remove((WeekDayObj)dataGrid.SelectedItem); } } return(availableWeekDays.ToArray()); }
public HourlyPeriods(params string[] coppieOnOff) { if (coppieOnOff.Length % 2 > 0) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "L'array coppieOnOff contiene un numero di orari non pari, coppieOnOff.Length:<" + coppieOnOff.Length + ">"))); } for (int i = 0; i < coppieOnOff.Length - 1; i += 2) { this.Items.Add(new PeriodoOrario(new Orario(coppieOnOff[i]), new Orario(coppieOnOff[i + 1]))); } }
public MonthsAndDays(params byte[] coppieGiornoMese) { if (coppieGiornoMese.Length % 2 > 0) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "L'array coppieGiornoMese contiene un numero di giorni mesi non pari, coppieGiornoMese.Length:<" + coppieGiornoMese.Length + ">"))); } for (int i = 0; i < coppieGiornoMese.Length; i += 2) { this.Items.Add(new MonthAndDay(coppieGiornoMese[i], coppieGiornoMese[i + 1])); } }
} //Costruttore per datagrid public OnOffSeries(params UInt16[] onOffTuple) { if (onOffTuple.Length % 2 > 0) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "L'array onOffTuple contiene un numero di on off non pari, onOffTuple.Length:<" + onOffTuple.Length + ">"))); } for (int i = 0; i < onOffTuple.Length; i += 2) { this.Items.Add(new OnOff(onOffTuple[i], onOffTuple[i + 1])); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType != typeof(Visibility)) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "The target must be a Visibility"))); } if (value == null) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Rcevuto param value a nothing"))); } if (value.GetType() == typeof(Boolean)) { if ((Boolean)value == true) { return(Visibility.Visible); } if ((Boolean)value == false) { return(Visibility.Hidden); } } if (value.IsNumeric() == false) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Rcevuto param value non booleano ne numerico"))); } switch (value) { case 0: return(Visibility.Hidden); case 1: return(Visibility.Visible); case 2: return(Visibility.Collapsed); default: throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto valore numerico disatteso per param value:<" + value.ToString() + ">"))); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter == null) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto parameter a null"))); } if (parameter.GetType().FullName != "System.RuntimeType") { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto parameter di tipo:<" + parameter.GetType().ToString() + ">, deve essere di tipo Type"))); } try { if (value == null) { if (parameter == null) { return(true); } else { return(false); } } if (parameter == null) { if (value == null) { return(true); } else { return(false); } } return(((Type)value).FullName == ((Type)parameter).FullName ? true : false); } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Eccezione ex.mess:<" + ex.Message + ">"))); } }
public override object ProvideValue(IServiceProvider serviceProvider) { if (this._enumType == null) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "The EnumType must be specified."))); } Type actualEnumType = Nullable.GetUnderlyingType(this._enumType) ?? this._enumType; Array enumValues = Enum.GetValues(actualEnumType); if (actualEnumType == this._enumType) { return(enumValues); } Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1); enumValues.CopyTo(tempArray, 1); return(tempArray); }
private string StrXQry(Object valore) { //strXQry ha la funzione di trasormare il valore in modo da essere compatibile in una query o noQuery if (valore == null) { if (this.ValPred == null) { return("NULL"); } else { return("DEFAULT"); //Indica a sql di impostare il valore predefinito } } string str; if (Tipo.GetType() == typeof(ColumnTypes.Bit)) { str = Convert.ToByte(valore).ToString(); //Usare Convert.ToByte e non cByte (poichè cByte converte True in 255 invece che 1), Non può andare in eccezione poichè sono sicuro che è un boolean } else if (Tipo.GetType() == typeof(ColumnTypes.NVarChar)) { str = valore.ToString().Replace("'", "''"); } else if (Tipo.GetType() == typeof(ColumnTypes.TinyInt) || Tipo.GetType() == typeof(ColumnTypes.SmallInt) || Tipo.GetType() == typeof(ColumnTypes.Int) || Tipo.GetType() == typeof(ColumnTypes.BigInt) || Tipo.GetType() == typeof(ColumnTypes.Decimal)) { str = valore.ToString(); } else if (Tipo.GetType() == typeof(ColumnTypes.DateTime)) { str = ((DateTime)valore).ToString("yyyy/MM/dd HH:mm:ss.FFF"); } else if (Tipo.GetType() == typeof(ColumnTypes.Date)) { str = ((DateTime)valore).ToString("yyyy/MM/dd"); } else { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "tipo valore sconosciuto, tipo.GetType:<" + Tipo.GetType().Name + ">"))); } return(Tipo.valQryTraApici == true ? "'" + str + "'" : str); }
public SortBindList(List <Sorting> ordinamenti = null, bool oggConValidazione = true) : base(oggConValidazione: oggConValidazione) { if (typeof(ISortBindObj).IsAssignableFrom(typeof(T)) == false) { //Verifico se il tipo degli oggetti ha l'interfaccia ISortBindObj throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "T di tipo:<" + typeof(T).Name + "> non implementa l'interfaccia ISortBindObj"))); } if (ordinamenti == null) { ordinamenti = new List <Sorting> { new Sorting("IndiceOrd", ListSortDirection.Ascending) } } ; GeneraListaOrdinamenti(ordinamenti); T oggTmp = (T)Activator.CreateInstance(typeof(T)); Serialize.SerializeInText(oggTmp, ref defaultValueOfNewT); }
/// <param name="timeoutSec">Se omesso o 0 si prende il valore defaultTimeoutSec dell'oggetto di tipo ConfigDownload, non può essere infinito</param> public UploadItem(string urlFolder, object oggettoUpload, byte priority = 128, string nomeFile = "", string suffFileCorrotto = "", string idSubsetOperaz = "", UploadType tipoUpload = UploadType.Ftp, string utente = "", string password = "", int timeoutSec = 0, LogType tipoLogTimeout = LogType.Warn, LogType tipoLogEccezione = LogType.ERR, Progressione progressione = null) : base(urlFolder, priority, idSubsetOperaz, timeoutSec, progressione, tipoLogTimeout, tipoLogEccezione) { if (oggettoUpload.GetType() == typeof(byte)) { Data = (byte[])oggettoUpload; } else if (oggettoUpload.GetType() == typeof(String)) { if (File.Exists((string)oggettoUpload) == false) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto oggettoUpload di tipo con tipo String ma il file non esiste, oggettoUpload:<" + oggettoUpload + ">"))); } Data = File.ReadAllBytes((string)oggettoUpload); } else { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto oggettoUpload di tipo disatteso, oggettoUpload.GetType:<" + oggettoUpload.GetType().ToString() + ">"))); } if (nomeFile != "") { this.FileName = nomeFile; } else { if (oggettoUpload.GetType() == typeof(string)) { this.FileName = Path.GetFileName((string)oggettoUpload); } else { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto nomeFile vuoto e oggettoUpload non è una stringa, impossibile ricavare nome file, oggettoUpload.GetType:<" + oggettoUpload.GetType().ToString() + ">"))); } } this.CorruptFileNameSuffix = suffFileCorrotto; this.User = utente; this.Password = password; this.UploadType = tipoUpload; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType != typeof(bool)) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Il target deve essere boolean"))); } if (value == null) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Rcevuto param value a nothing"))); } try { return(!System.Convert.ToBoolean(value)); } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Eccezione ex.mess:<" + ex.Message + ">"))); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType != typeof(Visibility)) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Il target deve essere Visibility"))); } if (value == null) { return(Visibility.Collapsed); } else { if (parameter == null || parameter.GetType() != typeof(Visibility)) { return(Visibility.Visible); } else { return(parameter); } } }
public void SetResult(TextBlock txbAction) { switch (txbAction.Name) { case "txbYes": MsgBxResult = MsgBxButton.Yes; break; case "txbNo": MsgBxResult = MsgBxButton.No; break; case "txbOk": MsgBxResult = MsgBxButton.Ok; break; case "txbCancel": MsgBxResult = MsgBxButton.Cancel; break; default: throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Ricevuto txbAction.Name disatteso:<" + txbAction.Name + ">"))); } }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { string valore, stringaFormattata; bool letteraPrecMaiu; stringaFormattata = ""; ParamEnumToStringa attributo = new ParamEnumToStringa(); //La new serve così ce l'ho inizializzato if (value.GetType().IsEnum == false) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "value non è di tipo IEnumerable"))); } if (destinationType != typeof(string) && destinationType != typeof(object)) { throw new InvalidOperationException(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "The target must be a boolean"))); } object[] tmpAttr = value.GetType().GetCustomAttributes(typeof(ParamEnumToStringa), false); if (tmpAttr.Count() > 0) { attributo = (ParamEnumToStringa)tmpAttr[0]; } if (LeggiDescrizioneVoceEnum(value, destinationType, ref stringaFormattata) == true) { return(stringaFormattata); //Se c'è una descrizione dell'enum ritorno quello altrimenti ritorno la scritta dell'enum formattata } valore = value.ToString(); //Bisogna fare il ToString altrimenti l'enum restituisce il numero e non la scritta //****1° lettera if (attributo.Lett1Maiu == false) { stringaFormattata = Convert.ToString(System.Char.ToLower(valore[0])); letteraPrecMaiu = false; } else { stringaFormattata = Convert.ToString(System.Char.ToUpper(valore[0])); letteraPrecMaiu = true; } //****Dalla 2° lettera in poi, verifico anche gli acronimi come WPF che devono rimanere maiuscoli for (int i = 1; i < valore.Length; i++) { if (System.Char.IsUpper(valore[i])) { if (i + 1 <= valore.Length - 1) //Se dopo c'è ancora un carattere(lo verifico poichè se la scritta è "CiaoWPFVaiAllaGrande" deve diventare "Ciao WPF vai alla grande") { if (System.Char.IsUpper(valore[i + 1]) || valore[i + 1].IsNumeric()) { stringaFormattata += letteraPrecMaiu == true?Convert.ToString(valore[i]) : " " + valore[i]; } else { stringaFormattata += " " + Char.ToLower(valore[i]); } } else //Dopo non c'è alcuna lettera { stringaFormattata += letteraPrecMaiu == true?Convert.ToString(valore[i]) : " " + Char.ToLower(valore[i]); } letteraPrecMaiu = true; } else { stringaFormattata += valore[i]; letteraPrecMaiu = false; } } return(stringaFormattata); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(Excep.ScriviLogInEx(new Mess(LogType.ERR, "", Main.Binds.Converters.errCnvBackNotImpl))); }
protected void Ordina(object oggT = null, bool updateListeners = true) { if (Thr.UIDispatcher.CheckAccess() == false) { //ATTENZIONE: deve stare fuori da Try poichè altrimenti all'esecuzione dell'Exit Sub eseguirebbe OnListChanged che è proprio quello che da problemi se eseguito con... Thr.UIDispatcher.Invoke(() => Ordina(oggT, updateListeners)); //... un thread diverso da quello della ui poichè scatena il riaggiornamento dei datagrid collegati alla SortBindList e da eccezione di crossThread. return; } try { if (listaOrdinamenti == null) { return; } if (oggT != null) { return; //&& oggT.saltaRiordino == true } IOrderedEnumerable <T> orderedList = null; bool isPrimoOrdin = true; foreach (ListSortDescription ordinamento in listaOrdinamenti) { PropertyDescriptor prop = ordinamento.PropertyDescriptor; Type interfaceType = prop.PropertyType.GetInterface("IComparable"); if (interfaceType == null) { //Check if this is a Nullable(Of IComparable) if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { //Check if the type parameter implements IComparable Type tType = prop.PropertyType.GetGenericArguments()[0]; interfaceType = tType.GetInterface("IComparable"); } } if (interfaceType == null) { //If the property type does not implement IComparable, let the user know. throw new NotSupportedException(String.Format("Cannot sort by {0}. {1} does not implement IComparable.", prop.Name, prop.PropertyType.ToString())); } if (isPrimoOrdin) { orderedList = ordinamento.SortDirection == ListSortDirection.Ascending ? Items.OrderBy((x) => prop.GetValue(x)) : Items.OrderByDescending((x) => prop.GetValue(x)); isPrimoOrdin = false; } else { orderedList = ordinamento.SortDirection == ListSortDirection.Ascending ? orderedList.ThenBy((x) => prop.GetValue(x)) : orderedList.ThenByDescending((x) => prop.GetValue(x)); } } if (orderedList == null) { return; } //Sorting succeeded var result = orderedList.ToList(); //Copy the sorted items back into the list. Items.Clear(); foreach (T tItem in result) { Items.Add(tItem); } } catch (Exception ex) { throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "Eccezione ex.mess:<" + ex.Message + ">"))); } finally { OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); //Va comunque fatto il reset e non il ListChangedType.ItemAdded o altri poichè dopo il riordino, l'ultimo elemento non è detto... // ...che sia il nuovo e quindi i listiner visualizzarebbero una riga in più duplicando l'ultimo elemento } }