/// <summary>
        /// Get async devices that belong to a uniq user.
        /// </summary>
        /// <param name="uniq">Unique user identifier.</param>
        /// <returns>Devices data</returns>
        public async Task <DevicesInfo> GetDevicesAsync(string uniq)
        {
            ValidateUniq(uniq);

            using (WebClient client = new WebClient())
            {
                PrepareWebClient(client);
                this.LogRequest(DevicesEndpoint, uniq: uniq);

                try
                {
                    var    endPoint = $"{DevicesEndpoint}?v={this._version}&uniq={uniq}";
                    string res      = await client.DownloadStringTaskAsync(endPoint);

                    DevicesInfo info = JsonConvert.DeserializeObject <DevicesInfo>(res);

                    return(info);
                }
                catch (WebException ex)
                {
                    HandleWebException(ex);
                }
                return(null);
            }
        }
Example #2
0
        void OpenSerialDialog()
        {
            Form_Serial form_Serial = new Form_Serial();

            if (form_Serial.ShowDialog() == DialogResult.OK)
            {
                zingoTIFUART = new ZingoTIFUART(form_Serial.GetCom(), 115200);
                DevicesInfo devicesInfo = new DevicesInfo();
                devicesInfo.shortid = "0x0000";
                deviceList.AddLast(devicesInfo);
                //zingoTIFUART.GetMacCmd("0x0000");
                zingoTIFUART.AddCallback((data) =>
                {
                    DateTime time = DateTime.Now;
                    string timedata;
                    timedata = time.ToString() + " " + data;
                    File.AppendAllText(mypath, timedata);
                    if (data.Contains("ERROR"))
                    {
                        addREDText(timedata);
                    }
                    else
                    {
                        addText(timedata);
                    }
                    //JoinHandle(data);
                    //BlindHandle(data);
                    BulbHandle(data);
                });
                //zingoTIFUART.OpenNetwork();
            }
        }
