예제 #1
0
        public ActionResult UpdateDevice(Guid key, string ip)
        {
            _logger.LogDebug("Device attempts to update its address {0} for device key {1}.", ip, key);
            try
            {
                if (string.IsNullOrEmpty(ip))
                {
                    throw new ArgumentNullException("You must provide a valid IP address to this update routine.");
                }

                var deviceCriteria = UnitOfWorkSession.CreateCriteria <RemoteDevice>();
                deviceCriteria.Add(Expression.Eq("DeviceKey", key));

                var devices = deviceCriteria.List <RemoteDevice>();

                if (devices.Count() == 1)
                {
                    devices[0].LastOnline = DateTime.Now;
                    devices[0].Address    = ip;
                    GTSDataRepository.Update <RemoteDevice>(devices[0]);
                    _logger.LogInfo("Device address update for {0} is succesful: address {1}", devices[0].Name, devices[0].Address);
                }
                else
                {
                    throw new InvalidOperationException("Device not found or devices found with duplicate keys.");
                }

                return(new HttpStatusCodeResult(200));
            }
            catch (Exception)
            {
                _logger.LogError("Device adress update for key: {0} and address {1} failed.");
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Updates an order line.
        /// </summary>
        /// <param name="orderLineJSON">The order line json.</param>
        /// <returns></returns>
        public ActionResult UpdateOrderLine(string orderLineJSON)
        {
            _logger.LogInfo("User {0} attempts to update an order line in the shipping management interface.", User.Identity.Name);

            try
            {
                var orderLine = new JavaScriptSerializer().Deserialize <OrderLine>(orderLineJSON);

                var existingOrderLine = UnitOfWorkSession.CreateCriteria <OrderLine>()
                                        .Add(Expression.Eq("PickingBOM", orderLine.PickingBOM))
                                        .Add(Expression.Eq("OrderLineNr", orderLine.OrderLineNr)).List <OrderLine>().ToList().Single();

                // check if input was required but not given
                //if (string.IsNullOrEmpty(orderLine.FieldInput) && orderLine.InputRequirement == "SERIE")
                //    throw new InvalidOperationException(string.Format("The orderline {0} for BOM {1} expects input which wasn't provided.", orderLine.OrderLineNr, orderLine.PickingBOM));

                // check if part nr is associated with a product model
                var productModelBaseId = GetProductModelBaseIdByPartNumber(orderLine.PartNr);

                // check if an actual physical product exists
                var assembly = GTSDataRepository.GetByProductSerial <ProductAssembly>(orderLine.FieldInput, productModelBaseId);
                if (assembly == null)
                {
                    throw new InvalidOperationException("Could not find assembly with serial: " + orderLine.FieldInput);
                }

                // check if associated assembly has any remarks
                if (assembly.RemarkSymptoms.Where(remark => remark.Resolved == false).Count() > 0)
                {
                    throw new InvalidOperationException(string.Format("Assembly with serial {0} has open remarks and cannot be shipped", assembly.ProductSerial));
                }

                // check if associated assembly is "Delivered"
                if (assembly.ProductModelState.Name.ToLower() != "delivered")
                {
                    throw new InvalidOperationException(string.Format("Assembly with serial {0} does not have the state 'Delivered'", assembly.ProductSerial));
                }

                // update id and EditedBy
                existingOrderLine.FieldInput = orderLine.FieldInput;
                existingOrderLine.EditedBy   = User.Identity.Name;

                // update existing order line in the database
                GTSDataRepository.Update <OrderLine>(existingOrderLine);

                return(SerializeForWeb(orderLine));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Starts the stop shipping preparation.
        /// </summary>
        /// <param name="doStart">if set to <c>true</c> [do start].</param>
        /// <param name="bomNr">The bom nr.</param>
        /// <returns></returns>
        public ActionResult PersistAndStartStopShippingPreparation(bool doStart, string bomNr)
        {
            _logger.LogDebug("User {0} attempts to set the Shipping Preparation with Bom Nr {2}'s IsActive property to {1}.", User.Identity.Name, doStart, bomNr);
            try
            {
                var newGuid             = Guid.NewGuid();
                var shippingPreparation = UnitOfWorkSession.CreateCriteria <ShippingPreparation>()
                                          .Add(Expression.Eq("BOMNr", bomNr)).UniqueResult <ShippingPreparation>()
                                          ?? new ShippingPreparation // if retrieval fails, create a new shippingPreparation
                {
                    Id            = newGuid,
                    BOMNr         = bomNr,
                    EditedBy      = User.Identity.Name,
                    StartDateTime = DateTime.Now,
                };

                shippingPreparation.IsActive = doStart;

                if (newGuid == shippingPreparation.Id)
                {
                    _logger.LogInfo("Shipping preparation did not exist yet, creating new ShippingPreparation entity with id {0}", newGuid);
                    GTSDataRepository.Create <ShippingPreparation>(shippingPreparation);
                }
                else
                {
                    GTSDataRepository.Update <ShippingPreparation>(shippingPreparation);
                }

                _logger.LogInfo("User {0} has successfully set the Shipping Preparation with Bom Nr {2}'s IsActive property to {1}.", User.Identity.Name, doStart, bomNr);

                return(new HttpStatusCodeResult(200));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                throw;
            }
        }
예제 #4
0
        /// <summary>
        /// Updates an assembly.
        /// </summary>
        /// <param name="objectAsString">The object as a json string.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">
        /// No product serial was found in incoming device data.
        /// or
        /// Could not find product with serial: " + postData["productSerial"]
        /// or
        /// Data is corrupted: the system found more than one product with serial " + postData["productSerial"]
        /// or
        /// Could not find component assemblies for product with serial: " + postData["productSerial"]
        /// </exception>
        private ActionResult UpdateAssemblyParsed(string objectAsString)
        {
            _logger.LogInfo("Incoming data from a remote device: {0}", objectAsString);

            try
            {
                var postData = (Dictionary <string, object>) new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(objectAsString);

                if (postData["productSerial"] == null || string.IsNullOrEmpty(postData["productSerial"].ToString()))
                {
                    throw new InvalidOperationException("No product serial was found in incoming device data.");
                }

                var keyWords = postData.Keys.ToList().Where(x => x.ToString() != "productSerial" && x.ToString() != "baseModelId" && x.ToString() != "deviceKey").ToArray <string>();

                var doCreateRemark = false;
                if (postData["createRemark"].ToString().ToLower() == "true")
                {
                    doCreateRemark = true;
                }

                // check if product exists
                var productAssemblyCriteria = UnitOfWorkSession.CreateCriteria <ProductAssembly>();
                productAssemblyCriteria = productAssemblyCriteria.Add(Expression.Eq("ProductSerial", postData["productSerial"]));
                var productAssembly = productAssemblyCriteria.List <ProductAssembly>();
                if (productAssembly.Count() == 0)
                {
                    throw new InvalidOperationException("Could not find product with serial: " + postData["productSerial"]);
                }
                if (productAssembly.Count() > 1)
                {
                    throw new InvalidOperationException("Data is corrupted: the system found more than one product with serial " + postData["productSerial"]);
                }

                var componentAssemblyCriteria = UnitOfWorkSession.CreateCriteria <ComponentAssembly>();
                componentAssemblyCriteria = componentAssemblyCriteria.CreateAlias("ProductAssembly", "pa");
                componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pa.ProductSerial", postData["productSerial"]));
                componentAssemblyCriteria = componentAssemblyCriteria.CreateAlias("ProductComponent", "pc");
                componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.In("pc.DeviceKeyword", keyWords));
                componentAssemblyCriteria = componentAssemblyCriteria.CreateAlias("pc.ProductModel", "pm");
                componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pm.IsReleased", true));
                //componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pm.IsArchived", false));
                if (postData.Keys.Contains <string>("baseModelId"))
                {
                    componentAssemblyCriteria = componentAssemblyCriteria.Add(Expression.Eq("pm.BaseModelId", Guid.Parse(postData["baseModelId"].ToString())));
                }

                var filteredComponentAssemblies = componentAssemblyCriteria.List <ComponentAssembly>();

                if (filteredComponentAssemblies.Count() == 0)
                {
                    throw new InvalidOperationException("Could not find component assemblies for product with serial: " + postData["productSerial"]);
                }

                // find matching component assemblies for any device keywords in the post data
                keyWords.ToList().ForEach(x =>
                {
                    filteredComponentAssemblies.Where(y => y.ProductComponent.DeviceKeyword == x).ToList().ForEach(z =>
                    {
                        // update component assembly
                        if (postData[x] != null)
                        {
                            z.Revision = postData[x].ToString();
                            GTSDataRepository.Update <ComponentAssembly>(z);
                        }
                    });
                });

                // create remark when needed
                if (doCreateRemark)
                {
                    var remarkMessage = string.Format("Product with serial {0} failed its automated tests. Reasons given: ", postData["productSerial"].ToString());

                    if (productAssembly[0].ProductModel.Name.ToLower().Contains("wing"))
                    {
                        if (postData["deviceApproval"] != null && postData["deviceApproval"].ToString() == "no")
                        {
                            remarkMessage += "Product found to be invalid by wing checker tool, ";
                            if (postData["errorMessage"] != null)
                            {
                                remarkMessage += postData["errorMessage"].ToString();
                            }
                        }
                        if (postData["minmax"] != null && postData["minmax"].ToString() == "no")
                        {
                            remarkMessage += "User did not approve min and / or max, ";
                        }
                    }
                    else if (productAssembly[0].ProductModel.Name.ToLower().Contains("ux11 motor"))
                    {
                        if (!(bool)postData["userApproval"])
                        {
                            remarkMessage += "User disapproves (" + postData["disapprovalReason"].ToString() + "), ";
                        }
                        if (!(bool)postData["systemApprovalVoltage"])
                        {
                            remarkMessage += "Measured voltage does not conform to expectations, ";
                        }
                        if (!(bool)postData["systemApprovalCurrent"])
                        {
                            remarkMessage += "Measured current does not conform to expectations, ";
                        }
                        if (!(bool)postData["systemApprovalRPM"])
                        {
                            remarkMessage += "Measured rpm does not conform to expectations, ";
                        }
                        if (!(bool)postData["systemApprovalDirection"])
                        {
                            remarkMessage += "Measured direction of spin does not conform to expectations, ";
                        }
                    }

                    var newRemark = new RemarkSymptom
                    {
                        Id                = Guid.NewGuid(),
                        CreationDate      = DateTime.Now,
                        ResolutionDate    = DateTime.MaxValue,
                        Description       = remarkMessage,
                        ProductAssembly   = productAssembly[0],
                        EditedBy          = postData["user"].ToString(),
                        RemarkSymptomType = GTSDataRepository.GetListByQuery <RemarkSymptomType>("FROM RemarkSymptomType WHERE Name = '" + postData["remarkSymptomType"].ToString() + "'").FirstOrDefault(),
                    };

                    GTSDataRepository.Create <RemarkSymptom>(newRemark);
                }

                return(new HttpStatusCodeResult(200, "Data received"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);

                return(new HttpStatusCodeResult(500, ex.Message));
            }
        }