Example #1
0
 ///<summary>Returns true if Update(JobControl,JobControl) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(JobControl jobControl, JobControl oldJobControl)
 {
     if (jobControl.UserNum != oldJobControl.UserNum)
     {
         return(true);
     }
     if (jobControl.JobControlType != oldJobControl.JobControlType)
     {
         return(true);
     }
     if (jobControl.ControlData != oldJobControl.ControlData)
     {
         return(true);
     }
     if (jobControl.XPos != oldJobControl.XPos)
     {
         return(true);
     }
     if (jobControl.YPos != oldJobControl.YPos)
     {
         return(true);
     }
     if (jobControl.Width != oldJobControl.Width)
     {
         return(true);
     }
     if (jobControl.Height != oldJobControl.Height)
     {
         return(true);
     }
     return(false);
 }
Example #2
0
        ///<summary>Inserts one JobControl into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(JobControl jobControl, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                jobControl.JobControlNum = ReplicationServers.GetKey("jobcontrol", "JobControlNum");
            }
            string command = "INSERT INTO jobcontrol (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "JobControlNum,";
            }
            command += "UserNum,JobControlType,ControlData,XPos,YPos,Width,Height) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(jobControl.JobControlNum) + ",";
            }
            command +=
                POut.Long(jobControl.UserNum) + ","
                + POut.Int((int)jobControl.JobControlType) + ","
                + "'" + POut.String(jobControl.ControlData) + "',"
                + POut.Int(jobControl.XPos) + ","
                + POut.Int(jobControl.YPos) + ","
                + POut.Int(jobControl.Width) + ","
                + POut.Int(jobControl.Height) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                jobControl.JobControlNum = Db.NonQ(command, true, "JobControlNum", "jobControl");
            }
            return(jobControl.JobControlNum);
        }
        // When a manipulation that's a result of inertia begins, change the color of the
        // the object to reflect that inertia has taken over
        void OnManipulationInertiaStarting(object sender,
                                           ManipulationInertiaStartingEventArgs e)
        {
            JobControl jc = element as JobControl;

            jc.Highlight = new SolidColorBrush(Colors.Green);
        }
        // When a manipulation has finished, reset the color of the object
        // Plsce the Job in the correct column by setting its status
        void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            if (element is JobControl)
            {
                JobControl jc = element as JobControl;
                if (jc.DataContext is Job)
                {
                    Job j = jc.DataContext as Job;
                    jc.Highlight = new SolidColorBrush(Colors.DarkGray);

                    //need to determine which column it is over
                    Grid   g           = reference as Grid;
                    double width       = g.ActualWidth;
                    double columnWidth = width / 3;
                    if (e.Position.X < columnWidth)
                    {
                        Jobs.jobsViewModel.MoveJob(j, JobStatus.Backlog);
                    }
                    else if (e.Position.X < columnWidth * 2)
                    {
                        Jobs.jobsViewModel.MoveJob(j, JobStatus.WIP);
                    }
                    else
                    {
                        Jobs.jobsViewModel.MoveJob(j, JobStatus.Done);
                    }
                    g.Children.Remove(jc);
                }
            }
        }
Example #5
0
        public async Task DownloadAsync()
        {
            EventHandler <ProgressUpdatedEventArgs> eventHandler = (sender, e) =>
            {
                this.DownloadMessage  = e.Message;
                this.DownloadProgress = e.Progress;
            };

            try
            {
                this.ClientState = ClientState.PrepareDownload;
                _dataService.Progress.ProgressChanged += eventHandler;

                var selectedDatasets = this.GetSelectedDatasets().Select(dataset => dataset.Model).ToList();

                // security check
                var projectIds = selectedDatasets.Select(dataset => dataset.Parent.Parent.Id).Distinct();

                foreach (var projectId in projectIds)
                {
                    if (!Utilities.IsProjectAccessible(_userIdService.User, projectId, _databaseManager.Database))
                    {
                        throw new UnauthorizedAccessException($"The current user is not authorized to access project '{projectId}'.");
                    }
                }

                //
                var job = new ExportJob()
                {
                    Owner      = _userIdService.User.Identity.Name,
                    Parameters = this.ExportParameters
                };

                var exportJobService = _serviceProvider.GetRequiredService <JobService <ExportJob> >();

                _exportJobControl = exportJobService.AddJob(job, _dataService.Progress, (jobControl, cts) =>
                {
                    var task = _dataService.ExportDataAsync(this.ExportParameters,
                                                            selectedDatasets,
                                                            cts.Token);

                    return(task);
                });

                var downloadLink = await _exportJobControl.Task;

                if (!string.IsNullOrWhiteSpace(downloadLink))
                {
                    var fileName = downloadLink.Split("/").Last();
                    await _jsRuntime.FileSaveAs(fileName, downloadLink);
                }
            }
            finally
            {
                _dataService.Progress.ProgressChanged -= eventHandler;
                this.ClientState      = ClientState.Normal;
                this.DownloadMessage  = string.Empty;
                this.DownloadProgress = 0;
            }
        }
