示例#1
0
        /**
         * This is taken from https://gist.github.com/afawcett/8dbfc0e1d8c43c982881.
         *
         * This method works on the principle that serializing and deserialising child records is supported
         *
         *   System.assertEquals(1, ((List<Master__c>)
         *    JSON.deserialize(
         *	    JSON.serialize(
         *         [select Id, Name,
         *            (select Id, Name from Children__r) from Master__c]), List<Master__c>.class))
         *               [0].Children__r.size());
         *
         * This method results internally in constructing this JSON, before deserialising it back into SObject's
         *
         *		[
         *		    {
         *		        "attributes": {
         *		            "type": "Master__c",
         *		            "url": "/services/data/v32.0/sobjects/Master__c/a0YG0000005Jn5uMAC"
         *		        },
         *		        "Name": "Fred",
         *		        "Id": "a0YG0000005Jn5uMAC",
         *		        "Children__r": {
         *		            "totalSize": 1,
         *		            "done": true,
         *		            "records": [
         *		                {
         *		                    "attributes": {
         *		                        "type": "Child__c",
         *		                        "url": "/services/data/v32.0/sobjects/Child__c/a0ZG0000006JGPAMA4"
         *		                    },
         *		                    "Name": "Bob",
         *		                    "Id": "a0ZG0000006JGPAMA4",
         *		                    "Master__c": "a0YG0000005Jn5uMAC"
         *		                }
         *		            ]
         *		        }
         *      ]
         */
        public static object makeRelationship(Type parentsType, List <SObject> parents, SObjectField relationshipField, List <List <SObject> > children)
        {
            // Find out more about this relationship...
            string relationshipFieldName = relationshipField.getDescribe().getName();
            DescribeSObjectResult           parentDescribe     = parents.getSObjectType().getDescribe();
            List <Schema.ChildRelationship> childRelationships = parentDescribe.getChildRelationships();
            string relationshipName = null;

            foreach (Schema.ChildRelationship childRelationship in childRelationships)
            {
                if (childRelationship.getField() == relationshipField)
                {
                    relationshipName = childRelationship.getRelationshipName();
                    break;
                }
            }

            // Stream the parsed JSON representation of the parent objects back out, injecting children as it goes
            JSONParser    parentsParser  = JSON.createParser(JSON.serialize(parents));
            JSONParser    childrenParser = JSON.createParser(JSON.serialize(children));
            JSONGenerator combinedOutput = JSON.createGenerator(false);

            streamTokens(parentsParser, combinedOutput, new InjectChildrenEventHandler(childrenParser, relationshipName, children));

            // Derserialise back into SObject list complete with children
            return(JSON.deserialize(combinedOutput.getAsString(), parentsType));
        }
示例#2
0
        public static void Main()
        {
            IDatabase db = new Database();

            //read from zip file & populate the database with more data + create updates pdf, xml & json files
            var reader = new ReadExcelFromZip();
            var movies = reader.SelectExcelFilesFromZip("../../../../Movies.zip");


            foreach (var movie in movies)
            {
                Console.WriteLine(movie.Name);
            }

            var import = new MoviesImportToSql();

            import.Import(movies);

            Console.WriteLine("Importing data from xml...");
            //Importing data from xml
            XmlImporter.ImportXml(db);

            //Console.WriteLine("Importing data to Mongo...");
            //Importing data to MongoDB
            //ImportToMongo.ImportToMongo.ImportData();

            Console.WriteLine("Generating xml files...");
            //Generating Xml file report
            var generateXMLFile = new XMLGenerator();

            generateXMLFile.Generate(db);

            Console.WriteLine("Generating json files...");
            //Generating Json file reports
            var generateJsonReports = new JSONGenerator();

            generateJsonReports.Generate(db);

            Console.WriteLine("Generating pdf reports...");
            //Generating Pdf fle reports
            var generatePdfReports = new PDFGenerator();

            generatePdfReports.Generate(db);

            Console.WriteLine("Sending data to MySql...");
            //Sending data to MySql
            var sendDataToMySQL = new MySqlManager();

            sendDataToMySQL.SendDataToMySql();

            Console.WriteLine("Exporting data from MySql to excel file...");
            //Exporting data from MySql to excel file
            var mySqlExcelExport = new MySqlManager();

            mySqlExcelExport.ExportDataFromMySql();
        }
