Exemple #1
0
        /// <summary>
        /// Write to a key file. If keyClass is PRIVATE, then also update mapping.txt.
        /// </summary>
        ///
        /// <param name="keyName"></param>
        /// <param name="keyClass">[PUBLIC, PRIVATE, SYMMETRIC]</param>
        /// <param name="data"></param>
        /// <exception cref="IOException"></exception>
        /// <exception cref="System.Security.SecurityException"></exception>
        private void write(Name keyName, KeyClass keyClass, byte[] data)
        {
            String extension = (String)ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_, keyClass);

            try {
                String filePath;
                if (keyClass == net.named_data.jndn.security.KeyClass.PRIVATE)
                {
                    filePath = maintainMapping(keyName.toUri()) + extension;
                }
                else
                {
                    filePath = nameTransform(keyName.toUri(), extension).FullName;
                }

                var writer = (new StreamWriter(filePath));
                try {
                    String base64Data = net.named_data.jndn.util.Common.base64Encode(data, true);
                    writer.Write(base64Data, 0, base64Data.Substring(0, base64Data.Length));
                    writer.flush();
                } finally {
                    writer.close();
                }
            } catch (SecurityException e) {
                throw new SecurityException(
                          "FilePrivateKeyStorage: Failed to write key: "
                          + e.Message);
            } catch (IOException e_0) {
                throw new SecurityException(
                          "FilePrivateKeyStorage: Failed to write key: "
                          + e_0.Message);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key">ключ</param>
        /// <param name="text">текст</param>
        /// <returns></returns>
        public string Encoding_(string key, string text)
        {
            string result = new KeyClass().SwapPC_1(key);

            var CD = new KeyClass().Split(result);


            var res = new KeyClass().Shift(CD);

            var res_c = res[0];
            var res_d = res[1];

            var keys = new KeyClass().SwapPC_2(res);



            var    IPTExt = new General().SwapIP(text);
            var    R_L    = new General().SplitIP(IPTExt);
            string L      = R_L[0];
            string R      = R_L[1];

            var res_texts = new General().GAMMA(L, R, keys);

            var resout = Convert.ToInt64(res_texts, 2);
            var tt     = Convert.ToString(resout, 16);

            // Console.WriteLine("Шифровка");
            //Console.WriteLine(tt);

            return(res_texts);
        }
Exemple #3
0
        /// <summary>
        /// Read from a key file
        /// </summary>
        ///
        /// <param name="keyName"></param>
        /// <param name="keyClass">[PUBLIC, PRIVATE, SYMMETRIC]</param>
        /// <returns>The key bytes.</returns>
        /// <exception cref="IOException"></exception>
        /// <exception cref="System.Security.SecurityException"></exception>
        private byte[] read(Name keyName, KeyClass keyClass)
        {
            String        extension = (String)ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_, keyClass);
            StringBuilder contents  = new StringBuilder();

            try {
                TextReader reader = new FileReader(nameTransform(keyName.toUri(), extension).FullName);
                // Use "try/finally instead of "try-with-resources" or "using"
                // which are not supported before Java 7.
                try {
                    String line = null;
                    while ((line = reader.readLine()) != null)
                    {
                        contents.append(line);
                    }
                } finally {
                    reader.close();
                }
            } catch (SecurityException e) {
                throw new SecurityException(
                          "FilePrivateKeyStorage: Failed to read key: "
                          + e.Message);
            } catch (IOException e_0) {
                throw new SecurityException(
                          "FilePrivateKeyStorage: Failed to read key: "
                          + e_0.Message);
            }

            return(net.named_data.jndn.util.Common.base64Decode(contents.toString()));
        }
        public void KeyAttributeGenerateTest()
        {
            var test = new KeyClass { Uid = 1000 };
            var kg = new IdentityKeyGenerator();
            var key = kg.Generate(test);

            Assert.AreEqual("uid:1000", key.ToString());
        }
Exemple #5
0
    void AssignCommandAndKey(string command, string key)
    {
        KeyClass newKey = (KeyClass)KeyClass.CreateInstance("KeyClass");

        newKey.SetCommand(command);
        newKey.SetKeyCode(key);

        allCommands.Add(newKey);
    }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="catalog"></param>
        /// <param name="srcTable"></param>
        internal void CreateTable(
            Catalog catalog,
            DataTable srcTable)
        {
            string tableName = Sanitize(srcTable.TableName);
            Table  newTable  = new TableClass();

            newTable.Name = tableName;
            catalog.Tables.Append(newTable);

            // ArrayList keySet = new ArrayList();

            foreach (DataColumn srcColumn in srcTable.Columns)
            {
                Column column = new ColumnClass();

                column.Name          = Sanitize(srcColumn.ColumnName);
                column.Type          = TypeFor(srcColumn);
                column.DefinedSize   = SizeFor(srcColumn);
                column.ParentCatalog = catalog;

                if (srcColumn.AllowDBNull)
                {
                    column.Attributes = ColumnAttributesEnum.adColNullable;
                }

                LookupTable(catalog, srcTable).Columns.Append(
                    column,
                    DataTypeEnum.adVarWChar, // default
                    0);                      // default
            }

            if (srcTable.PrimaryKey.Length > 0)
            {
                Key key = new KeyClass();
                key.Name         = Sanitize(String.Format("{0}", tableName));
                key.Type         = KeyTypeEnum.adKeyPrimary;
                key.RelatedTable = tableName;
                foreach (DataColumn srcColumn in srcTable.PrimaryKey)
                {
                    Column column = LookupColumn(catalog, srcColumn);
                    key.Columns.Append(
                        column.Name,
                        DataTypeEnum.adVarWChar,    // default
                        0);                         // default
                }

                LookupTable(catalog, srcTable).Keys.Append(
                    key,
                    KeyTypeEnum.adKeyPrimary,         // default
                    Type.Missing,                     // default
                    String.Empty,                     // default
                    String.Empty);                    // default
            }
        }
        private double Calc(KeyClass selector)
        {
            double sum = Records[KeyClass.Productive] + Records[KeyClass.Destructive] + Records[KeyClass.Navigation] + Records[KeyClass.Meta];

            if (sum == 0d)
            {
                return(0);
            }

            var ratio = Records[selector] / sum;

            return(ToTwoDidigts(ratio * 100d));
        }
