public T DeserializeDataFromStream <T>(Stream stream)
            where T : class, new()
        {
            try
            {
                if (stream != null)
                {
                    var modelXml = new StreamReader(stream).ReadToEnd();

                    if (!string.IsNullOrEmpty(modelXml))
                    {
                        return(SPMeta2Model.FromXML(modelXml) as T);
                    }
                }

                if (ShouldThrowException)
                {
                    HadException = true;
                    throw new ApplicationException("ShouldThrowException = true");
                }
            }
            catch (Exception)
            {
                // TODO

                return(null);
            }

            return(null);
        }
Exemplo n.º 2
0
        protected virtual void EnsureSerializationSupport(IEnumerable <ModelNode> models)
        {
            foreach (var model in models)
            {
                var xml = SPMeta2Model.ToXML(model);
                var xmlModelInstance = SPMeta2Model.FromXML(xml);

                var json = SPMeta2Model.ToJSON(model);
                var jsonModelInstance = SPMeta2Model.FromJSON(json);
            }
        }
        public virtual List <ModelNode> GetSerializedAndRestoredModels(IEnumerable <ModelNode> models)
        {
            var result = new List <ModelNode>();

            foreach (var model in models)
            {
                var xml = SPMeta2Model.ToXML(model);
                var xmlModelInstance = SPMeta2Model.FromXML(xml);

                var json = SPMeta2Model.ToJSON(model);
                var jsonModelInstance = SPMeta2Model.FromJSON(json);

                result.Add(xmlModelInstance);
                result.Add(jsonModelInstance);
            }

            return(result);
        }
Exemplo n.º 4
0
        public void CanSerialize_SiteModelToXMLAndBack()
        {
            var orginalModel = SPMeta2Model.NewSiteModel(site =>
            {
            });

            TraceUtils.WithScope(trace =>
            {
                var modelString = SPMeta2Model.ToXML(orginalModel);
                Assert.IsFalse(string.IsNullOrEmpty(modelString));

                trace.WriteLine("XML");
                trace.WriteLine(modelString);

                var deserializedModel = SPMeta2Model.FromXML(modelString);
                Assert.IsNotNull(deserializedModel);
            });
        }
Exemplo n.º 5
0
        private void Can_Unpack_Internal_2(NuGetSolutionPackageService service)
        {
            Can_Unpack_Internal(service,
                                (rawPackage, unpackedPackage) =>
            {
                var solutionPackage         = rawPackage as SolutionPackageBase;
                var unpackedSolutionPackage = unpackedPackage as SolutionPackageBase;

                Assert.IsNotNull(solutionPackage);
                Assert.IsNotNull(unpackedSolutionPackage);

                Assert.AreEqual(solutionPackage.Name, unpackedSolutionPackage.Name);
                Assert.AreEqual(solutionPackage.Title, unpackedSolutionPackage.Title);
                Assert.AreEqual(solutionPackage.Description, unpackedSolutionPackage.Description);
                Assert.AreEqual(solutionPackage.Id, unpackedSolutionPackage.Id);
                Assert.AreEqual(solutionPackage.Authors, unpackedSolutionPackage.Authors);
                Assert.AreEqual(solutionPackage.Company, unpackedSolutionPackage.Company);
                Assert.AreEqual(solutionPackage.Version, unpackedSolutionPackage.Version);
                Assert.AreEqual(solutionPackage.Owners, unpackedSolutionPackage.Owners);

                Assert.AreEqual(solutionPackage.ReleaseNotes, unpackedSolutionPackage.ReleaseNotes);
                Assert.AreEqual(solutionPackage.Summary, unpackedSolutionPackage.Summary);

                Assert.AreEqual(solutionPackage.ProjectUrl, unpackedSolutionPackage.ProjectUrl);
                Assert.AreEqual(solutionPackage.IconUrl, unpackedSolutionPackage.IconUrl);
                Assert.AreEqual(solutionPackage.LicenseUrl, unpackedSolutionPackage.LicenseUrl);
                Assert.AreEqual(solutionPackage.Copyright, unpackedSolutionPackage.Copyright);
                Assert.AreEqual(solutionPackage.Tags, unpackedSolutionPackage.Tags);

                Assert.AreEqual(solutionPackage.Dependencies.Count, unpackedSolutionPackage.Dependencies.Count);

                foreach (var dependency in solutionPackage.Dependencies)
                {
                    var unpackedDependency =
                        unpackedSolutionPackage.Dependencies.FirstOrDefault(d => d.Id == dependency.Id);

                    Assert.AreEqual(dependency.Id, unpackedDependency.Id);
                    Assert.AreEqual(dependency.Version, unpackedDependency.Version);
                }


                if (service is SPMeta2SolutionPackageService)
                {
                    var m2package         = solutionPackage as SolutionPackageBase;
                    var m2unpackedPackage = unpackedSolutionPackage as SolutionPackageBase;

                    Assert.IsNotNull(m2package);
                    Assert.IsNotNull(m2unpackedPackage);

                    Assert.AreEqual(m2package.GetModels().Count(), m2unpackedPackage.GetModels().Count());

                    foreach (var modelContainer in m2unpackedPackage.GetModels())
                    {
                        Assert.IsNotNull(modelContainer.Model);
                        Assert.IsNotNull(modelContainer.AdditionalOptions);

                        // we should be able o unpack it
                        var modelXml = Encoding.UTF8.GetString(modelContainer.Model);

                        Assert.IsTrue(!string.IsNullOrEmpty(modelXml));

                        var m2model = SPMeta2Model.FromXML(modelXml);
                        Assert.IsNotNull(m2model);
                    }
                }

                if (service is SharePointPnPSolutionPackageService)
                {
                    var pnpPackage         = solutionPackage as SolutionPackageBase;
                    var pnpUnpackedPackage = unpackedSolutionPackage as SolutionPackageBase;

                    Assert.IsNotNull(pnpPackage);

                    Assert.IsNotNull(pnpPackage);
                    Assert.IsNotNull(pnpUnpackedPackage);

                    Assert.AreEqual(pnpPackage.GetModels().Count(), pnpUnpackedPackage.GetModels().Count());

                    foreach (var modelContainer in pnpUnpackedPackage.GetModels())
                    {
                        Assert.IsNotNull(modelContainer.Model);
                        Assert.IsNotNull(modelContainer.AdditionalOptions);
                    }
                }
            });
        }