ArcGISRuntimeXamarin.Models.SampleModel.Create C# (CSharp) Метод

Create() статический приватный Метод

Creates new instance of SampleModel by deserializing it from the json file provided.
static private Create ( string samplePath ) : SampleModel
samplePath string Full path to the metadata JSON file
Результат SampleModel
        internal static SampleModel Create(string samplePath)
        {
            var metadataStream = SampleManager.Current.GetMetadataManifest(samplePath);

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SampleModel));

            SampleModel sampleModel = null;

            // The samplePath is the path specified in the groups.json file for each metadata.json file
            try
            {
                // TODO: Wondering if we can rework this to not have to open two different MemoryStreams.
                using (Stream stream = metadataStream)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        stream.CopyTo(ms);
                        var jsonInBytes = ms.ToArray();

                        using (MemoryStream ms2 = new MemoryStream(jsonInBytes))
                        {
                            sampleModel = serializer.ReadObject(ms2) as SampleModel;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return sampleModel;
        }
        #endregion // Factory methods

Usage Example

Пример #1
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="groupsJSON">Full path to the groups JSON file</param>
        /// <returns>Deserialized <see cref="SampleStructureMap"/></returns>
        internal static SampleStructureMap Create(Stream groupsJSON)
        {
            var serializer = new DataContractJsonSerializer(typeof(SampleStructureMap));

            SampleStructureMap structureMap = null;

            try
            {
                // KD - Need two MemoryStreams? Need to investigate. Has to do with needing to open the json from the Android
                // Activity which gives you a stream. Then you need to get back to bytes.
                using (groupsJSON)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        groupsJSON.CopyTo(ms);
                        var jsonInBytes = ms.ToArray();

                        using (MemoryStream ms2 = new MemoryStream(jsonInBytes))
                        {
                            structureMap         = serializer.ReadObject(ms2) as SampleStructureMap;
                            structureMap.Samples = new List <SampleModel>();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Logger.WriteLine(ex.Message);
            }

            #region CreateSamples

            List <string> 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("/", "."));
                        }
                    }
                }
            }

            var sampleModel = new SampleModel();
            foreach (var samplePath in pathList)
            {
                sampleModel = SampleModel.Create(samplePath);
                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 sampleName in subCategory.SampleInfos)
                    {
                        var sample = structureMap.Samples.FirstOrDefault(x => x.SampleName == sampleName.SampleName);

                        if (sample == null)
                        {
                            continue;
                        }

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

            #endregion

            return(structureMap);
        }
All Usage Examples Of ArcGISRuntimeXamarin.Models.SampleModel::Create
SampleModel