Exemplo n.º 1
0
        public void LoadData()
        {
            try
            {
                //cleans store and index
                Progress("Cleaning", 0);
                store.Clean();
                index.Clean();

                Progress("Loading data...");
                this.resources = GetExampleData();

                var resarray = resources.ToArray();
                var rescount = resarray.Count();

                for (int x = 0; x <= rescount - 1; x++)
                {
                    //Thread.Sleep(1000);
                    var res = resarray[x];
                    Key key = res.ExtractKey();

                    if (res.Id != null && res.Id != "")
                    {

                        service.Put(key, res);
                    }
                    else
                    {
                        service.Create(key, res);
                    }

                    // Sending message:

                    var msg = new ImportProgressMessage
                    {
                        Message = "Importing " + res.ResourceType.ToString() + " " + res.Id + "...",
                        Progress = (int)(x + 1) * 100 / rescount
                    };

                    Clients.Caller.sendMessage(msg);
                }

                Progress("Import completed!", 100);
            }
            catch (Exception e)
            {
                Progress("Error: " + e.Message);
            }
        }
Exemplo n.º 2
0
        public void LoadData()
        {
            var messages = new StringBuilder();
            messages.AppendLine("Import completed!");
            try
            {
                //cleans store and index
                Progress("Clearing the database...", 0);
                fhirStore.Clean();
                fhirIndex.Clean();

                Progress("Loading examples data...", 5);
                this.resources = GetExampleData();

                var resarray = resources.ToArray();
                ResourceCount = resarray.Count();

                for (int x = 0; x <= ResourceCount - 1; x++)
                {
                    var res = resarray[x];
                    // Sending message:
                    var msg = Message("Importing " + res.ResourceType.ToString() + " " + res.Id + "...", x);
                    Clients.Caller.sendMessage(msg);

                    try
                    {
                        //Thread.Sleep(1000);
                        Key key = res.ExtractKey();

                        if (res.Id != null && res.Id != "")
                        {

                            fhirService.Put(key, res);
                        }
                        else
                        {
                            fhirService.Create(key, res);
                        }
                    }
                    catch (Exception e)
                    {
                        // Sending message:
                        var msgError = Message("ERROR Importing " + res.ResourceType.ToString() + " " + res.Id + "... ", x);
                        Clients.Caller.sendMessage(msg);
                        messages.AppendLine(msgError.Message + ": " + e.Message);
                    }


                }

                Progress(messages.ToString(), 100);
            }
            catch (Exception e)
            {
                Progress("Error: " + e.Message);
            }
        }