public ParseCommandResult(object parsedCommand, string commandType, DomainVersion version, ClaimsPrincipal user, CultureInfo culture, IDictionary <string, object> metadata)
 {
     if (parsedCommand == null)
     {
         throw new ArgumentNullException(nameof(parsedCommand));
     }
     if (commandType == null)
     {
         throw new ArgumentNullException(nameof(commandType));
     }
     if (version == null)
     {
         throw new ArgumentNullException(nameof(version));
     }
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     if (culture == null)
     {
         throw new ArgumentNullException(nameof(culture));
     }
     if (metadata == null)
     {
         throw new ArgumentNullException(nameof(metadata));
     }
     ParsedCommand = parsedCommand;
     CommandType   = commandType;
     Version       = version;
     User          = user;
     Culture       = culture;
     Metadata      = metadata;
 }
Beispiel #2
0
 public MediaTypeInfo(string mediaType, string encoding, string schema, DomainVersion schemaVersion, string domainModel, DomainVersion domainModelVersion)
 {
     MediaType          = mediaType;
     Encoding           = encoding;
     Schema             = schema;
     SchemaVersion      = schemaVersion;
     DomainModel        = domainModel;
     DomainModelVersion = domainModelVersion;
 }
 public MediaTypeInfo(string mediaType, string encoding, string schema, DomainVersion schemaVersion, string domainModel, DomainVersion domainModelVersion)
 {
     MediaType = mediaType;
     Encoding = encoding;
     Schema = schema;
     SchemaVersion = schemaVersion;
     DomainModel = domainModel;
     DomainModelVersion = domainModelVersion;
 }
 public MetadataVersion(string domainModel, DomainVersion version, bool?isObsolete = null)
 {
     if (domainModel == null)
     {
         throw new ArgumentNullException(nameof(domainModel));
     }
     if (version == null)
     {
         throw new ArgumentNullException(nameof(version));
     }
     DomainModel = domainModel;
     Version     = version;
     IsObsolete  = isObsolete;
 }
 public ParseCommandResult(object parsedCommand, string commandType, DomainVersion version, ClaimsPrincipal user, CultureInfo culture, IDictionary<string, object> metadata)
 {
     if (parsedCommand == null) throw new ArgumentNullException(nameof(parsedCommand));
     if (commandType == null) throw new ArgumentNullException(nameof(commandType));
     if (version == null) throw new ArgumentNullException(nameof(version));
     if (user == null) throw new ArgumentNullException(nameof(user));
     if (culture == null) throw new ArgumentNullException(nameof(culture));
     if (metadata == null) throw new ArgumentNullException(nameof(metadata));
     ParsedCommand = parsedCommand;
     CommandType = commandType;
     Version = version;
     User = user;
     Culture = culture;
     Metadata = metadata;
 }
        private CommandInfo ExtractCommandInfo(NancyContext context)
        {
            var contentType = context.Request.Headers.ContentType;

            if (contentType == null)
            {
                return(null);
            }
            MediaTypeHeaderValue header;

            if (!MediaTypeHeaderValue.TryParse(contentType, out header))
            {
                return(null);
            }
            var encoding = default(Encoding);

            if (header.CharSet != null)
            {
                encoding = Encoding.GetEncoding(header.CharSet);
            }
            var domainModel = header.Parameters.FirstOrDefault(p => p.Name == "domain-model")?.Value;
            var ver         = header.Parameters.FirstOrDefault(p => p.Name == "domain-version")?.Value;

            if (domainModel == null || ver == null)
            {
                return(null);
            }
            DomainVersion domver;

            if (!DomainVersion.TryParse(ver, out domver))
            {
                return(null);
            }
            var version = new MetadataVersion(domainModel, domver);

            return(new CommandInfo(version, encoding,
                                   header.MediaType,
                                   header.Parameters.FirstOrDefault(p => p.Name == "schema")?.Value,
                                   header.Parameters.FirstOrDefault(p => p.Name == "schema-version")?.Value));
        }
        private async Task loadAllFiles()
        {
            isLoadInProgress = true;

            selectedFile = null;

            notesViewModel.SelectedFile = null;

            messenger.Send(new FileLoadingMessage());

            allFileEntities.ForEach(fe => fe.PropertyChanged -= onFileEntityViewModelChanged);

            allFileEntities.Clear();

            allFiles.Clear();

            viewModel.Files.Clear();

            if (String.IsNullOrEmpty(settings.PathToGame))
            {
                return;
            }

            LoadProgressMessage progress = new LoadProgressMessage {
                Text = "Loading Game Files..."
            };

            messenger.Send(progress);

            try {
                version = await repository.GetGameVersion(settings.PathToGame);
            }
            catch (FileNotFoundException) {
                messenger.Send(new MessageBoxDialogMessage {
                    Header = "Game Version File Not Found", Message = "The ..\\bin\\Version.ini file could not be found.\n\nPlease ensure your settings are pointed to the 'contents' directory.", HasCancel = false
                });

                progress.IsComplete = true;

                messenger.Send(progress);

                isLoadInProgress = false;

                return;
            }

            try {
                locale = await repository.GetGameLocale(settings.PathToGame);
            }
            catch (FileNotFoundException) {
                locale = CultureInfo.CurrentCulture.EnglishName.ToLowerInvariant();
            }

            List <DomainUpkFile> localFiles = await loadGameFiles();

            if (!localFiles.Any())
            {
                progress.IsComplete = true;

                messenger.Send(progress);

                isLoadInProgress = false;

                return;
            }

            localFiles.ForEach(f => f.CurrentVersion = version);

            List <DomainUpkFile> mods = (from row in localFiles
                                         let path = Path.GetDirectoryName(row.GameFilename)
                                                    where path != null &&
                                                    !path.EndsWith("CookedPC", StringComparison.CurrentCultureIgnoreCase)
                                                    select row).ToList();

            localFiles.RemoveAll(f => mods.Contains(f));

            progress.Text = "Loading Remote Database...";

            messenger.Send(progress);

            List <DomainUpkFile> remoteFiles = new List <DomainUpkFile>();

            string message = "No files returned from repository.";

            CancellationToken token = resetToken(ref remoteTokenSource);

            bool loadError = false;

            try {
                if (!menuViewModel.IsOfflineMode)
                {
                    remoteFiles = await remoteRepository.LoadUpkFiles(token);
                }
            }
            catch (Exception ex) {
                message = ex.Message;

                remoteFiles = new List <DomainUpkFile>();

                loadError = true;
            }

            if ((loadError || token.IsCancellationRequested) && !remoteFiles.Any())
            {
                if (loadError)
                {
                    messenger.Send(new MessageBoxDialogMessage {
                        Header = "Error Received from Remote Database", Message = $"The remote database returned an error.  Please try again in a few minutes.\n\n{message}\n\nThe program will continue using local files only.  Saving of file notes will be disabled.", HasCancel = false
                    });
                }

                progress.IsLocalMode = true;

                menuViewModel.IsOfflineMode = true;

                viewModel.IsShowFilesWithType = false;
            }

            remoteFiles.ForEach(f => {
                f.CurrentVersion = version;
                f.CurrentLocale  = locale;
            });

            List <DomainUpkFile> matches = (from row1 in localFiles
                                            join row2 in remoteFiles on new { row1.ContentsRoot, row1.Package } equals new { row2.ContentsRoot, row2.Package }
                                            where row2.Exports.Any(f => f.Versions.Contains(version) && f.Locale == locale && f.Filesize == row1.Filesize)
                                            let a = row2.GameFilename = row1.GameFilename
                                                                        select row2).ToList();

            if (matches.Any())
            {
                allFiles.AddRange(matches.OrderBy(f => f.Filename));
            }

            List <DomainUpkFile> changes = (from row1 in localFiles
                                            join row2 in remoteFiles on new { row1.ContentsRoot, row1.Package } equals new { row2.ContentsRoot, row2.Package }
                                            where row2.Exports.All(f => !f.Versions.Contains(version) || f.Locale != locale)
                                            let a = row2.GameFilename = row1.GameFilename
                                                                        select row2).ToList();

            if (changes.Any())
            {
                allFiles.AddRange(changes.OrderBy(f => f.Filename));

                allFiles.Sort(domainUpkfileComparison);

                await scanUpkFiles(changes);
            }

            List <DomainUpkFile> adds = (from row1 in localFiles
                                         join row2 in remoteFiles on new { row1.ContentsRoot, row1.Package } equals new { row2.ContentsRoot, row2.Package } into fileGroup
                                         from sub  in fileGroup.DefaultIfEmpty()
                                         where sub == null
                                         select row1).ToList();

            if (adds.Any())
            {
                allFiles.AddRange(adds.OrderBy(f => f.Filename));

                allFiles.Sort(domainUpkfileComparison);

                if (!menuViewModel.IsOfflineMode)
                {
                    await scanUpkFiles(adds);
                }
                else
                {
                    adds.ForEach(f => f.Id = Guid.NewGuid().ToString());
                }
            }

            viewModel.AllTypes = menuViewModel.IsOfflineMode ? new ObservableCollection <string>() : new ObservableCollection <string>(allFiles.SelectMany(f => f.GetCurrentExports().Types.Select(e => e.Name)).Distinct().OrderBy(s => s));

            allFiles.ForEach(f => { f.ModdedFiles.AddRange(mods.Where(mf => Path.GetFileName(mf.GameFilename) == Path.GetFileName(f.GameFilename) &&
                                                                      (Path.GetDirectoryName(mf.GameFilename) ?? String.Empty).StartsWith(Path.GetDirectoryName(f.GameFilename) ?? String.Empty))); });

            allFileEntities.AddRange(mapper.Map <List <FileViewEntity> >(allFiles));

            allFileEntities.ForEach(fe => fe.PropertyChanged += onFileEntityViewModelChanged);

            showFileTypes();

            progress.IsComplete = true;

            messenger.Send(progress);

            messenger.Send(new FileListingLoadedMessage {
                Allfiles = allFiles
            });

            isLoadInProgress = false;
        }