示例#1
0
 public Stream Job_Get(int? id)
 {
     using( DatabaseDataContext db = new DatabaseDataContext() )
     {
         return ToStream( XmlSerialize.ToXML( db.Job_GetBy( id, null, null, null, null, true ).Select( job => new JobDTO( job ) ).ToList(), ReturnType.Default, true ) );
     }
 }
示例#2
0
        //
        // GET: /Job/
        public ActionResult Index()
        {
            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                JobIndexViewModel jobIndex = new JobIndexViewModel();

                foreach( Job job in from jobsTbl in db.Jobs select jobsTbl )
                {
                    string totalProgress = XDocument.Parse( job.JobXML.ToString()).Root.Attribute("TotalProgress").Value;

                    if( totalProgress == "1" || totalProgress == "0" )
                        continue;

                    jobIndex.CurrentlyRunningJobs.Add( job );
                }

                int totalCount = db.Jobs.Count();

                foreach( var job in from jobsTbl in db.Jobs group jobsTbl by jobsTbl.Status into g select new { StatusType = g.Key, Count = g.Count() })
                {
                    jobIndex.JobStatisticsAggregates.Add(new JobStatisticsAggregate { StatusType = job.StatusType.Type, Count = job.Count, Percent = (double)job.Count / totalCount });
                }

                return View( jobIndex );
            }
        }
示例#3
0
 public IJobData GetJobByStatus(int status)
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         return (IJobData)db.Job_GetBy( null,
                                        status,
                                        null, null, null
                                       );
 }
示例#4
0
        public void SetUp()
        {
            _DB = new DatabaseDataContext();

            _DB.Test_CleanAndInsertDummyData(Regex.Replace(System.Environment.CurrentDirectory, "(src)(\\\\)(test)(\\\\)[\\w.-]+(\\\\)(bin)(\\\\)(Debug|Release)$", "bin\\plugins\\"));

            PluginLoader.Clear();
        }
示例#5
0
 public IList<IComputedJobData> Job_Get()
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         return (
             from job in db.Job_GetBy(null, null, null, null, null)
             select (IComputedJobData)job
             ).ToList();
 }
示例#6
0
 public IList<IComputedJobData> Job_Get(int? id, int? statusID, DateTime? createdDate, DateTime? lastModifiedDate)
 {
     using (DatabaseDataContext db = new DatabaseDataContext(OctopusConnectionString))
         return (
             from job in db.Job_GetBy(id, statusID, null, createdDate, true).ToList()
             select (IComputedJobData)job
             ).ToList();
 }
        public void Should_Add_Job_To_Database()
        {
            IJobData job =  AddJob(DTO.JobData.JobXML.ToString());

            using( DatabaseDataContext db = new DatabaseDataContext() )
                Assert.AreEqual(
                    db.Job_GetBy(job.ID, null, null, null, true).ToList().Count, 1
                    );
        }
示例#8
0
        public void SetUp()
        {
            _DB = new DatabaseDataContext();

            _DB.Test_CleanAndInsertDummyData(Regex.Replace(Environment.CurrentDirectory, "(src)(\\\\)(test)(\\\\)[\\w.-]+(\\\\)(bin)(\\\\)(Debug|Release)$", "bin\\plugins\\"));
            foreach (AssemblyInfo info in _DB.AssemblyInfo_Get(null, null, null, null, null, null, null, true))
            {
                PluginLoader.Add(info.Version + ", " + info.Name, info.ReadURL); // Add AssemblyIdentifier !!!!!!!!!!!!!!
            }
        }
示例#9
0
 public void Setup()
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
     {
         db.Test_CleanAndInsertDummyData(
             Regex.Replace(
                 System.Environment.CurrentDirectory,
                 "(src)(\\\\)(test)(\\\\)[\\w.-]+(\\\\)(bin)(\\\\)(Debug|Release)$",
                 "bin\\plugins\\"
                 )
             );
     }
 }
