Пример #1
0
        public void PickKey(KeyType keyType)
        {
            log.Debug("Picking a " + keyType.ToString() + " key.");
            try {
                List <ApiKey> keyRing = (keyType == KeyType.Standard) ? standardKeys : subscriberKeys;
                if (keyRing == null || keyRing.Count == 0)
                {
                    log.Warn(keyType.ToString() + " keyring is empty!");
                    if (!string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier) &&
                        !string.IsNullOrEmpty(Settings.Instance.AssignedClientSecret))
                    {
                        log.Debug("Using key from settings file.");
                        key = new ApiKey(Settings.Instance.AssignedClientIdentifier, Settings.Instance.AssignedClientSecret);
                    }
                    else
                    {
                        log.Debug("Reverting to default key.");
                        Key = new ApiKey.DefaultKey(keyType);
                    }
                    return;
                }

                if (!string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier))
                {
                    log.Fine("Checking " + (Settings.Instance.AssignedClientIdentifier == new ApiKey.DefaultKey(keyType).ClientId ? "" : "non-") + "default assigned API key is still on the keyring.");
                    ApiKey retrievedKey = keyRing.Find(k => k.ClientId == Settings.Instance.AssignedClientIdentifier);
                    if (retrievedKey == null)
                    {
                        log.Warn("Could not find assigned key on keyring!");
                        if (standardKeys.Concat(subscriberKeys).Any(k => k.ClientId == Settings.Instance.AssignedClientIdentifier))
                        {
                            log.Warn("The key was been taken from the other keyring!");
                        }
                        log.Debug("Picking a new key from the ring.");
                    }
                    else
                    {
                        if (retrievedKey.Status == KeyStatus.DEAD.ToString())
                        {
                            log.Warn("The assigned key can no longer be used. A new key must be assigned.");
                        }
                        else
                        {
                            Key = retrievedKey;
                            return;
                        }
                    }
                }
                keyRing = keyRing.Where(k => k.Status == KeyStatus.ACTIVE.ToString()).ToList();
                Random rnd       = new Random();
                int    chosenKey = rnd.Next(0, keyRing.Count - 1);
                log.Fine("Picked random active key #" + chosenKey + 1);
                Key = keyRing[chosenKey];
            } catch (System.Exception ex) {
                log.Fail("Failed picking " + keyType.ToString() + " API key. clientID=" + Settings.Instance.AssignedClientIdentifier);
                OGCSexception.Analyse(ex);
                log.Debug("Reverting to default key.");
                Key = new ApiKey.DefaultKey(keyType);
            }
        }
Пример #2
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("keyType");
     writer.WriteStringValue(KeyType.ToString());
     writer.WriteEndObject();
 }
Пример #3
0
    private bool AddOnDefalut(char operation, KeyType type)
    {
        Debug.Log("AddOnEquation():" + " bufferStr = " + bufferStr + ", bufferType = " + bufferType.ToString());
        Debug.Log("AddOnDefalut():" + " operation = " + operation + " type = " + type.ToString());

        bool isAdd = false;

        switch (type)
        {
        case KeyType.NumberKey:
        case KeyType.BacketLeftKey:
        case KeyType.BacketRightKey:
            isAdd = false;
            break;

        case KeyType.NumberPointKey:
        case KeyType.OperatorKey:
            isAdd = true;
            break;
        }

        bufferStr  = operation.ToString();
        bufferType = type;

        return(isAdd);
    }
Пример #4
0
 internal static bool AddUpdate(string userId, string keyId, string vCode, KeyType keyType)
 {
     if (string.IsNullOrWhiteSpace(userId))
     {
         throw new ArgumentException("user_id cannot be empty");
     }
     if (string.IsNullOrWhiteSpace(keyId))
     {
         throw new ArgumentException("KeyID cannot be empty");
     }
     if (string.IsNullOrWhiteSpace(vCode))
     {
         throw new ArgumentException("vCode cannot be empty");
     }
     using (SlackEvePingEntities ef = new SlackEvePingEntities()){
         UserMapping user = ef.UserMappings.FirstOrDefault(x => x.UserID == userId.Trim());
         if (user == null)
         {
             user = new UserMapping {
                 UserID = userId.Trim()
             };
             ef.UserMappings.AddObject(user);
         }
         user.KeyID   = keyId.Trim();
         user.vCode   = vCode.Trim();
         user.KeyType = keyType.ToString();
         ef.SaveChanges();
     }
     return(true);
 }
