Exemple #1
0
        private void biMatchSelectedJob_Click(object sender, EventArgs e)
        {
            if (!MatchWarn())
            {
                return;
            }
            pbProgress.Visible  = true;
            lblProgress.Visible = true;
            DataGridViewRow row = GetSelectedRowFromCell(this.gridJobs);

            if (row != null)
            {
                JobsBO       jbo       = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));
                JobContainer container = jbo.FindByName(row.Cells[0].Value.ToString());
                if (container != null)
                {
                    SynchronizeBO bo = (SynchronizeBO)SingletonManager.GetSingleton(typeof(SynchronizeBO));
                    bo.aSynchronizeDirectory(
                        container.SourceDirectory,
                        container.SourceDirectory,
                        container.DestinationDirectory,
                        container.WatchSubDirectories,
                        true);
                    //RefreshFiles();
                }
            }
            else
            {
                MessageForm frm = new MessageForm();
                frm.Msg = "No job was selected, please select a job by click on its name and try again.";
                frm.ShowDialog();
            }
        }
Exemple #2
0
        private void SaveJob(DataGridView dgv, int rowIndex)
        {
            if (dgv.Rows.Count < rowIndex - 1)
            {
                return;
            }
            DataGridViewRow row = dgv.Rows[rowIndex];

            if (row.Cells[0].Value != null &&
                row.Cells[1].Value != null &&
                row.Cells[2].Value != null &&
                //row.Cells[3].Value != null &&
                row.Cells[0].Value.ToString().CompareTo("") != 0 &&
                row.Cells[1].Value.ToString().CompareTo("") != 0 &&
                row.Cells[2].Value.ToString().CompareTo("") != 0 /*&&
                                                                  * row.Cells[3].Value.ToString().CompareTo("") != 0*/)
            {
                //ok to save
                JobsBO       bo        = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));
                JobContainer container = bo.FindByName(row.Cells[0].Value.ToString());
                if (container == null)
                {
                    JobContainer container2 = new JobContainer();
                    container2.Name = row.Cells[0].Value.ToString();
                    bo.Add(container2);
                    container = bo.FindByName(row.Cells[0].Value.ToString());
                }
                container.SourceDirectory      = row.Cells[1].Value.ToString();
                container.DestinationDirectory = row.Cells[2].Value.ToString();
                container.WatchSubDirectories  = (bool)row.Cells[3].EditedFormattedValue;
                bo.Save();
            }
        }
Exemple #3
0
        private void RefreshFiles()
        {
            if (gridJobs.Rows.Count == 0)
            {
                dataGridView1.Rows.Clear();
                return;
            }
            DataGridViewRow row = GetSelectedRowFromCell(gridJobs);

            if (row == null || row.Cells[0].Value == null)
            {
                return;
            }
            lblLoadingFiles.Visible = true;
            JobsBO       bo        = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));
            JobContainer container = bo.FindByName(row.Cells[0].Value.ToString());

            if (container != null)
            {
                FileRefresher fr = new FileRefresher(container);
                fr.dataGridView1  = dataGridView1;
                fr.Finished      += new FileRefresherFinishedEventHandler(fr_Finished);
                LatestJobForFiles = container;
                fr.Run();
            }
        }