示例#10
0
        public void Should_Initialize_Agent_From_A_ID()
        {
            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                int          agentID = db.Agent_GetBy( null, null ).First().ID;
                IAgentEngine agent   = new AgentEngine(agentID);

                Assert.IsNotNull(agent.ExecutionManager);
                Assert.IsNotNull(agent.PluginManager);
                Assert.Greater(agent.ExecutionManager.Count, 0);
                Assert.Greater(agent.PluginManager.GetAllocationDefinitions().Count(), 0);
            }
        }
示例#11
0
        public IJobData AddJob(string jobXml)
        {
            // TODO: Validate jobXml

            // TODO: Add to database if valid
            XmlDocument xml = new XmlDocument();

            xml.LoadXml( jobXml );

            using( DatabaseDataContext db = new DatabaseDataContext() )
                return (IJobData)db.Job_Insert( 0,
                                                jobXml
                                              );
        }
示例#12
0
        public AgentEngine( int settingsID ):this(  )
        {
            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                foreach (var executionSlotData in db.ExecutionSlot_GetBy( null, settingsID, null, null ) )
                {
                    IAllocationDefinition definition = new AllocationDefinition(Convert.ToUInt32(executionSlotData.MaxSlots));

                    foreach (var pluginInfo in db.PluginInfo_GetBy(null, executionSlotData.ID, null, null, null, null, null, null, null, null))
                        definition.Add(pluginInfo);

                    AddDefinition( definition );
                }
            }
        }
示例#13
0
        public IComputedJobData Job_Create(int jobTemplateID, string xmldata)
        {
            using (DatabaseDataContext db = new DatabaseDataContext(OctopusConnectionString))
            {
                JobTemplate jobTemplate = db.JobTemplate_Get(jobTemplateID, null).Single();

                string templateUri = jobTemplate.JobTemplateUri;

                string templateXml = GetTemplateXml(templateUri);

                string jobXml = TransformXslt(
                    templateXml,
                    xmldata
                    );

                return (IComputedJobData)db.Job_Insert(null, jobXml).Single();
            }
        }
示例#14
0
        static void Main( string[] args )
        {
            if( args.Length != 3 )
            {
                System.Console.WriteLine( "[sourcePath] [searchFilter] [destinationPath]" );
                return;
            }

            source      = new DirectoryInfo( args[0] );
            Filter      = args[1];
            destination = new DirectoryInfo( args[2] );

            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                db.Test_InsertDemoData("\\Lib");

                foreach( FileInfo file in GetFiles( source ) )
                {
                    IJob  job   = new Job( );
                    IStep step1 = new Step();

                    CutVideoFramePlugin still = new CutVideoFramePlugin();
                    TranscodeTwoPassh264Plugin transcode = new TranscodeTwoPassh264Plugin();

                    still.SourceFilePath      = file.FullName;
                    still.DestinationFilePath = Path.Combine( destination.FullName, Path.Combine(file.Name, ".png") );

                    transcode.SourceFilePath      = file.FullName;
                    transcode.DestinationFilePath = Path.Combine(destination.FullName, file.Name);
                    transcode.VideoBitrate        = ( 1024 - 128 ) * 1024;
                    transcode.AudioBitrate        = 128 * 1024;

                    step1.Add(still);
                    step1.Add(transcode);

                    job.Add(step1);

                    System.Console.WriteLine( file.FullName + ", added");

                    db.Job_Insert(job.StatusID, job.JobXML.ToString());
                }
            }
        }
        public void TestOctopusTranscode()
        {
            using (DatabaseDataContext db = new DatabaseDataContext())
            {
                db.Test_InsertDemoData(Regex.Replace(Environment.CurrentDirectory, @"src\\(?:demo|test)\\(?:plugins\\)?[\w.\-]+\\bin\\(?:Debug|Release)$", "bin\\plugins\\"));

                using (IControllerEngine controllerEngine = new ControllerEngine(true))
                {
                    var job = new Job();
                    var step = new Step();

                    step.Add(CreatePlugin());
                    job.Add(step);

                    db.Job_Insert( job.StatusID, job.JobXML.ToString());

                    Timing.WaitUntil(() => db.Job_GetUnfinishedJobs().ToList().Count == 1, 10 * 1000, "Wait til job has been added");
                    Timing.WaitUntil(() => db.Job_GetUnfinishedJobs().ToList().Count == 0, 120 * 1000, "Wait til job has completed");
                }
            }
        }