Exemple #8
0
        /// <summary>
        /// Check if a particular key exists.
        /// </summary>
        ///
        /// <param name="keyName">The name of the key.</param>
        /// <param name="keyClass"></param>
        /// <returns>True if the key exists, otherwise false.</returns>
        public sealed override bool doesKeyExist(Name keyName, KeyClass keyClass)
        {
            String keyURI    = keyName.toUri();
            String extension = (String)ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_, keyClass);

            if (extension == null)
            {
                throw new SecurityException("Unrecognized key class");
            }
            else
            {
                return(nameTransform(keyURI, extension).Exists);
            }
        }
Exemple #9
0
        public IXILMapping TryAllocate(Component host, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes, IProject targetProject)
        {
            if (instr.Name != InstructionCodes.Concat)
            {
                return(null);
            }

            int[] inWidths = operandTypes.Select(t => Marshal.SerializeForHW(t.GetSampleInstance()).Size).ToArray();
            var   key      = new KeyClass(inWidths);
            InlineConcatMapperTransactionSite taSite =
                new InlineConcatMapperTransactionSite(this, host, inWidths);

            return(new ConcatMapping(taSite));
        }
Exemple #10
0
 public static void KeyMix(ref KeyClass KClass, KeyClass KClass1, KeyClass KClass2)
 {
     KClass.Key_Z      = KClass1.Key_Z | KClass2.Key_Z;
     KClass.Key_X      = KClass1.Key_X | KClass2.Key_X;
     KClass.Key_C      = KClass1.Key_C | KClass2.Key_C;
     KClass.Key_Shift  = KClass1.Key_Shift | KClass2.Key_Shift;
     KClass.Key_Ctrl   = KClass1.Key_Ctrl | KClass2.Key_Ctrl;
     KClass.ArrowLeft  = KClass1.ArrowLeft | KClass2.ArrowLeft;
     KClass.ArrowRight = KClass1.ArrowRight | KClass2.ArrowRight;
     KClass.ArrowDown  = KClass1.ArrowDown | KClass2.ArrowDown;
     KClass.ArrowUp    = KClass1.ArrowUp | KClass2.ArrowUp;
     KClass.Key_ESC    = KClass1.Key_ESC | KClass2.Key_ESC;
     KClass.Key_plus   = KClass1.Key_plus | KClass2.Key_plus;
     KClass.Key_minus  = KClass1.Key_minus | KClass2.Key_minus;
 }
 /// <summary>
 /// Check if a particular key exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <param name="keyClass"></param>
 /// <returns>True if the key exists, otherwise false.</returns>
 public override bool doesKeyExist(Name keyName, KeyClass keyClass)
 {
     if (keyClass == net.named_data.jndn.security.KeyClass.PUBLIC)
     {
         return(publicKeyStore_.Contains(keyName.toUri()));
     }
     else if (keyClass == net.named_data.jndn.security.KeyClass.PRIVATE)
     {
         return(privateKeyStore_.Contains(keyName.toUri()));
     }
     else
     {
         // KeyClass.SYMMETRIC not implemented yet.
         return(false);
     }
 }
    public override bool Equals(object other)
    {
        if (other == null)
        {
            return(false);
        }

        // Casting object other to type KeyClass
        KeyClass obj = other as KeyClass;

        if (obj == null)
        {
            return(false);
        }
        return(this.key == other.key);
    }
Exemple #13
0
        public void EqualHashDifferentKey()
        {
            KeyClass key1 = new KeyClass("a");
            KeyClass key2 = new KeyClass("b");

            DiskDictionary <KeyClass, int> dict = new DiskDictionary <KeyClass, int>();

            dict.Add(key1, 2);
            dict.Add(key2, 3);

            Assert.IsTrue(dict[key1] == 2);
            Assert.IsTrue(dict[key2] == 3);

            Assert.IsTrue(dict.Remove(key1));
            Assert.IsTrue(dict.Remove(key2));
        }
Exemple #14
0
        /// <summary>
        /// Imports a key of specifed type given the raw key bytes and key class.
        /// </summary>
        /// <param name="session">The Cryptoki session context.</param>
        /// <param name="keyData">The raw key data bytes.</param>
        /// <param name="keyClass">The class of key represented by the raw bytes.</param>
        /// <param name="keyType">The type of key represented by the raw bytes.</param>
        /// <param name="canBeExported">true if the key can be exported, false other wise.</param>
        /// <returns>The key created from the specified bytes.</returns>
        public static CryptoKey ImportKey(Session session, byte[] keyData, KeyClass keyClass, KeyType keyType, bool canBeExported)
        {
            CryptokiAttribute[] keyImport = new CryptokiAttribute[]
            {
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class, Utility.ConvertToBytes((int)keyClass)),
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.KeyType, Utility.ConvertToBytes((int)keyType)),
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.Value, keyData),
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.Extractable, Utility.ConvertToBytes(canBeExported ? 1 : 0)),
            };

            CryptoKey ret = LoadKey(session, keyImport);

            session.AddSessionObject(ret);

            return(ret);
        }