示例#3
0
        /**
         * Utility function to stream tokens from a reader to a write, while providing a basic eventing model
         **/
        private static void streamTokens(JSONParser fromStream, JSONGenerator toStream, JSONParserEvents events)
        {
            int depth = 0;

            while (fromStream.nextToken() != null)
            {
                // Give event handler chance to inject
                if (events != null)
                {
                    events.nextToken(fromStream, depth, toStream);
                }

                // Forward to output stream
                JSONToken currentToken = fromStream.getCurrentToken();
                if (currentToken == JSONToken.START_ARRAY)
                {
                    toStream.writeStartArray();
                    depth++;
                }
                else if (currentToken == JSONToken.START_OBJECT)
                {
                    toStream.writeStartObject();
                    depth++;
                }
                else if (currentToken == JSONToken.FIELD_NAME)
                {
                    toStream.writeFieldName(fromStream.getCurrentName());
                }
                else if (currentToken == JSONToken.VALUE_STRING ||
                         currentToken == JSONToken.VALUE_FALSE ||
                         currentToken == JSONToken.VALUE_TRUE ||
                         currentToken == JSONToken.VALUE_NUMBER_FLOAT ||
                         currentToken == JSONToken.VALUE_NUMBER_INT)
                {
                    toStream.writeString(fromStream.getText());
                }
                else if (currentToken == JSONToken.END_OBJECT)
                {
                    toStream.writeEndObject();
                    depth--;
                }
                else if (currentToken == JSONToken.END_ARRAY)
                {
                    toStream.writeEndArray();
                    depth--;
                }

                // Don't continue to stream beyond the initial starting point
                if (depth == 0)
                {
                    break;
                }
            }
        }
示例#4
0
 public PPTSlide(SlidePart slidePart, int slideIndex, DefaultTextStyle defaultTextStyle, string fileName, SlideSize SlideSizes)
 {
     this.advanceAfterTime = -1;
     this.slideIndex       = slideIndex;
     this.fileName         = fileName;
     this.defaultTextStyle = defaultTextStyle;
     SlideLayoutPart       = slidePart.SlideLayoutPart;
     SetShapeNonVisualProperties(slidePart);
     SetSpecificProperties(slidePart);
     Id         = "s1s0";
     Transition = JSONGenerator.GenerateTransitionAnimationObject(slidePart.Slide.Transition);
     Animations = new List <IAnimation>();
     AddAnimations(slidePart.Slide.Timing, Animations, SlideSizes);
 }
示例#5
0
            public void nextToken(JSONParser fromStream, int depth, JSONGenerator toStream)
            {
                // Inject children?
                JSONToken currentToken = fromStream.getCurrentToken();

                if (depth == 2 && currentToken == JSONToken.END_OBJECT)
                {
                    toStream.writeFieldName(relationshipName);
                    toStream.writeStartObject();
                    toStream.writeNumberField("totalSize", children[childListIdx].size());
                    toStream.writeBooleanField("done", true);
                    toStream.writeFieldName("records");
                    streamTokens(childrenParser, toStream, null);
                    toStream.writeEndObject();
                    childListIdx++;
                }
            }
 public ActionResult DataSet(string type, long keyReference)
 {
     using (var activity = new RFDataSetsActivity(Context))
     {
         ViewBag.KeyReference = keyReference;
         ViewBag.Type         = type;
         var columnTypes     = new List <KeyValuePair <string, Type> >();
         var dataSetDocument = activity.GetDataSetDocument(keyReference);
         if (dataSetDocument != null)
         {
             ViewBag.Key         = String.Format("{0} / {1}", dataSetDocument.Key.FriendlyString(), dataSetDocument.Key.GetInstance());
             ViewBag.Data        = JSONGenerator.ExportToJSON(dataSetDocument.GetContent <IRFDataSet>(), columnTypes);
             ViewBag.ColumnTypes = columnTypes;
         }
         return(View());
     }
 }