Exemple #4
0
        private void Delete()
        {
            QuestionForm frm = new QuestionForm();

            frm.Msg = "Delete this job?";
            if (frm.ShowDialog() == DialogResult.OK)
            {
                DataGridViewRow row = GetSelectedRowFromCell(gridJobs);
                if (row == null)
                {
                    return;
                }
                gridJobs.Rows.Remove(row);
                if (row.Cells[0].Value == null)
                {
                    //RefreshFiles();
                    ClearFiles();
                    return;
                }
                string       name      = row.Cells[0].Value.ToString();
                JobsBO       bo        = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));
                JobContainer container = bo.FindByName(name);
                if (container != null)
                {
                    bo.Delete(container);
                    bo.Save();
                    //RefreshFiles();
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// ロード
        /// </summary>
        /// <param name="sender">イベント発生元</param>
        /// <param name="e">イベント引数</param>
        private void SelectJobForm_Load(object sender, EventArgs e)
        {
            var jobs = this.JobFilter.Split(',');

            try
            {
                this.JobsCheckedListBox.SuspendLayout();

                this.JobsCheckedListBox.Items.Clear();
                foreach (var job in Jobs.List
                         .OrderBy(x => x.Role))
                {
                    if (job.ID != JobIDs.Unknown)
                    {
                        var jobId     = (int)job.ID;
                        var container = new JobContainer(job);
                        this.JobsCheckedListBox.Items.Add(
                            container,
                            jobs.Any(x => x == jobId.ToString()));

                        this.DummyCheckBox.Text = container.ToString();
                        if (this.DummyCheckBox.Width >
                            this.JobsCheckedListBox.ColumnWidth)
                        {
                            this.JobsCheckedListBox.ColumnWidth = (int)(this.DummyCheckBox.Width * 1.5d);
                        }
                    }
                }
            }
            finally
            {
                this.JobsCheckedListBox.ResumeLayout();
            }
        }
        public void Submit(Action <Action> job, Action completed)
        {
            JobContainer jc = new JobContainer(job, completed);

            m_jobs.Add(jc);
            jc.Run();
        }
Exemple #7
0
 public void Add(JobContainer container)
 {
     if (jContainer == null)
     {
         LoadJobs();
     }
     jContainer.Jobs.Add(container);
 }
Exemple #8
0
 public void Delete(JobContainer container)
 {
     if (jContainer == null)
     {
         LoadJobs();
     }
     jContainer.Jobs.Remove(container);
 }
Exemple #9
0
        private void Timer_Tick(object sender, System.Timers.ElapsedEventArgs args)
        {
            JobContainer jContainer  = this.wcontainer.Container;
            string       destination = SharedBO.CalculateDestination(
                jContainer.SourceDirectory, fullpath, jContainer.DestinationDirectory);                // Path.Combine(jContainer.DestinationDirectory, Path.GetFileName(this.fullpath));

            try {
                if (DoneTrying())
                {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "Attempted to copy file " + this.RetryCount + " times.", this.fullpath, destination));
                    this.QTimer.Stop();
                    this.OnFinished(EventArgs.Empty);
                }
                else
                {
                    if (!File.Exists(this.fullpath))
                    {
                        if (wcontainer.ChangeType == WatcherChangeTypes.Renamed)
                        {
                            string relativeOldDir = SharedBO.CalculateDestination(
                                wcontainer.OldFullPath,
                                jContainer.SourceDirectory,
                                jContainer.DestinationDirectory);
                            Directory.Move(relativeOldDir, destination);
                        }
                        else
                        {
                            if (!Directory.Exists(destination))
                            {
                                Directory.CreateDirectory(destination);
                            }
                        }

                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                    else
                    {
                        this.Copier.Copy(this.fullpath, destination, true);
                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                }
            }
            catch (System.IO.FileNotFoundException) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "File Not Found", this.fullpath, destination));
                this.QTimer.Stop();
                this.OnFinished(EventArgs.Empty);
            }
            catch (System.Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, ex.ToString(), this.fullpath, destination));
                this.RetryCount++;
            }
        }
        private void Watcher_Event(object sender, FileSystemEventArgs args)
        {
            string         dir        = Path.GetDirectoryName(args.FullPath);
            JobContainer   container  = AcquireJobContainerByDirectory(dir);         // (JobContainer)this.WatcherContainers[dir];
            WriteContainer wcontainer = new WriteContainer(container.SourceDirectory, container);

            try {
                if (WatcherChangeTypes.Deleted != args.ChangeType)
                {
                    this.ProcessFile(args.FullPath, wcontainer);
                }
                //TODO: Give users the option to copy a "delete" action
            }
            catch (Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
            }
        }
        private void Watcher_Renamed(object sender, RenamedEventArgs args)
        {
            string dir = Path.GetDirectoryName(args.FullPath);

            if (WatcherChangeTypes.Renamed == args.ChangeType)
            {
                //at this point the renamed item could be a directory
                try {
                    JobContainer   container  = AcquireJobContainerByDirectory(dir);                  //(JobContainer)this.WatcherContainers[dir];
                    WriteContainer wcontainer = new WriteContainer(container.SourceDirectory, container);
                    wcontainer.ChangeType  = args.ChangeType;
                    wcontainer.OldFullPath = args.OldFullPath;
                    this.ProcessFile(args.FullPath, wcontainer);
                }
                catch (Exception ex) {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
                }
            }
        }
 private void Update()
 {
     for (int i = m_jobs.Count - 1; i >= 0; --i)
     {
         JobContainer jc = m_jobs[i];
         lock (jc.Lock)
         {
             if (jc.IsCompleted)
             {
                 try
                 {
                     jc.RaiseCompleted();
                 }
                 finally
                 {
                     m_jobs.RemoveAt(i);
                 }
             }
         }
     }
 }