Пример #5
0
    private bool AddOnEquation(char operation, KeyType type)
    {
        Debug.Log("AddOnEquation():" + " bufferStr = " + bufferStr + ", bufferType = " + bufferType.ToString());
        Debug.Log("AddOnEquation():" + " operation = " + operation + ", type = " + type.ToString());

        if (bufferType == KeyType.NumberKey && (type == KeyType.NumberKey || type == KeyType.NumberPointKey))
        {
            if (bufferStr == num_zero.ToString())
            {
                return(false);
            }
            else
            {
                char point = CalculatorData.GetKeyValueByName(KeyName.Number_point);
                if (bufferStr.Contains(point.ToString()) && type == KeyType.NumberPointKey)
                {
                    return(false);
                }

                bufferStr += operation;
                return(true);
            }
        }

        bufferStr  = operation.ToString();
        bufferType = type;
        return(true);
    }
        private static JsonWebKey CreateKey(KeyType type, bool includePrivateParameters = false, IEnumerable <KeyOperation> keyOps = null)
        {
            switch (type.ToString())
            {
#if NET461
            case KeyType.EcValue:
            case KeyType.EcHsmValue:
                throw new IgnoreException("Creating JsonWebKey with ECDsa is not supported on net461.");
#else
            case KeyType.EcValue:
            case KeyType.EcHsmValue:
                return(new JsonWebKey(ECDsa.Create(), includePrivateParameters, keyOps));
#endif
            case KeyType.RsaValue:
            case KeyType.RsaHsmValue:
                return(new JsonWebKey(RSA.Create(), includePrivateParameters, keyOps));

            case KeyType.OctValue:
            case KeyType.OctHsmValue:
                return(new JsonWebKey(Aes.Create(), keyOps));

            default:
                throw new NotSupportedException(@$ "Key type " "{type}" " is not supported");
            }
        }
Пример #7
0
        public static string GetCloudKey(string keyfileName, KeyType key)
        {
            try
            {
                var keyPath = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    Path.Combine(
                        KeyFilesDir,
                        key.ToString(),
                        keyfileName
                        ));

                using (StreamReader r = new StreamReader(keyPath))
                {
                    string json = r.ReadToEnd();
                    return(json);
                }
            }
            catch (Exception ex)
            {
                #region Error Catch and response error
                Logger.PringDebug($"-----Error{ System.Reflection.MethodBase.GetCurrentMethod().Name }-----");
                Logger.PringDebug(ex.ToString());
                return("");

                #endregion
            }
        }
Пример #8
0
        private void WriteKeyProperties(Utf8JsonWriter json)
        {
            if (KeyType.HasValue)
            {
                json.WriteString(s_keyTypePropertyNameBytes, KeyType.ToString());
            }

            if (ReuseKey.HasValue)
            {
                json.WriteBoolean(s_reuseKeyPropertyNameBytes, ReuseKey.Value);
            }

            if (Exportable.HasValue)
            {
                json.WriteBoolean(s_exportablePropertyNameBytes, Exportable.Value);
            }

            if (KeyCurveName.HasValue)
            {
                json.WriteString(s_curveNamePropertyNameBytes, KeyCurveName.ToString());
            }

            if (KeySize.HasValue)
            {
                json.WriteNumber(s_keySizePropertyNameBytes, KeySize.Value);
            }
        }
Пример #9
0
        public void AddServiceKey(string displayName, byte[] keyValue, string protectionPassword, KeyType keyType, KeyUsage keyUsage)
        {
            try
            {
                var client           = this.CreateManagementServiceClient();
                var defaultStartDate = DateTime.UtcNow;
                var defaultEndDate   = defaultStartDate.AddYears(1);

                var serviceKey = new ServiceKey
                {
                    DisplayName = displayName,
                    Type        = keyType.ToString(),
                    Usage       = keyUsage.ToString(),
                    Value       = keyValue,
                    Password    = string.IsNullOrEmpty(protectionPassword) ? null : new UTF8Encoding().GetBytes(protectionPassword),
                    StartDate   = defaultStartDate,
                    EndDate     = defaultEndDate,
                    IsPrimary   = true
                };

                client.AddToServiceKeys(serviceKey);
                client.SaveChanges();
            }
            catch (Exception ex)
            {
                throw TryGetExceptionDetails(ex);
            }
        }