Exemple #15
0
 //Создаём новый предмет
 private void CreateNewItem()
 {
     if (itemType == "sword")
     {
         SwordClass asset = ScriptableObject.CreateInstance <SwordClass>();
         asset.itemName = itemName;
         AssetDatabase.CreateAsset(asset, itemPath + itemName + ".asset");
         Selection.activeObject = asset;
     }
     else if (itemType == "bow")
     {
         BowClass asset = ScriptableObject.CreateInstance <BowClass>();
         asset.itemName = itemName;
         AssetDatabase.CreateAsset(asset, itemPath + itemName + ".asset");
         Selection.activeObject = asset;
     }
     else if (itemType == "boomerang")
     {
         BoomerangClass asset = ScriptableObject.CreateInstance <BoomerangClass>();
         asset.itemName = itemName;
         AssetDatabase.CreateAsset(asset, itemPath + itemName + ".asset");
         Selection.activeObject = asset;
     }
     else if (itemType == "heart")
     {
         HeartClass asset = ScriptableObject.CreateInstance <HeartClass>();
         asset.itemName = itemName;
         AssetDatabase.CreateAsset(asset, itemPath + itemName + ".asset");
         Selection.activeObject = asset;
     }
     else if (itemType == "key")
     {
         KeyClass asset = ScriptableObject.CreateInstance <KeyClass>();
         asset.itemName = itemName;
         AssetDatabase.CreateAsset(asset, itemPath + itemName + ".asset");
         Selection.activeObject = asset;
     }
     else if (itemType == "item")
     {
         ItemClass asset = ScriptableObject.CreateInstance <ItemClass>();
         asset.itemName = itemName;
         AssetDatabase.CreateAsset(asset, itemPath + itemName + ".asset");
         Selection.activeObject = asset;
     }
     AssetDatabase.SaveAssets();
     EditorUtility.FocusProjectWindow();
 }
Exemple #16
0
        internal void ApplyKey(ModifierKeys modifiers, Key key)
        {
            KeyClass keyClass = new KeyClass(modifiers, key);

            KeyPressed = keyClass.ToString();

            try
            {
                Status = "Executing...";
                _qms.Execute(keyClass);
                Status = "Ready";
            }
            catch (Exception ex)
            {
                Status = "Error: " + ex.Message;
            }
        }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="catalog"></param>
        /// <param name="relation"></param>
        internal void CreateRelation(
            Catalog catalog,
            DataRelation relation)
        {
            Key   foreignKey  = new KeyClass();
            Table parentTable = LookupTable(catalog, relation.ParentTable);
            Table childTable  = LookupTable(catalog, relation.ChildTable);

            foreignKey.Name         = Sanitize(relation.RelationName);
            foreignKey.Type         = KeyTypeEnum.adKeyForeign;
            foreignKey.RelatedTable = parentTable.Name;
            foreignKey.DeleteRule   = RuleEnum.adRICascade;
            foreignKey.UpdateRule   = RuleEnum.adRINone;

            //
            // Assumption, child and parent columns are at the same index
            // in their respective collections.
            //

            Debug.Assert(
                relation.ChildColumns.Length == relation.ParentColumns.Length);

            for (int i = 0; i < relation.ChildColumns.Length; ++i)
            {
                Column childColumn
                    = LookupColumn(catalog, relation.ChildColumns[i]);
                Column parentColumn
                    = LookupColumn(catalog, relation.ParentColumns[i]);

                foreignKey.Columns.Append(
                    childColumn.Name,
                    DataTypeEnum.adVarWChar, // default
                    0);                      // default

                foreignKey.Columns[childColumn.Name].RelatedColumn
                    = parentColumn.Name;
            }

            childTable.Keys.Append(
                foreignKey,
                KeyTypeEnum.adKeyPrimary,     // default
                Type.Missing,                 // default
                String.Empty,                 // default
                String.Empty);                // default
        }
Exemple #18
0
        public IEnumerable <IXILMapping> TryMap(ITransactionSite taSite, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            var fu = taSite.Host;

            if (instr.Name != InstructionCodes.Concat)
            {
                yield break;
            }

            int[] inWidths = operandTypes.Select(t => Marshal.SerializeForHW(t.GetSampleInstance()).Size).ToArray();
            var   key      = new KeyClass(inWidths);
            var   taCM     = taSite as InlineConcatMapperTransactionSite;

            if (taCM == null)
            {
                yield break;
            }
            if (!taCM.ArgWidths.SequenceEqual(inWidths))
            {
                yield break;
            }
            yield return(new ConcatMapping(taCM));
        }