Example #6
0
 ///<summary>Inserts one JobControl into the database.  Returns the new priKey.</summary>
 public static long Insert(JobControl jobControl)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         jobControl.JobControlNum = DbHelper.GetNextOracleKey("jobcontrol", "JobControlNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(jobControl, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     jobControl.JobControlNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(jobControl, false));
     }
 }
Example #7
0
 public static string[] ListJobs(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         return(jobControl.ListJobs());
     }
 }
Example #8
0
 public static void CancelError(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         jobControl.CancelError();
     }
 }
Example #9
0
 public static string GetUserVarS(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] int no
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         return(jobControl.GetUserVarS(no));
     }
 }
Example #10
0
 public static string GetMasterJob(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] short taskNo = 0
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         return(jobControl.GetMasterJob(taskNo));
     }
 }
Example #11
0
 public static void Hold(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] bool hold = true
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         jobControl.Hold(hold);
     }
 }
Example #12
0
 public static void PutUserVarR(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] int no,
     [InputPin(PropertyMode = PropertyMode.Default)] double value
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         jobControl.PutUserVarR(no, value);
     }
 }
Example #13
0
 public static Tuple <string, int, int> GetCurJob(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] short taskNo = 0
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         var info = jobControl.GetCurJob(taskNo);
         return(Tuple.Create <string, int, int>(info.JobName, info.Step, info.Line));
     }
 }
Example #14
0
 public static void SetCurJob(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] string jobName,
     [InputPin(PropertyMode = PropertyMode.Default)] int line = 0
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         jobControl.SetCurJob(jobName, line);
     }
 }
Example #15
0
 public static void WaitForJobEnd(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] short taskNo      = 0,
     [InputPin(PropertyMode = PropertyMode.Default)] short timeSeconds = 1
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         jobControl.WaitForJobEnd(taskNo, timeSeconds);
     }
 }
Example #16
0
        private bool TryAddJob(JobControl <T> jobControl)
        {
            var result = _jobs.TryAdd(jobControl.Job.Id, jobControl);

            if (result)
            {
                this.RaisePropertyChanged("Jobs");
            }

            return(result);
        }
Example #17
0
 public async static Task StartJobAndWaitForEnd(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] string jobName,
     [InputPin(PropertyMode = PropertyMode.Default)] short taskNo = 0,
     CancellationToken cancel = default(CancellationToken)
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         await jobControl.StartJobAndWaitForEnd(jobName, taskNo, cancel);
     }
 }
Example #18
0
 public static void SetAlarm(
     [InputPin(PropertyMode = PropertyMode.Default, DefaultValue = DEFAULT_MOTOMAN_SDA10F_BASE_NAME)] string robotName,
     [InputPin(PropertyMode = PropertyMode.Default)] short code     = 8000,
     [InputPin(PropertyMode = PropertyMode.Default)] string message = "Application Alarm",
     [InputPin(PropertyMode = PropertyMode.Default)] byte subCode   = 0
     )
 {
     using (var jobControl = new JobControl(rosClient.GlobalNodeHandle, robotName))
     {
         jobControl.SetAlarm(code, message, subCode);
     }
 }