Пример #10
0
 public static PSServiceKey ToPSServiceKey(this RegenerateKeyOutput serviceKey, KeyType keyType)
 {
     return(new PSServiceKey
     {
         Key = serviceKey.Key,
         KeyType = keyType.ToString()
     });
 }
 /// <summary>
 /// Constructs a command to create a mobile service
 /// </summary>
 internal RegenerateMobileServiceKeyCommand(string serviceName, KeyType type = KeyType.Application)
 {
     OperationId = "mobileservices";
     ServiceType = "services";
     Name = serviceName;
     HttpVerb = HttpVerbPost;
     KeyType = type;
     HttpCommand = String.Format("mobileservices/{0}/regenerateKey?type={1}", serviceName.ToLower(), type.ToString().ToLower());
 }
Пример #12
0
        public Boolean PickKey(KeyType keyType)
        {
            log.Debug("Picking a " + keyType.ToString() + " key.");
            try {
                List <ApiKey> keyRing = (keyType == KeyType.Standard) ? standardKeys : subscriberKeys;
                if (keyRing == null || keyRing.Count == 0)
                {
                    log.Debug(keyType.ToString() + " keyring is empty.");
                    Settings.Instance.AssignedClientIdentifier = "";
                    return(false);
                }
                if (string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier) &&
                    !string.IsNullOrEmpty(Settings.Instance.RefreshToken))
                {
                    log.Debug("Legacy user with default API key.");
                    //Let them carry on with the default key, else everyone will have to re-authorise OGCS
                    //on a key with less quota
                    return(false);
                }

                if (!string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier))
                {
                    Key = keyRing.Find(k => k.ClientId == Settings.Instance.AssignedClientIdentifier);
                    if (key != null)
                    {
                        return(true);
                    }
                    else
                    {
                        log.Warn("Could not find assigned key!");
                    }
                }
                Random rnd       = new Random();
                int    chosenKey = rnd.Next(0, keyRing.Count - 1);
                log.Fine("Picked random key #" + chosenKey + 1);
                Key = keyRing[chosenKey];
                return(true);
            } catch (System.Exception ex) {
                log.Error("Failed picking API key. clientID=" + Settings.Instance.AssignedClientIdentifier);
                log.Error(ex.Message);
                Settings.Instance.AssignedClientIdentifier = "";
                return(false);
            }
        }
Пример #13
0
        public async Task RegenerateKeyAsync()
        {
            var client = StorageAccount.GetRestClient("/keys?action=regenerate");

            var ns = XmlNamespaces.WindowsAzure;

            var content = new XElement(ns + "RegenerateKeys",
                                       new XElement(ns + "KeyType", KeyType.ToString()));

            await client.PostAsync(content);
        }
Пример #14
0
 public virtual void SaveToXml(System.Xml.XmlTextWriter xmlWriter)
 {
     xmlWriter.WriteStartElement("Key");
     xmlWriter.WriteAttributeString("Time", Time.ToString());
     xmlWriter.WriteAttributeString("Value", Value.ToString());
     xmlWriter.WriteAttributeString("InFunction", InFunction.ToString());
     xmlWriter.WriteAttributeString("BaseTweenType", BaseTweenType.ToString());
     xmlWriter.WriteAttributeString("P1", P1.ToString());
     xmlWriter.WriteAttributeString("P2", P2.ToString());
     xmlWriter.WriteAttributeString("P3", P3.ToString());
     xmlWriter.WriteAttributeString("P4", P4.ToString());
     xmlWriter.WriteEndElement();
 }
        //수집요청
        public string RequestJob(string CorpNum, KeyType cbType, string SDate, string EDate, string UserID = null)
        {
            string uri = "/HomeTax/Cashbill/" + cbType.ToString();

            uri += "?SDate=" + SDate;
            uri += "&EDate=" + EDate;

            JobIDResponse response;

            response = httppost <JobIDResponse>(uri, CorpNum, null, null, null, UserID);

            return(response.jobID);
        }
Пример #16
0
        public String RequestJob(String CorpNum, KeyType tiType, String DType, String SDate, String EDate, String UserID)
        {
            String uri = "/HomeTax/Taxinvoice/" + tiType.ToString();

            uri += "?DType=" + DType;
            uri += "&SDate=" + SDate;
            uri += "&EDate=" + EDate;

            JobIDResponse response;

            response = httppost <JobIDResponse>(uri, CorpNum, UserID, null, null);

            return(response.jobID);
        }
        private RSA GetRSA(KeyType keyType)
        {
            var cert = _certificateProvider.GetCertificate();

            switch (keyType)
            {
            case KeyType.Private:
                return(cert.GetRSAPrivateKey());

            case KeyType.Public:
                return(cert.GetRSAPublicKey());

            default:
                throw new UserException("Unknown KeyType " + keyType.ToString());
            }
        }