Exemple #19
0
 internal void SetKeys(KeyClass keyClass)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Read from a key file
        /// </summary>
        ///
        /// <param name="keyName"></param>
        /// <param name="keyClass">[PUBLIC, PRIVATE, SYMMETRIC]</param>
        /// <returns>The key bytes.</returns>
        /// <exception cref="IOException"></exception>
        /// <exception cref="System.Security.SecurityException"></exception>
        private byte[] read(Name keyName, KeyClass keyClass)
        {
            String extension = (String) ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_,keyClass);
            StringBuilder contents = new StringBuilder();
            try {
                TextReader reader = new FileReader(nameTransform(keyName.toUri(), extension).FullName);
                // Use "try/finally instead of "try-with-resources" or "using"
                // which are not supported before Java 7.
                try {
                    String line = null;
                    while ((line = reader.readLine()) != null)
                        contents.append(line);
                } finally {
                    reader.close();
                }
            } catch (SecurityException e) {
                throw new SecurityException(
                        "FilePrivateKeyStorage: Failed to read key: "
                                + e.Message);
            } catch (IOException e_0) {
                throw new SecurityException(
                        "FilePrivateKeyStorage: Failed to read key: "
                                + e_0.Message);
            }

            return net.named_data.jndn.util.Common.base64Decode(contents.toString());
        }
 /// <summary>
 /// Check if a particular key exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <param name="keyClass"></param>
 /// <returns>True if the key exists, otherwise false.</returns>
 public override sealed bool doesKeyExist(Name keyName, KeyClass keyClass)
 {
     String keyURI = keyName.toUri();
     String extension = (String) ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_,keyClass);
     if (extension == null)
         throw new SecurityException("Unrecognized key class");
     else
         return nameTransform(keyURI, extension).Exists;
 }
        /// <summary>
        /// Write to a key file. If keyClass is PRIVATE, then also update mapping.txt.
        /// </summary>
        ///
        /// <param name="keyName"></param>
        /// <param name="keyClass">[PUBLIC, PRIVATE, SYMMETRIC]</param>
        /// <param name="data"></param>
        /// <exception cref="IOException"></exception>
        /// <exception cref="System.Security.SecurityException"></exception>
        private void write(Name keyName, KeyClass keyClass, byte[] data)
        {
            String extension = (String) ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_,keyClass);
            try {
                String filePath;
                if (keyClass == net.named_data.jndn.security.KeyClass.PRIVATE)
                    filePath = maintainMapping(keyName.toUri()) + extension;
                else
                    filePath = nameTransform(keyName.toUri(), extension).FullName;

                var writer = (new StreamWriter(filePath));
                try {
                    String base64Data = net.named_data.jndn.util.Common.base64Encode(data);
                    writer.Write(base64Data,0,base64Data.Substring(0,base64Data.Length));
                    writer.flush();
                } finally {
                    writer.close();
                }
            } catch (SecurityException e) {
                throw new SecurityException(
                        "FilePrivateKeyStorage: Failed to write key: "
                                + e.Message);
            } catch (IOException e_0) {
                throw new SecurityException(
                        "FilePrivateKeyStorage: Failed to write key: "
                                + e_0.Message);
            }
        }
