Example #1
0
        public void CreateItems()
        {
            int COUNT = 50;

            CatfishDbContext    db        = new CatfishDbContext();
            List <CFEntityType> itemTypes = db.EntityTypes.Where(t => t.TargetTypes.Contains(CFEntityType.eTarget.Items.ToString())).ToList(); //db.EntityTypes.Where(t => t.TargetType == EntityType.eTarget.Items).ToList();

            if (itemTypes.Count == 0)
            {
                throw new Exception("No entity types have been defined for collections.");
            }
            var         rand = new Random();
            ItemService srv  = new ItemService(db);

            for (int i = 0; i < COUNT; ++i)
            {
                CFEntityType cType = itemTypes[rand.Next(0, itemTypes.Count)];
                CFItem       c     = srv.CreateEntity <CFItem>(cType.Id);
                string       name  = TestData.LoremIpsum(5, 10);
                c.SetDescription(TestData.LoremIpsum(20, 100, 1, 10));
                c.SetName("Item: " + name);
                c.Serialize();
                db.Items.Add(c);
            }
            db.SaveChanges();
        }
Example #2
0
        private static void import(CatfishDbContext Db)
        {
            Console.InputEncoding = Encoding.UTF8;
            XElement file = XElement.Load(Console.OpenStandardInput());

            IngestionService srv = new IngestionService(Db);

            srv.Import(file);

            Db.SaveChanges();
        }
Example #3
0
        private static void import(CatfishDbContext Db)
        {
#if DEBUG
            Console.Error.WriteLine("Starting ingestion import...");
#endif

            Console.InputEncoding = Encoding.UTF8;

            IngestionService srv = new IngestionService(Db);
            srv.Import(Console.OpenStandardInput(), 4);

            Db.SaveChanges();
        }
Example #4
0
        private int ReIndexBucket(IEnumerable <int> bucket, string taskId)
        {
            int result = 0;

            using (CatfishDbContext db = new CatfishDbContext())
            {
                var SolrOperations = CommonServiceLocator.ServiceLocator.Current.GetInstance <SolrNet.ISolrOperations <Dictionary <string, object> > >();

                foreach (int aggregationId in bucket)
                {
                    CFAggregation aggregation = db.Aggregations.Find(aggregationId);
                    aggregation.RecalculateInheritedPermissions();
                    aggregation.Serialize();

                    if (aggregation.MappedGuid != aggregation.Guid)
                    {
                        aggregation.MappedGuid      = aggregation.Guid;
                        db.Entry(aggregation).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        // No need to update the entire model.
                        SolrOperations.Add(aggregation.ToSolrDictionary());
                    }

                    ++result;

                    try
                    {
                        ReIndexState.TaskProcessedCount[taskId] = result;
                    }
                    catch (KeyNotFoundException ex)
                    {
                        ReIndexState.TaskProcessedCount.Add(taskId, result);
                    }
                }

                try
                {
                    SolrOperations.Commit();
                    db.SaveChanges();
                }catch (Exception ex)
                {
                    ReIndexState.Errors.Add(string.Format("Error occured while saving data on task {2}: {0}\n{1}", ex.Message, ex.StackTrace, taskId));
                    result = 0;
                }
            }

            return(result);
        }
Example #5
0
        private void AddPublicUserListIfDoesNotExist()
        {
            // publicGuid guid is all 0
            Guid             publicGuid     = AccessContext.PublicAccessGuid;
            CatfishDbContext db             = new CatfishDbContext();
            CFUserList       publicUserList = db.UserLists.Where(x => x.Id == publicGuid).FirstOrDefault();

            if (publicUserList == null)
            {
                // Add public user list
                publicUserList      = new CFUserList();
                publicUserList.Id   = publicGuid;
                publicUserList.Name = "Public";
                db.UserLists.Add(publicUserList);
                db.SaveChanges();
            }
        }
Example #6
0
        static int CreateForm(Form form)
        {
            // TODO: We need to change these to a selenium method when possible.
            CatfishDbContext db = new CatfishDbContext();

            Catfish.Core.Contexts.AccessContext current = new AccessContext(AccessContext.PublicAccessGuid, true, db);
            AccessContext.current = current;

            SubmissionService formSrv = new SubmissionService(db);

            form.Serialize();

            int result = formSrv.SaveForm(form);

            db.SaveChanges();

            return(result);
        }
Example #7
0
        private void UpdateFileList(FormField field)
        {
            List <CFDataFile> filesList = new List <CFDataFile>();

            foreach (CFFileDescription fileDescription in field.Files)
            {
                string     fileGuid = fileDescription.Guid;
                CFDataFile file     = Db.XmlModels.Where(m => m.MappedGuid == fileGuid)
                                      .Select(m => m as CFDataFile)
                                      .FirstOrDefault();

                if (file != null)
                {
                    MoveFileToField(file, field);
                    fileDescription.DataFile = file;
                    Db.XmlModels.Remove(file);
                }
            }
            Db.SaveChanges();
        }