Example #3
0
 void JoinHandle(string data)
 {
     if (data.Contains("Device Announce"))
     {
         string      shortid = zingoTIFUART.GetShortID(data);
         DevicesInfo devices = new DevicesInfo();
         devices.shortid = shortid;
         deviceList.AddLast(devices);
         zingoTIFUART.GetMacCmd(shortid);
         return;
     }
     ;
     //收到是获取MAC地址的回复
     if (data.Contains("IEEE Address response"))
     {
         string      macadress = zingoTIFUART.GetMac(data);
         DevicesInfo info      = deviceList.Last.Value;
         if (info.mac == null || info.mac == "")
         {
             info.mac = macadress;
         }
         if (deviceList.Count > 1)
         {
             string source        = deviceList.First.Value.mac;
             string dedestination = deviceList.Last.Value.mac;
             string shortid       = deviceList.Last.Value.shortid;
             zingoTIFUART.BindCMD(source, shortid, dedestination);
         }
         return;
     }
     ;
     //收到绑定的回复
     if (data.Contains("command 0x8021") && data.Contains("status: 0x00"))
     {
         string shortid = deviceList.Last.Value.shortid;
         zingoTIFUART.ReportCMD(shortid);
         return;
     }
     //收到send-me-a-report的回复
     if (data.Contains("cmd 07") && data.Contains("payload[00 ]") && deviceList.Count > 1)
     {
         DevicesInfo info = deviceList.Last.Value;
         if (info.test == false)
         {
             info.test = true;
             deviceList.RemoveLast();
             deviceList.AddLast(info);
             new BlindTest(zingoTIFUART, info.shortid, 3000 * 1000);
         }
     }
 }
        public Int32 Generation = 0; // номер поколоения, к которому относятся ОРД

        #endregion Fields

        #region Constructors

        public SharedDataInfo(OracleConnection Connection, FileLogger Log, string UpdatePath, UInt32 UpdateBlockSize, CardScriptPluginsInfo CardScripts)
            : this()
        {
            this.Log = Log;
              // Порядок создания важен. Не менять!
              this.CardScripts = CardScripts == null ? new CardScriptPluginsInfo(Connection, this) : CardScripts; // this - for Log

              PCParameters = new PCParametersInfo(Connection);

              Owners = new OwnersInfo(Connection, this);
              ProcessingCenters = new ProcessingCentersInfo(Connection, this); // this - for Owners, PCParameters

              Calc = new ScriptCalculations(ProcessingCenters.Current.Parameters.RoundingMethod);

              Devices = new DevicesInfo(Connection);
              DevicesGroups = new DevicesGroupsInfo(Connection, this); // this for Devices
              Networks = new NetworksInfo(Connection, this); // this - for Owners, DevicesGroups
              Currencies = new CurrenciesInfo(Connection);
              TimeOffsetPeriods = new TimeOffsetPeriodsInfo(Connection);
              Regions = new RegionsInfo(Connection, this); // this - for Currencies
              RetailSystems = new RetailSystemsInfo(Connection, this); // this - for Owners
              ServicePoints = new ServicePointsInfo(Connection, this); // this - for Regions, Networks, Retail systems
              Terminals = new TerminalsInfo(Connection, this); // this - for Service points, Devices
              ProductGoods = new LogicalProductGoodsInfo(Connection, this); // this - for Retail systems
              ProductGroups = new LogicalProductGroupsInfo(Connection);
              MeasureUnits = new MeasureUnitsInfo(Connection);
              Products = new LogicalProductsInfo(Connection, this); // this - for Groups, MeasureUnits
              Purses = new PursesInfo(this);
              Statuses = new CardStatusesInfo(Connection);
              Parameters = new ParametersInfo(Connection); // параметры скриптов обработки карты
              ParameterSets = new ParameterSetsInfo(Connection, this); // this - for Calc, CardScripts
              Counters = new CountersInfo(Connection, this); // this - for Calc
              Graduations = new GraduationsInfo(Connection, this); // this - for Calc, Products, ProductGroups, Counters
              GraduationGroups = new GraduationGroupsInfo(Connection, this); // this - for Graduations
              Tariffs = new TariffsInfo(Connection, this); // this - for Calc, GraduationGroups, Graduations
              CardRanges = new CardRangesInfo(Connection, this); // this - for ProcessingCenters
              DataElements = new DataElementsInfo(Connection, this); // this - for Owners
              EventActionTypes = new EventActionTypesInfo(Connection);
              Events = new EventsInfo(Connection, this); // this - for Owners, Counters, EventActionTypes
              EmailProviders = new EmailProvidersInfo(Connection, this); // this - for Owners
              SMSProviders = new SMSProvidersInfo(Connection, this); // this - for Owners
              DBVersion = new OnlineDBVersion(Connection, this); // this - for ProcessingCenters.Current

              this.UpdatePath = UpdatePath;
              this.UpdateBlockSize = UpdateBlockSize;
        }
        public void TestGetDevices()
        {
            // Arrange
            MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevicesInfo);
            AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

            // Act
            DevicesInfo devicesResp = sdk.GetDevices(uniq);

            this.logger.Debug(JsonConvert.SerializeObject(devicesResp));

            // Assert
            Assert.IsNotNull(devicesResp);
            Assert.AreEqual(this.devicesInfo.ResponseId, devicesResp.ResponseId);

            Assert.AreEqual(this.devicesInfo.Devices.Count, devicesResp.Devices.Count);
        }
        /// <summary>
        /// Get devices that belong to a uniq user.
        /// </summary>
        /// <param name="uniq">Unique user identifier.</param>
        /// <returns>Devices data</returns>
        public DevicesInfo GetDevices(string uniq)
        {
            ValidateUniq(uniq);

            using (IWebClient client = this._webClientFactory.Create())
            {
                PrepareWebClient((WebClient)client);
                this.LogRequest(DevicesEndpoint, uniq: uniq);

                try
                {
                    var         endPoint = $"{DevicesEndpoint}?v={this._version}&uniq={uniq}";
                    string      res      = client.DownloadString(endPoint);
                    DevicesInfo info     = JsonConvert.DeserializeObject <DevicesInfo>(res);

                    return(info);
                }
                catch (WebException ex)
                {
                    HandleWebException(ex);
                }
                return(null);
            }
        }
        public void TestSdkInit()
        {
            ILoggerFactory factory = LogFactory.GetLoggerFactory();

            this.logger = factory.GetLogger(typeof(AccessSDKTestBase).ToString());

            deviceInfo        = new DeviceInfo();
            deviceInfo.Device = new Device {
                Country = ipGeo, Region = "ID", GeoLat = 43.37, GeoLong = -116.200, Id = fingerprint, IpAddress = ipAddress, IpGeo = ipGeo, Mobile = 1, Proxy = 0
            };
            deviceInfo.ResponseId = responseId;
            jsonDevInfo           = JsonConvert.SerializeObject(deviceInfo);

            velocityInfo                  = new VelocityInfo();
            velocityInfo.Device           = deviceInfo.Device;
            velocityInfo.ResponseId       = responseId;
            velocityInfo.Velocity         = new Velocity();
            velocityInfo.Velocity.Account = new SubAccount {
                dlh = 1, dlm = 1, iplh = 1, iplm = 1, plh = 1, plm = 1, ulh = 1, ulm = 1
            };
            velocityInfo.Velocity.Device = new SubDevice {
                alh = 1, alm = 1, iplh = 3, iplm = 3, plh = 2, plm = 2, ulh = 1, ulm = 1
            };
            velocityInfo.Velocity.IpAddress = new SubAddress {
                ulm = 3, ulh = 3, plm = 3, plh = 3, alh = 2, alm = 2, dlh = 1, dlm = 1
            };
            velocityInfo.Velocity.Password = new SubPassword {
                dlm = 2, dlh = 2, alm = 2, alh = 2, iplh = 1, iplm = 1, ulh = 3, ulm = 3
            };
            velocityInfo.Velocity.User = new SubUser {
                iplm = 3, iplh = 3, alh = 2, alm = 2, dlh = 2, dlm = 2, plh = 1, plm = 1
            };
            jsonVeloInfo = JsonConvert.SerializeObject(velocityInfo);

            decisionInfo            = new DecisionInfo();
            decisionInfo.Device     = deviceInfo.Device;
            decisionInfo.ResponseId = responseId;
            decisionInfo.Velocity   = velocityInfo.Velocity;
            decisionInfo.Decision   = new Decision
            {
                Errors = new List <string> {
                    "E1", "E2"
                },
                Warnings = new List <string> {
                    "W1", "W2"
                },
                Reply = new Reply
                {
                    RuleEvents = new RuleEvents
                    {
                        Decision = decision,
                        Total    = 10,
                        Events   = new List <string> {
                            "Event 1", "Event 2"
                        }
                    }
                }
            };

            jsonDeciInfo = JsonConvert.SerializeObject(decisionInfo);

            info            = new Info();
            info.Device     = deviceInfo.Device;
            info.Decision   = decisionInfo.Decision;
            info.Velocity   = velocityInfo.Velocity;
            info.ResponseId = responseId;
            info.Trusted    = new TrustState()
            {
                State = DeviceTrustState.Trusted
            };
            info.BehavioSec = new BehavioSec()
            {
                Confidence = 0,
                IsBot      = false,
                IsTrained  = false,
                PolicyId   = 4,
                Score      = 0
            };

            jsonInfo = JsonConvert.SerializeObject(info);

            devicesInfo            = new DevicesInfo();
            devicesInfo.ResponseId = responseId;
            devicesInfo.Devices    = new List <DeviceBasicInfo>()
            {
                new DeviceBasicInfo()
                {
                    DeviceId = "54569fcbd187483a8a1570a3c67d1113", FriendlyName = "Device A", TrustState = DeviceTrustState.Trusted, DateFirstSeen = DateTime.UtcNow.AddHours(-1)
                },
                new DeviceBasicInfo()
                {
                    DeviceId = "abcdef12345678910abcdef987654321", FriendlyName = "Device B", TrustState = DeviceTrustState.Banned, DateFirstSeen = DateTime.UtcNow.AddHours(-2)
                }
            };

            jsonDevicesInfo = JsonConvert.SerializeObject(devicesInfo);

            uniquesInfo            = new UniquesInfo();
            uniquesInfo.ResponseId = responseId;
            uniquesInfo.Uniques    = new List <Unique>()
            {
                new Unique()
                {
                    UniqueId = "55e9fbfda2ce489d83b4a99c84c6f3e1", DateLastSeen = DateTime.UtcNow.AddHours(-1), TrustState = DeviceTrustState.Trusted
                },
                new Unique()
                {
                    UniqueId = "55e9fbfda2ce489d83b4a99c84c6f3e2", DateLastSeen = DateTime.UtcNow.AddHours(-2), TrustState = DeviceTrustState.Banned
                }
            };

            jsonUniquesInfo = JsonConvert.SerializeObject(uniquesInfo);
        }