示例#7
0
        public static void Main()
        {
            //var db = new MoviesDatabaseOfTeamSingaporeSlingEntities();
            //var employees = db.Employees
            //                .Where(e => e.FirstName == "Tom")
            //                .Select(n =>
            //                new
            //                {
            //                    FirstName = n.FirstName,
            //                    LastName = n.LastName,
            //                    Salary = n.Salary,
            //                    Movies = n.Movies.Select(m => m.Name).ToList(),
            //                    IsDirector = n.IsDirector
            //                }
            //                    )
            //                .ToList();

            //foreach (var employee in employees)
            //{
            //    Console.WriteLine("The actor {0} {1} has participated in this movies:", employee.FirstName, employee.LastName);
            //    foreach (var movie in employee.Movies)
            //    {
            //        Console.WriteLine(movie);
            //    }
            //}
            var db = new Database();

            //Generating Xml file report
            var generateXMLFile = new XMLGenerator();

            generateXMLFile.Generate(db);
            //Generating Json file reports
            var generateJsonReports = new JSONGenerator();

            generateJsonReports.Generate(db);
            //Generating Pdf fle reports
            var generatePdfReports = new PDFGenerator();

            generatePdfReports.Generate(db);

            //XMLImporter.ImportXML();
        }
示例#8
0
        public bool Handle(string report)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(report);

            XmlNode node     = doc.FirstChild;
            string  nodetype = node.Name;

            bool proceed = true;

            switch (nodetype)
            {
            case "start-run":
                OutputChannel.WriteLine(JSONGenerator.StartJudgement());
                break;

            case "start-suite":
                if (node.Attributes["type"].Value == "TestFixture")
                {
                    string tabName = node.Attributes["name"].Value;
                    OutputChannel.WriteLine(JSONGenerator.StartTab(tabName));
                }
                break;

            case "start-test":
                OutputChannel.WriteLine(JSONGenerator.StartContext());

                string testcaseDescription = node.Attributes["name"].Value;

                if (node.SelectNodes("stdin").Count == 0)
                {
                    OutputChannel.WriteLine(JSONGenerator.StartTestcase(testcaseDescription));
                }
                else
                {
                    OutputChannel.WriteLine(JSONGenerator.StartTestcase(node.SelectSingleNode("stdin").ChildNodes[0].Value.Trim()));
                }
                break;

            case "test-case":
                if (node.SelectNodes("assertions").Count == 0)     /* runtime error */
                {
                    string messagetext = node.SelectSingleNode("failure/message").ChildNodes[0].Value;
                    OutputChannel.WriteLine(JSONGenerator.AppendMessage(Format.PLAIN, messagetext));
                    OutputChannel.WriteLine(JSONGenerator.EscalateStatus(Status.RUNTIME_ERROR));
                    OutputChannel.WriteLine(JSONGenerator.CloseFailedTestcase());
                }
                else
                {
                    foreach (XmlNode assertion in node.SelectSingleNode("assertions"))
                    {
                        string testresult = assertion.Attributes["result"].Value;
                        string expected   = "";
                        string generated  = "";
                        string message    = "";
                        if (assertion.SelectNodes("actual").Count != 0 && assertion.SelectNodes("expected").Count != 0)
                        {
                            expected  = assertion.SelectSingleNode("expected").ChildNodes[0].Value.Trim();
                            generated = assertion.SelectSingleNode("actual").ChildNodes[0].Value.Trim();
                        }
                        if (assertion.SelectNodes("message").Count != 0)
                        {
                            message = assertion.SelectSingleNode("message").ChildNodes[0].Value.Trim();
                        }

                        if (generated != "" || expected != "" || message != "")
                        {
                            OutputChannel.WriteLine(JSONGenerator.StartTest(expected));
                            if (message.Length != 0)
                            {
                                OutputChannel.WriteLine(JSONGenerator.AppendMessage(Format.PLAIN, message));
                            }
                            OutputChannel.WriteLine(JSONGenerator.CloseTest(ResultMap[testresult], generated));
                        }
                    }
                    OutputChannel.WriteLine(JSONGenerator.CloseTestcase());
                }
                OutputChannel.WriteLine(JSONGenerator.CloseContext());
                break;

            case "test-suite":
                if (node.Attributes["type"].Value == "TestFixture")
                {
                    OutputChannel.WriteLine(JSONGenerator.CloseTab());
                }
                break;

            case "test-run":
                OutputChannel.WriteLine(JSONGenerator.CloseJudgement());
                proceed = false;
                break;
            }
            return(proceed);
        }
