Ejemplo n.º 1
0
        private GridProteinFoldingEntities AddToContext(GridProteinFoldingEntities context,
                                                        Entities.Internal.Configuration entity, int count, int commitCount, bool recreateContext)
        {
            context.Set <Entities.Internal.Configuration>().Add(entity);

            if (count % commitCount == 0)
            {
                context.SaveChanges();
                if (recreateContext)
                {
                    context.Dispose();
                    context = new GridProteinFoldingEntities();
                    //context.Configuration.AutoDetectChangesEnabled = false;
                }
            }

            return(context);
        }
Ejemplo n.º 2
0
        public void LoadConfigurationOutPutForOrigin()
        {
            GICO.WriteLine(String.Format("  Output: LoadConfigurationOutPutToOrigin: Delete..."));
            ////Delete IF EXIST
            //using (GridProteinFoldingEntities ctx = new GridProteinFoldingEntities())
            //{
            //    ctx.Database.ExecuteSqlCommand("DELETE FROM OUTPUT WHERE guid= {0}", param.dataToProcess.Guid);
            //}

            string readerFile = dirBaseWeb.FullName() + this.param.dataToProcess.Guid + @"\Result\Configuration.dat";

            using (ExtendedStreamReader souceFile = new ExtendedStreamReader(readerFile,
                                                                             this.param.dataToProcess.Guid, false))
            {
                string line;
                int    i = 0;


                GICO.WriteLine(String.Format("  Output: LoadConfigurationOutPutToOrigin: Insert..."));
                while ((line = souceFile.ReadLine()) != null)
                {
                    if (String.IsNullOrEmpty(line))
                    {
                        break;
                    }

                    //pulas cabeçalho e o número de discartes
                    if (i == 0)
                    {
                        line = souceFile.ReadLine();
                    }

                    string[] data   = line.Split('\t').ToArray();
                    Int32    mcStep = 0;
                    int      order  = 0;
                    int      count  = 0;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        GridProteinFoldingEntities ctx = null;

                        try
                        {
                            ctx = new GridProteinFoldingEntities();
                            Entities.Internal.Configuration configuration = null;

                            for (int j = 0; j < data.Length; j++)
                            {
                                if (j == 0)
                                {
                                    mcStep = Convert.ToInt32(data[j]); j++;
                                }

                                configuration = new Entities.Internal.Configuration();

                                configuration.process_guid = this.param.dataToProcess.Guid;
                                configuration.mcStep       = mcStep;
                                configuration.order        = order;
                                configuration.x            = Convert.ToInt32(data[j]); j++;
                                configuration.y            = Convert.ToInt32(data[j]); j++;
                                configuration.z            = Convert.ToInt32(data[j]);

                                order++;

                                ++count;
                                ctx = AddToContext(ctx, configuration, count, 100, true);
                                //ctx.Configuration.Add(configuration);
                            }

                            if (configuration != null)
                            {
                                ctx.SaveChanges();
                                configuration = null;
                            }
                        }
                        finally
                        {
                            if (ctx != null)
                            {
                                ctx.Dispose();
                            }
                        }
                        scope.Complete();
                    }
                    i++;
                }


                souceFile.Close();
                //souceFile = null;
                souceFile.Dispose();
            }
        }