Пример #18
0
        /// <summary>
        /// Gets the Xml tree for the custom serialiser
        /// </summary>
        /// <returns>An XElement </returns>
        public XElement GetXmlTree()
        {
            if (String.IsNullOrEmpty(FingerPrint) || String.IsNullOrEmpty(Path))
            {
                throw new FluentManagementException("The fingerprint or path has to have a value", "SSHKey");
            }

            var element     = new XElement(Namespaces.NsWindowsAzure + _keyType.ToString());
            var fingerPrint = new XElement(Namespaces.NsWindowsAzure + "Fingerprint", FingerPrint);
            var path        = new XElement(Namespaces.NsWindowsAzure + "Path", Path);

            element.Add(fingerPrint);
            element.Add(path);

            return(element);
        }
Пример #19
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("typeName");
     writer.WriteStringValue(KeyType.ToString());
     writer.WritePropertyName("subscriptionId");
     writer.WriteStringValue(SubscriptionId);
     writer.WritePropertyName("resourceGroupName");
     writer.WriteStringValue(ResourceGroupName);
     writer.WritePropertyName("vaultName");
     writer.WriteStringValue(VaultName);
     writer.WritePropertyName("secretName");
     writer.WriteStringValue(SecretName);
     writer.WritePropertyName("secretVersion");
     writer.WriteStringValue(SecretVersion);
     writer.WriteEndObject();
 }
Пример #20
0
        /// <inheritdoc />
        public override string ToString()
        {
            string s = "";

            s += bindingType.ToString();

            switch (bindingType)
            {
            case KeyType.Key:
                s += ": " + ((KeyCode)code).ToString();
                break;

            case KeyType.Mouse:
                s += ": " + ((MouseButton)code).ToString();
                break;
            }
            return(s);
        }
Пример #21
0
 private void button5_Click(object sender, EventArgs e)
 {
     using (RAPIlib.Connector node = new Connector())
     {
         KeyType my_key = new KeyType();
         if (MessageBox.Show("Load you public key?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             openFileDialog1.FileName = "";
             if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 byte[] kk = File.ReadAllBytes(openFileDialog1.FileName);
                 kk.CopyTo(my_key.data, 0);
                 mykeystr = my_key.ToString();
             }
         }
         KeyType k = node.cmdGetInfo(my_key);
         MessageBox.Show(string.Format("{0}\r\n{1}", k.ToString(), mykeystr));
     }
 }
Пример #22
0
        private void button8_Click(object sender, EventArgs e)
        {
            KeyType  pub  = new KeyType();
            HashType priv = new HashType();

            ConfigManager.noconnectflg = true;
            using (Connector node = new Connector())
            {
                if (node.GenKeyPair(ref pub, ref priv))
                {
                    MessageBox.Show(string.Format("Key pair generated\r\npub key:\r\n{0}\r\npriv key:\r\n{1}",
                                                  pub.ToString(), priv.ToString()));
                }
                else
                {
                    MessageBox.Show("Key pair do not been generated");
                }
            }
        }
Пример #23
0
        private void LoadRotationKeys()
        {
            // For euler, use m_LocalEuler
            var length = niFile.Reader.ReadInt32();

            if (length != 0)
            {
                rotationInterpolation = (KeyType)niFile.Reader.ReadInt32();
                if (rotationInterpolation == KeyType.EulerAngles)
                {
                    throw new NotImplementedException(rotationInterpolation.ToString());
                    //eulerKeys = new NiKeyframe<Vector3>[length];
                }
                else
                {
                    quaternionKeys = new NiQuaternionKeyframeGroup(length, rotationInterpolation, niFile.Reader);
                }
            }
        }
Пример #24
0
    public void Save()
    {
        PlayerPrefs.SetString(
            action,
            type.ToString()
            );

        if (type == KeyType.KeyDown)
        {
            PlayerPrefs.SetString(
                action + "_value",
                keyCode.ToString()
                );
        }
        else
        {
            PlayerPrefs.SetString(
                action + "_value",
                mouseButton.ToString()
                );
        }
    }