示例#9
0
        public void AddAnimations(OpenXmlCompositeElement element, List <IAnimation> resultList, SlideSize SlideSizes)
        {
            if (element == null)
            {
                return;
            }

            List <AnimateMotion> motions = new List <AnimateMotion>();
            IAnimation           animationForThisNode = null;

            if (element.GetType().Equals(typeof(CommonTimeNode)))
            {
                CommonTimeNode node = (CommonTimeNode)element;
                animationForThisNode = new JSONGenerator(this).getSimpleAnimationFromCommonTimeNodePreset(node, SlideSizes);

                if (animationForThisNode != null)
                {
                    resultList.Add(animationForThisNode);
                    //Check if object id is presented in animation list.
                    CheckAndSetAnimatableProperty(animationForThisNode.ObjectId);

                    if ((animationForThisNode.InnerAnimations == null ||
                         animationForThisNode.InnerAnimations.Count == 0) &&
                        animationForThisNode.IsItEntranceAnimation())
                    {
                        MakeShapeInvisible("s1s" + animationForThisNode.ObjectId);
                    }
                    else if (animationForThisNode.InnerAnimations != null)
                    {
                        foreach (IAnimation anAnimation in animationForThisNode.InnerAnimations)
                        {
                            if (anAnimation.IsItEntranceAnimation())
                            {
                                MakeShapeInvisible("s1s" + animationForThisNode.ObjectId);
                            }
                        }
                    }
                    return;
                }
                else
                {
                    /*
                     * Sometimes there are common time nodes without animations in them. They are used for grouping animations.
                     * Usually animations are grouped for timing purposes like adding delay to all, or start a group after another.
                     * It's a tree structure and here we try to follow it as much as possible. Later we will strip the unnecessary nodes
                     */

                    animationForThisNode = new SimpleAnimation();
                    if (node.NodeType != null)
                    {
                        ((SimpleAnimation)animationForThisNode).timingType = node.NodeType;
                    }
                    int delay = 0;
                    if (node.StartConditionList != null)
                    {
                        foreach (Condition cond in node.StartConditionList)
                        {
                            if (cond.Delay != null && "indefinite" != cond.Delay.Value && cond.Delay.HasValue)
                            {
                                delay = delay + int.Parse(cond.Delay.Value);
                            }
                        }
                    }
                    if (delay > 0)
                    {
                        animationForThisNode.Start = delay;
                    }
                }

                if (animationForThisNode != null)
                {
                    animationForThisNode.InnerAnimations = new List <IAnimation>();
                    resultList.Add(animationForThisNode);
                }
            }

            //Go recursive in the Open XML tree

            foreach (OpenXmlElement obj in element.ChildElements)
            {
                if (obj.GetType().IsSubclassOf(typeof(OpenXmlCompositeElement)))
                {
                    if (animationForThisNode == null)
                    {
                        AddAnimations((OpenXmlCompositeElement)obj, resultList, SlideSizes);
                    }
                    else
                    {
                        AddAnimations((OpenXmlCompositeElement)obj, animationForThisNode.InnerAnimations, SlideSizes);
                    }
                }
            }
        }