示例#16
0
        public void Should_Get_Plugins_While_Obeying_The_Step_Flow_Rules()
        {
            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                // Load all assemblies
                foreach (AssemblyInfo info in db.AssemblyInfo_Get(null, null, null, null, null, null, null, true))
                {
                    PluginLoader.Add(info.Version + ", " + info.Name, info.ReadURL); // Add AssemblyIdentifier !!!!!!!!!!!!!!
                }
            }

            using (IJobManager mgr = new JobManager())
            {
                bool isSynced = false;
                mgr.SynchronizeOnce();
                mgr.SyncCompleted += (sender, eventArgs) => isSynced = true;

                Timing.WaitUntil(() => isSynced, 10000, "Wait til JobManager is synced");

                IList<IPlugin> firstRunnablePlugins = new List<IPlugin>();

                foreach (IJob job in mgr)
                {
                    foreach (IPlugin plugin in job.GetRunablePlugins())
                    {
                        firstRunnablePlugins.Add( plugin );
                        Assert.IsTrue(plugin.Status == PluginStatus.Initialized, "Not all firstRunnablePlugins are Queued, Status is: " + plugin.Status);
                    }
                }

                foreach( IPlugin plugin in firstRunnablePlugins )
                {
                    plugin.BeginExecute();
                }

                Assert.AreEqual(6, firstRunnablePlugins.Count, "first count");

                IList<IPlugin> secondRunnablePlugins = new List<IPlugin>();

                foreach (IJob job in mgr)
                {
                    foreach (IPlugin plugin in job.GetRunablePlugins())
                    {
                        secondRunnablePlugins.Add(plugin);
                        Assert.IsTrue(plugin.Status == PluginStatus.Initialized, "Not all secondRunnablePlugins are Queued, Status is: " + plugin.Status);
                    }
                }

                foreach( IPlugin plugin in secondRunnablePlugins )
                {
                    plugin.BeginExecute();
                }

                Assert.AreEqual(1, secondRunnablePlugins.Count, "second count");

                IList<IPlugin> thirdRunnablePlugins = new List<IPlugin>();

                foreach (IJob job in mgr)
                {
                    foreach (IPlugin plugin in job.GetRunablePlugins())
                    {
                        thirdRunnablePlugins.Add(plugin);
                        Assert.IsTrue(plugin.Status == PluginStatus.Initialized, "Not all thirdRunnablePlugins are Queued, Status is: " + plugin.Status);
                    }
                }

                foreach( IPlugin plugin in thirdRunnablePlugins )
                {
                    plugin.BeginExecute();
                }

                Assert.AreEqual(3, thirdRunnablePlugins.Count, "third count");

                IList<IPlugin> fourthRunnablePlugins = new List<IPlugin>();

                foreach (IJob job in mgr)
                {
                    foreach (IPlugin plugin in job.GetRunablePlugins())
                    {
                        fourthRunnablePlugins.Add(plugin);
                        Assert.IsTrue(plugin.Status == PluginStatus.Initialized, "Not all fourthRunnablePlugins are Queued, Status is: " + plugin.Status);
                    }
                }

                foreach( IPlugin plugin in fourthRunnablePlugins )
                {
                    plugin.BeginExecute();
                }

                Assert.AreEqual(1, fourthRunnablePlugins.Count, "fourth count");

                foreach (IJob job in mgr)
                {
                    foreach (IPlugin plugin in job.GetAllPlugins())
                    {
                        if (plugin.Status == PluginStatus.Initialized)
                            Assert.Fail("There should be no more runnable plugins");
                    }
                }
            }
        }
