public Importer(DeltinScript deltinScript, FileGetter fileGetter, Uri initial)
 {
     _deltinScript = deltinScript;
     _diagnostics  = deltinScript.Diagnostics;
     _fileGetter   = fileGetter;
     ImportedFiles.Add(initial);
 }
        // The binding parameter is an ImportedFile
        public void ExecuteAddFileCommand()
        {
            bool containsExistingDataSets = false;

            if (SelectedImportedFile == null)
            {
                return;
            }

            if (SelectedImportedFile.RowType != ImportedFileRowTypes.Normal)
            {
                return;
            }

            if (WebsiteViewModel.Website.Datasets.Any())
            {
                containsExistingDataSets = true;
            }
            WebsiteDatasets.Add(SelectedImportedFile);
            //var count = WebsiteViewModel.Website.Datasets.Count();

            if (containsExistingDataSets)
            {
                Application.DoEvents();
                Events.GetEvent <GenericNotificationEvent>().Publish("Dataset added. Please be sure to make relevant measure and report selections as you proceed");
            }
            //Events.GetEvent<SelectedItemsForNewlyAddedDatasets>().Publish(true);

            // ???
            SelectedImportedFile.IsSelected = WebsiteDatasets.Count > 0;

            // copy it before removing, then set selected to [0], then remove copy
            var temp = SelectedImportedFile;

            // always select the special row
            SelectedImportedFile = ImportedFiles[0];

            ImportedFiles.Remove(temp);

            // If no more normal files remain, replace the special Please item with the special All item
            if (!ImportedFiles.Any(f => f.RowType == ImportedFileRowTypes.Normal))
            {
                ImportedFiles[0].RowType = ImportedFileRowTypes.AllFilesAdded;
            }
            Manager.IsNewDatasetIncluded = true;
            var datasetType = SelectedImportedFile.DataSetFile.Name;

            Manager.IsTrendingYearUpdated = !string.IsNullOrEmpty(datasetType) && (datasetType.Contains("Inpatient Discharge") || datasetType.Contains("ED Treat And Release"));
        }
        // The binding parameter is an ImportedFile
        public void ExecuteRemoveFileCommand(object param)
        {
            var file = param as IImportedFile;

            if (file == null)
            {
                return;
            }
            WebsiteDatasets.Remove(file);
            ImportedFiles.Add(file);

            // now there is at least 1 normal file in the dropdown, so show the Please message
            ImportedFiles[0].RowType = ImportedFileRowTypes.PleaseSelect;

            // always select the special row
            SelectedImportedFile = ImportedFiles[0];

            // ???
            file.IsSelected = WebsiteDatasets.Count > 0;
            Manager.IsNewDatasetIncluded = true;

            string datasetTypeName = null;

            if (file.DataSetFile.Dataset == null || file.DataSetFile.Dataset.ContentType == null)
            {
                var provider = ServiceLocator.Current.GetInstance <IDomainSessionFactoryProvider>();
                using (var session = provider.SessionFactory.OpenStatelessSession())
                {
                    datasetTypeName = session.Query <Dataset>()
                                      .Where(d => d.Id == file.DataSetFile.DatasetId)
                                      .Select(d => d.ContentType.Name)
                                      .FirstOrDefault();
                }
            }
            else
            {
                datasetTypeName = file.DataSetFile.Dataset.ContentType.Name;
            }

            Manager.IsTrendingYearUpdated = !string.IsNullOrEmpty(datasetTypeName) && (datasetTypeName.Contains("Inpatient Discharge") || datasetTypeName.Contains("ED Treat And Release"));
        }
        internal IEnumerable <Import> ResolveImport(
            IMSBuildEvaluationContext fileContext,
            string thisFilePath,
            ExpressionNode importExpr,
            string importExprString,
            string sdk)
        {
            //FIXME: add support for MSBuildUserExtensionsPath, the context does not currently support it
            if (importExprString.IndexOf("$(MSBuildUserExtensionsPath)", StringComparison.OrdinalIgnoreCase) > -1)
            {
                yield break;
            }

            //TODO: can we we re-use this context? the propvals may change between evaluations
            var context = new MSBuildCollectedValuesEvaluationContext(fileContext, PropertyCollector);

            bool foundAny   = false;
            bool isWildcard = false;

            foreach (var filename in context.EvaluatePathWithPermutation(importExpr, Path.GetDirectoryName(thisFilePath)))
            {
                if (string.IsNullOrEmpty(filename))
                {
                    continue;
                }

                //dedup
                if (!ImportedFiles.Add(filename))
                {
                    foundAny = true;
                    continue;
                }

                //wildcards
                var wildcardIdx = filename.IndexOf('*');

                //arbitrary limit to skip improbably short values from bad evaluation
                const int MIN_WILDCARD_STAR_IDX    = 15;
                const int MIN_WILDCARD_PATTERN_IDX = 10;
                if (wildcardIdx > MIN_WILDCARD_STAR_IDX)
                {
                    isWildcard = true;
                    var lastSlash = filename.LastIndexOf(Path.DirectorySeparatorChar);
                    if (lastSlash < MIN_WILDCARD_PATTERN_IDX)
                    {
                        continue;
                    }
                    if (lastSlash > wildcardIdx)
                    {
                        continue;
                    }

                    string[] files;
                    try {
                        var dir = filename.Substring(0, lastSlash);
                        if (!Directory.Exists(dir))
                        {
                            continue;
                        }

                        //finding the folder's enough for this to "count" as resolved even if there aren't any files in it
                        foundAny = true;

                        var pattern = filename.Substring(lastSlash + 1);

                        files = Directory.GetFiles(dir, pattern);
                    } catch (Exception ex) when(IsNotCancellation(ex))
                    {
                        LoggingService.LogError($"Error evaluating wildcard in import candidate '{filename}'", ex);
                        continue;
                    }

                    foreach (var f in files)
                    {
                        Import wildImport;
                        try {
                            wildImport = GetCachedOrParse(importExprString, f, sdk, File.GetLastWriteTimeUtc(f));
                        } catch (Exception ex) when(IsNotCancellation(ex))
                        {
                            LoggingService.LogError($"Error reading wildcard import candidate '{files}'", ex);
                            continue;
                        }
                        yield return(wildImport);
                    }

                    continue;
                }

                Import import;
                try {
                    var fi = new FileInfo(filename);
                    if (!fi.Exists)
                    {
                        continue;
                    }
                    import = GetCachedOrParse(importExprString, filename, sdk, fi.LastWriteTimeUtc);
                } catch (Exception ex) when(IsNotCancellation(ex))
                {
                    LoggingService.LogError($"Error reading import candidate '{filename}'", ex);
                    continue;
                }

                foundAny = true;
                yield return(import);

                continue;
            }

            //yield a placeholder for tooltips, imports pad etc to query
            if (!foundAny)
            {
                yield return(new Import(importExprString, sdk, null, DateTime.MinValue));
            }

            // we skip logging for wildcards as these are generally extensibility points that are often unused
            // this is here (rather than being folded into the next condition) for ease of breakpointing
            if (!foundAny && !isWildcard)
            {
                if (PreviousRootDocument == null && failedImports.Add(importExprString))
                {
                    LoggingService.LogDebug($"Could not resolve MSBuild import '{importExprString}'");
                }
            }
        }
示例#5
0
 public static void Write(this BinaryWriter writer, ImportedFiles importedFiles) => importedFiles.WriteTo(writer);