Пример #25
0
        public void TestEqualAndGetHashCode()
        {
            var dict = new Dictionary <ColumnType, string>();
            // add PrimitiveTypes, KeyType & corresponding VectorTypes
            PrimitiveType tmp;
            VectorType    tmp1, tmp2;

            foreach (var kind in (DataKind[])Enum.GetValues(typeof(DataKind)))
            {
                tmp = PrimitiveType.FromKind(kind);
                if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                {
                    Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                }
                dict[tmp] = tmp.ToString();
                for (int size = 0; size < 5; size++)
                {
                    tmp1 = new VectorType(tmp, size);
                    if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                    {
                        Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                    }
                    dict[tmp1] = tmp1.ToString();
                    for (int size1 = 0; size1 < 5; size1++)
                    {
                        tmp2 = new VectorType(tmp, size, size1);
                        if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                        {
                            Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                        }
                        dict[tmp2] = tmp2.ToString();
                    }
                }

                // KeyType & Vector
                if (!KeyType.IsValidDataKind(kind))
                {
                    continue;
                }
                for (ulong min = 0; min < 5; min++)
                {
                    for (var count = 0; count < 5; count++)
                    {
                        tmp = new KeyType(kind, min, count);
                        if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                        {
                            Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                        }
                        dict[tmp] = tmp.ToString();
                        for (int size = 0; size < 5; size++)
                        {
                            tmp1 = new VectorType(tmp, size);
                            if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                            {
                                Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                            }
                            dict[tmp1] = tmp1.ToString();
                            for (int size1 = 0; size1 < 5; size1++)
                            {
                                tmp2 = new VectorType(tmp, size, size1);
                                if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                                {
                                    Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                                }
                                dict[tmp2] = tmp2.ToString();
                            }
                        }
                    }
                    tmp = new KeyType(kind, min, 0, false);
                    if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                    {
                        Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                    }
                    dict[tmp] = tmp.ToString();
                    for (int size = 0; size < 5; size++)
                    {
                        tmp1 = new VectorType(tmp, size);
                        if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                        {
                            Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                        }
                        dict[tmp1] = tmp1.ToString();
                        for (int size1 = 0; size1 < 5; size1++)
                        {
                            tmp2 = new VectorType(tmp, size, size1);
                            if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                            {
                                Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                            }
                            dict[tmp2] = tmp2.ToString();
                        }
                    }
                }
            }

            // add ImageTypes
            for (int height = 1; height < 5; height++)
            {
                for (int width = 1; width < 5; width++)
                {
                    var tmp4 = new ImageType(height, width);
                    if (dict.ContainsKey(tmp4))
                    {
                        Assert.True(false, dict[tmp4] + " and " + tmp4.ToString() + " are duplicates.");
                    }
                    dict[tmp4] = tmp4.ToString();
                }
            }
        }
Пример #26
0
        public Boolean PickKey(KeyType keyType)
        {
            log.Debug("Picking a " + keyType.ToString() + " key.");
            try {
                if (string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier) &&
                    !string.IsNullOrEmpty(Settings.Instance.RefreshToken))
                {
                    log.Debug("Legacy user with default API key.");
                    //Let them carry on with the default key, else everyone will have to re-authorise OGCS
                    //on a key with less quota
                    return(false);
                }

                List <ApiKey> keyRing = (keyType == KeyType.Standard) ? standardKeys : subscriberKeys;
                if (keyRing == null || keyRing.Count == 0)
                {
                    log.Warn(keyType.ToString() + " keyring is empty!");
                    if (!string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier) &&
                        !string.IsNullOrEmpty(Settings.Instance.AssignedClientSecret))
                    {
                        log.Debug("Using key from settings file.");
                        key = new ApiKey(Settings.Instance.AssignedClientIdentifier, Settings.Instance.AssignedClientSecret);
                        return(true);
                    }
                    else
                    {
                        log.Debug("Reverting to default key.");
                        Settings.Instance.AssignedClientIdentifier = "";
                        return(false);
                    }
                }

                if (!string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier))
                {
                    ApiKey retrievedKey = keyRing.Find(k => k.ClientId == Settings.Instance.AssignedClientIdentifier);
                    if (retrievedKey == null)
                    {
                        log.Warn("Could not find assigned key on keyring!");
                        if (standardKeys.Concat(subscriberKeys).Any(k => k.ClientId == Settings.Instance.AssignedClientIdentifier))
                        {
                            log.Warn("The key was been taken from the other keyring!");
                        }
                        if (!string.IsNullOrEmpty(Settings.Instance.AssignedClientIdentifier) &&
                            !string.IsNullOrEmpty(Settings.Instance.AssignedClientSecret))
                        {
                            log.Debug("Using key from settings file.");
                            key = new ApiKey(Settings.Instance.AssignedClientIdentifier, Settings.Instance.AssignedClientSecret);
                            return(true);
                        }
                    }
                    else
                    {
                        if (retrievedKey.Status == KeyStatus.DEAD.ToString())
                        {
                            log.Warn("The assigned key can no longer be used. A new key must be assigned.");
                        }
                        else
                        {
                            key = retrievedKey;
                            return(true);
                        }
                    }
                }
                keyRing = keyRing.Where(k => k.Status == KeyStatus.ACTIVE.ToString()).ToList();
                Random rnd       = new Random();
                int    chosenKey = rnd.Next(0, keyRing.Count - 1);
                log.Fine("Picked random active key #" + chosenKey + 1);
                Key = keyRing[chosenKey];
                return(true);
            } catch (System.Exception ex) {
                log.Error("Failed picking API key. clientID=" + Settings.Instance.AssignedClientIdentifier);
                log.Error(ex.Message);
                Settings.Instance.AssignedClientIdentifier = "";
                return(false);
            }
        }
