Exemplo n.º 1
0
        public IHttpActionResult Order(UnitEntry entry, int orderCount)
        {
            using (var repository = new UnitRepository())
            {
                var listOfUnitEntries = repository.GetAll();

                var client = GetWebClient(SERVICE_URL);
                var list   = client.Magazine.GetAllProducts();

                var magazineEntry = list.Where(l => (l.Name == entry.Name && l.Localization == MAGAZINE_LOCATION))
                                    .FirstOrDefault();
                var unitEntry = listOfUnitEntries.Where(l => l.Id == entry.Id).FirstOrDefault();

                if (magazineEntry != null && unitEntry != null)
                {
                    if (magazineEntry.Count >= orderCount)
                    {
                        repository.Update(unitEntry.Id, unitEntry.Count + orderCount, unitEntry.Price);
                        client.Magazine.ModifyMagazineProduct(magazineEntry.Id.GetValueOrDefault(), magazineEntry.Count.GetValueOrDefault() - orderCount);
                        return(Ok());
                    }
                }
            }

            return(BadRequest());
        }
Exemplo n.º 2
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='entry'>
 /// </param>
 /// <param name='orderCount'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> OrderAsync(this IOrder operations, UnitEntry entry, int orderCount, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.OrderWithHttpMessagesAsync(entry, orderCount, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemplo n.º 3
0
        public void SubscribeUnit(string sn, string plan, double ovenTemperature, string board, int seat)
        {
            if (_unitSet.FindAll(x => x.Sn == sn).Any())
            {
                throw new Exception(sn + " exists in current system.");
            }
            this.Log.Info(sn + "\t>>>>\t[Unit Pool]");

            var  driverType = FetchPlans.Inst(this._param.tbiesServer).GetDriverType(plan);
            Guid id         = dataService.CreateBiRecord(sn, driverType, plan, board, seat.ToString());
            var  entry      = new UnitEntry()
            {
                Id          = id,
                Sn          = sn,
                Plan        = plan,
                Board       = board,
                Seat        = seat,
                Cost        = 0,
                Comment     = "",
                State       = UnitState.READY,
                Result      = UnitResult.PASS,
                CreateTime  = DateTime.Now,
                CostCounter = DateTime.Now,
                ReadCounter = DateTime.Now,
                FinishTime  = DateTime.Now,
                OutSpec     = false,
                OutStart    = DateTime.Now,
            };

            _unitSet.Add(entry);
            DumpEntry(entry);
            _runList.Add(id);
            Utility.Dump(_targetFile, _runList);
            ProductsUpdate?.Invoke(this, null);
        }
Exemplo n.º 4
0
 public void SyncFromStore(IDatabaseService dataService)
 {
     this.dataService = dataService;
     foreach (var item in _runList)
     {
         string    target = Path.Combine(Utility.RunTimeDirectory, item.ToString());
         UnitEntry entry  = null;
         Utility.Load(target, out entry);
         _unitSet.Add(entry);
     }
     ProductsUpdate?.Invoke(this, null);
 }
Exemplo n.º 5
0
 public IHttpActionResult AddMagazineProduct(string name, int count, float Price)
 {
     using (var repository = new UnitRepository())
     {
         var entry = new UnitEntry();
         entry.Name  = name;
         entry.Count = count;
         entry.Price = Price;
         repository.Add(entry);
     }
     return(Ok());
 }