Exemple #13
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterWebApi(GlobalConfiguration.Configuration);

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            //debug模式下不启动系统自动运行的任务
            bool isDebugMode = Config.GetAppSetting <bool>("debugMode");

            if (isDebugMode == false)
            {
                ISchedulerFactory factory = new StdSchedulerFactory();
                scheduler = factory.GetScheduler();
                JobContainer.ExecuteJobs(scheduler);
                scheduler.Start();
            }

            //加入以下代码的目的是使API响应的内容类型(Content-Type)为xml/json
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        }
 /// <summary>
 /// 自动执行的系统任务测试
 /// </summary>
 /// <returns></returns>
 public ActionResult SystemTaskTest()
 {
     JobContainer.DebugJobs();
     return(View());
 }
Exemple #15
0
        internal static JobContainer ConvertToJobContainer(
            TemplateContext context,
            TemplateToken value,
            bool allowExpressions = false)
        {
            var result = new JobContainer();

            if (allowExpressions && value.Traverse().Any(x => x is ExpressionToken))
            {
                return(result);
            }

            if (value is StringToken containerLiteral)
            {
                if (String.IsNullOrEmpty(containerLiteral.Value))
                {
                    return(null);
                }

                result.Image = containerLiteral.Value;
            }
            else
            {
                var containerMapping = value.AssertMapping($"{PipelineTemplateConstants.Container}");
                foreach (var containerPropertyPair in containerMapping)
                {
                    var propertyName = containerPropertyPair.Key.AssertString($"{PipelineTemplateConstants.Container} key");

                    switch (propertyName.Value)
                    {
                    case PipelineTemplateConstants.Image:
                        result.Image = containerPropertyPair.Value.AssertString($"{PipelineTemplateConstants.Container} {propertyName}").Value;
                        break;

                    case PipelineTemplateConstants.Env:
                        var env     = containerPropertyPair.Value.AssertMapping($"{PipelineTemplateConstants.Container} {propertyName}");
                        var envDict = new Dictionary <String, String>(env.Count);
                        foreach (var envPair in env)
                        {
                            var envKey   = envPair.Key.ToString();
                            var envValue = envPair.Value.AssertString($"{PipelineTemplateConstants.Container} {propertyName} {envPair.Key.ToString()}").Value;
                            envDict.Add(envKey, envValue);
                        }
                        result.Environment = envDict;
                        break;

                    case PipelineTemplateConstants.Options:
                        result.Options = containerPropertyPair.Value.AssertString($"{PipelineTemplateConstants.Container} {propertyName}").Value;
                        break;

                    case PipelineTemplateConstants.Ports:
                        var ports    = containerPropertyPair.Value.AssertSequence($"{PipelineTemplateConstants.Container} {propertyName}");
                        var portList = new List <String>(ports.Count);
                        foreach (var portItem in ports)
                        {
                            var portString = portItem.AssertString($"{PipelineTemplateConstants.Container} {propertyName} {portItem.ToString()}").Value;
                            portList.Add(portString);
                        }
                        result.Ports = portList;
                        break;

                    case PipelineTemplateConstants.Volumes:
                        var volumes    = containerPropertyPair.Value.AssertSequence($"{PipelineTemplateConstants.Container} {propertyName}");
                        var volumeList = new List <String>(volumes.Count);
                        foreach (var volumeItem in volumes)
                        {
                            var volumeString = volumeItem.AssertString($"{PipelineTemplateConstants.Container} {propertyName} {volumeItem.ToString()}").Value;
                            volumeList.Add(volumeString);
                        }
                        result.Volumes = volumeList;
                        break;

                    case PipelineTemplateConstants.Credentials:
                        result.Credentials = ConvertToContainerCredentials(containerPropertyPair.Value);
                        break;

                    default:
                        propertyName.AssertUnexpectedValue($"{PipelineTemplateConstants.Container} key");
                        break;
                    }
                }
            }

            if (result.Image.StartsWith("docker://", StringComparison.Ordinal))
            {
                result.Image = result.Image.Substring("docker://".Length);
            }

            if (String.IsNullOrEmpty(result.Image))
            {
                context.Error(value, "Container image cannot be empty");
            }

            return(result);
        }
