how can i figure out when the object is in busy mode and busy Saving?
we use telerick control and a converter to figure out when the CSLA object isbusy and in a spesific state:
converter:
public class CheckIsLoadingIsSavingFromCanSaveConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null)
{
ITrackStatus targetObject = value as ITrackStatus;
if (targetObject != null)
{
if (targetObject.IsSelfDirty && targetObject.IsSavable && targetObject.IsSelfValid)
return "Loading"; //return "Saving"; saving not working because above flags are always true,
//it is always loading, what else can I use to check whether a object is
//busy Saving?
else
return "Loading";
}
else
return "Loading";
}
else
return "";
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
}
*Xaml:
<telerik:RadBusyIndicator
x:Name="TelerikRadBusyIndicatorMain"
Background="Transparent"
BorderThickness="0"
BusyContent="{Binding Path=Data, Converter={StaticResource CheckIsLoadingIsSavingFromCanSaveConverter}}" Foreground="White"
VerticalContentAlignment="Top"
HorizontalContentAlignment="Center" Margin="0,0,0,0">
<telerik:RadBusyIndicator.OverlayStyle>
<Style TargetType="Rectangle">
<Setter Property="Fill" Value="Transparent" />
</Style>
</telerik:RadBusyIndicator.OverlayStyle>
<Grid x:Name="LayoutRoot" Background="{x:Null}">
.....
</Grid>
</telerik:RadBusyIndicator>
all is working fine, but need to figure out when it is IsBusy and Saving
Hi,
Look at Csla.Xaml.ViewModelBase
This class implements CanSave and other properties as properties with INotifyPropertyChanged events to enable Binding with the UI.
I cannot use ViewModelBase<>, because
- objects use CSLAAdapters and not viewmodels
- if all my objects was using viewmodels, then in the converter will still not know what viewmodel it is working with, that is why I used ITrackStatus
- I can do this:
if (value.GetType() == typeof(Business.ActivityCategoryActivityEC))
{
Business.ActivityCategoryActivityEC tempObject = (Business.ActivityCategoryActivityEC)value;
if (tempObject.IsSelfDirty && tempObject.IsSavable && tempObject.IsSelfValid)
return "Saving";
else
return "Loading";
}
but then I have to add and check all my class objects, that is bad
any suggestions?
I am not sure Jonny was saying to USE ViewModelBase - but you should look at it to understand how it works.
The metastate properties on CSLA objects aren't bindable. You need an intermediate object to make them bindable. ViewModelBase and CslaDataProvider and PropertyStatus and PropertyInfo all implement this type of intermediate behavior. You will have to do something similar or use one of these existing controls.
this also did not work:
public class CheckIsLoadingIsSavingFromCanSaveConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null)
{
try
{
Type thisType = value.GetType();
if (thisType != null)
{
bool IsDirty = false;
bool IsSavable = false;
bool IsValid = false;
bool IsBusy = false;
//System.Reflection.MethodInfo theMethod = thisType.GetMethod("IsDirty");
//if (theMethod != null)
//{
// IsDirty = (bool)theMethod.Invoke(value, null);
//}
//System.Reflection.FieldInfo field = thisType.GetField("IsDirty", System.Reflection.BindingFlags.Public |
// System.Reflection.BindingFlags.Static);
//if (field != null)
//{
// IsDirty = (bool)field.GetValue(null);
//}
System.Reflection.PropertyInfo theProperty = thisType.GetProperty("IsDirty");
if (theProperty != null)
{
//IsDirty = (bool)theProperty.GetValue(value, new Object[] { 0 });
IsDirty = (bool)theProperty.GetValue(value, null);
}
theProperty = thisType.GetProperty("IsSavable");
if (theProperty != null)
{
IsSavable = (bool)theProperty.GetValue(value, null);
}
theProperty = thisType.GetProperty("IsValid");
if (theProperty != null)
{
IsValid = (bool)theProperty.GetValue(value, null);
}
theProperty = thisType.GetProperty("IsBusy");
if (theProperty != null)
{
IsBusy = (bool)theProperty.GetValue(value, null);
}
if (IsDirty && IsSavable && IsValid && IsBusy)
return "Saving";
else
return "Loading";
}
else return "";
}
catch (Exception eeee) { return ""; }
}
else
return "";
//ITrackStatus targetObject = value as ITrackStatus;
// if (targetObject != null)
// {
// if (targetObject.IsSelfDirty && targetObject.IsSavable && targetObject.IsSelfValid)
// return "Loading"; //return "Saving"; but not working because above flags are always true, what else can I use to check whether a object is busy Saving
// else
// return "Loading";
// }
// else
// return "Loading";
//}
//else
// return "";
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
}
so I understand the CSLA object is not close enough with the xaml change events. I looked at the INotifyPropertyChanged:
CanSave = CanEditObject && targetObject.IsSavable && !isObjectBusy;
CanCancel = CanEditObject && targetObject.IsDirty && !isObjectBusy;
CanCreate = CanCreateObject && !targetObject.IsDirty && !isObjectBusy;
CanDelete = CanDeleteObject && !isObjectBusy;
CanFetch = CanGetObject && !targetObject.IsDirty && !isObjectBusy;
protected virtual void BeginSave()
{
try
{
var savable = Model as Csla.Core.ISavable;
if (ManageObjectLifetime)
{
// clone the object if possible
ICloneable clonable = Model as ICloneable;
if (clonable != null)
savable = (Csla.Core.ISavable)clonable.Clone();
//apply changes
var undoable = savable as Csla.Core.ISupportUndo;
if (undoable != null)
undoable.ApplyEdit();
}
savable.Saved += (o, e) =>
{
IsBusy = false;
if (e.Error == null)
{
var result = e.NewObject;
var model = (T)result;
OnSaving(model);
Model = model;
}
else
{
Error = e.Error;
}
OnSaved();
};
Error = null;
IsBusy = true;
savable.BeginSave();
}
catch (Exception ex)
{
IsBusy = false;
Error = ex;
OnSaved();
}
}
like I understand is that I must create something that determines when is is in the BeginSave sycn/async call?
Copyright (c) Marimer LLC