Esempio n. 1
0
        /// <summary>
        /// Получает индивидуальные настройки устройства
        /// </summary>
        private async Task GetReceiptSettings()
        {
            AddItemToLogBox("Старт получения индивидуальных настроек...");
            while (true)
            {
                try
                {
                    while (CurrentState == States.DispenseChange || CurrentState == States.ReadyToDispenseWater)
                    {
                        await Task.Delay(10000);
                    }
                    ClientRequest tmpreq             = RequestEncoder.EncodeRequestData(GlobalVars.RegID);
                    Dictionary <string, string> data = new Dictionary <string, string>
                    {
                        { "Request", tmpreq.Request },
                        { "Signature", tmpreq.Signature },
                        { "AData", tmpreq.AData },
                        { "BData", tmpreq.BData }
                    };
                    HttpFormUrlEncodedContent content = new HttpFormUrlEncodedContent(data);
                    HttpClient          httpClient    = NewWebClient();
                    Uri                 requestUri    = new Uri(GlobalVars.SERVER_ENDPOINT + GlobalVars.GET_DEVICE_SETTINGS_PATH);
                    HttpResponseMessage httpResponse  = new HttpResponseMessage();
                    httpResponse = await httpClient.PostAsync(requestUri, content);

                    httpResponse.EnsureSuccessStatusCode();
                    string tmpres = await httpResponse.Content.ReadAsStringAsync();

                    DeviceSettings tmp = (Deserialize <DeviceSettings>(tmpres));
                    if (tmp.SettingsVersion != CurrentDeviceSettings.SettingsVersion)
                    {
                        CurrentDeviceSettings = tmp;
                        var xs  = new XmlSerializer(tmp.GetType());
                        var xml = new Utf8StringWriter();
                        xs.Serialize(xml, tmp);
                        string ssfilename = ApplicationData.Current.LocalFolder.Path + "\\" + GlobalVars.HardWareID + ".012";
                        File.WriteAllText(ssfilename, xml.ToString());
                        AddItemToLogBox("Новые настройки получены");
                        if (StartIfNewCurrentReceiptSettings)
                        {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                            Task.Run(() => { RunAfterInit(); });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                            StartIfNewCurrentReceiptSettings = false;
                        }
                    }
                }
                catch
                {
                }
                await Task.Delay(60000);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Инкассация - изымаем купюры и монеты из кэшбокса, обнуляем счетчики
        /// </summary>
        public async void MakeIncassation()
        {
            try
            {
                CashCounterAccessFlag.Wait();
                WaterDeviceIncasso tmpincasso = new WaterDeviceIncasso
                {
                    CommandID           = 0,
                    ID                  = 0,
                    IncassoBABills      = SystemState.BABillsCount,
                    IncassoBASum        = SystemState.BASum,
                    IncassoCashboxCoins = SystemState.CBCount,
                    IncassoCashboxSum   = SystemState.CBSum,
                    IncassoDatetime     = 0,
                    IncassoDatetimeStr  = "",
                    WaterDeviceID       = GlobalVars.RegID
                };
                ClientRequest tmpreq             = RequestEncoder.EncodeRequestData(tmpincasso);
                Dictionary <string, string> data = new Dictionary <string, string>
                {
                    { "Request", tmpreq.Request },
                    { "Signature", tmpreq.Signature },
                    { "AData", tmpreq.AData },
                    { "BData", tmpreq.BData }
                };
                HttpFormUrlEncodedContent content = new HttpFormUrlEncodedContent(data);
                HttpClient          httpClient    = NewWebClient();
                Uri                 requestUri    = new Uri(GlobalVars.SERVER_ENDPOINT + GlobalVars.INCASSO_REPORT_PATH);
                HttpResponseMessage httpResponse  = new HttpResponseMessage();
                httpResponse = await httpClient.PostAsync(requestUri, content);

                httpResponse.EnsureSuccessStatusCode();
                string tmpres = await httpResponse.Content.ReadAsStringAsync();

                if (Convert.ToDouble(tmpres) == SystemState.BASum + SystemState.CBSum)
                {
                    byte[] ccdata          = new byte[24];
                    string wcfilename      = GlobalVars.HardWareID + ".005";
                    byte[] tmpcbccount     = BitConverter.GetBytes(0);
                    byte[] tmpcbcsum       = BitConverter.GetBytes(0.00);
                    byte[] tmpbabillscount = BitConverter.GetBytes(0);
                    byte[] tmpbasum        = BitConverter.GetBytes(0.00);
                    SystemState.IncassoSum   = 0;
                    SystemState.CBCount      = 0;
                    SystemState.CBSum        = 0;
                    SystemState.BABillsCount = 0;
                    SystemState.BASum        = 0;
                    byte[] updatedccdata = new byte[24];
                    Array.Copy(tmpcbccount, 0, updatedccdata, 0, 4);
                    Array.Copy(tmpcbcsum, 0, updatedccdata, 4, 8);
                    Array.Copy(tmpbabillscount, 0, updatedccdata, 12, 4);
                    Array.Copy(tmpbasum, 0, updatedccdata, 16, 8);
                    StorageFile wcfile = null;
                    wcfile = await ApplicationData.Current.LocalFolder.GetFileAsync(wcfilename);

                    using (StorageStreamTransaction transaction = await wcfile.OpenTransactedWriteAsync())
                    {
                        using (DataWriter dataWriter = new DataWriter(transaction.Stream))
                        {
                            dataWriter.WriteBytes(updatedccdata);
                            transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file

                            await transaction.CommitAsync();
                        }
                    }
                }
            }
            catch
            {
            }
            CashCounterAccessFlag.Release();
        }