Exemple #23
0
        /// <summary>
        /// Imports a key of specifed type given the raw key bytes and key class.
        /// </summary>
        /// <param name="session">The Cryptoki session context.</param>
        /// <param name="keyData">The raw key data bytes.</param>
        /// <param name="keyClass">The class of key represented by the raw bytes.</param>
        /// <param name="keyType">The type of key represented by the raw bytes.</param>
        /// <param name="canBeExported">true if the key can be exported, false other wise.</param>
        /// <returns>The key created from the specified bytes.</returns>
        public static CryptoKey ImportKey(Session session, byte[] keyData, KeyClass keyClass, KeyType keyType, bool canBeExported)
        {
            CryptokiAttribute[] keyImport = new CryptokiAttribute[]
            {
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class  , Utility.ConvertToBytes((int)keyClass)),
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.KeyType, Utility.ConvertToBytes((int)keyType)),
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.Value, keyData),
                new CryptokiAttribute(CryptokiAttribute.CryptokiType.Extractable, Utility.ConvertToBytes(canBeExported ? 1 : 0)),
            };

            CryptoKey ret = LoadKey(session, keyImport);

            session.AddSessionObject(ret);

            return ret;
        }
        public IXILMapping TryAllocate(Component host, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes, IProject targetProject)
        {
            if (instr.Name != InstructionCodes.Concat)
                return null;

            int[] inWidths = operandTypes.Select(t => Marshal.SerializeForHW(t.GetSampleInstance()).Size).ToArray();
            var key = new KeyClass(inWidths);
            InlineConcatMapperTransactionSite taSite = 
                new InlineConcatMapperTransactionSite(this, host, inWidths);

            return new ConcatMapping(taSite);
        }
        public IEnumerable<IXILMapping> TryMap(ITransactionSite taSite, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            var fu = taSite.Host;
            if (instr.Name != InstructionCodes.Concat)
                yield break;

            int[] inWidths = operandTypes.Select(t => Marshal.SerializeForHW(t.GetSampleInstance()).Size).ToArray();
            var key = new KeyClass(inWidths);
            var taCM = taSite as InlineConcatMapperTransactionSite;
            if (taCM == null)
                yield break;
            if (!taCM.ArgWidths.SequenceEqual(inWidths))
                yield break;
            yield return new ConcatMapping(taCM);
        }
        //Реструктуризация БД по схеме
        public bool RestructDB(string pathDB)
        {
            if (!m_isSchema)
            {
                return(false);
            }

            File.Copy(pathDB, pathDB + ".old", true);

            bool isRestructed = false;

            ConnectionClass conn = null;

            try
            {
                conn = new ConnectionClass();
                conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathDB, "", "", 0);
                m_catalogADOX.ActiveConnection = conn;

                for (int i = 0; i < m_schema.tables.Length; ++i)
                {
                    string tableName;
                    try
                    {
                        tableName = m_catalogADOX.Tables[m_schema.tables[i].name].Name;
                    }
                    catch
                    {
                        AddTableADOX(m_schema.tables[i].name);
                        tableName    = m_schema.tables[i].name;
                        isRestructed = true;
                    }

                    jcolumns[] cols = m_schema.tables[i].columns;
                    for (int j = 0; j < cols.Length; ++j)
                    {
                        string            columnName = cols[j].name;
                        ADOX.DataTypeEnum columnType = cols[j].type;
                        int columnPrecision          = cols[j].precision;
                        int columnDefSize            = cols[j].definedSize;

                        try
                        {
                            string temp = m_catalogADOX.Tables[tableName].Columns[columnName].Name;
                        }
                        catch
                        {
                            ColumnClass columnADOX = new ColumnClass();

                            columnADOX.ParentCatalog = m_catalogADOX;

                            columnADOX.Name        = columnName;
                            columnADOX.Type        = columnType;
                            columnADOX.DefinedSize = columnDefSize;
                            columnADOX.Precision   = columnPrecision;
                            columnADOX.Properties["Autoincrement"].Value = (object)cols[j].autoincrement;
                            columnADOX.Properties["Nullable"].Value      = (object)cols[j].nullable;
                            columnADOX.Properties["Fixed Length"].Value  = (object)cols[j].fixedLength;

                            AddColumnADOX(tableName, columnADOX, columnType, columnDefSize);
                            isRestructed = true;
                        }

                        ADOX.DataTypeEnum temp_type = m_catalogADOX.Tables[tableName].Columns[columnName].Type;
                        int temp_precision          = m_catalogADOX.Tables[tableName].Columns[columnName].Precision;
                        int temp_definedSize        = m_catalogADOX.Tables[tableName].Columns[columnName].DefinedSize;

                        if (columnType != temp_type || columnPrecision != temp_precision || columnDefSize != temp_definedSize ||
                            cols[j].autoincrement != (bool)m_catalogADOX.Tables[tableName].Columns[columnName].Properties["Autoincrement"].Value ||
                            cols[j].nullable != (bool)m_catalogADOX.Tables[tableName].Columns[columnName].Properties["Nullable"].Value ||
                            cols[j].fixedLength != (bool)m_catalogADOX.Tables[tableName].Columns[columnName].Properties["Fixed Length"].Value
                            )
                        {
                            ALTERColumnADOX(conn, tableName, columnName, columnType, columnPrecision, columnDefSize, cols[j]);
                            isRestructed = true;
                        }
                    }

                    //index
                    jindexs[] ind = m_schema.tables[i].indexs;
                    if (ind != null)
                    {
                        for (int j = 0; j < ind.Length; j++)
                        {
                            try
                            {
                                string name = m_catalogADOX.Tables[m_schema.tables[i].name].Indexes[ind[j].name].Name;
                            }
                            catch
                            {
                                IndexClass indexADOX = new IndexClass();

                                indexADOX.Name       = ind[j].name;
                                indexADOX.Clustered  = ind[j].clustered;
                                indexADOX.IndexNulls = ind[j].indexNulls;
                                indexADOX.PrimaryKey = ind[j].primaryKey;
                                indexADOX.Unique     = ind[j].unique;
                                indexADOX.Columns.Append(ind[j].name, ADOX.DataTypeEnum.adInteger, 0);


                                //m_catalogADOX.Tables[m_schema.tables[i].name].Indexes.Refresh();
                                try
                                {
                                    m_catalogADOX.Tables[m_schema.tables[i].name].Indexes.Append(ind[j].name, ind[j].name);
                                }
                                catch {}
                                //catch (System.Runtime.InteropServices.COMException e)
                                //{
                                //System.Windows.Forms.MessageBox.Show(e.Message);
                                //}
                                isRestructed = true;
                            }
                        }
                    }

                    //keys
                    jkeys[] key = m_schema.tables[i].keys;
                    if (key != null)
                    {
                        for (int j = 0; j < key.Length; j++)
                        {
                            try
                            {
                                string name = m_catalogADOX.Tables[m_schema.tables[i].name].Keys[key[j].name].Name;
                            }
                            catch
                            {
                                KeyClass keyADOX = new KeyClass();
                                keyADOX.Name = key[j].name;
                                keyADOX.Type = key[j].type;

                                m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Append(
                                    key[j].name, key[j].type, m_catalogADOX.Tables[m_schema.tables[i].name].Columns[key[j].column], "", "");
                                //key[j].name, key[j].type, key[j].column, "", "");

                                //Без этой записи на win2000 выдавала глюк!!! Первая строка в vars отказывалась записыватся
                                m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Refresh();
                            }
                        }
                    }

                    //Data
                    jrows[] rows = m_schema.tables[i].rows;
                    if (rows != null && m_schema.tables[i].name == "vars")
                    {
                        FillDataRestruct(conn, m_schema.tables[i].name, rows);
                    }
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
                //System.Runtime.InteropServices.Marshal.ReleaseComObject(m_catalogADOX);
                //m_catalogADOX = new CatalogClass();
            }
            return(isRestructed);
        }
        public void EqualHashDifferentKey()
        {
            KeyClass key1 = new KeyClass("a");
            KeyClass key2 = new KeyClass("b");

            DiskDictionary<KeyClass,int> dict = new DiskDictionary<KeyClass, int>();
            dict.Add(key1, 2);
            dict.Add(key2, 3);

            Assert.IsTrue( dict[key1] == 2 );
            Assert.IsTrue( dict[key2] == 3 );

            Assert.IsTrue(dict.Remove(key1));
            Assert.IsTrue(dict.Remove(key2));
        }
 /// <summary>
 /// Check if a particular key exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <param name="keyClass"></param>
 /// <returns>True if the key exists, otherwise false.</returns>
 public abstract bool doesKeyExist(Name keyName, KeyClass keyClass);
        //Создаем новую пустую БД из схемы
        public void CreateDB(string pathDB)
        {
            if (!m_isSchema)
            {
                return;
            }

            if (File.Exists(pathDB))
            {
                File.Copy(pathDB, pathDB + ".old", true);
                File.Delete(pathDB);
            }

            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathDB;

            try
            {
                m_catalogADOX.Create(connStr);

                for (int i = 0; i < m_schema.tables.Length; i++)
                {
                    TableClass tableADOX = new TableClass();
                    tableADOX.Name          = m_schema.tables[i].name;
                    tableADOX.ParentCatalog = m_catalogADOX;

                    jcolumns[] cols = m_schema.tables[i].columns;
                    for (int j = 0; j < cols.Length; j++)
                    {
                        ColumnClass columnADOX = new ColumnClass();

                        columnADOX.ParentCatalog = m_catalogADOX;

                        columnADOX.Name        = cols[j].name;
                        columnADOX.Type        = cols[j].type;
                        columnADOX.DefinedSize = cols[j].definedSize;
                        columnADOX.Precision   = cols[j].precision;

                        columnADOX.Properties["Autoincrement"].Value = (object)cols[j].autoincrement;
                        columnADOX.Properties["Nullable"].Value      = (object)cols[j].nullable;
                        columnADOX.Properties["Fixed Length"].Value  = (object)cols[j].fixedLength;

                        tableADOX.Columns.Append(columnADOX, cols[j].type, cols[j].definedSize);
                    }

                    m_catalogADOX.Tables.Append(tableADOX);

                    //index
                    jindexs[] ind = m_schema.tables[i].indexs;
                    if (ind != null)
                    {
                        for (int j = 0; j < ind.Length; j++)
                        {
                            IndexClass indexADOX = new IndexClass();
                            indexADOX.Name       = ind[j].name;
                            indexADOX.Clustered  = ind[j].clustered;
                            indexADOX.IndexNulls = ind[j].indexNulls;
                            indexADOX.PrimaryKey = ind[j].primaryKey;
                            indexADOX.Unique     = ind[j].unique;

                            m_catalogADOX.Tables[m_schema.tables[i].name].Indexes.Append(ind[j].name, ind[j].name);
                        }
                    }

                    //key
                    jkeys[] key = m_schema.tables[i].keys;
                    if (key != null)
                    {
                        for (int j = 0; j < key.Length; j++)
                        {
                            KeyClass keyADOX = new KeyClass();
                            keyADOX.Name = key[j].name;
                            keyADOX.Type = key[j].type;
                            //keyADOX.Columns = key[j].column;
                            //keyADOX.Columns.Append(key[j].column, ADOX.DataTypeEnum.adInteger, 0);
                            //ColumnClass columnADOX = new ColumnClass();
                            //columnADOX.Name = key[j].column;

                            m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Append(
                                key[j].name, key[j].type, m_catalogADOX.Tables[m_schema.tables[i].name].Columns[key[j].column], "", "");

                            //Без этой записи на win2000 выдавала глюк!!! Первая строка в vars отказывалась запичыватся
                            m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Refresh();
                        }
                    }
                }
            }
            finally
            {
                //if (conn != null)
                //	conn.Close();
                //m_catalogADOX.ActiveConnection = null;
            }

            //Data и
            ConnectionClass conn = null;

            try
            {
                conn = new ConnectionClass();
                conn.Open(connStr, "", "", 0);

                for (int i = 0; i < m_schema.tables.Length; i++)
                {
                    jrows[] rows = m_schema.tables[i].rows;
                    if (rows != null && m_schema.tables[i].name == "vars")
                    {
                        FillDataRestruct(conn, m_schema.tables[i].name, rows);
                    }
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Exemple #30
0
		//Реструктуризация БД по схеме
		public bool RestructDB( string pathDB)
		{
			if (!m_isSchema)
				return false;
			
			File.Copy( pathDB, pathDB+".old", true);

			bool isRestructed = false;

			ConnectionClass conn = null;
			try
			{
				conn = new ConnectionClass();
				conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+pathDB,"","",0);
				m_catalogADOX.ActiveConnection = conn;

				for ( int i = 0; i < m_schema.tables.Length; ++i )
				{
					string tableName;
					try
					{
						tableName = m_catalogADOX.Tables[m_schema.tables[i].name].Name;
					}
					catch
					{
						AddTableADOX( m_schema.tables[i].name);
						tableName = m_schema.tables[i].name;
						isRestructed = true;
					}

					jcolumns[] cols = m_schema.tables[i].columns;
					for ( int j = 0; j < cols.Length; ++j )
					{
						string columnName = cols[j].name;
						ADOX.DataTypeEnum columnType = cols[j].type;
						int columnPrecision = cols[j].precision;
						int columnDefSize = cols[j].definedSize;
						
						try
						{
							string temp = m_catalogADOX.Tables[tableName].Columns[columnName].Name;
						}
						catch
						{
							ColumnClass columnADOX = new ColumnClass();

							columnADOX.ParentCatalog = m_catalogADOX;

							columnADOX.Name = columnName;
							columnADOX.Type = columnType;
							columnADOX.DefinedSize = columnDefSize;
							columnADOX.Precision = columnPrecision;
							columnADOX.Properties["Autoincrement"].Value = (object)cols[j].autoincrement;
							columnADOX.Properties["Nullable"].Value = (object)cols[j].nullable;
							columnADOX.Properties["Fixed Length"].Value = (object)cols[j].fixedLength;

							AddColumnADOX( tableName, columnADOX, columnType, columnDefSize);
							isRestructed = true;
						}

						ADOX.DataTypeEnum temp_type = m_catalogADOX.Tables[tableName].Columns[columnName].Type;
						int temp_precision = m_catalogADOX.Tables[tableName].Columns[columnName].Precision;
						int temp_definedSize = m_catalogADOX.Tables[tableName].Columns[columnName].DefinedSize;

						if (columnType != temp_type || columnPrecision != temp_precision || columnDefSize != temp_definedSize
							|| cols[j].autoincrement != (bool)m_catalogADOX.Tables[tableName].Columns[columnName].Properties["Autoincrement"].Value 
							|| cols[j].nullable != (bool)m_catalogADOX.Tables[tableName].Columns[columnName].Properties["Nullable"].Value 
							|| cols[j].fixedLength != (bool)m_catalogADOX.Tables[tableName].Columns[columnName].Properties["Fixed Length"].Value
							)
						{
							ALTERColumnADOX( conn, tableName, columnName, columnType, columnPrecision, columnDefSize, cols[j]);
							isRestructed = true;
						}
					}

					//index
					jindexs[] ind = m_schema.tables[i].indexs;
					if (ind != null)
					{
						for ( int j = 0; j < ind.Length; j++ )
						{
							try
							{
								string name = m_catalogADOX.Tables[m_schema.tables[i].name].Indexes[ind[j].name].Name;
							}
							catch
							{
								IndexClass indexADOX = new IndexClass();
								
								indexADOX.Name = ind[j].name;
								indexADOX.Clustered = ind[j].clustered;
								indexADOX.IndexNulls = ind[j].indexNulls;
								indexADOX.PrimaryKey = ind[j].primaryKey;
								indexADOX.Unique = ind[j].unique;
								indexADOX.Columns.Append(ind[j].name, ADOX.DataTypeEnum.adInteger, 0);
								

								//m_catalogADOX.Tables[m_schema.tables[i].name].Indexes.Refresh();
								try
								{
									m_catalogADOX.Tables[m_schema.tables[i].name].Indexes.Append( ind[j].name, ind[j].name);
								}
								catch{}
								//catch (System.Runtime.InteropServices.COMException e)
								//{
									//System.Windows.Forms.MessageBox.Show(e.Message);
								//}
								isRestructed = true;
							}
						}
					}

					//keys
					jkeys[] key = m_schema.tables[i].keys;
					if (key != null)
					{
						for ( int j = 0; j < key.Length; j++ )
						{
							try
							{
								string name = m_catalogADOX.Tables[m_schema.tables[i].name].Keys[key[j].name].Name;
							}
							catch
							{

								KeyClass keyADOX = new KeyClass();
								keyADOX.Name = key[j].name;
								keyADOX.Type = key[j].type;

								m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Append(
									key[j].name, key[j].type, m_catalogADOX.Tables[m_schema.tables[i].name].Columns[key[j].column], "", "");
									//key[j].name, key[j].type, key[j].column, "", "");

								//Без этой записи на win2000 выдавала глюк!!! Первая строка в vars отказывалась записыватся
								m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Refresh();
							}
						}
					}

					//Data
					jrows[] rows = m_schema.tables[i].rows;
					if (rows != null && m_schema.tables[i].name=="vars")
						FillDataRestruct( conn, m_schema.tables[i].name, rows);
				}
			}
			finally
			{
				if (conn != null)
					conn.Close();
				//System.Runtime.InteropServices.Marshal.ReleaseComObject(m_catalogADOX);
				//m_catalogADOX = new CatalogClass();
			}
			return isRestructed;
		}
Exemple #31
0
        private void initOperationFlags()
        {
            DirectoryInfo SettingsFolder = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Decal Plugins\Gleaner\Settings");
            bool[] operationflags = new bool[2];
            try {
            if (!SettingsFolder.Exists) {
                SettingsFolder.Create();
            }
            FileInfo SettingsFile = new FileInfo(SettingsFolder.FullName + @"\Settings.xml");
            FileInfo KeyFile = new FileInfo(SettingsFolder.FullName + @"\Keys.xml");

            if (SettingsFile.Exists)
            {
                using (XmlReader reader = XmlReader.Create(SettingsFile.ToString()))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(bool[]));
                    operationflags = (bool[])serializer.Deserialize(reader);
                    reader.Close();
                }
            }

            if(KeyFile.Exists)
            {
                using (XmlReader reader2 = XmlReader.Create(KeyFile.ToString()))
                {
                    XmlSerializer serializer2 = new XmlSerializer(typeof(KeyClass));
                    MasterKeyClass = (KeyClass)serializer2.Deserialize(reader2);
                    reader2.Close();
                }
            }

            if(!SettingsFile.Exists)
            {
                operationflags[0] = true;
                operationflags[1] = false;

                using (XmlWriter writer = XmlWriter.Create(SettingsFile.ToString()))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(bool[]));
                    serializer.Serialize(writer, operationflags);
                    writer.Close();
                }
            }

            gleaneron = operationflags[0];
            gleanerreport = operationflags[1];

            }
            catch {CoreManager.Current.Actions.AddChatText(("Operations flags exception."), 9, 5);}
            return;
        }
