Beispiel #1
0
    public static void Main()
    {
        //string json = string.Format("{{'TableDefId':{0},'CheckId':{1}}}",2,101);
        //Console.WriteLine(json);
        var model = new StuffModel()
        {
            Finished = false,
            Name     = "Guido"
        };

        Console.WriteLine(model.ToString());

        var machine = new Machine();

        ThreadPool.QueueUserWorkItem(new WaitCallback(machine.DoStuff), model);

        Stopwatch s = new Stopwatch();

        s.Start();
        while (s.ElapsedMilliseconds < 10000 && !model.Finished)
        {
            //Thread.Sleep(1);
            Console.WriteLine(model.ToString());
        }
        Console.WriteLine(model.ToString());
        Console.ReadLine();
    }
Beispiel #2
0
        public async Task <IActionResult> GetList([FromQuery] int page, [FromQuery] string search)
        {
            StuffModel result = string.IsNullOrWhiteSpace(search)
                ? await _stuffRepo.GetListAsync(page)
                : await _stuffRepo.SearchListAsync(search);

            return(Ok(result));
        }
        public static StuffModel ToStuffModel(this ICollection <TStuff> input, int page, int dbCount, int totalPages, int itemsPerPage)
        {
            var result = new StuffModel
            {
                Page       = page,
                PerPage    = itemsPerPage,
                Total      = dbCount,
                TotalPages = totalPages,
                DatumList  = input.ToDatumListModel()
            };

            return(result);
        }
Beispiel #4
0
        private async void blockButton_Clicked(object sender, EventArgs e)
        {
            StartLoading();
            var stuff = new StuffModel();

            stuff.MobileDevicKey = MobileStaticVariables.UserInfo.MobileDeviceKey;
            stuff.ColegueList.Add(_colegue);
            var cancellationTokenSource = new CancellationTokenSource();
            await Task.Factory.StartNew(x =>
            {
                try
                {
                    string registration = "";
                    registration        = MobileStaticVariables.WebUtils.SendAuthRequest("BlockManager", stuff);
                    Logger.WriteLine("BlockManager : " + registration);
                    if (registration == "")
                    {
                        throw new Exception("Получена пустая строка");
                    }
                    stuff.ParseJson(registration);
                    if (stuff.ResultState == RequestResult.Results.Success)
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await DisplayAlert("Ура", "Оператор заблокирован", "Продолжить");
                            EndLoading();
                            await Navigation.PopToRootAsync();
                        });
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await DisplayAlert("Внимание", stuff.TranslateResult(stuff.ResultState), "Продолжить");
                            EndLoading();
                        });
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        EndLoading();
                        await DisplayAlert("Внимание", "Не удается соедениться с сервером", "Повторить");
                    });
                }
            },
                                        TaskCreationOptions.AttachedToParent, cancellationTokenSource.Token);
        }
Beispiel #5
0
 /// <summary>
 /// Запрос для регистрации пользователя в системе
 /// </summary>
 /// <param name="typeTag">Register - Регистрация пользователя
 /// RegisterInfo - Запрос информации для регистрации пользователя по Email</param>
 /// <param name="detailValue">Регистрационные данные</param>
 /// <returns></returns>
 public string SendAuthRequest(string typeTag, StuffModel detailValue)
 {
     for (int i = 0; i < MobileStaticVariables.ConectSettings.OrderTries; i++) // TODO добавить количество попыток запроса авторизации
     {
         try
         {
             return(SendRequest(Request.GetAuthXml(typeTag, Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(detailValue))))));
         }
         catch (Exception ex)
         {
             Logger.WriteError(ex);
         }
     }
     Logger.WriteLine("SendAuthRequest : Can't connect to server");
     throw new Exception("ErrorCannotConnectToSever");
 }
