本文整理汇总了C#中IDataContext.AddOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# IDataContext.AddOrUpdate方法的具体用法?C# IDataContext.AddOrUpdate怎么用?C# IDataContext.AddOrUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataContext
的用法示例。
在下文中一共展示了IDataContext.AddOrUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveState
public override void SaveState(IDataContext state)
{
if (_viewModels.Count == 0)
return;
var states = new List<IDataContext>();
foreach (var viewModel in _viewModels)
states.Insert(0, ViewModelProvider.PreserveViewModel(viewModel, null));
state.AddOrUpdate(ViewModelsState, new StateList { State = states });
}
示例2: GetAccessor
protected virtual ISingleBindingSourceAccessor GetAccessor(object model, string path, IDataContext context, bool isSource, Func<IDataContext, object> commandParameterDelegate = null)
{
var source = new MultiPathObserver(model, BindingPath.Create(path), false);
if (commandParameterDelegate != null)
{
context = context.ToNonReadOnly();
context.AddOrUpdate(BindingBuilderConstants.CommandParameter, commandParameterDelegate);
}
return new BindingSourceAccessor(source, context, !isSource);
}
示例3: ClearNavigationStackIfNeed
private void ClearNavigationStackIfNeed(IDataContext context)
{
#if WINDOWSCOMMON
if (context == null)
context = DataContext.Empty;
if (!context.GetData(NavigationConstants.ClearBackStack) || _frame.BackStack.IsReadOnly)
return;
_frame.BackStack.Clear();
context.AddOrUpdate(NavigationProvider.ClearNavigationCache, true);
#endif
}
示例4: SaveState
public void SaveState(IDataContext state)
{
state.AddOrUpdate("Depth", Depth);
}
示例5: SaveState
public virtual void SaveState(IDataContext state)
{
var selectedItem = SelectedItem;
if (selectedItem != null)
state.AddOrUpdate(StateKey, ViewModelProvider.PreserveViewModel(selectedItem, null));
}
示例6: ClearNavigationStackIfNeed
private void ClearNavigationStackIfNeed(IDataContext context)
{
if (context == null)
context = DataContext.Empty;
if (!context.GetData(NavigationConstants.ClearBackStack))
return;
while (_frame.BackStack.OfType<object>().Any())
_frame.RemoveBackEntry();
context.AddOrUpdate(NavigationProvider.ClearNavigationCache, true);
}
示例7: Navigate
public virtual bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
{
Should.NotBeNull(source, "source");
if (!RaiseNavigating(new NavigatingCancelEventArgs(source, NavigationMode.New, parameter)))
return false;
if (dataContext == null)
dataContext = DataContext.Empty;
var activity = PlatformExtensions.CurrentActivity ?? SplashScreenActivityBase.Current;
var context = activity ?? Application.Context;
var intent = new Intent(context, source.ViewType);
if (activity == null)
intent.AddFlags(ActivityFlags.NewTask);
else if (dataContext.GetData(NavigationConstants.ClearBackStack))
{
if (PlatformExtensions.IsApiLessThanOrEqualTo10)
{
intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
ServiceProvider.EventAggregator.Publish(this, MvvmActivityMediator.FinishActivityMessage.Instance);
}
else
intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
dataContext.AddOrUpdate(NavigationProvider.ClearNavigationCache, true);
}
if (parameter != null)
intent.PutExtra(ParameterString, parameter);
_isNew = true;
_parameter = parameter;
StartActivity(context, intent, dataContext);
return true;
}
示例8: Navigate
public virtual bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
{
Should.NotBeNull(source, nameof(source));
if (dataContext == null)
dataContext = DataContext.Empty;
bool bringToFront;
dataContext.TryGetData(NavigationProviderConstants.BringToFront, out bringToFront);
if (!RaiseNavigating(new NavigatingCancelEventArgs(source, bringToFront ? NavigationMode.Refresh : NavigationMode.New, parameter)))
return false;
UIViewController viewController = null;
IViewModel viewModel = dataContext.GetData(NavigationConstants.ViewModel);
if (bringToFront && viewModel != null)
{
var viewControllers = new List<UIViewController>(NavigationController.ViewControllers);
for (int i = 0; i < viewControllers.Count; i++)
{
var controller = viewControllers[i];
if (controller.DataContext() == viewModel)
{
viewControllers.RemoveAt(i);
viewController = controller;
NavigationController.ViewControllers = viewControllers.ToArray();
dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateCache, true);
break;
}
}
}
if (viewController == null)
{
if (viewModel == null)
viewController = (UIViewController)ServiceProvider.Get<IViewManager>().GetViewAsync(source, dataContext).Result;
else
viewController = (UIViewController)ViewManager.GetOrCreateView(viewModel, null, dataContext);
}
viewController.SetNavigationParameter(parameter);
bool shouldNavigate = true;
if (_window != null)
{
bool navigated;
InitializeNavigationController(GetNavigationController(_window, viewController, out navigated));
shouldNavigate = !navigated;
_window = null;
}
if (shouldNavigate)
{
bool animated;
if (dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
{
if (viewModel != null)
viewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated);
}
else
animated = UseAnimations;
if (!ClearNavigationStackIfNeed(viewController, dataContext, animated))
NavigationController.PushViewController(viewController, animated);
}
var view = viewController as IViewControllerView;
if (view == null || view.Mediator.IsAppeared)
RaiseNavigated(viewController, bringToFront ? NavigationMode.Refresh : NavigationMode.New, parameter);
else
{
if (bringToFront)
view.Mediator.ViewDidAppearHandler += OnViewDidAppearHandlerRefresh;
else
view.Mediator.ViewDidAppearHandler += OnViewDidAppearHandlerNew;
}
return true;
}
示例9: MergeParameters
private static void MergeParameters(IDataContext ctxFrom, IDataContext ctxTo)
{
string viewName = ctxFrom.GetData(InitializationConstants.ViewName);
if (!string.IsNullOrEmpty(viewName))
ctxTo.AddOrUpdate(InitializationConstants.ViewName, viewName);
IocContainerCreationMode creationMode;
if (ctxFrom.TryGetData(InitializationConstants.IocContainerCreationMode, out creationMode))
ctxTo.AddOrUpdate(InitializationConstants.IocContainerCreationMode, creationMode);
ObservationMode observationMode;
if (ctxFrom.TryGetData(InitializationConstants.ObservationMode, out observationMode))
ctxTo.AddOrUpdate(InitializationConstants.ObservationMode, observationMode);
}
示例10: RestoreViewModel
/// <summary>
/// Restores the view model from state context.
/// </summary>
/// <param name="viewModelState">The specified state <see cref="IDataContext" />.</param>
/// <param name="throwOnError">
/// <c>true</c> to throw an exception if the view model cannot be restored; <c>false</c> to return null.
/// </param>
/// <param name="dataContext">The specified <see cref="IDataContext" />.</param>
/// <returns>
/// An instance of <see cref="IViewModel" />.
/// </returns>
public IViewModel RestoreViewModel(IDataContext viewModelState, IDataContext dataContext, bool throwOnError)
{
try
{
dataContext = dataContext.ToNonReadOnly();
if (viewModelState == null)
viewModelState = DataContext.Empty;
else
dataContext.Merge(viewModelState);
IViewModel viewModel;
if (!dataContext.GetData(InitializationConstants.IgnoreRestoredViewModelCache))
{
Guid id;
if (viewModelState.TryGetData(IdViewModelConstant, out id))
{
viewModel = GetOrAddRestoredViewModel(id).GetViewModel();
if (viewModel != null)
return viewModel;
}
}
RestoredViewModel restoredParentViewModel = null;
IViewModel parentViewModel = null;
Guid idParent;
if (viewModelState.TryGetData(IdParentViewModelConstant, out idParent))
{
restoredParentViewModel = GetOrAddRestoredViewModel(idParent);
parentViewModel = restoredParentViewModel.GetViewModel();
if (parentViewModel != null)
dataContext.AddOrUpdate(InitializationConstants.ParentViewModel, parentViewModel);
}
viewModel = RestoreViewModel(viewModelState, dataContext);
if (viewModel != null)
{
if (restoredParentViewModel != null && parentViewModel == null)
restoredParentViewModel.AddChildViewModel(viewModel);
OnViewModelRestored(viewModel, viewModelState, dataContext);
Tracer.TraceViewModel(AuditAction.Restored, viewModel);
if (ReferenceEquals(viewModelState, DataContext.Empty))
Tracer.Warn("The view model '{0}' was restored without state.", viewModel);
return viewModel;
}
if (throwOnError)
throw ExceptionManager.ViewModelCannotBeRestored();
}
catch (Exception e)
{
if (throwOnError)
throw;
Tracer.Warn(e.Flatten(true));
}
return null;
}
示例11: Navigate
public virtual bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
{
Should.NotBeNull(source, nameof(source));
if (dataContext == null)
dataContext = DataContext.Empty;
bool bringToFront;
dataContext.TryGetData(NavigationProviderConstants.BringToFront, out bringToFront);
if (!RaiseNavigating(new NavigatingCancelEventArgs(source, bringToFront ? NavigationMode.Refresh : NavigationMode.New, parameter)))
return false;
var activity = PlatformExtensions.CurrentActivity ?? SplashScreenActivityBase.Current;
var context = activity ?? Application.Context;
var intent = new Intent(context, source.ViewType);
if (activity == null)
intent.AddFlags(ActivityFlags.NewTask);
else if (dataContext.GetData(NavigationConstants.ClearBackStack))
{
if (PlatformExtensions.IsApiLessThanOrEqualTo10)
intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
else
intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
ServiceProvider.EventAggregator.Publish(this, MvvmActivityMediator.FinishActivityMessage.Instance);
dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateAllCache, true);
}
if (parameter != null)
intent.PutExtra(ParameterString, parameter);
if (bringToFront)
{
_isReorder = true;
//http://stackoverflow.com/questions/20695522/puzzling-behavior-with-reorder-to-front
//http://code.google.com/p/android/issues/detail?id=63570#c2
bool closed = false;
if (PlatformExtensions.IsApiGreaterThanOrEqualTo19)
{
var viewModel = dataContext.GetData(NavigationConstants.ViewModel);
if (viewModel != null)
{
var view = viewModel.Settings.Metadata.GetData(ViewModelConstants.View);
var activityView = ToolkitExtensions.GetUnderlyingView<object>(view) as Activity;
if (activityView != null && activityView.IsTaskRoot)
{
var message = new MvvmActivityMediator.FinishActivityMessage(viewModel);
ServiceProvider.EventAggregator.Publish(this, message);
closed = message.Finished;
}
}
}
if (!closed)
intent.AddFlags(ActivityFlags.ReorderToFront);
dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateCache, true);
}
_isNew = true;
_parameter = parameter;
StartActivity(context, intent, source, dataContext);
return true;
}
示例12: RestoreViewModel
public IViewModel RestoreViewModel(IDataContext viewModelState, IDataContext dataContext, bool throwOnError)
{
try
{
dataContext = dataContext.ToNonReadOnly();
if (viewModelState == null)
viewModelState = DataContext.Empty;
else
dataContext.Merge(viewModelState);
IViewModel viewModel;
if (!dataContext.GetData(InitializationConstants.IgnoreViewModelCache))
{
Guid id;
if (viewModelState.TryGetData(ViewModelConstants.Id, out id))
{
viewModel = GetOrAddCachedViewModel(id).GetViewModel();
if (viewModel != null)
return viewModel;
}
}
CachedViewModel restoredParentViewModel = null;
IViewModel parentViewModel = null;
Guid idParent;
if (viewModelState.TryGetData(ViewModelConstants.IdParent, out idParent))
{
restoredParentViewModel = GetOrAddCachedViewModel(idParent);
parentViewModel = restoredParentViewModel.GetViewModel();
if (parentViewModel != null)
dataContext.AddOrUpdate(InitializationConstants.ParentViewModel, parentViewModel);
}
var restoring = Restoring;
if (restoring != null)
{
var args = new ViewModelRestoringEventArgs { Context = dataContext, ViewModelState = viewModelState };
restoring(this, args);
dataContext = args.Context ?? DataContext.Empty;
}
viewModel = RestoreViewModelInternal(viewModelState, dataContext);
if (viewModel != null)
{
if (restoredParentViewModel != null && parentViewModel == null)
restoredParentViewModel.AddChildViewModel(viewModel);
OnViewModelRestored(viewModel, viewModelState, dataContext);
var restored = Restored;
if (restored != null)
{
var args = new ViewModelRestoredEventArgs(viewModel)
{
Context = dataContext,
ViewModelState = viewModelState
};
restored(this, args);
}
Tracer.TraceViewModel(ViewModelLifecycleType.Restored, viewModel);
if (ReferenceEquals(viewModelState, DataContext.Empty))
Tracer.Warn("The view model '{0}' was restored without state.", viewModel);
return viewModel;
}
if (throwOnError)
throw ExceptionManager.ViewModelCannotBeRestored();
}
catch (Exception e)
{
if (throwOnError)
throw;
Tracer.Warn(e.Flatten(true));
}
return null;
}
示例13: Navigate
public virtual bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
{
Should.NotBeNull(source, nameof(source));
if (_rootPage == null)
return false;
if (dataContext == null)
dataContext = DataContext.Empty;
dataContext.TryGetData(NavigationProviderConstants.BringToFront, out _bringToFront);
if (!RaiseNavigating(new NavigatingCancelEventArgs(source, _bringToFront ? NavigationMode.Refresh : NavigationMode.New, parameter, true, false)))
return false;
var viewModel = dataContext.GetData(NavigationConstants.ViewModel);
bool animated;
if (dataContext.TryGetData(NavigationConstants.UseAnimations, out animated))
{
if (viewModel != null)
viewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated);
}
else
animated = UseAnimations;
Page page = null;
if (_bringToFront && viewModel != null)
{
var navigation = _rootPage.Navigation;
if (navigation != null)
{
for (int i = 0; i < navigation.NavigationStack.Count; i++)
{
var p = navigation.NavigationStack[i];
if (p.BindingContext == viewModel)
{
page = p;
navigation.RemovePage(p);
dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateCache, true);
break;
}
}
}
}
if (page == null)
{
if (viewModel == null)
page = (Page)ServiceProvider.Get<IViewManager>().GetViewAsync(source, dataContext).Result;
else
page = (Page)ViewManager.GetOrCreateView(viewModel, null, dataContext);
}
page.SetNavigationParameter(parameter);
ClearNavigationStackIfNeed(dataContext, page, _rootPage.PushAsync(page, animated));
return true;
}
示例14: ClearNavigationStackIfNeed
private void ClearNavigationStackIfNeed(IDataContext context)
{
#if WINDOWS_PHONE
var page = _frame.Content as Page;
if (page == null || page.NavigationService == null)
return;
var navigationService = page.NavigationService;
if (context == null)
context = DataContext.Empty;
if (!context.GetData(NavigationConstants.ClearBackStack))
return;
while (navigationService.BackStack.OfType<object>().Any())
navigationService.RemoveBackEntry();
context.AddOrUpdate(NavigationProvider.ClearNavigationCache, true);
#endif
}
示例15: Navigate
public bool Navigate(IViewMappingItem source, string parameter, IDataContext dataContext)
{
Should.NotBeNull(source, nameof(source));
if (dataContext == null)
dataContext = DataContext.Empty;
dataContext.TryGetData(NavigationProviderConstants.BringToFront, out _bringToFront);
var bringToFront = _bringToFront;
var result = Navigate(source.ViewType, parameter, dataContext.GetData(NavigationConstants.ViewModel));
if (result)
{
if (bringToFront)
dataContext.AddOrUpdate(NavigationProviderConstants.InvalidateCache, true);
ClearNavigationStackIfNeed(dataContext);
}
return result;
}