Exemple #32
0
 protected bool Equals(KeyClass other)
 {
     return(Value == other.Value);
 }
 /// <summary>
 /// Check if a particular key exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <param name="keyClass"></param>
 /// <returns>True if the key exists, otherwise false.</returns>
 public override bool doesKeyExist(Name keyName, KeyClass keyClass)
 {
     if (keyClass == net.named_data.jndn.security.KeyClass.PUBLIC)
         return publicKeyStore_.Contains(keyName.toUri());
     else if (keyClass == net.named_data.jndn.security.KeyClass.PRIVATE)
         return privateKeyStore_.Contains(keyName.toUri());
     else
         // KeyClass.SYMMETRIC not implemented yet.
         return false;
 }
Exemple #34
0
		//Создаем новую пустую БД из схемы
		public void CreateDB( string pathDB)
		{
			if (!m_isSchema)
				return;

			if (File.Exists(pathDB))
			{
				File.Copy( pathDB, pathDB+".old", true);
				File.Delete( pathDB);
			}

			string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+pathDB;
			try
			{
				m_catalogADOX.Create(connStr);

				for ( int i = 0; i < m_schema.tables.Length; i++ )
				{
					TableClass tableADOX = new TableClass();
					tableADOX.Name = m_schema.tables[i].name;
					tableADOX.ParentCatalog = m_catalogADOX;

					jcolumns[] cols = m_schema.tables[i].columns;
					for ( int j = 0; j < cols.Length; j++ )
					{
						ColumnClass columnADOX = new ColumnClass();

						columnADOX.ParentCatalog = m_catalogADOX;

						columnADOX.Name = cols[j].name;
						columnADOX.Type = cols[j].type;
						columnADOX.DefinedSize = cols[j].definedSize;
						columnADOX.Precision = cols[j].precision;

						columnADOX.Properties["Autoincrement"].Value = (object)cols[j].autoincrement;
						columnADOX.Properties["Nullable"].Value = (object)cols[j].nullable;
						columnADOX.Properties["Fixed Length"].Value = (object)cols[j].fixedLength;

						tableADOX.Columns.Append(columnADOX, cols[j].type, cols[j].definedSize);
					}

					m_catalogADOX.Tables.Append(tableADOX);

					//index
					jindexs[] ind = m_schema.tables[i].indexs;
					if (ind != null)
					{
						for ( int j = 0; j < ind.Length; j++ )
						{
							IndexClass indexADOX = new IndexClass();
							indexADOX.Name = ind[j].name;
							indexADOX.Clustered = ind[j].clustered;
							indexADOX.IndexNulls = ind[j].indexNulls;
							indexADOX.PrimaryKey = ind[j].primaryKey;
							indexADOX.Unique = ind[j].unique;

							m_catalogADOX.Tables[m_schema.tables[i].name].Indexes.Append( ind[j].name, ind[j].name);
						}
					}

					//key
					jkeys[] key = m_schema.tables[i].keys;
					if (key != null)
					{
						for ( int j = 0; j < key.Length; j++ )
						{
							KeyClass keyADOX = new KeyClass();
							keyADOX.Name = key[j].name;
							keyADOX.Type = key[j].type;
							//keyADOX.Columns = key[j].column;
							//keyADOX.Columns.Append(key[j].column, ADOX.DataTypeEnum.adInteger, 0);
							//ColumnClass columnADOX = new ColumnClass();
							//columnADOX.Name = key[j].column; 

							m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Append(
								key[j].name, key[j].type, m_catalogADOX.Tables[m_schema.tables[i].name].Columns[key[j].column], "", "");

							//Без этой записи на win2000 выдавала глюк!!! Первая строка в vars отказывалась запичыватся
							m_catalogADOX.Tables[m_schema.tables[i].name].Keys.Refresh();
						}
					}
				}
			}
			finally
			{
				//if (conn != null)
				//	conn.Close();
				//m_catalogADOX.ActiveConnection = null;
			}

			//Data и 
			ConnectionClass conn = null;
			try
			{
				conn = new ConnectionClass();
				conn.Open(connStr,"","",0);

				for ( int i = 0; i < m_schema.tables.Length; i++ )
				{

					jrows[] rows = m_schema.tables[i].rows;
					if (rows != null && m_schema.tables[i].name=="vars")
						FillDataRestruct( conn, m_schema.tables[i].name, rows);
				}
			}
			finally
			{
				if (conn != null)
					conn.Close();
			}
		}