示例#17
0
 public IEnumerable<IJobData> GetJobs()
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         return db.Job_GetBy( null, null, null, null, true);
 }
示例#18
0
        public void Should_Sync_DB_With_InMemory_Collection()
        {
            using (DatabaseDataContext db = new DatabaseDataContext())
            {
                // Load all assemblies
                foreach (AssemblyInfo info in db.AssemblyInfo_Get(null, null, null, null, null, null, null, true))
                {
                    PluginLoader.Add(info.Version + ", " + info.Name, info.ReadURL); // Add AssemblyIdentifier !!!!!!!!!!!!!!
                }
            }

            using( IJobManager mgr = new JobManager() )
            {
                bool isSynced = false;
                mgr.SynchronizeOnce();
                mgr.SyncCompleted += (sender, eventArgs) => isSynced = true;

                Timing.WaitUntil(() => isSynced, 10000, "Wait til JobManager is synced");

                // Change the Jobs
                foreach (IJob engineJob in mgr)
                {
                    engineJob.StatusID = 1000;
                }

                isSynced = false;
                mgr.SynchronizeOnce();  // Resync, to make sure changes in the InMemory collection is syncronised as well.
                mgr.SyncCompleted += (sender, eventArgs) => isSynced = true;

                Timing.WaitUntil(() => isSynced, 10000, "Wait til JobManager is synced");

                _DB.Dispose();
                _DB = new DatabaseDataContext();

                int count = _DB.Job_GetUnfinishedJobs().ToList().Count;

                Assert.AreEqual(1, mgr.ToList().Count);

                // Check if all the in memory objects are in the DB, and has the correct values
                foreach (IJob engineJob in mgr)
                {
                    int currentCount = 0;

                    foreach (Data.Job job in _DB.Job_GetUnfinishedJobs().ToList())
                    {
                        currentCount++;

                        if( Compare( engineJob, job ) )
                            break;

                        if( currentCount == count )
                            Assert.Fail(job.ID + " didn't compare correctly");
                    }
                }
            }
        }
示例#19
0
        public void Should_Sync_With_DB()
        {
            using (DatabaseDataContext db = new DatabaseDataContext())
            {
                // TODO: Load all assemblies
                foreach (AssemblyInfo info in db.AssemblyInfo_Get(null, null, null, null, null, null, null, true))
                {
                    PluginLoader.Add(info.Version + ", " + info.Name, info.ReadURL); // Add AssemblyIdentifier !!!!!!!!!!!!!!
                }
            }

            using (IJobManager mgr = new JobManager())
            {
                bool isSynced = false;
                mgr.SynchronizeOnce();
                mgr.SyncCompleted += (sender, eventArgs) => isSynced = true;

                Timing.WaitUntil(() => isSynced, 10000, "Wait til JobManager is synced");

                foreach (Data.Job job in _DB.Job_GetUnfinishedJobs())
                {
                    if (!mgr.ContainsKey(job.ID))
                        Assert.Fail();
                }
            }
        }
示例#20
0
 public void TearDown()
 {
     using( DatabaseDataContext db = new DatabaseDataContext() )
         db.Test_Clean();
 }
示例#21
0
 public IComputedJobData Job_GetByID(int id)
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         return (IComputedJobData)db.Job_GetBy(id, null, null, null, null);
 }
