Ejemplo n.º 1
0
        private void UpdateDIObject <T>(T obj, string resourceXmlString, XDocument resourceXml, string name, string formatName, INotifier notifier)
        {
            Type   type    = typeof(T);
            string xml     = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);
            var    currXml = XDocument.Parse(xml);

            if (!XDocument.DeepEquals(currXml, resourceXml))
            {
                var browser = type.InvokeMember("Browser", BindingFlags.GetProperty | BindingFlags.Public, null, obj, null);
                browser.GetType().InvokeMember("ReadXml", BindingFlags.InvokeMethod | BindingFlags.Public,
                                               null, browser, new object[] { resourceXmlString, 0 });
                int ret = (int)type.InvokeMember("Update", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);
                if (ret != 0)
                {
                    string err;
                    company.GetLastError(out ret, out err);
                    string exceptionErr = String.Format(Messages.ErrorUpdatingDI, name, formatName, err);
                    Logger.Error(exceptionErr);
                    notifier.Do(x => x.OnError(resourceXml.ToString(), ret, err));
                    throw new Exception(exceptionErr);
                }
                else
                {
                    Logger.Info(String.Format(Messages.SuccessUpdatingDI, name, formatName));
                    notifier.Do(x => x.OnSuccess(resourceXml.ToString(), ""));
                }
            }
            else
            {
                Logger.Debug(DebugString.Format(Messages.UpdateDINotNecessary, name));
            }
        }
Ejemplo n.º 2
0
        private void UpdatePermission(UserPermissionTree userPermissionTree, Attribute.PermissionAttribute permissionAttribute)
        {
            var currPerm = XDocument.Parse(userPermissionTree.GetAsXML());

            userPermissionTree.PermissionID = permissionAttribute.PermissionID;
            userPermissionTree.Name         = permissionAttribute.Name;
            userPermissionTree.ParentID     = permissionAttribute.ParentID;
            userPermissionTree.UserPermissionForms.FormType = permissionAttribute.FormType;
            userPermissionTree.Options = permissionAttribute.Options;
            var attrPerm = XDocument.Parse(userPermissionTree.GetAsXML());

            if (!XDocument.DeepEquals(currPerm, attrPerm))
            {
                int ret = userPermissionTree.Update();
                if (ret != 0)
                {
                    string err;
                    company.GetLastError(out ret, out err);
                    string exceptionErr = String.Format(Messages.PermissionUpdateError, permissionAttribute.PermissionID, err);
                    Logger.Error(exceptionErr);
                }
                else
                {
                    Logger.Info(String.Format(Messages.PermissionUpdateSuccess, permissionAttribute.PermissionID));
                }
            }
        }
Ejemplo n.º 3
0
        private static Action <HttpResponseMessage> AssertContentNotEqual(XDocument content)
        {
            return(response =>
            {
                AssertContentExists(response);

                var actualContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

                try
                {
                    var actualXmlContent = XDocument.Parse(actualContent);

                    if (!XDocument.DeepEquals(content, actualXmlContent))
                    {
                        return;
                    }
                }
                catch (XmlException)
                {
                }

                var message = $@"Expected content to not be ""{content}""";

                throw new OmicronException(message);
            });
        }
Ejemplo n.º 4
0
        public void TestIdentityTransform()
        {
            var input     = GetInputDocument();
            var transform = GetIdentityTransformDocument();

            var output = new XdtTransformer().Transform(input, transform);

            Assert.IsTrue(XDocument.DeepEquals(input, output));
        }
Ejemplo n.º 5
0
        private bool compare(XDocument first, XDocument second)
        {
            bool result = (first == null && second == null);

            if (first != null && second != null)
            {
                result = XDocument.DeepEquals(first, second);
            }

            return(result);
        }