Example #8
0
        /// <summary>
        /// Simple Example within the Constructor.
        /// </summary>
        public KountAccessExample()
        {
            try
            {
                // Create the SDK. If any of these values are invalid, an com.kount.kountaccess.AccessException will be
                // thrown along with a message detailing why.
                AccessSdk sdk = new AccessSdk(host, merchantId, apiKey);

                // If you want the device information for a particular user's session, just pass in the sessionId. This
                // contains the id (fingerprint), IP address, IP Geo Location (country), whether the user was using a proxy
                // (and it was bypassed), and ...
                DeviceInfo deviceInfo = sdk.GetDevice(this.session);

                this.PrintDeviceInfo(deviceInfo.Device);

                // ... if you want to see the velocity information in relation to the users session and their account
                // information, you can make an access (velocity) request. Usernames and passwords will be hashed prior to
                // transmission to Kount within the SDK. You may optionally hash prior to passing them in as long as the
                // hashing method is consistent for the same value.
                String       username   = "******";
                String       password   = "******";
                VelocityInfo accessInfo = sdk.GetVelocity(session, username, password);

                // Let's see the response
                Console.WriteLine("Response: " + accessInfo);

                // Each Access Request has its own uniqueID
                Console.WriteLine("This is our access response_id: " + accessInfo.ResponseId);

                // The device is included in an access request:
                this.PrintDeviceInfo(accessInfo.Device);

                // you can get the device information from the accessInfo object
                Device device = accessInfo.Device;

                string jsonVeloInfo = JsonConvert.SerializeObject(accessInfo);
                Console.WriteLine(jsonVeloInfo);

                this.PrintVelocityInfo(accessInfo.Velocity);

                // Or you can access specific Metrics directly. Let's say we want the
                // number of unique user accounts used by the current sessions device
                // within the last hour
                int numUsersForDevice = accessInfo.Velocity.Device.ulh;
                Console.WriteLine(
                    "The number of unique user access request(s) this hour for this device is:" + numUsersForDevice);

                // Decision Information is stored in a JSONObject, by entity type
                DecisionInfo decisionInfo = sdk.GetDecision(session, username, password);
                Decision     decision     = decisionInfo.Decision;
                // Let's look at the data
                this.PrintDecisionInfo(decision);

                // Get Kount Access data for session based on what was requested in the info flag
                String          uniq    = "uniq(customer identifier)";
                DataSetElements dataSet = new DataSetElements()
                                          .WithInfo()
                                          .WithVelocity()
                                          .WithDecision()
                                          .WithTrusted()
                                          .WithBehavioSec();

                Info info = sdk.GetInfo(session, username, password, uniq, dataSet);
                this.PrintDeviceInfo(info.Device);
                this.PrintDecisionInfo(info.Decision);
                this.PrintVelocityInfo(info.Velocity);
                this.PrintFields(info.Trusted);
                this.PrintFields(info.BehavioSec);

                // Get devices that belong to a uniq user.
                DevicesInfo devices = sdk.GetDevices(uniq);
                foreach (var d in devices.Devices)
                {
                    this.PrintFields(d);
                }

                // Get the uniq users that belong to a device.
                string deviceId = "DEVICE_ID";
                var    uniques  = sdk.GetUniques(deviceId);
                foreach (var u in uniques.Uniques)
                {
                    this.PrintFields(u);
                }

                // Update device trust referenced by session ID
                sdk.SetDeviceTrustBySession(session, uniq, DeviceTrustState.Banned);

                // Update device trust referenced by device ID
                sdk.SetDeviceTrustByDevice(uniq, deviceId, DeviceTrustState.Trusted);

                // Update behavior data.
                string timing = "timing data";
                // BehavioHost and BehavioEnvironment can be set via AccessSdk constructor too.
                // sdk.BehavioHost = "https://api.behavio.kaptcha.com";
                //sdk.BehavioEnvironment = "sandbox";

                //sdk.SetBehavioSec(session, uniq, timing);
            }
            catch (AccessException ae)
            {
                // These can be thrown if there were any issues making the request.
                // See the AccessException class for more information.
                Console.WriteLine("ERROR Type: " + ae.ErrorType);
                Console.WriteLine("ERROR: " + ae.Message);
            }
        }