Example #19
0
        ///<summary>Updates one JobControl in the database.</summary>
        public static void Update(JobControl jobControl)
        {
            string command = "UPDATE jobcontrol SET "
                             + "UserNum       =  " + POut.Long(jobControl.UserNum) + ", "
                             + "JobControlType=  " + POut.Int((int)jobControl.JobControlType) + ", "
                             + "ControlData   = '" + POut.String(jobControl.ControlData) + "', "
                             + "XPos          =  " + POut.Int(jobControl.XPos) + ", "
                             + "YPos          =  " + POut.Int(jobControl.YPos) + ", "
                             + "Width         =  " + POut.Int(jobControl.Width) + ", "
                             + "Height        =  " + POut.Int(jobControl.Height) + " "
                             + "WHERE JobControlNum = " + POut.Long(jobControl.JobControlNum);

            Db.NonQ(command);
        }
Example #20
0
        public WorkerSummary(JobControl jobs)
        {
            InitializeComponent();
            panel1.Controls.Clear(); // they're just there for the designer
            panel1.Dock = DockStyle.Top;
            int width = panel1.Width;

            panel1.Dock     = DockStyle.None;
            panel1.Height   = 0;
            panel1.Width    = width;
            panel1.Location = new Point(0, 0);
            panel1.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            this.jobs       = jobs;
        }
Example #21
0
 ///<summary>Inserts one JobControl into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(JobControl jobControl)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(jobControl, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             jobControl.JobControlNum = DbHelper.GetNextOracleKey("jobcontrol", "JobControlNum");                  //Cacheless method
         }
         return(InsertNoCache(jobControl, true));
     }
 }
Example #22
0
        /// <exception cref="System.IO.IOException"/>
        public static JobControl CreateValueAggregatorJobs(string[] args, Type[] descriptors
                                                           )
        {
            JobControl  theControl    = new JobControl("ValueAggregatorJobs");
            AList <Job> dependingJobs = new AList <Job>();
            JobConf     aJobConf      = CreateValueAggregatorJob(args);

            if (descriptors != null)
            {
                SetAggregatorDescriptors(aJobConf, descriptors);
            }
            Job aJob = new Job(aJobConf, dependingJobs);

            theControl.AddJob(aJob);
            return(theControl);
        }
Example #23
0
        public WorkerSummary(JobControl jobs)
        {
            InitializeComponent();
            panel1.Controls.Clear(); // they're just there for the designer
            panel1.Dock = DockStyle.Top;
            int width = panel1.Width;

            panel1.Dock     = DockStyle.None;
            panel1.Height   = 0;
            panel1.Width    = width;
            panel1.Location = new Point(0, 0);
            panel1.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            Util.SetSize(this, MeGUI.Properties.Settings.Default.WorkerSummarySize, MeGUI.Properties.Settings.Default.WorkerSummaryWindowState);
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
            this.jobs = jobs;
        }
Example #24
0
        /// <exception cref="System.IO.IOException"/>
        public static JobControl CreateValueAggregatorJobs(string[] args, Type[] descriptors
                                                           )
        {
            JobControl            theControl    = new JobControl("ValueAggregatorJobs");
            AList <ControlledJob> dependingJobs = new AList <ControlledJob>();
            Configuration         conf          = new Configuration();

            if (descriptors != null)
            {
                conf = SetAggregatorDescriptors(descriptors);
            }
            Job           job  = CreateValueAggregatorJob(conf, args);
            ControlledJob cjob = new ControlledJob(job, dependingJobs);

            theControl.AddJob(cjob);
            return(theControl);
        }
Example #25
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <JobControl> TableToList(DataTable table)
        {
            List <JobControl> retVal = new List <JobControl>();
            JobControl        jobControl;

            foreach (DataRow row in table.Rows)
            {
                jobControl = new JobControl();
                jobControl.JobControlNum  = PIn.Long(row["JobControlNum"].ToString());
                jobControl.UserNum        = PIn.Long(row["UserNum"].ToString());
                jobControl.JobControlType = (OpenDentBusiness.JobControlType)PIn.Int(row["JobControlType"].ToString());
                jobControl.ControlData    = PIn.String(row["ControlData"].ToString());
                jobControl.XPos           = PIn.Int(row["XPos"].ToString());
                jobControl.YPos           = PIn.Int(row["YPos"].ToString());
                jobControl.Width          = PIn.Int(row["Width"].ToString());
                jobControl.Height         = PIn.Int(row["Height"].ToString());
                retVal.Add(jobControl);
            }
            return(retVal);
        }