Beispiel #6
0
        public async Task StuffController_Read_ShouldReturn_Null()
        {
            // Arrange
            var mockUserRepo = Mock.Of <IStuffRepo>();
            var controller   = new StuffController(mockUserRepo);

            // Act
            IActionResult actionResult = await controller.Read("1");

            // Assert
            var        okResult      = Assert.IsType <OkObjectResult>(actionResult);
            var        contentResult = okResult.Value;
            StuffModel expected      = null;
            var        actual        = contentResult;

            Assert.Equal(expected, actual);
        }
        private async void continueButton_Clicked(object sender, EventArgs e)
        {
            string login    = (Regex.IsMatch(loginEntry.Text, emailRegex)) ? loginEntry.Text : "";
            string name     = nameEntry.Text.Trim();
            string position = positionEntry.Text.Trim();
            string Shop     = selectShopButton.Text;

            if (name != "")
            {
                if (login != "")
                {
                    if ((Shop != "Магазин не выбран" && MobileStaticVariables.UserInfo.ShopList.Count != 1) || MobileStaticVariables.UserInfo.ShopList.Count == 1)
                    {
                        if (_colegue == null)
                        {
                            _colegue = new Colegue();
                        }
                        _colegue.Email    = login;
                        _colegue.Name     = name;
                        _colegue.Position = position;
                        if (MobileStaticVariables.UserInfo.ShopList.Count == 1)
                        {
                            _colegue.ShopKey = MobileStaticVariables.UserInfo.ShopList.FirstOrDefault().ShopKey;
                        }
                        else
                        {
                            if (dictTO.TryGetValue(Shop, out int shopKey))
                            {
                                _colegue.ShopKey = shopKey;
                            }
                        }

                        var stuff = new StuffModel();
                        stuff.MobileDevicKey = MobileStaticVariables.UserInfo.MobileDeviceKey;
                        stuff.ColegueList.Clear();
                        stuff.ColegueList.Add(_colegue);
                        var cancellationTokenSource = new CancellationTokenSource();
                        try
                        {
                            StartLoading();
                            await Task.Factory.StartNew(x =>
                            {
                                try
                                {
                                    string registration = "";
                                    registration        = MobileStaticVariables.WebUtils.SendAuthRequest("RegManager", stuff);
                                    Logger.WriteLine("registration : " + registration);
                                    if (registration == "")
                                    {
                                        throw new Exception("Получена пустая строка");
                                    }
                                    stuff.ParseJson(registration);
                                    if (stuff.ResultState == RequestResult.Results.Success)
                                    {
                                        Device.BeginInvokeOnMainThread(async() =>
                                        {
                                            await DisplayAlert("Ура", "Добавление прошло успешно", "Продолжить");
                                            EndLoading();
                                            await Navigation.PopToRootAsync();
                                        });
                                    }
                                    else
                                    {
                                        Device.BeginInvokeOnMainThread(async() =>
                                        {
                                            await DisplayAlert("Внимание", stuff.TranslateResult(stuff.ResultState), "Продолжить");
                                            EndLoading();
                                        });
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.WriteError(ex);
                                    Device.BeginInvokeOnMainThread(async() =>
                                    {
                                        EndLoading();
                                        await DisplayAlert("Внимание", "Не удается соедениться с сервером", "Повторить");
                                    });
                                }
                            },
                                                        TaskCreationOptions.AttachedToParent, cancellationTokenSource.Token);
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteError(ex);
                        }
                    }
                    else
                    {
                        await DisplayAlert("Внимание", "Введите магазин, в котором будет работать Ваш будущий коллега", "Хорошо");

                        positionEntry.Focus();
                    }
                }
                else
                {
                    await DisplayAlert("Внимание", "Введите почту, чтобы мы могли связаться с Вашим будущим колегой", "Хорошо");

                    loginEntry.Focus();
                }
            }
            else
            {
                await DisplayAlert("Внимание", "Введите имя Вашего будущего коллеги", "Хорошо");

                nameEntry.Focus();
            }
        }
Beispiel #8
0
        private void LoadStuff()
        {
            try
            {
                string     crewInfo = "";
                StuffModel crew     = new StuffModel();
                crew.MobileDevicKey = MobileStaticVariables.UserInfo.MobileDeviceKey;
                crewInfo            = MobileStaticVariables.WebUtils.SendAuthRequest("GetMyCrew", crew);

                Logger.WriteLine("crewInfo : " + crewInfo);
                if (crewInfo == "")
                {
                    throw new Exception("crewInfo не получены");
                }
                crew = JsonConvert.DeserializeObject <StuffModel>(crewInfo);
                if (crew.ResultState == RequestResult.Results.Success)
                {
                    StuffList.Clear();
                    MobileStaticVariables.UserInfo.Stuff = crew.ColegueList;
                    MobileStaticVariables.UserInfo.SaveSetting((int)SettingsEnum.Stuff, JsonConvert.SerializeObject(MobileStaticVariables.UserInfo.Stuff));
                    if (crew.ColegueList.Count == 0)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            listView.IsVisible = false;
                            EndLoading();
                            emptyFrame.IsVisible = true;
                        });
                    }
                    {
                        foreach (var item in crew.ColegueList)
                        {
                            var view = new CollegueModel();
                            view.Name = item.Name;
                            view.Shop = item.ShopName;
                            if (item.Position.Length == 0)
                            {
                                view.Posision = "(нет применчаний)";
                            }
                            else
                            {
                                view.Posision = "(" + item.Position + ")";
                            }
                            view.Data = item;
                            if (item.UserState == UserStates.Blocked)
                            {
                                view.Name += " (заблокирован)";
                            }
                            StuffList.Add(view);
                        }
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            listView.ItemsSource = StuffList;
                            EndLoading();
                        });
                    }
                }
                else
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (IsVisible)
                        {
                            await DisplayAlert("Внимание", crew.TranslateResult(crew.ResultState), "Хорошо");
                            EndLoading();
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                Device.BeginInvokeOnMainThread(() =>
                {
                    EndLoading();
                    noConnectionLayout.IsVisible = true;
                    Device.StartTimer(new TimeSpan(0, 0, 1), WaitInternetConnection);
                });
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    EndLoading();
                });
            }
        }