addVersion() public method

public addVersion ( string previousVersion, Node newNode ) : Node
previousVersion string
newNode Node
return Node
Beispiel #1
0
        public void Test2()
        {
            // Test case 2 - merge with conflicting edits
            var rootNode1 = new Node("docId","data",0);
            rootNode1.addVersion("data1",1);
            rootNode1.addVersion("data2",2);
            //Console.WriteLine(rootNode1.toString());

            var rootNode2 = new Node("docId2", "data",3);
            rootNode2.addVersion("data1",4);
            rootNode2.addVersion("rootnode2-data2",5);
            rootNode2.addVersion("rootnode2-data3",6);
            //Console.WriteLine(rootNode2.toString());

            List<Node> conflicts = rootNode1.merge(rootNode2);

            Console.WriteLine();
            Console.WriteLine("Conflicts");
            Console.WriteLine("=========");

            foreach (Node node in conflicts)
            {
                Console.WriteLine(node.rev_id);
            }

            Console.WriteLine();
            Console.WriteLine("Result");
            Console.WriteLine("======");

            //Console.WriteLine(rootNode1.toString());

            Console.WriteLine(new[] { 1, 2, 3 }.ToJson());
            Console.WriteLine(rootNode1.revision.ToJson<Dictionary<string, Node>>());
            //Console.WriteLine(rootNode1.ToString());
        }
Beispiel #2
0
        public static Node Parse(string json)
        {
            string tempStr = json.Split(',')[0];
            string docId   = tempStr.Split(':')[1];
            Node   newNode = new Node(docId);

            json = json.Split('[')[1];
            json = json.Split(']')[0];

            var nodeList    = json.Split('{');
            var versionList = new Dictionary <string, Dictionary <string, string> >();

            foreach (string node in nodeList)
            {
                if (node != "")
                {
                    var propertyList = node.Split(',');

                    var propList = new Dictionary <string, string>();

                    foreach (string property in propertyList)
                    {
                        string propStr = property.Split('}')[0];

                        string propName  = propStr.Split(':')[0];
                        string propValue = propStr.Split(':')[1];

                        propList.Add(propName, propValue);
                    }

                    versionList.Add(propList["version"], propList);
                    newNode.addVersion(propList["version"], propList["sequence"], propList["rev_id"]);
                }
            }

            return(newNode);
        }
Beispiel #3
0
        public static Node Parse(string json)
        {
            string tempStr= json.Split(',')[0];
            string docId = tempStr.Split(':')[1];
            Node newNode = new Node(docId);

            json = json.Split('[')[1];
            json = json.Split(']')[0];

            var nodeList = json.Split('{');
            var versionList = new Dictionary<string,Dictionary<string,string>>();

            foreach (string node in nodeList)
            {
                if (node != "")
                {
                    var propertyList = node.Split(',');

                    var propList = new Dictionary<string, string>();

                    foreach (string property in propertyList)
                    {
                        string propStr = property.Split('}')[0];

                        string propName = propStr.Split(':')[0];
                        string propValue = propStr.Split(':')[1];

                        propList.Add(propName, propValue);
                    }

                    versionList.Add(propList["version"], propList);
                    newNode.addVersion(propList["version"],propList["sequence"],propList["rev_id"]);
                }
            }

            return newNode;
        }