Exemple #35
0
        public static bool WriteInfoSummaryFile(string targetFile, Dictionary <string, string> countfiles)
        {
            var infofiles = (from c in countfiles
                             let cfile = c.Value.EndsWith(".xml") ? Path.GetDirectoryName(c.Value) + "/" + Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(c.Value)) : c.Value
                                         select new
            {
                Name = c.Key,
                CountFile = cfile,
                InfoFile = Path.ChangeExtension(cfile, ".info")
            }).ToList();

            var notexists = infofiles.FirstOrDefault(m => !File.Exists(m.InfoFile));

            if (notexists != null)
            {
                Console.WriteLine("WriteInfoSummaryFile ignored, info file not exists : " + notexists.InfoFile);
                return(false);
            }

            notexists = infofiles.FirstOrDefault(m => !File.Exists(m.CountFile));
            if (notexists != null)
            {
                Console.WriteLine("WriteInfoSummaryFile ignored, count file not exists : " + notexists.CountFile);
                return(false);
            }

            var infos = (from f in infofiles
                         select new
            {
                Name = f.Name,
                FeatureCount = File.ReadAllLines(f.CountFile).Length - 1,
                Data = new MapItemReader(0, 1, hasHeader: false).ReadFromFile(f.InfoFile)
            }).OrderBy(m => m.Name).ToList();

            using (StreamWriter sw = new StreamWriter(targetFile))
            {
                var keys = (from key in infos.First().Data.Keys
                            where !key.StartsWith("#")
                            select key).ToList();

                sw.Write("Name\t" + keys.Merge("\t"));
                KeyClass keyc = keys.Contains(Key1.TotalKey) ? Key1 : keys.Contains(Key2.TotalKey) ? Key2 : null;

                var percentage = keys.Contains(keyc.TotalKey) && keys.Contains(keyc.MappedKey) && keys.Contains(keyc.FeatureKey);
                if (percentage)
                {
                    sw.WriteLine("\tMapped/Total\tFeature/Mapped\tFeature/Total\tFeatureCount");
                }
                else
                {
                    sw.WriteLine("\tFeatureCount");
                }

                foreach (var info in infos)
                {
                    sw.Write("{0}\t{1}", info.Name, (from key in keys
                                                     select info.Data[key].Value).Merge("\t"));
                    if (percentage)
                    {
                        sw.WriteLine("\t{0:0.00}%\t{1:0.00}%\t{2:0.00}%\t{3}",
                                     double.Parse(info.Data[keyc.MappedKey].Value) * 100 / double.Parse(info.Data[keyc.TotalKey].Value),
                                     double.Parse(info.Data[keyc.FeatureKey].Value) * 100 / double.Parse(info.Data[keyc.MappedKey].Value),
                                     double.Parse(info.Data[keyc.FeatureKey].Value) * 100 / double.Parse(info.Data[keyc.TotalKey].Value),
                                     info.FeatureCount
                                     );
                    }
                    else
                    {
                        sw.WriteLine("\t{0}", info.FeatureCount);
                    }
                }
            }

            return(true);
        }
 /// <summary>
 /// Check if a particular key exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <param name="keyClass"></param>
 /// <returns>True if the key exists, otherwise false.</returns>
 public abstract bool doesKeyExist(Name keyName, KeyClass keyClass);