示例#22
0
        private IList<IJob> SyncDBWithInMemoryCollection( )
        {
            
            IList<IJob> deleteJobs   = new List<IJob>();
            IList<IJob> currentQueue = new List<IJob>();

            lock( JobQueue )
            {
                foreach( IJob job in JobQueue )
                {
                    currentQueue.Add( job );

                    if( job.CurrentCommand == JobCommand.None )
                        deleteJobs.Add(job);
                }
            }

            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
            	var jobsStatus = new List<uint>{0, 0, 0, 0, 0};
				var jobsTotalProgress = 0d;

                foreach( IJob job in currentQueue )
                {
                	jobsStatus[(int)job.CurrentCommand]++;
					jobsTotalProgress += job.TotalProgress;

                    db.Job_Update(job); // Slows down the Lock, if inside!
                }

            	Trace.Write(
            		string.Format(
						"Thread: {0}\tTotal: {1}({2})\tExecute: {3}\tCommit: {4}\tRollback: {5}\tFinalize: {6}\tNone: {7}\n",
            			Thread.CurrentThread.ManagedThreadId, currentQueue.Count,
											(currentQueue.Count == 0 ? 0 : jobsTotalProgress / currentQueue.Count).ToString("F"),
            								jobsStatus[(int) JobCommand.Execute],
											jobsStatus[(int)JobCommand.Commit],
											jobsStatus[(int)JobCommand.Rollback],
											jobsStatus[(int)JobCommand.Finalize],
											jobsStatus[(int)JobCommand.None]));
            }

            return deleteJobs;
        }
示例#23
0
 public void Should_Get_All_Jobs()
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         Assert.Greater(GetJobs().Count, 0);
 }
示例#24
0
		private IList<IJob> SyncInMemoryCollectionWithDB()
        {
            IList<IJob> addedJobs = new List<IJob>();

			using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                foreach( Data.Job job in db.Job_GetUnfinishedJobs() )
                {
                    if( ContainsKey( job.ID ) ) 
                        continue;

					addedJobs.Add( new Job( job ) );
                }
            }

            return addedJobs;
        }
示例#25
0
        private void UpdateWatchFolders()
        {
            if( WatchFolders == null )
                WatchFolders = new Dictionary<FileSystemWatcher, WatchFolder>();

            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                foreach( WatchFolder watchFolder in db.WatchFolder_Get( null, null ) )
                {
                    if( IsWatchfolderAlreadyAddedAndUnchanged( watchFolder ) )
                        continue;

                    FileSystemWatcher watcher = GetWatchfolder( watchFolder.ID );

                    if( WatchFolders.ContainsKey( watcher ) )
                        WatchFolders[ watcher ] = watchFolder;
                    else
                        WatchFolders.Add( watcher, watchFolder );

                    watcher.InternalBufferSize  = 32 * 1024;
                    watcher.Filter              = watchFolder.Filter;
                    watcher.Path                = watchFolder.Destination.WriteURL;
                    watcher.EnableRaisingEvents = watchFolder.IsEnabled;                    
                }
            }
        }
示例#26
0
        private void InitializeAgents()
        {
            using( var db = new DatabaseDataContext() )
            {
                foreach( var agentData in db.Agent_GetBy(null,null) )
                    Broker.Add( new AgentEngine( agentData.ID ) );

                PluginLoader.Clear();

                foreach( AssemblyInfo info in db.AssemblyInfo_Get( null, null, null, null, null, null, null, true ) )
                {
                    if( !PluginLoader.IsAssemblyLoaded( info.Version + ", " + info.Name ) )
                        PluginLoader.Add( info.Version + ", " + info.Name, info.ReadURL ); // Add AssemblyIdentifier !!!!!!!!!!!!!!
                }
            }
        }
示例#27
0
 public void AddJob( int? statusID, string jobXML )
 {
     using( DatabaseDataContext db = new DatabaseDataContext() )
     {
         db.Job_Insert( statusID, jobXML );
     }
 }
示例#28
0
 public IJobData GetJobByID(int id)
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         return (IJobData)db.Job_GetBy( id, null, null, null, null );
 }
示例#29
0
 public IEnumerable<IJobData> GetUnfinishedJobs()
 {
     using (DatabaseDataContext db = new DatabaseDataContext())
         return db.Job_GetUnfinishedJobs();
 }
示例#30
0
 public IComputedJobData Job_Create(string jobXml)
 {
     using (DatabaseDataContext db = new DatabaseDataContext(OctopusConnectionString))
         return (IComputedJobData)db.Job_Insert(null, jobXml).Single();
 }