Пример #27
0
        public void TestEqualAndGetHashCode()
        {
            var dict = new Dictionary <ColumnType, string>();
            // add PrimitiveTypes, KeyType & corresponding VectorTypes
            VectorType tmp1, tmp2;
            var        types = new PrimitiveType[] { NumberType.I1, NumberType.I2, NumberType.I4, NumberType.I8,
                                                     NumberType.U1, NumberType.U2, NumberType.U4, NumberType.U8, NumberType.UG,
                                                     TextType.Instance, BoolType.Instance, DateTimeType.Instance, DateTimeOffsetType.Instance, TimeSpanType.Instance };

            foreach (var type in types)
            {
                var tmp = type;
                if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                {
                    Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                }
                dict[tmp] = tmp.ToString();
                for (int size = 0; size < 5; size++)
                {
                    tmp1 = new VectorType(tmp, size);
                    if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                    {
                        Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                    }
                    dict[tmp1] = tmp1.ToString();
                    for (int size1 = 0; size1 < 5; size1++)
                    {
                        tmp2 = new VectorType(tmp, size, size1);
                        if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                        {
                            Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                        }
                        dict[tmp2] = tmp2.ToString();
                    }
                }

                // KeyType & Vector
                var rawType = tmp.RawType;
                if (!KeyType.IsValidDataType(rawType))
                {
                    continue;
                }
                for (ulong min = 0; min < 5; min++)
                {
                    for (var count = 0; count < 5; count++)
                    {
                        tmp = new KeyType(rawType, min, count);
                        if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                        {
                            Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                        }
                        dict[tmp] = tmp.ToString();
                        for (int size = 0; size < 5; size++)
                        {
                            tmp1 = new VectorType(tmp, size);
                            if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                            {
                                Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                            }
                            dict[tmp1] = tmp1.ToString();
                            for (int size1 = 0; size1 < 5; size1++)
                            {
                                tmp2 = new VectorType(tmp, size, size1);
                                if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                                {
                                    Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                                }
                                dict[tmp2] = tmp2.ToString();
                            }
                        }
                    }
                    tmp = new KeyType(rawType, min, 0, false);
                    if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                    {
                        Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                    }
                    dict[tmp] = tmp.ToString();
                    for (int size = 0; size < 5; size++)
                    {
                        tmp1 = new VectorType(tmp, size);
                        if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                        {
                            Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                        }
                        dict[tmp1] = tmp1.ToString();
                        for (int size1 = 0; size1 < 5; size1++)
                        {
                            tmp2 = new VectorType(tmp, size, size1);
                            if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                            {
                                Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                            }
                            dict[tmp2] = tmp2.ToString();
                        }
                    }
                }
            }

            // add ImageTypes
            for (int height = 1; height < 5; height++)
            {
                for (int width = 1; width < 5; width++)
                {
                    var tmp4 = new ImageType(height, width);
                    if (dict.ContainsKey(tmp4))
                    {
                        Assert.True(false, dict[tmp4] + " and " + tmp4.ToString() + " are duplicates.");
                    }
                    dict[tmp4] = tmp4.ToString();
                }
            }
        }
