예제 #1
0
        public void DoWork()
        {
            MasterProcess masterProcess = new MasterProcess();

            masterProcess.ProcessID = Master.CurrentProcess.Id;
            masterProcess.ID        = masterProcess.HostName + "=" + masterProcess.ProcessID;
            while (true)
            {
                try
                {
                    masterProcess.StartDateTime = DateTime.Now;
                    IdQuery <MasterProcess>       idQuery      = new IdQuery <MasterProcess>(Master.CurrentProcess.Id);
                    IChangeResult <MasterProcess> changeResult = Master.SpaceProxy.Change <MasterProcess>(idQuery, new ChangeSet().Set("LastUpdateDateTime", DateTime.Now).Lease(5000));
                    if (changeResult.NumberOfChangedEntries == 0)
                    {
                        WriteHeartBeat(masterProcess);
                    }
                    Thread.Sleep(timeout);
                }
                catch (Exception)
                {
                    // do nothing
                }
                Thread.Sleep(timeout);
            }
        }
예제 #2
0
 private void WriteHeartBeat(MasterProcess masterProcess)
 {
     masterProcess.HostName           = Master.HostName;
     masterProcess.ProcessID          = Master.CurrentProcess.Id;
     masterProcess.ID                 = masterProcess.HostName + "=" + masterProcess.ProcessID;
     masterProcess.StartDateTime      = DateTime.Now;
     masterProcess.LastUpdateDateTime = DateTime.Now;
     Master.SpaceProxy.Write(masterProcess, 5000);
 }
예제 #3
0
        public void DoWork()
        {
            MasterProcess masterProcess = new MasterProcess();

            masterProcess.HostName           = Master.HostName;
            masterProcess.ProcessID          = Master.CurrentProcess.Id;
            masterProcess.ID                 = masterProcess.HostName + "=" + masterProcess.ProcessID;
            masterProcess.StartDateTime      = DateTime.Now;
            masterProcess.LastUpdateDateTime = DateTime.Now;
            Master.SpaceProxy.Write(masterProcess, 5000);

            while (true)
            {
                masterProcess.StartDateTime = DateTime.Now;
                Master.SpaceProxy.Change(new IdQuery <MasterProcess>(masterProcess.ID), new ChangeSet().Set("LastUpdateDateTime", DateTime.Now).Lease(5000));
                Thread.Sleep(timeout);
            }
        }