Example #26
0
        public JobControl <T> AddJob(T job, Progress <ProgressUpdatedEventArgs> progress, Func <JobControl <T>, CancellationTokenSource, Task <string> > createTask)
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var jobControl = new JobControl <T>()
            {
                Start = DateTime.UtcNow,
                Job   = job,
                CancellationTokenSource = cancellationTokenSource,
            };

            var progressHandler = (EventHandler <ProgressUpdatedEventArgs>)((sender, e) =>
            {
                jobControl.OnProgressUpdated(e);
                this.RaisePropertyChanged("Jobs");
            });

            progress.ProgressChanged += progressHandler;
            jobControl.Task           = createTask(jobControl, cancellationTokenSource);

            Task.Run(async() =>
            {
                try
                {
                    await jobControl.Task;
                }
                finally
                {
                    jobControl.OnCompleted();
                    jobControl.ProgressUpdated -= progressHandler;
                    this.RaisePropertyChanged("Jobs");
                }
            });

            this.TryAddJob(jobControl);
            return(jobControl);
        }
Example #27
0
 public bool TryGetJob(Guid key, out JobControl <T> jobControl)
 {
     return(_jobs.TryGetValue(key, out jobControl));
 }
Example #28
0
        /// <summary>
        /// <para>POST api/job</para>
        /// <para></para>
        /// </summary>
        /// <param name="value">JobControl model object input</param>
        /// <returns>JSON GenericResponse indicating success or failure</returns>
        public GenericResponse Post([FromBody] JobControl value)
        {
            if (value == null)
            {
                return(GenericResponse.Failure("Invalid request"));
            }

            int       id     = value.JobId;
            string    option = value.Option;
            StoredJob job    = ProcessManager.GetJob(id);

            if (job == null)
            {
                return(GenericResponse.Failure("Job not stored"));
            }

            if (job.Completed)
            {
                return(GenericResponse.Failure("Job already completed"));
            }

            if (!job.Started)
            {
                return(GenericResponse.Failure("Job not started"));
            }

            if (option == "PAUSE")
            {
                Action c = delegate { job.Paused = true; }; //Pause the job here, if already paused do nothing
                c();
                return(GenericResponse.Success(value.JobId));
            }
            else if (option == "RESUME")
            {
                Action d = delegate { job.Paused = false; };
                d();
                return(GenericResponse.Success());
            }
            else if (option == "STOP")
            {
                Action e = delegate {
                    job.Stopped = true;
                    if (job.exeProcess != null && !job.exeProcess.HasExited)
                    {
                        job.exeProcess.Kill();
                    }
                };
                e();

                return(GenericResponse.Success());
            }
            else if (option == "RESTART")
            {
                Action f = delegate { job.Stopped = false; job.Paused = false; JobQueue.AddToQueue(job.Command, job.JobId); };
                f();

                return(GenericResponse.Success());
            }
            else
            {
                return(GenericResponse.Failure("Option does not exist"));
            }
        }
        // When a manipulation begins, change the color of the object to reflect
        // that a manipulation is in progress
        void OnManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            JobControl jc = element as JobControl;

            jc.Highlight = new SolidColorBrush(Colors.Red);
        }
Example #30
0
        ///<summary>Updates one JobControl in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(JobControl jobControl, JobControl oldJobControl)
        {
            string command = "";

            if (jobControl.UserNum != oldJobControl.UserNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserNum = " + POut.Long(jobControl.UserNum) + "";
            }
            if (jobControl.JobControlType != oldJobControl.JobControlType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "JobControlType = " + POut.Int((int)jobControl.JobControlType) + "";
            }
            if (jobControl.ControlData != oldJobControl.ControlData)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ControlData = '" + POut.String(jobControl.ControlData) + "'";
            }
            if (jobControl.XPos != oldJobControl.XPos)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "XPos = " + POut.Int(jobControl.XPos) + "";
            }
            if (jobControl.YPos != oldJobControl.YPos)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "YPos = " + POut.Int(jobControl.YPos) + "";
            }
            if (jobControl.Width != oldJobControl.Width)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Width = " + POut.Int(jobControl.Width) + "";
            }
            if (jobControl.Height != oldJobControl.Height)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Height = " + POut.Int(jobControl.Height) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE jobcontrol SET " + command
                      + " WHERE JobControlNum = " + POut.Long(jobControl.JobControlNum);
            Db.NonQ(command);
            return(true);
        }