Пример #28
0
        public void TestEqualAndGetHashCode()
        {
            var dict = new Dictionary <DataViewType, string>();
            // add PrimitiveTypes, KeyType & corresponding VectorTypes
            VectorType tmp1, tmp2;
            var        types = new PrimitiveDataViewType[] { NumberDataViewType.SByte, NumberDataViewType.Int16, NumberDataViewType.Int32, NumberDataViewType.Int64,
                                                             NumberDataViewType.Byte, NumberDataViewType.UInt16, NumberDataViewType.UInt32, NumberDataViewType.UInt64, RowIdDataViewType.Instance,
                                                             TextDataViewType.Instance, BooleanDataViewType.Instance, DateTimeDataViewType.Instance, DateTimeOffsetDataViewType.Instance, TimeSpanDataViewType.Instance };

            foreach (var type in types)
            {
                var tmp = type;
                if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                {
                    Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                }
                dict[tmp] = tmp.ToString();
                for (int size = 0; size < 5; size++)
                {
                    tmp1 = new VectorType(tmp, size);
                    if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                    {
                        Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                    }
                    dict[tmp1] = tmp1.ToString();
                    for (int size1 = 0; size1 < 5; size1++)
                    {
                        tmp2 = new VectorType(tmp, size, size1);
                        if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                        {
                            Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                        }
                        dict[tmp2] = tmp2.ToString();
                    }
                }

                // KeyType & Vector
                var rawType = tmp.RawType;
                if (!KeyType.IsValidDataType(rawType))
                {
                    continue;
                }
                for (ulong min = 0; min < 5; min++)
                {
                    for (var count = 1; count < 5; count++)
                    {
                        tmp = new KeyType(rawType, count);
                        if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                        {
                            Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                        }
                        dict[tmp] = tmp.ToString();
                        for (int size = 0; size < 5; size++)
                        {
                            tmp1 = new VectorType(tmp, size);
                            if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                            {
                                Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                            }
                            dict[tmp1] = tmp1.ToString();
                            for (int size1 = 0; size1 < 5; size1++)
                            {
                                tmp2 = new VectorType(tmp, size, size1);
                                if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                                {
                                    Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                                }
                                dict[tmp2] = tmp2.ToString();
                            }
                        }
                    }
                    Assert.True(rawType.TryGetDataKind(out var kind));
                    tmp = new KeyType(rawType, kind.ToMaxInt());
                    if (dict.ContainsKey(tmp) && dict[tmp] != tmp.ToString())
                    {
                        Assert.True(false, dict[tmp] + " and " + tmp.ToString() + " are duplicates.");
                    }
                    dict[tmp] = tmp.ToString();
                    for (int size = 0; size < 5; size++)
                    {
                        tmp1 = new VectorType(tmp, size);
                        if (dict.ContainsKey(tmp1) && dict[tmp1] != tmp1.ToString())
                        {
                            Assert.True(false, dict[tmp1] + " and " + tmp1.ToString() + " are duplicates.");
                        }
                        dict[tmp1] = tmp1.ToString();
                        for (int size1 = 0; size1 < 5; size1++)
                        {
                            tmp2 = new VectorType(tmp, size, size1);
                            if (dict.ContainsKey(tmp2) && dict[tmp2] != tmp2.ToString())
                            {
                                Assert.True(false, dict[tmp2] + " and " + tmp2.ToString() + " are duplicates.");
                            }
                            dict[tmp2] = tmp2.ToString();
                        }
                    }
                }
            }

            // add ImageTypes
            for (int height = 1; height < 5; height++)
            {
                for (int width = 1; width < 5; width++)
                {
                    var tmp4 = new ImageType(height, width);
                    if (dict.ContainsKey(tmp4))
                    {
                        Assert.True(false, dict[tmp4] + " and " + tmp4.ToString() + " are duplicates.");
                    }
                    dict[tmp4] = tmp4.ToString();
                }
            }
        }
        public void AddServiceKey(string displayName, byte[] keyValue, string protectionPassword, KeyType keyType, KeyUsage keyUsage)
        {
            try
            {
                var client = this.CreateManagementServiceClient();
                var defaultStartDate = DateTime.UtcNow;
                var defaultEndDate = defaultStartDate.AddYears(1);

                var serviceKey = new ServiceKey
                                     {
                                         DisplayName = displayName,
                                         Type = keyType.ToString(),
                                         Usage = keyUsage.ToString(),
                                         Value = keyValue,
                                         Password = string.IsNullOrEmpty(protectionPassword) ? null : new UTF8Encoding().GetBytes(protectionPassword),
                                         StartDate = defaultStartDate,
                                         EndDate = defaultEndDate,
                                         IsPrimary = true
                                     };

                client.AddToServiceKeys(serviceKey);
                client.SaveChanges();
            }
            catch (Exception ex)
            {
                throw TryGetExceptionDetails(ex);
            }
        }
Пример #30
0
 public static PSServiceKey ToPSServiceKey(this RegenerateKeyOutput serviceKey, KeyType keyType)
 {
     return new PSServiceKey
     {
         Key = serviceKey.Key,
         KeyType = keyType.ToString()
     };
 }