Exemplo n.º 6
0
 private void QuantityEntry_Completed(object sender, EventArgs e)
 {
     if (QuantityEntry.Text.Length.ToString() != string.Empty)
     {
         //Go to Unit
         singleItem.Quantity     = Convert.ToDouble(QuantityEntry.Text.ToString());
         QuantityEntry.IsEnabled = false;
         QuantityLabel.IsVisible = false;
         UnitEntry.IsVisible     = true;
         UnitEntry.Focus();
         UnitLabel.IsVisible = true;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Adds a UI element to scene based off <para>unit</para> data
        /// </summary>
        /// <param name="unit"></param>
        public GameObject CreateUnitEntry(IUnit unit)
        {
            UnitEntry unitEntryData = UnitEntry.CreateInstance(unit);

            GameObject unitEntryObject = Instantiate(unitEntryPrefab) as GameObject;

            unitEntryObject.transform.SetParent(unitListPanel.transform);
            unitEntryObject.transform.localRotation = Quaternion.identity;
            unitEntryObject.transform.localScale    = new Vector3(2, 1, .8f);

            unitEntryObject.GetComponent <UnitEntryDisplay>().unitEntry = unitEntryData;
            unitEntryObject.GetComponent <UnitEntryDisplay>().SetDisplay();
            unitEntryObject.GetComponent <ShowEntryModel>().Initialize(displayModelController.GetModel(unit.Role.Name), displayModelController.EnableModel);
            unitEntryObject.GetComponent <ShowEntryData>().Initialize(unit, displayDataController.SetData);
            unitEntryObject.GetComponent <SetActiveEntry>().Initialize(SetActiveEntry);

            return(unitEntryObject);
        }
Exemplo n.º 8
0
        private void OnTriggerEnter(Collider other)
        {
            var rb = other.GetComponent <Rigidbody>();

            if (rb == null)
            {
                return;
            }

            var entry = new UnitEntry
            {
                unit           = rb,
                gravityEnabled = rb.useGravity
            };

            _unitsInTrigger[other] = entry;
            rb.useGravity          = (other.transform.position.y >= this.gravityHeight);
        }
        protected override async Task OnAppearingAnimationEndAsync()
        {
            if (!IsAnimationEnabled)
            {
                return;
            }

            var translateLength = 400u;

            await Task.WhenAll(
                HabitEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                HabitEntry.FadeTo(1),
                DescriptionLabel.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                DescriptionLabel.FadeTo(1),
                DescriptionEditor.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                DescriptionEditor.FadeTo(1),
                StartPicker.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                StartPicker.FadeTo(1),
                EndPicker.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                EndPicker.FadeTo(1),
                AmountEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                AmountEntry.FadeTo(1),
                UnitEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                UnitEntry.FadeTo(1)

                //(new Func<Task>(async () =>
                //{
                //    await Task.Delay(300);
                //    await Task.WhenAll(
                //            //RememberCheckBox.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                //            //RememberCheckBox.FadeTo(1)
                //        );
                //}))()
                );

            await Task.WhenAll(
                EditButton.ScaleTo(1),
                EditButton.FadeTo(1),
                SaveButton.ScaleTo(1),
                SaveButton.FadeTo(1),
                DeleteButton.ScaleTo(1),
                DeleteButton.FadeTo(1)
                );
        }
Exemplo n.º 10
0
 public UnitEntryDisplay(UnitEntry a) : base(a.Id, a.Name, a.Count, a.Price)
 {
     Selected = false;
 }
Exemplo n.º 11
0
        /// <param name='entry'>
        /// </param>
        /// <param name='orderCount'>
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <object> > OrderWithHttpMessagesAsync(UnitEntry entry, int orderCount, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entry == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "entry");
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("entry", entry);
                tracingParameters.Add("orderCount", orderCount);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "Order", tracingParameters);
            }
            // Construct URL
            var           _baseUrl         = this.Client.BaseUri.AbsoluteUri;
            var           _url             = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/Order/Order").ToString();
            List <string> _queryParameters = new List <string>();

            _queryParameters.Add(string.Format("orderCount={0}", Uri.EscapeDataString(SafeJsonConvert.SerializeObject(orderCount, this.Client.SerializationSettings).Trim('"'))));
            if (_queryParameters.Count > 0)
            {
                _url += "?" + string.Join("&", _queryParameters);
            }
            // Create HTTP transport objects
            HttpRequestMessage  _httpRequest  = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("POST");
            _httpRequest.RequestUri = new Uri(_url);
            // Set Headers
            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (entry != null)
            {
                _requestContent      = SafeJsonConvert.SerializeObject(entry, this.Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Set Credentials
            if (this.Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 200)
            {
                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <object>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            // Deserialize Response
            if ((int)_statusCode == 200)
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                try
                {
                    _result.Body = SafeJsonConvert.DeserializeObject <object>(_responseContent, this.Client.DeserializationSettings);
                }
                catch (JsonException ex)
                {
                    _httpRequest.Dispose();
                    if (_httpResponse != null)
                    {
                        _httpResponse.Dispose();
                    }
                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
                }
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
Exemplo n.º 12
0
		/// <summary>
		/// Adds a unit to the group.
		/// </summary>
		/// <param name="unit">Unit to add to the group.</param>
		/// <returns>Unit result value.</returns>
		public UnitResult AddUnit(UnitEntry unit)
		{
			m_Units[unit.Name] = unit;
			return UnitResult.NoError;
		}
Exemplo n.º 13
0
        private void DumpEntry(UnitEntry entry)
        {
            string entryTarget = Path.Combine(Utility.RunTimeDirectory, entry.Id.ToString());

            Utility.Dump(entryTarget, entry);
        }
Exemplo n.º 14
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='entry'>
 /// </param>
 /// <param name='orderCount'>
 /// </param>
 public static object Order(this IOrder operations, UnitEntry entry, int orderCount)
 {
     return(Task.Factory.StartNew(s => ((IOrder)s).OrderAsync(entry, orderCount), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }