private async void CopyProgramMessageCallback(MessageboxResult result)
        {
            DateTime copyStartTime;

            lock (_copyLock)
            {
                if (_isCopying)
                {
                    return;
                }

                _isCopying    = true;
                copyStartTime = DateTime.UtcNow;
            }

            _dialogResult = result;

            if (_dialogResult == MessageboxResult.Ok)
            {
                ServiceLocator.TraceService.Add(TraceType.Info, "About to copy local program",
                                                "Program name: " + _copyProgramName);

                if (CurrentProgram != null && _copyProgramName == CurrentProgram.Name)
                {
                    await CurrentProgram.Save();
                }

                var sourceProgramName      = _copyProgramName;
                var destinationProgramName = await ServiceLocator.ContextService.
                                             CopyProgramPart1(_copyProgramName);

                await UpdateLocalPrograms();

                _copyProgramName = null;

                await ServiceLocator.ContextService.CopyProgramPart2(
                    sourceProgramName, destinationProgramName);

                var minDeleteTime     = new TimeSpan(0, 0, 2);
                var remainingCopyTime = minDeleteTime.Subtract(
                    DateTime.UtcNow.Subtract(copyStartTime));

                if (remainingCopyTime > new TimeSpan(0))
                {
                    await Task.Delay(remainingCopyTime);
                }

                await UpdateLocalPrograms();

                //var program = await ServiceLocator.ContextService.CopyProgramPart2(
                //    _copyProgramName, updatedProgramName);

                //await UpdateLocalPrograms();
            }

            lock (_copyLock)
            {
                _isCopying = false;
            }
        }
        private async void ShareLocalProgramAction()
        {
            await CurrentProgram.Save();

            //var message = new GenericMessage<LocalProgramHeader>(CurrentProgram.LocalProgramHeader);
            //Messenger.Default.Send(message, ViewModelMessagingToken.ShareProgramHeaderListener);

            ServiceLocator.NavigationService.NavigateTo <ProgramExportViewModel>();
            _performedExport = true;
        }
        private async void SaveAction()
        {
            string validName = await ServiceLocator.ContextService.ConvertToValidFileName(ProgramName);

            if (CurrentProgram.Name != ProgramName)
            {
                ProgramName = await ServiceLocator.ContextService.FindUniqueProgramName(validName);

                if (CurrentProgram.LocalProgramHeader == CurrentProgramHeader)
                {
                    CurrentProgram.LocalProgramHeader.ProjectName = ProgramName;
                    await CurrentProgram.SetProgramNameAndRenameDirectory(ProgramName);

                    CurrentProgram.Description = ProgramDescription;
                }
                else
                {
                    var oldProgramPath = CurrentProgram.BasePath;
                    CurrentProgramHeader.ProjectName = ProgramName;
                    CurrentProgram.Description       = ProgramDescription;
                    await CurrentProgram.Save();

                    var programChangedMessage1 = new GenericMessage <Program>(null);
                    Messenger.Default.Send(programChangedMessage1,
                                           ViewModelMessagingToken.CurrentProgramChangedListener);

                    using (var storage = StorageSystem.GetStorage())
                    {
                        await storage.RenameDirectoryAsync(oldProgramPath, ProgramName);
                    }

                    var programChangedMessage2 = new GenericMessage <Program>(null);
                    Messenger.Default.Send(programChangedMessage2,
                                           ViewModelMessagingToken.CurrentProgramChangedListener);

                    await App.SaveContext(CurrentProgram);

                    var localProgramsChangedMessage = new MessageBase();
                    Messenger.Default.Send(localProgramsChangedMessage,
                                           ViewModelMessagingToken.LocalProgramsChangedListener);

                    base.GoBackAction();
                }
            }
        }
Beispiel #4
0
        private async void SaveAction()
        {
            GoBackAction();

            if (CurrentProgram != null)
            {
                await CurrentProgram.Save();
            }

            string validName = await ServiceLocator.ContextService.ConvertToValidFileName(ProgramName);

            string uniqueName = await ServiceLocator.ContextService.FindUniqueProgramName(validName);

            if (CreateEmptyProgram)
            {
                CurrentProgram = await ServiceLocator.ContextService.CreateEmptyProgram(uniqueName);
            }
            else if (CreateTemplateProgram)
            {
                CurrentProgram = await SelectedTemplateOption.ProjectGenerator.GenerateProgram(uniqueName, true);
            }

            if (CurrentProgram != null)
            {
                await CurrentProgram.Save();

                //await ServiceLocator.ContextService.
                //    CreateThumbnailsForNewProgram(CurrentProgram.Name);

                var programChangedMessage = new GenericMessage <Program>(CurrentProgram);
                Messenger.Default.Send(programChangedMessage, ViewModelMessagingToken.CurrentProgramChangedListener);
            }

            var localProgramsChangedMessage = new MessageBase();

            Messenger.Default.Send(localProgramsChangedMessage,
                                   ViewModelMessagingToken.LocalProgramsChangedListener);
        }
        public async override void NavigateTo()
        {
            if (CurrentProgram == null ||
                CurrentProgram.Name != CurrentProgramHeader.ProjectName)
            {
                lock (_loadingLock)
                {
                    if (IsActivatingLocalProgram)
                    {
                        return;
                    }

                    IsActivatingLocalProgram           = true;
                    CurrentProgramHeader.ValidityState = ProgramState.Unknown;
                    RaisePropertiesChanges();
                }

                if (CurrentProgram != null)
                {
                    await CurrentProgram.Save();
                }

                var result = await ServiceLocator.ProgramValidationService.CheckProgram(
                    Path.Combine(StorageConstants.ProgramsPath, CurrentProgramHeader.ProjectName));

                var newProgram = result.Program;

                CurrentProgramHeader.ValidityState = result.State;


                IsActivatingLocalProgram = false;

                if (newProgram != null)
                {
                    ServiceLocator.DispatcherService.RunOnMainThread(() =>
                    {
                        CurrentProgramHeader.ValidityState = ProgramState.Valid;
                    });

                    CurrentProgram = newProgram;

                    var projectChangedMessage = new GenericMessage <Program>(newProgram);
                    Messenger.Default.Send(projectChangedMessage,
                                           ViewModelMessagingToken.CurrentProgramChangedListener);

                    IsActivatingLocalProgram = false;
                }
                else
                {
                    ServiceLocator.DispatcherService.RunOnMainThread(() =>
                    {
                        CurrentProgram = null;
                    });
                }
            }
            if (_performedExport)
            {
                await ServiceLocator.ProgramExportService.CleanUpExport();

                _performedExport = false;
            }
            IsActivatingLocalProgram = false;
            RaisePropertiesChanges();

            base.NavigateTo();
        }