Exemple #16
0
 public FileRefresher(JobContainer jcon)
 {
     container = jcon;
 }
Exemple #17
0
 public FileRefresherFinishedEventArgs(List <DataGridViewRow> rows, JobContainer container)
 {
     Rows = rows; Container = container;
 }
Exemple #18
0
        private JobsContainer ReadJobs(string file)
        {
            JobsContainer container = new JobsContainer();
            XmlTextReader reader    = null;

            try {
                reader = new XmlTextReader(new StreamReader(file));
                JobContainer job         = null;
                bool         valuesAdded = false;
                while (!reader.EOF)
                {
                    reader.Read();
                    if (reader.IsStartElement())
                    {
                        if (reader.Name == "JobContainer")
                        {
                            if (job != null)
                            {
                                container.Jobs.Add(job);
                            }
                            job = new JobContainer();
                        }
                        else if (reader.Name == "WatchSubDirectories")
                        {
                            reader.MoveToContent();
                            reader.Read();
                            job.WatchSubDirectories = bool.Parse(reader.Value);
                            valuesAdded             = true;
                        }
                        else if (reader.Name == "SourceDirectory")
                        {
                            reader.MoveToContent();
                            reader.Read();
                            job.SourceDirectory = reader.Value;
                            valuesAdded         = true;
                        }
                        else if (reader.Name == "DestinationDirectory")
                        {
                            reader.MoveToContent();
                            reader.Read();
                            job.DestinationDirectory = reader.Value;
                            valuesAdded = true;
                        }
                        else if (reader.Name == "Name")
                        {
                            reader.MoveToContent();
                            reader.Read();
                            job.Name    = reader.Value;
                            valuesAdded = true;
                        }
                    }
                }
                if (valuesAdded)
                {
                    container.Jobs.Add(job);                              //add the final job that is never added because it has no job behind it
                }
                return(container);
            }
            catch {            //(Exception e){
                //System.Windows.Forms.MessageBox.Show(e.ToString());
                return(null);
            }
            finally { if (reader != null)
                      {
                          reader.Close();
                      }
            }
        }
Exemple #19
0
 private JobsContainer ReadJobs(string file)
 {
     JobsContainer container = new JobsContainer();
     XmlTextReader reader = null;
     try {
         reader = new XmlTextReader(new StreamReader(file));
         JobContainer job = null;
         bool valuesAdded = false;
         while (!reader.EOF) {
             reader.Read();
             if (reader.IsStartElement()) {
                 if (reader.Name == "JobContainer") {
                     if (job != null) container.Jobs.Add(job);
                     job = new JobContainer();
                 }
                 else if (reader.Name == "WatchSubDirectories") {
                     reader.MoveToContent();
                     reader.Read();
                     job.WatchSubDirectories = bool.Parse(reader.Value);
                     valuesAdded = true;
                 }
                 else if (reader.Name == "SourceDirectory") {
                     reader.MoveToContent();
                     reader.Read();
                     job.SourceDirectory = reader.Value;
                     valuesAdded = true;
                 }
                 else if (reader.Name == "DestinationDirectory") {
                     reader.MoveToContent();
                     reader.Read();
                     job.DestinationDirectory = reader.Value;
                     valuesAdded = true;
                 }
                 else if (reader.Name == "Name") {
                     reader.MoveToContent();
                     reader.Read();
                     job.Name = reader.Value;
                     valuesAdded = true;
                 }
             }
         }
         if (valuesAdded) container.Jobs.Add(job); //add the final job that is never added because it has no job behind it
         return container;
     }
     catch {//(Exception e){
         //System.Windows.Forms.MessageBox.Show(e.ToString());
         return null;
     }
     finally { if (reader != null) reader.Close(); }
 }
Exemple #20
0
 public void Delete(JobContainer container)
 {
     if (jContainer == null) LoadJobs();
     jContainer.Jobs.Remove(container);
 }
Exemple #21
0
 public void Add(JobContainer container)
 {
     if (jContainer == null) LoadJobs();
     jContainer.Jobs.Add(container);
 }