Using Backup/Restore feature

Feb 9, 2011 at 2:50 AM

This is my first attempt to do a Online backup/restore.

I've made a DomainService that receives a "WebFile" class, containing info and the bytes of a stream created by silverlight client to create some kind of CSV file on webserver

public class WebFile
    {

        [Key]
        public string FileName { get; set; }
        public int UserId { get; set; }
        public byte[] FileContent { get; set; }
        public bool IsCompressed { get; set; }

    }

 

At Silverlight Client, the method I use to create an instance of a webfile class is:

 

static void SaveTable()
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    //header
                    streamWriter.WriteLine("EntityStatus;Id;EstacionamentoId;DataCadastro;Status");
                    foreach (var tableKey in Global.LocalDbService.Database.Query<TabelaPreco, Guid>())
                    {
                        var tabelaPreco = tableKey.LazyValue.Value;
                        streamWriter.Write((int)tabelaPreco.EntityStatus + ";");
                        streamWriter.Write(tabelaPreco.Id + ";");
                        streamWriter.Write(tabelaPreco.EstacionamentoId + ";");
                        streamWriter.Write(tabelaPreco.DataCadastro + ";");
                        streamWriter.Write(tabelaPreco.Status);
                        streamWriter.WriteLine();
                    }
                    streamWriter.Flush();
                    var file = new WebFile
                                   {
                                       UserId = Global.UsuarioRegistradoId,
                                       IsCompressed = false,
                                       FileName = "01_TabelasPrecos_" + DateTime.Now.Ticks,
                                       FileContent = memoryStream.ToArray()
                                   };
                    RemoteSaveDomainContext.WebFiles.Add(file);
                }
            }

            RemoteSaveDomainContext.SubmitChanges(submit =>
                                                      {
                                                          if (submit.HasError)
                                                          {
                                                              HandleError(submit);
                                                              return;
                                                          }
                                                          Finish();
                                                      }, null);

        }

This is the method of the DomainService on the server project:

public void InsertFile(WebFile file)
        {

            if (ProcessFile(FileHandler.HandleFile(file)) >= 0)
            {
                //delete file after processing
            }
        }

the ProcessFile method writes the contents of the Webfile instance to the disk, and then iterate over the CSV, doing inserts/updates/deletes.

That's a boring work to do.

 

I would like to see if someone is using the new backup/restore feateure of sterling current version, and examples.