コード例 #1
0
        /// <summary>
        /// Creates whole sample structure.
        /// </summary>
        private async Task CreateAllAsync()
        {
            try
            {
                await Task.Run(() =>
                {
#if NETFX_CORE
                    var filePath = string.Format("ms-appx:///{0}", "ArcGISRuntime.UWP.Samples/groups.json");
                    try
                    {
                        filePath = Path.Combine(Package.Current.InstalledLocation.Path, "ArcGISRuntime.UWP.Samples", "groups.json");
                    }
                    catch (Exception)
                    {
                        throw new NotImplementedException("groups.json file is missing");
                    }
#else
                   var filePath = "groups.json";
                    
                    if (!File.Exists(filePath))
                        throw new NotImplementedException("groups.json file is missing");
#endif

                    _sampleStructureMap = SampleStructureMap.Create(filePath, _selectedLanguage);
                });
            }
            // This is thrown if even one of the files requires permissions greater 
            // than the application provides. 
            catch (UnauthorizedAccessException e)
            {
                throw; //TODO
            }
            catch (DirectoryNotFoundException e)
            {
                throw; //TODO
            }
            catch (Exception e)
            {
                throw; //TODO
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates new instance of <see cref="SampleStructureMap"/> by deserializing it from the json file provided.
        /// Returned instance will be fully loaded including other information that is not provided
        /// in the json file like samples.
        /// </summary>
        /// <param name="metadataFilePath">Full path to the metadata JSON file</param>
        /// <param name="language">Language that is used to create the samples</param>
        /// <returns>Deserialized <see cref="SampleStructureMap"/></returns>
        internal static SampleStructureMap Create(string metadataFilePath, Language language = Language.CSharp)
        {
            var serializer = new DataContractJsonSerializer(typeof(SampleStructureMap));

            SampleStructureMap structureMap = null;

            var groupsMetadataFileInfo = new FileInfo(metadataFilePath);

            if (!groupsMetadataFileInfo.Exists || groupsMetadataFileInfo == null)
            {
                throw new FileNotFoundException("Groups.json file not found from given location.");
            }

            // Create new instance of SampleStuctureMap
            var json = File.ReadAllText(metadataFilePath);

            var jsonInBytes = Encoding.UTF8.GetBytes(json);

            using (var stream = new MemoryStream(jsonInBytes))
            {
                // De-serialize sample model
                structureMap = serializer.ReadObject(stream) as SampleStructureMap;
                if (structureMap == null)
                {
                    throw new SerializationException("Couldn't create StructureMap from provided groups.json file stream.");
                }
                structureMap.Samples = new List <SampleModel>();
            }

            var pathList = new List <string>();

            foreach (var category in structureMap.Categories)
            {
                foreach (var subCategory in category.SubCategories)
                {
                    if (subCategory.SampleInfos != null)
                    {
                        foreach (var sample in subCategory.SampleInfos)
                        {
                            pathList.Add(sample.Path.Replace("/", "\\"));
                        }
                    }
                }
            }

            foreach (var samplePath in pathList)
            {
                var sampleMetadataFilePath = Path.Combine(
                    groupsMetadataFileInfo.Directory.FullName, samplePath, "metadata.json");
                var sampleModel = SampleModel.Create(sampleMetadataFilePath);
                if (sampleModel != null)
                {
                    structureMap.Samples.Add(sampleModel);
                }
            }

            foreach (var category in structureMap.Categories)
            {
                foreach (var subCategory in category.SubCategories)
                {
                    if (subCategory.Samples == null)
                    {
                        subCategory.Samples = new List <SampleModel>();
                    }

                    foreach (var sampleInfo in subCategory.SampleInfos)
                    {
                        var sample = structureMap.Samples.FirstOrDefault(x => x.SampleName == sampleInfo.SampleName);

                        if (sample == null)
                        {
                            continue;
                        }

                        subCategory.Samples.Add(sample);
                    }
                }
            }

            if (structureMap.Featured == null)
            {
                structureMap.Featured = new List <FeaturedModel>();
            }

            // Set all sample models to the featured models
            foreach (var featured in structureMap.Featured)
            {
                var sample = structureMap.Samples.FirstOrDefault(x => x.SampleName == featured.SampleName);
                if (sample != null)
                {
                    featured.Sample = sample;
                }
            }

            return(structureMap);
        }
コード例 #3
0
        /// <summary>
        /// Creates new instance of <see cref="SampleStructureMap"/> by desirialing it from the json file provided.
        /// Returned instance will be fully loaded including other information that is not provided
        /// in the json file like samples.
        /// </summary>
        /// <param name="metadataFilePath">Full path to the metadata JSON file</param>
        /// <param name="language">Language that is used to create the samples</param>
        /// <returns>Deserialized <see cref="SampleStructureMap"/></returns>
        internal static SampleStructureMap Create(string metadataFilePath, Language language = Language.CSharp)
        {
            var serializer = new DataContractJsonSerializer(typeof(SampleStructureMap));

            SampleStructureMap structureMap = null;

            // Create new instance of SampleStuctureMap
            var metadataFile = new FileInfo(metadataFilePath);
            var json         = File.ReadAllText(metadataFilePath);

            var jsonInBytes = Encoding.UTF8.GetBytes(json);

            using (MemoryStream stream = new MemoryStream(jsonInBytes))
            {
                // De-serialize sample model
                structureMap         = serializer.ReadObject(stream) as SampleStructureMap;
                structureMap.Samples = new List <SampleModel>();
            }

            // Create all samples and add them to the groups since they are not part of
            // main configuration file
            var rootDirectory = metadataFile.Directory;

            var samplesDirectory   = new DirectoryInfo(Path.Combine(rootDirectory.FullName, "Samples"));
            var tutorialsDirectory = new DirectoryInfo(Path.Combine(rootDirectory.FullName, "Tutorials"));
            var workflowDirectory  = new DirectoryInfo(Path.Combine(rootDirectory.FullName, "Workflows"));

            var sampleGroupFolders = samplesDirectory.GetDirectories();

            // Create all samples
            foreach (var sampleGroupFolder in sampleGroupFolders) // ie. Samples\Layers
            {
                // This creates samples from all folders and adds them to the samples list
                // This means that sample is created even if it's not defined in the groups list
                var sampleFolders = sampleGroupFolder.GetDirectories();
                foreach (var sampleFolder in sampleFolders)  // ie. Samples\Layers\ArcgISTiledLayerFromUrl
                {
                    var sampleModel = SampleModel.Create(
                        Path.Combine(sampleFolder.FullName, "metadata.json"));

                    if (sampleModel != null)
                    {
                        structureMap.Samples.Add(sampleModel);
                    }
                }
            }

            // Create all tutorials
            if (tutorialsDirectory.Exists)
            {
                foreach (var sampleFolder in tutorialsDirectory.GetDirectories()) // ie. Tutorials\AddMapToApp
                {
                    var sampleModel = SampleModel.Create(
                        Path.Combine(sampleFolder.FullName, "metadata.json"));

                    if (sampleModel != null)
                    {
                        structureMap.Samples.Add(sampleModel);
                    }
                }
            }

            // Create all workflows
            if (workflowDirectory.Exists)
            {
                foreach (var sampleFolder in workflowDirectory.GetDirectories()) // ie. Workflows\SearchFeatures
                {
                    var sampleModel = SampleModel.Create(
                        Path.Combine(sampleFolder.FullName, "metadata.json"));

                    if (sampleModel != null)
                    {
                        structureMap.Samples.Add(sampleModel);
                    }
                }
            }

            // Set samples to the sub-categories
            var addedSamples = new List <SampleModel>();

            foreach (var cateory in structureMap.Categories)
            {
                foreach (var subCategory in cateory.SubCategories)
                {
                    if (subCategory.Samples == null)
                    {
                        subCategory.Samples = new List <SampleModel>();
                    }

                    if (subCategory.SampleNames == null)
                    {
                        subCategory.SampleNames = new List <string>();
                    }

                    foreach (var sampleName in subCategory.SampleNames)
                    {
                        var sample = structureMap.Samples.FirstOrDefault(x => x.SampleName == sampleName);

                        if (sample == null)
                        {
                            continue;
                        }

                        subCategory.Samples.Add(sample);
                        addedSamples.Add(sample);
                    }
                }
            }

            // Add samples that are not defined to the end of the groups
            var notAddedSamples = structureMap.Samples.Where(x => !addedSamples.Contains(x)).ToList();

            foreach (var sampleModel in notAddedSamples)
            {
                var category = structureMap.Categories.FirstOrDefault(x => x.CategoryName == sampleModel.Category);
                if (category == null)
                {
                    continue;
                }

                var subCategory = category.SubCategories.FirstOrDefault(x => x.SubCategoryName == sampleModel.SubCategory);
                if (subCategory != null)
                {
                    subCategory.SampleNames.Add(sampleModel.SampleName);
                    subCategory.Samples.Add(sampleModel);
                }
            }

            if (structureMap.Featured == null)
            {
                structureMap.Featured = new List <FeaturedModel>();
            }

            // Set all sample models to the featured models
            foreach (var featured in structureMap.Featured)
            {
                var sample = structureMap.Samples.FirstOrDefault(x => x.SampleName == featured.SampleName);
                if (sample != null)
                {
                    featured.Sample = sample;
                }
            }

            return(structureMap);
        }
コード例 #4
0
 /// <summary>
 /// Creates whole sample structure.
 /// </summary>
 private async Task CreateAllAsync()
 {
    List<DirectoryInfo> sampleDirectories = new List<DirectoryInfo>();
    var serializer = new DataContractJsonSerializer(typeof(SampleModel));
   
     try
     {
         await Task.Run(() =>
         {
             if (!File.Exists("groups.json"))
                 throw new NotImplementedException("groups.json file is missing");
             _sampleStructureMap = SampleStructureMap.Create("groups.json", _selectedLanguage);
         });
     }
     // This is thrown if even one of the files requires permissions greater 
     // than the application provides. 
     catch (UnauthorizedAccessException e)
     {
         throw; //TODO
     }
     catch (DirectoryNotFoundException e)
     {
         throw; //TODO
     }
     catch (Exception e)
     {
         throw; //TODO
     }
 }