Ejemplo n.º 6
0
        public override bool RunTask()
        {
            string rawapk = "wearable_app.apk";
            string intermediateApkPath = Path.Combine(IntermediateOutputPath, "res", "raw", rawapk);
            string intermediateXmlFile = Path.Combine(IntermediateOutputPath, "res", "xml", "wearable_app_desc.xml");

            var doc             = XDocument.Load(WearAndroidManifestFile);
            var wearPackageName = AndroidAppManifest.CanonicalizePackageName(doc.Root.Attribute("package").Value);
            var modified        = new List <string> ();

            if (PackageName != wearPackageName)
            {
                Log.LogCodedError("XA5211", Properties.Resources.XA5211, wearPackageName, PackageName);
            }

            if (!File.Exists(WearApplicationApkPath))
            {
                Log.LogWarning("This application won't contain the paired Wear package because the Wear application package .apk is not created yet. If you are using MSBuild or XBuild, you have to invoke \"SignAndroidPackage\" target.");
                return(true);
            }

            var xml = string.Format(@"<wearableApp package=""{0}"">
  <versionCode>{1}</versionCode>
  <versionName>{2}</versionName>
  <rawPathResId>{3}</rawPathResId>
</wearableApp>
", wearPackageName, doc.Root.Attribute(androidNs + "versionCode").Value, doc.Root.Attribute(androidNs + "versionName").Value, Path.GetFileNameWithoutExtension(rawapk));

            if (MonoAndroidHelper.CopyIfChanged(WearApplicationApkPath, intermediateApkPath))
            {
                Log.LogDebugMessage("    Copied APK to {0}", intermediateApkPath);
                modified.Add(intermediateApkPath);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(intermediateXmlFile));
            if (!File.Exists(intermediateXmlFile) || !XDocument.DeepEquals(XDocument.Load(intermediateXmlFile), XDocument.Parse(xml)))
            {
                File.WriteAllText(intermediateXmlFile, xml);
                Log.LogDebugMessage("    Created additional resource as {0}", intermediateXmlFile);
                modified.Add(intermediateXmlFile);
            }
            WearableApplicationDescriptionFile = new TaskItem(intermediateXmlFile);
            WearableApplicationDescriptionFile.SetMetadata("_FlatFile", Monodroid.AndroidResource.CalculateAapt2FlatArchiveFileName(intermediateXmlFile));
            WearableApplicationDescriptionFile.SetMetadata("_ArchiveDirectory", AndroidLibraryFlatFilesDirectory);
            WearableApplicationDescriptionFile.SetMetadata("IsWearApplicationResource", "True");
            BundledWearApplicationApkResourceFile = new TaskItem(intermediateApkPath);
            BundledWearApplicationApkResourceFile.SetMetadata("_FlatFile", Monodroid.AndroidResource.CalculateAapt2FlatArchiveFileName(intermediateApkPath));
            BundledWearApplicationApkResourceFile.SetMetadata("_ArchiveDirectory", AndroidLibraryFlatFilesDirectory);
            BundledWearApplicationApkResourceFile.SetMetadata("IsWearApplicationResource", "True");
            ModifiedFiles = modified.ToArray();

            return(true);
        }
Ejemplo n.º 7
0
        public void TestIdentityTransform()
        {
            // supply an empty transform document

            var input = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"" />
                ");

            var output = new XdtTransformer().Transform(input, transform);

            Assert.IsTrue(XDocument.DeepEquals(input, output));
        }
Ejemplo n.º 8
0
        private List <int> ListMissingOrOutdatedKeysBOM(IBOM bom, bool update = false)
        {
            object     obj         = null;
            List <int> missingKeys = new List <int>();

            string xmlBom = bom.Serialize();

            company.XmlExportType = BoXmlExportTypes.xet_ExportImportMode;
            company.XMLAsString   = true;

            int length = company.GetXMLelementCount(xmlBom);

            for (int i = 0; i < length; i++)
            {
                Logger.Debug(DebugString.Format(Messages.StartListMissingBOMKeys, bom.BO[i].GetName()));
                Type type = bom.BO[i].GetBOClassType();
                try
                {
                    obj = company.GetBusinessObject(bom.BO[i].GetBOType());
                    var browser = type.InvokeMember("Browser", BindingFlags.GetProperty | BindingFlags.Public, null, obj, null);
                    browser.GetType().InvokeMember("ReadXml", BindingFlags.InvokeMethod | BindingFlags.Public,
                                                   null, browser, new object[] { xmlBom, i });
                    string   xml         = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);
                    var      resourceXml = XDocument.Parse(xml);
                    object[] keys        = GetKeys(obj, bom.BO[i].GetBOType(), bom.BO[i].GetKey());
                    bool     found       = (bool)type.InvokeMember("GetByKey", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, keys);
                    if (!found)
                    {
                        missingKeys.Add(i);
                    }
                    else if (update)
                    {
                        xml = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);
                        var currXml = XDocument.Parse(xml);
                        if (!XDocument.DeepEquals(currXml, resourceXml))
                        {
                            missingKeys.Add(i);
                        }
                    }
                }
                finally
                {
                    if (obj != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    }
                }
                Logger.Debug(DebugString.Format(Messages.EndListMissingBOMKeys, bom.BO[i].GetName()));
            }
            return(missingKeys);
        }
        public override bool Execute()
        {
            Log.LogDebugMessage("PrepareWearApplicationFiles task");
            Log.LogDebugTaskItems("  WearAndroidManifestFile:", WearAndroidManifestFile);
            Log.LogDebugTaskItems("  IntermediateOutputPath:", IntermediateOutputPath);
            Log.LogDebugTaskItems("  WearApplicationApkPath:", WearApplicationApkPath);

            string rawapk = "wearable_app.apk";
            string intermediateApkPath = Path.Combine(IntermediateOutputPath, "res", "raw", rawapk);
            string intermediateXmlFile = Path.Combine(IntermediateOutputPath, "res", "xml", "wearable_app_desc.xml");

            var doc             = XDocument.Load(WearAndroidManifestFile);
            var wearPackageName = AndroidAppManifest.CanonicalizePackageName(doc.Root.Attribute("package").Value);

            if (PackageName != wearPackageName)
            {
                Log.LogCodedError("XA5211", "Embedded wear app package name differs from handheld app package name ({0} != {1}).", wearPackageName, PackageName);
            }

            if (!File.Exists(WearApplicationApkPath))
            {
                Log.LogWarning("This application won't contain the paired Wear package because the Wear application package .apk is not created yet. If you are using MSBuild or XBuild, you have to invoke \"SignAndroidPackage\" target.");
                return(true);
            }

            var xml = string.Format(@"<wearableApp package=""{0}"">
  <versionCode>{1}</versionCode>
  <versionName>{2}</versionName>
  <rawPathResId>{3}</rawPathResId>
</wearableApp>
", wearPackageName, doc.Root.Attribute(androidNs + "versionCode").Value, doc.Root.Attribute(androidNs + "versionName").Value, Path.GetFileNameWithoutExtension(rawapk));

            MonoAndroidHelper.CopyIfChanged(WearApplicationApkPath, intermediateApkPath);

            Directory.CreateDirectory(Path.GetDirectoryName(intermediateXmlFile));
            if (!File.Exists(intermediateXmlFile) || !XDocument.DeepEquals(XDocument.Load(intermediateXmlFile), XDocument.Parse(xml)))
            {
                File.WriteAllText(intermediateXmlFile, xml);
                Log.LogDebugMessage("    Created additional resource as {0}", intermediateXmlFile);
            }
            WearableApplicationDescriptionFile = new TaskItem(intermediateXmlFile);
            WearableApplicationDescriptionFile.SetMetadata("IsWearApplicationResource", "True");
            BundledWearApplicationApkResourceFile = new TaskItem(intermediateApkPath);
            BundledWearApplicationApkResourceFile.SetMetadata("IsWearApplicationResource", "True");

            return(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Check if the file has changes compared to the original on disk.
        /// </summary>
        public static bool HasChanges(XDocument newFile, string path, ILogger log)
        {
            if (newFile == null)
            {
                // The file should be deleted if it is null.
                return(File.Exists(path));
            }
            else
            {
                var existing = ReadExisting(path, log);

                if (existing != null)
                {
                    return(!XDocument.DeepEquals(existing, newFile));
                }
            }

            return(true);
        }
Ejemplo n.º 11
0
        public void DirectedGraph_IsXmlSerialized_AsExpected()
        {
            var graph = new DirectedGraph();

            graph.Name     = "Sample Graph";
            graph.Vertices = new Vertice[] { new Vertice("1", "A"), new Vertice("2", "B") };
            graph.Edges    = new Edge[] { new Edge(graph.Vertices.First(), graph.Vertices.Last(), "V") };

            var serializer = new XmlSerializer(typeof(DirectedGraph), "http://schemas.microsoft.com/vs/2009/dgml");

            var writer = new StringWriter();

            serializer.Serialize(writer, graph);

            var actual   = XDocument.Parse(writer.ToString());
            var expected = XDocument.Load(Path.Combine(Environment.CurrentDirectory, Path.Combine("TestData", "SampleDgmlTest.dgml")));

            Assert.IsTrue(XDocument.DeepEquals(actual, expected));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Permette di verificare se l'oggetto passato, è uguale a ciò che mi ha permesso di generarlo
        /// </summary>
        public static void TestaUguaglianzaDocumentoOggetto(XDocument documentoCaricato, object oggettoSerializzato)
        {
            // Deserializzo l'oggetto appena serializzato per verificare che sia tutto uguale
            var documentoSerializzato = Util.CreateXmlFromObj(oggettoSerializzato);

            // Eseguo il test prima di procedere nel salvataggio per verificare che documento di
            // partenza e quello risultante dalla serializzazione dell'oggetto inizializzato siano uguali
            Tuple <XObject, XObject> result = documentoCaricato.DeepEquals(documentoSerializzato, XObjectComparisonOptions.Semantic);

            if (result != null)
            {
                throw new Exception("Conversion error. Exception: " + result);
            }

            result = documentoSerializzato.DeepEquals(documentoCaricato, XObjectComparisonOptions.Semantic);
            if (result != null)
            {
                throw new Exception("Conversion error. Exception: " + result);
            }
        }
Ejemplo n.º 13
0
        public static void TestSerializeExpression(
            TestContext testContext,
            Expression expression,
            string fileName,
            bool validate = true)
        {
            try
            {
                var expectedDoc = !string.IsNullOrWhiteSpace(fileName) ? XDocument.Load(fileName) : null;
                var expected    = expectedDoc != null?expectedDoc.ToString(SaveOptions.OmitDuplicateNamespaces) : "";

                testContext.WriteLine("EXPECTED:\n{0}\n", expected);

                var actualDoc = new XmlExpressionSerializer().ToXmlDocument(expression);
                var actual    = actualDoc.ToString(SaveOptions.OmitDuplicateNamespaces);

                testContext.WriteLine("ACTUAL:\n{0}\n", actual);

                if (validate)
                {
                    Assert.IsTrue(XmlValidator.Validate(expectedDoc, testContext));
                    Assert.IsTrue(XmlValidator.Validate(actualDoc, testContext));
                }
                Assert.IsTrue(
                    XDocument.DeepEquals(actualDoc, expectedDoc) ||
                    actual.Equals(expected));
            }
            catch (AssertFailedException)
            {
                throw;
            }
            catch (Exception x)
            {
                testContext.WriteLine("{0}", x.DumpString());
                throw;
            }
        }
Ejemplo n.º 14
0
        public void TestDefaultSame()
        {
            Tuple <XObject, XObject> result = _doc1.DeepEquals(_doc2);

            Assert.IsNull(result, $"{result}");
        }
Ejemplo n.º 15
0
        public void Verify_DbGeography_AsGml_method()
        {
            var gml = XDocument.Parse(spatialServices.GeographyFromText(PointWKT).AsGml());

            Assert.True(XDocument.DeepEquals(gml, GeographyPointGml));
        }