Пример #31
0
        public NiKeyframeGroup(int length, KeyType interpolation, System.IO.BinaryReader reader)
        {
            this.length        = length;
            this.interpolation = interpolation;
            this.reader        = reader;

            Keyframes = new NiKeyframe <T> [length];

            // Read all the keys
            for (var i = 0; i < length; i++)
            {
                var time  = reader.ReadSingle();
                var value = GetValue();

                switch (interpolation)
                {
                case KeyType.Linear:
                case KeyType.Constant:
                    Keyframes[i] = new NiKeyframe <T>(time, value);
                    break;

                case KeyType.Quadratic:
                    var forward  = GetValue();
                    var backward = GetValue();
                    Keyframes[i] = new NiKeyframe <T>(time, value, forward, backward);
                    break;

                case KeyType.Tbc:
                    var tension    = reader.ReadSingle();
                    var bias       = reader.ReadSingle();
                    var continuity = reader.ReadSingle();
                    Keyframes[i] = new NiKeyframe <T>(time, value, tension, bias, continuity);
                    break;

                default:
                    throw new NotImplementedException(interpolation.ToString());
                }
            }

            // After keys are read, they should be "processed" so tangents for quadratic/tbc can  be calculated
            animationKeyframes = new Keyframe[AnimCurveCount][];
            for (var i = 0; i < AnimCurveCount; i++)
            {
                animationKeyframes[i] = new Keyframe[Keyframes.Length];
            }

            // Set tangents for first frame
            // Some animations only have one frame, do this to avoid errors
            if (Keyframes.Length == 1)
            {
                switch (interpolation)
                {
                case KeyType.Linear:
                    SetLinearCurves(0, 0, 0);
                    break;

                case KeyType.Quadratic:
                    SetQuadraticCurves(0);
                    break;

                case KeyType.Tbc:
                    SetTbcCurves(0, 0, 0);
                    break;

                case KeyType.Constant:
                    SetConstantCurves(0);
                    break;

                default:
                    throw new NotImplementedException(interpolation.ToString());
                }

                return;
            }


            switch (interpolation)
            {
            case KeyType.Linear:
                SetLinearCurves(0, 0, 1);
                break;

            case KeyType.Quadratic:
                SetQuadraticCurves(0);
                break;

            case KeyType.Tbc:
                SetLinearCurves(0, 0, 1);
                break;

            case KeyType.Constant:
                SetConstantCurves(0);
                break;

            default:
                throw new NotImplementedException(interpolation.ToString());
            }

            // Don't set tangents here for first or last frame
            for (var i = 1; i < Keyframes.Length - 2; i++)
            {
                switch (interpolation)
                {
                case KeyType.Linear:
                    SetLinearCurves(i, i - 1, i + 1);
                    break;

                case KeyType.Quadratic:
                    SetQuadraticCurves(i);
                    break;

                case KeyType.Tbc:
                    SetTbcCurves(i, i - 1, i + 1);
                    break;

                case KeyType.Constant:
                    SetConstantCurves(i);
                    break;

                default:
                    throw new NotImplementedException(interpolation.ToString());
                }
            }

            // Set tangents for last frame
            switch (interpolation)
            {
            case KeyType.Linear:
                SetLinearCurves(Keyframes.Length - 1, Keyframes.Length - 2, Keyframes.Length - 1);
                break;

            case KeyType.Quadratic:
                SetQuadraticCurves(Keyframes.Length - 1);
                break;

            case KeyType.Tbc:
                SetTbcCurves(Keyframes.Length - 1, Keyframes.Length - 2, Keyframes.Length - 1);
                break;

            case KeyType.Constant:
                SetConstantCurves(Keyframes.Length - 1);
                break;

            default:
                throw new NotImplementedException(interpolation.ToString());
            }
        }
Пример #32
0
 public override string ToString()
 {
     return(Principal + "@" + Realm + "," + KeyType.ToString());
 }
        /// <summary>
        /// Retrieves all the entities from the tables given a key.
        /// </summary>
        /// <param name="key">The key we're searching with.</param>
        /// <returns>The list of entities having the provided key.</returns>
        public List <TEntity> GetAll(string key, KeyType keyType)
        {
            var query = new TableQuery <TEntity>().Where(TableQuery.GenerateFilterCondition(keyType.ToString(), QueryComparisons.Equal, key));

            return(CloudTable.ExecuteQuery(query, new TableRequestOptions()
            {
                RetryPolicy = this.azureSettings.RetryPolicy
            }).ToList());
        }