Exemplo n.º 1
0
        public async Task <LoggerResult> SaveProject()
        {
            if (PackageSession == null)
            {
                throw new InvalidOperationException("Cannot save the project before it was loaded.");
            }

            // TODO: check asset consistency

            // TODO: read more about Stride.Core.Assets.Editor.PackageViewModel
            //// Prepare packages to be saved by setting their dirty flag correctly
            //foreach (var package in LocalPackages)
            //{
            //    package.PreparePackageForSaving();
            //}

            var viewUpdater = Services.GetService <IViewUpdater>();

            PackageSessionResult sessionResult = await SetupResultProgress(viewUpdater, SaveProjectScope);

            // TODO: display a dialog with save progress

            // Force PackageSession.Save to be executed on the thread pool
            // otherwise it would block execution and we want this process to be async
            using (var scope = new TimedScope(SaveProjectScope, TimedScope.Status.Success))
            {
                await Task.Run(() =>
                {
                    try
                    {
                        var saveParameters = PackageSaveParameters.Default();

                        // TODO: read more about Stride.Core.Assets.Editor.AssetViewModel
                        // AllAssets.ForEach(x => x.PrepareSave(sessionResult));
                        PackageSession.Save(sessionResult, saveParameters);
                    }
                    catch (Exception e)
                    {
                        sessionResult.Error(string.Format("There was a problem saving the solution. {0}", e.Message), e);
                        scope.Result = TimedScope.Status.Failure;
                    }
                });

                if (sessionResult.HasErrors)
                {
                    scope.Result = TimedScope.Status.Failure;
                }
            }

            EditorViewModel.LoadingStatus = null;
            await viewUpdater.UpdateView();

            ProjectSaved?.Invoke(sessionResult);

            return(sessionResult);
        }
        public async Task <LoggerResult> SaveProject()
        {
            if (PackageSession == null)
            {
                throw new InvalidOperationException("Cannot save the project before it was loaded.");
            }

            // TODO: check asset consistency

            // TODO: read more about Stride.Core.Assets.Editor.PackageViewModel
            //// Prepare packages to be saved by setting their dirty flag correctly
            //foreach (var package in LocalPackages)
            //{
            //    package.PreparePackageForSaving();
            //}

            var sessionResult = new LoggerResult();

            // TODO: display a dialog with save progress

            // Force PackageSession.Save to be executed on the thread pool
            // otherwise it would block execution and we want this process to be async
            await Task.Run(() =>
            {
                try
                {
                    var saveParameters = PackageSaveParameters.Default();

                    // TODO: read more about Stride.Core.Assets.Editor.AssetViewModel
                    // AllAssets.ForEach(x => x.PrepareSave(sessionResult));
                    PackageSession.Save(sessionResult, saveParameters);
                }
                catch (Exception e)
                {
                    sessionResult.Error(string.Format("There was a problem saving the solution. {0}", e.Message), e);
                }
            });

            return(sessionResult);
        }