Пример #1
0
 public void AddTask(Enums.TaskAction action)
 {
     using (var model = new FileQueueEntities(ConnectionString))
     {
         var newTask = new IndexerTask
         {
             Id = Guid.NewGuid(),
             Action = action.ToString(),
             DateTime = DateTime.Now,
             InstanceId = InstanceId
         };
         model.AddToIndexerTasks(newTask);
         model.SaveChanges();
     }
 }
Пример #2
0
 private Guid CreateNewInstance()
 {
     using (var model = new FileQueueEntities(ConnectionString))
     {
         var instance = new IndexerInstance {DateTime = DateTime.Now, Id = Guid.NewGuid()};
         model.AddToIndexerInstances(instance);
         model.SaveChanges();
         return instance.Id;
     }
 }
Пример #3
0
        private void IndexNext()
        {
            using (var model = new FileQueueEntities(ConnectionString))
            {

                Func<FileQueue, bool> filter = f => f.Status == Enums.IndexStatus.Queued.ToString()
                                                    & f.InstanceId == InstanceId;
                var filequeue = model.FileQueues.Where(filter).FirstOrDefault();
                if (filequeue == null) return;
                filequeue.Status =  IndexFile(filequeue);
                filequeue.Attempts = filequeue.Attempts + 1;
                model.SaveChanges();
            }
        }
Пример #4
0
        private void UploadNext()
        {
            using (var model = new FileQueueEntities(ConnectionString))
            {

                Func<FileQueue, bool> filter = f => f.Status == Enums.IndexStatus.DataSynced.ToString()
                                                    & f.InstanceId == InstanceId;
                var filequeue = model.FileQueues.Where(filter).FirstOrDefault();
                if (filequeue == null)
                {
                    //wait a second before checking again if none found yet.
                    Thread.Sleep(1000);
                    return;
                }
                try
                {
                    FTPfile("BIMXchange Content", filequeue.FilePath);
                    FTPfile(@"inetpub/wwwroot/CADworks BIMXchange/Images/FileImages", filequeue.FilePath.Replace(".rfa", ".gif"));
                    filequeue.Status = Enums.IndexStatus.ContentUploaded.ToString();
                }
                catch (Exception)
                {
                    filequeue.Status = Enums.IndexStatus.ContentUploadFailed.ToString();
                }

                model.SaveChanges();
            }
        }
Пример #5
0
 private bool CanIndex()
 {
     using (var model = new FileQueueEntities(ConnectionString))
     {
         Func<IndexerTask, bool> lastTask = t => t.InstanceId == InstanceId;
         var task = model.IndexerTasks.Where(lastTask).OrderByDescending(t => t.DateTime).FirstOrDefault();
         return task != null;
     }
 }
Пример #6
0
 private void UpdateGrid()
 {
     using (var jobModel = new FileQueueEntities(ConnectionString))
     {
         lblTimeStamp.Text = String.Format("Last Updated: {0}", DateTime.Now.ToShortTimeString());
         var files = jobModel.FileQueues.Where(f => f.InstanceId == InstanceId);
         var strSuccess = Enums.IndexStatus.Succeeded.ToString();
         var strDataFailed = Enums.IndexStatus.DataSyncFailed.ToString();
         var strUploadFailed = Enums.IndexStatus.ContentUploadFailed.ToString();
         var strQueued = Enums.IndexStatus.Queued.ToString();
         var strDataSynced = Enums.IndexStatus.DataSynced.ToString();
         var strUploadSuccess = Enums.IndexStatus.ContentUploaded.ToString();
         lblDataSynced.Text = String.Format("DataSynced: {0}", files.Count(f => f.Status == strDataSynced));
         lblFailed.Text = String.Format("Failed: {0}", files.Count(f => f.Status == strDataFailed
                                                                      || f.Status == strUploadFailed));
         lblQueued.Text = String.Format("Queued: {0}", files.Count(f => f.Status == strQueued));
         lblSynced.Text = String.Format("Success: {0}", files.Count(f => f.Status == strSuccess
             || f.Status == strUploadSuccess));
         dataGridView1.DataSource = files;
     }
 }
Пример #7
0
        private Guid GetLastInstanceID()
        {
            using (var model = new FileQueueEntities(ConnectionString))
            {

                Func<IndexerInstance, bool> lastInstance = i => i.Id != InstanceId;
                var last =
                    model.IndexerInstances.Where(lastInstance)
                        .OrderByDescending(i => i.DateTime)
                        .FirstOrDefault();
                if (last != null) return last.Id;
            }
            return Guid.NewGuid();
        }
Пример #8
0
 private bool DoesExistIncompleteRecords(Guid lastInstanceId)
 {
     using (var model = new FileQueueEntities(ConnectionString))
     {
         Func<FileQueue, bool> incomplete = f =>
                                            f.InstanceId == lastInstanceId &&
                                            (f.Status != Enums.IndexStatus.Succeeded.ToString()
                                             || f.Status != Enums.IndexStatus.ContentUploaded.ToString());
         var failed = model.FileQueues.Where(incomplete);
         return failed.Any();
     }
 }
Пример #9
0
        private void btnIndex_Click(object sender, EventArgs e)
        {
            var fldBrowser = new FolderBrowserDialog { Description = "Select Root Directory to Index (All Sub Folders will be indexed)" };
            var result = fldBrowser.ShowDialog();
            if (result == DialogResult.OK)
            {
                var paths = Directory.GetFiles(fldBrowser.SelectedPath, "*.rfa", SearchOption.AllDirectories);

                using (var jobModel = new FileQueueEntities(ConnectionString))
                {
                    var indexType = Enums.IndexType.Full;
                    if (rbNewOnly.Checked) indexType = Enums.IndexType.NewOnly;
                    if (rbNewAndVersion.Checked) indexType = Enums.IndexType.NewAndVersionUpdate;
                    var library = fldBrowser.RootFolder.ToString();
                    foreach (var filequeue in paths.Select(path =>
                                                           new FileQueue
                                                               {
                                                                   Id = Guid.NewGuid(),
                                                                   InstanceId = InstanceId,
                                                                   Library = library,
                                                                   FilePath = path,
                                                                   Attempts = 0,
                                                                   Status = Enums.IndexStatus.Queued.ToString(),
                                                                   RevitVersion = RevitVersion,
                                                                   IndexType = indexType.ToString(),
                                                                   AddedDateTime = DateTime.Now,
                                                                   FileName = path.Split('/')[path.Split('/').Count() -1]
                                                               }))
                    {
                        jobModel.AddObject("FileQueues", filequeue);
                        jobModel.SaveChanges();

                    }
                }
            }
        }
Пример #10
0
        public void ReQueueFailed(Guid lastInstanceId)
        {
            using (var model = new FileQueueEntities(ConnectionString))
            {

                Func<FileQueue, bool> incomplete = f =>
                                                  f.InstanceId == lastInstanceId &&
                                                  (f.Status != Enums.IndexStatus.Succeeded.ToString()
                                                   || f.Status != Enums.IndexStatus.ContentUploaded.ToString());
                var failed = model.FileQueues.Where(incomplete);
                foreach (var f in failed)
                {
                    f.Status = Enums.IndexStatus.Queued.ToString();
                    f.InstanceId = InstanceId;
                }
                model.SaveChanges();
            }
            UpdateGrid();
        }