예제 #4
0
 /// <summary>
 /// Fungsi UpdateMasterProcessOrder merupakan sebuah fungsi yang digunakan untuk mengupdate nilai Process Order pada sebuah product
 /// </summary>
 /// <param name="masterProcessList">merupakan list of object dari masterprocess yang merupakan daftar master process yang akan mengalami perubahan process order</param>
 /// <returns>mengembalikan json yang berisikin status dan pesan perubahan apakan berhasil atau tidak</returns>
 public ActionResult UpdateMasterProcessOrder(List <MasterProcess> masterProcessList)
 {
     try
     {
         var      username = User.Identity.Name;
         DateTime now      = DateTime.Now;
         foreach (MasterProcess item in masterProcessList)
         {
             MasterProcess masterProcess = db.MasterProcesses.Find(item.ID);
             masterProcess.ProcessOrder   = item.ProcessOrder;
             masterProcess.LastModified   = now;
             masterProcess.LastModifiedBy = username;
             db.SaveChanges();
         }
         return(Json(new { success = true, responseText = "Value successfully updated" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         ViewBag.Exception(ex);
     }
     return(View("Error"));
 }
예제 #5
0
        public ActionResult Create(int productID, MasterProcessViewModel masterProcess)
        {
            var masterProcessList = GetMasterProcessList(productID);

            ViewBag.ProcessGroupID = new SelectList(db.ProcessGroups, "ID", "Name");
            ViewBag.ProductID      = Convert.ToString(productID);
            var viewModel = new MasterProcessViewModel
            {
                MasterProcessCollections = masterProcessList
            };

            int currentProcessOrder = 1;

            if (masterProcessList.LastOrDefault() != null)
            {
                currentProcessOrder = Convert.ToInt32(masterProcessList.LastOrDefault().ProcessOrder) + 1;
            }

            try
            {
                var username = User.Identity.Name;

                Products currentProduct = db.Products.Find(productID);
                // TODO: Add master process
                var newMasterProcess = new MasterProcess
                {
                    ProductID      = productID,
                    ProcessGroupID = masterProcess.ProcessGroupID,
                    Name           = masterProcess.Name,
                    ProcessOrder   = currentProcessOrder,//masterProcess.ProcessOrder,
                    ManHour        = masterProcess.ManHour,
                    ManPower       = masterProcess.ManPower,
                    CycleTime      = masterProcess.CycleTime,
                    Created        = DateTime.Now,
                    CreatedBy      = username,
                    LastModified   = DateTime.Now,
                    LastModifiedBy = username
                };
                currentProduct.IsTotalDayCalculated = false;
                currentProduct.TotalDay             = currentProduct.TotalDay == null ? 0 : currentProduct.TotalDay;
                currentProduct.MasterProcess.Add(newMasterProcess);
                //db.MasterProcesses.Add(newMasterProcess);
                db.SaveChanges();

                #region Add Master Process Dependency
                //this region have function to add dependency of masterProcess
                var newMasterProcessId = newMasterProcess.ID;
                foreach (int processID in masterProcess.SelectedProcess)
                {
                    var newProcessDependency = new ProcessDependency
                    {
                        MasterProcessID      = newMasterProcessId,
                        PredecessorProcessID = processID,
                        Created        = DateTime.Now,
                        CreatedBy      = username,
                        LastModified   = DateTime.Now,
                        LastModifiedBy = username
                    };

                    db.ProcessDependencies.Add(newProcessDependency);
                }
                db.SaveChanges();
                #endregion

                ViewBag.Message = "Success";
                return(View(viewModel));
            }
            catch (Exception ex)
            {
                ViewBag.Exception = ex;
            }
            return(View("Error"));
        }
예제 #6
0
        // GET: MasterProcess/Delete/5
        /// <summary>
        /// Fungsi Delete merupakan sebuah fungsi yang digunakan untuk mengahapus data master process
        /// </summary>
        /// <param name="id">sebuah bilangan integer yang berarti id dari master process yang akan dihapus</param>
        /// <returns>jika berhasil akan diredirect kehalaman daftar master process namu jika tidak berhasil akan menampilkan halaman error </returns>
        public ActionResult Delete(int id)
        {
            MasterProcess masterProcessData     = db.MasterProcesses.Find(id);
            Products      productData           = masterProcessData.Products;
            var           processDependencyList = db.ProcessDependencies.Where(x => x.PredecessorProcessID == masterProcessData.ID).ToList();
            var           currentProcessOrder   = masterProcessData.ProcessOrder;

            ViewBag.ProductID = masterProcessData.ProductID.ToString();
            try
            {
                if (masterProcessData.Processes.Count() > 0)
                {
                    ViewBag.ErrorMessage = "Can't delete" + " " + masterProcessData.Name + " " + "because the process has been assigned ";
                    ViewBag.ProductID    = masterProcessData.ProductID.ToString();
                    return(View("Error"));
                }
                //else if (masterProcessData.ProcessDailySchedules.Count() > 0)
                //{
                //    ViewBag.ErrorMessage = "Can't delete" + " " + masterProcessData.Name + " " + "because the process has been assigned into process daily schedule ";
                //    ViewBag.ProductID = masterProcessData.ProductID.ToString();
                //    return View("Error");
                //}
                else if (processDependencyList.Count > 0)
                {
                    ViewBag.ErrorMessage = "Can't delete" + " " + masterProcessData.Name + " " + "because the process is being used as dependecy to another process";
                    ViewBag.ProductID    = masterProcessData.ProductID.ToString();
                    return(View("Error"));
                }
                else
                {
                    var nextProcessOrderList = db.MasterProcesses.Where(x => x.ProcessOrder > currentProcessOrder).ToList();
                    foreach (var nextProcess in nextProcessOrderList)
                    {
                        nextProcess.ProcessOrder = nextProcess.ProcessOrder - 1;
                    }

                    db.ProcessDailySchedules.RemoveRange(masterProcessData.ProcessDailySchedules);
                    db.ProcessDependencies.RemoveRange(masterProcessData.ProcessDependencies);
                    db.ProcessDependencies.RemoveRange(masterProcessData.PredecessorProcessDependencies);
                    db.MasterProcesses.Remove(masterProcessData);

                    if (db.SaveChanges() > 0)
                    {
                        if (productData.MasterProcess.Count() == 0)
                        {
                            productData.TotalDay = null;
                        }
                        else
                        {
                            productData.TotalDay = 0;
                        }
                        productData.IsTotalDayCalculated = false;
                        productData.LastModified         = DateTime.Now;
                        productData.LastModifiedBy       = User.Identity.Name;

                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Details", "Product", new { id = productData.ID }));
            }
            catch (Exception ex)
            {
                ViewBag.Exception = ex;
            }
            return(View("Error"));
        }