Esempio n. 1
0
        private void SaveItems(string domainName, string fileName)
        {
            long     writtenCount = 0;
            SdbTable table;

            if (SdbTable.TryCreate(ServiceId, ServiceSecret, domainName, false, null, false, out table))
            {
                long expectedCount;
                long sizeBytes;

                table.GetInfo(out expectedCount, out sizeBytes);

                using (FileStream stream = new FileStream(fileName, FileMode.Create))
                {
                    using (XmlWriter writer = XmlWriter.Create(stream))
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("Domain");

                        using (IReader reader = table.Select(new string[] { }, null))
                        {
                            writtenCount = WriteItems(expectedCount, writer, reader);
                        }
                    }
                }

                Console.WriteLine("{0} saved {1} items {2} bytes", Path.GetFullPath(fileName), writtenCount, new FileInfo(fileName).Length);
            }
            else
            {
                Console.WriteLine("Domain does not exist");
            }
        }
Esempio n. 2
0
 private void SelectItems(string selectExpression)
 {
     using (IReader reader = SdbTable.Select(ServiceId, ServiceSecret, selectExpression))
     {
         WriteItems(reader);
     }
 }
Esempio n. 3
0
        private void LoadItems(string domainName, string fileName)
        {
            long readCount = 0;

            using (FileStream stream = new FileStream(fileName, FileMode.Open))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    SdbTable table = SdbTable.Create(ServiceId, ServiceSecret, domainName);

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.LocalName == "Item")
                            {
                                int depth = reader.Depth;

                                if (reader.MoveToAttribute("Name"))
                                {
                                    string itemName = reader.Value;
                                    reader.MoveToElement();

                                    table.Put(itemName, w =>
                                    {
                                        while (reader.Read() && reader.Depth > depth)
                                        {
                                            if (reader.NodeType == XmlNodeType.Element &&
                                                !reader.IsEmptyElement)
                                            {
                                                string name = XmlConvert.DecodeName(reader.LocalName);

                                                if (reader.Read())
                                                {
                                                    string value = reader.ReadContentAsString();

                                                    if (!string.IsNullOrEmpty(value))
                                                    {
                                                        w.AddAttribute(name, value);
                                                    }
                                                }
                                            }
                                        }
                                    });

                                    readCount++;
                                    WriteProgress("Loaded {0} items", readCount);
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine("{0} loaded {1} items {2} bytes", Path.GetFullPath(fileName), readCount, new FileInfo(fileName).Length);
        }
Esempio n. 4
0
        private void DeleteDomain(string domainName)
        {
            SdbTable table;

            if (SdbTable.TryCreate(ServiceId, ServiceSecret, domainName, false, null, false, out table))
            {
                table.Delete();

                Console.WriteLine("Deleted {0} domain", domainName);
            }
            else
            {
                Console.WriteLine("Domain does not exist");
            }
        }
Esempio n. 5
0
        private void ListItems(string domainName)
        {
            SdbTable table;

            if (SdbTable.TryCreate(ServiceId, ServiceSecret, domainName, false, null, false, out table))
            {
                using (IReader reader = table.Select(new string[] { }, null))
                {
                    WriteItems(reader);
                }
            }
            else
            {
                Console.WriteLine("Domain does not exist");
            }
        }
Esempio n. 6
0
        private void DeleteDomains(string domainNamePrefix)
        {
            int deletedCount = 0;

            foreach (SdbTable table in SdbTable.ListTables(ServiceId, ServiceSecret))
            {
                if (table.Name.StartsWith(domainNamePrefix))
                {
                    table.Delete();

                    deletedCount++;
                }
            }

            Console.WriteLine("Deleted {0} domains", deletedCount);
        }
Esempio n. 7
0
        private void ListDomains()
        {
            PrettyConsole console = new PrettyConsole();

            console.AddColumn("Name", 64);
            console.AddColumn("ItemCount", 16);
            console.AddColumn("SizeBytes", 16);
            console.WriteHeader();

            foreach (SdbTable table in SdbTable.ListTables(ServiceId, ServiceSecret))
            {
                long itemCount;
                long sizeBytes;

                table.GetInfo(out itemCount, out sizeBytes);

                console.WriteLine(table.Name, itemCount, sizeBytes);
            }
        }
Esempio n. 8
0
        private void SelectAndSaveItems(string selectExpression, string fileName)
        {
            long writtenCount = 0;

            using (FileStream stream = new FileStream(fileName, FileMode.Create))
            {
                using (XmlWriter writer = XmlWriter.Create(stream))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("Domain");

                    using (IReader reader = SdbTable.Select(ServiceId, ServiceSecret, selectExpression))
                    {
                        writtenCount = WriteItems(-1, writer, reader);
                    }
                }
            }

            Console.WriteLine("{0} saved {1} items {2} bytes", Path.GetFullPath(fileName), writtenCount, new FileInfo(fileName).Length);
        }
Esempio n. 9
0
 protected override ITable CreateTable()
 {
     return(AmazonReliability.Execute(() => new ReliableSdbTable(SdbTable.Create(
                                                                     AmazonTest.ServiceId, AmazonTest.ServiceSecret,
                                                                     GetNextDomainName(), true, SelectLimit))));
 }
Esempio n. 10
0
 protected override ITable CreateTable()
 {
     return(AmazonReliability.Execute(() => new ReliableSdbTable(new DelayedTable(SdbTable.Create(
                                                                                      AmazonTest.ServiceId, AmazonTest.ServiceSecret,
                                                                                      GetNextDomainName(), false, SelectLimit), DelayMilliseconds))));
 }
Esempio n. 11
0
        private void CreateDomain(string domainName)
        {
            SdbTable.Create(ServiceId, ServiceSecret, domainName);

            Console.WriteLine("Created {0} domain", domainName);
        }