Пример #1
0
        /// <summary>
        /// Returns whether or not the given NativeHeapIndex is a valid index for this container.  If true,
        /// that index can be used to Remove the element tied to that index from the container.
        ///
        /// This method will always return true if IsUsingSafetyChecks returns false.
        /// </summary>
        public bool IsValidIndex(NativeHeapIndex index, out string error)
        {
            error = null;

#if NHEAP_SAFE
            unsafe {
                AtomicSafetyHandle.CheckReadAndThrow(m_Safety);

                if (index.StructureId != _id)
                {
                    error = "The provided ItemHandle was not valid for this NativeHeap.  It was taken from a different instance.";
                    return(false);
                }

                if (index.TableIndex >= _data->Capacity)
                {
                    error = "The provided ItemHandle was not valid for this NativeHeap.";
                    return(false);
                }

                TableValue tableValue = _data->Table[index.TableIndex];
                if (tableValue.Version != index.Version)
                {
                    error = "The provided ItemHandle was not valid for this NativeHeap.  The item it pointed to might have already been removed.";
                    return(false);
                }
            }
#endif

            return(true);
        }
Пример #2
0
        public static IDataType GetDataType(object value)
        {
            Scalar scalarValue = value as Scalar;

            if (scalarValue != null)
            {
                return(scalarValue.DataType);
            }

            ListValue listValue = value as ListValue;

            if (listValue != null)
            {
                return(listValue.DataType);
            }

            Row rowValue = value as Row;

            if (rowValue != null)
            {
                return(rowValue.DataType);
            }

            TableValue tableValue = value as TableValue;

            if (tableValue != null)
            {
                return(tableValue.DataType);
            }

            throw new NotSupportedException("Non-scalar-valued attributes are not supported.");
        }
Пример #3
0
        public override object InternalExecute(Program program, object[] arguments)
        {
            string result;

            string     verb         = (string)arguments[0];
            string     uRL          = (string)arguments[1];
            TableValue headersTable = (TableValue)arguments[2];
            ITable     headers      = headersTable != null?headersTable.OpenCursor() : null;

            string body = (string)arguments[3];

            // Prepare the request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uRL);

            request.Method          = verb;
            request.ProtocolVersion = new Version(1, 1);
            request.KeepAlive       = false;
            request.Timeout         = 3600000;     // Setting to an hour to account for long running queries in the ruler

            if (headers != null)
            {
                using (Row row = new Row(program.ValueManager, headers.DataType.RowType))
                {
                    while (headers.Next())
                    {
                        headers.Select(row);

                        var header = (HttpRequestHeader)Enum.Parse(typeof(HttpRequestHeader), (string)row["Header"]);

                        switch (header)
                        {
                        case HttpRequestHeader.Accept: request.Accept = (string)row["Value"]; break;

                        case HttpRequestHeader.ContentType: request.ContentType = (string)row["Value"]; break;

                        default: request.Headers[header] = (string)row["Value"]; break;
                        }
                    }
                }
            }

            // Write the body
            if (!String.IsNullOrEmpty(body))
            {
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                    writer.Write(body);
            }

            // Get and read the response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream);
                result = reader.ReadToEnd();
                reader.Close();
            }

            return(result);
        }
Пример #4
0
    public int InsertNewWall()//returns new wall ID
    {
        TableOpreatorClass oTable = new TableOpreatorClass();

        TableValue value1 = new TableValue();

        value1.ValueName = "ID";
        int ID = oTable.GenerateNewID("ID", "Wall");

        value1.Value = ID;

        int returnValue = ID;

        TableValue value2 = new TableValue();

        value2.ValueName = "PublicationListID";
        ID           = oTable.GenerateNewID("ID", "PublicationList");
        value2.Value = ID;

        TableValue value3 = new TableValue();

        value3.ValueName = "DateTime";
        value3.Value     = DateTime.Now;

        List <TableValue> tableValueList = new List <TableValue>();

        tableValueList.Add(value1);
        tableValueList.Add(value2);
        tableValueList.Add(value3);

        oTable.InsertToTable(tableValueList, "Wall");//CreateNewWall

        return(returnValue);
    }
Пример #5
0
        private List <TableValue> GetAllTableValues(string tableXML)
        {
            List <string> valueList = GetXMLValues(tableXML);

            if (valueList.Any(s => s.Contains("&amp;") || s.Contains("&gt;") || s.Contains("&lt;") || s.Contains("&apos;") || s.Contains("&quot;")))
            {
                List <string> keyList    = GetXMLTagValues(tableXML, "Key");
                List <string> columnList = GetXMLTagValues(tableXML, "Column");
                List <string> rowList    = GetXMLTagValues(tableXML, "Row");
                List <string> groupList  = GetXMLTagValues(tableXML, "Group");

                tableXML = CreateXML(valueList, keyList, columnList, rowList, groupList);
            }

            XDocument doc = XDocument.Parse(tableXML);

            List <TableValue> tblDocVal = new List <TableValue>();

            var list = doc.Root.Elements("Value")
                       .Select(element => new { Key = element.Element("Key").Value, Value = element.Element("Value").Value, Row = element.Element("Row").Value, Column = element.Element("Column").Value, Group = element.Element("Group").Value })
                       .ToList();

            for (int i = 0; i < list.Count(); i++)
            {
                TableValue tab = new TableValue();
                tab.Key    = list.ElementAt(i).Key;
                tab.Value  = list.ElementAt(i).Value;
                tab.Row    = list.ElementAt(i).Row;
                tab.Column = list.ElementAt(i).Column;
                tab.Group  = list.ElementAt(i).Group;
                tblDocVal.Add(tab);
            }
            return(tblDocVal);
        }
Пример #6
0
        // Left is a scalar. Right is a single-column table.
        // See in_ST()
        public static Func <IRContext, FormulaValue[], FormulaValue> InScalarTableOperator(bool exact)
        {
            return((irContext, args) =>
            {
                var left = args[0];
                var right = args[1];

                if (!exact && left is StringValue strLhs)
                {
                    left = strLhs.ToLower();
                }

                TableValue source = (TableValue)right;

                foreach (var row in source.Rows)
                {
                    if (row.IsValue)
                    {
                        var rhs = row.Value.Fields.First().Value;

                        if (!exact && rhs is StringValue strRhs)
                        {
                            right = strRhs.ToLower();
                        }

                        if (RuntimeHelpers.AreEqual(left, rhs))
                        {
                            return new BooleanValue(irContext, true);
                        }
                    }
                }
                return new BooleanValue(irContext, false);
            });
        }
Пример #7
0
        public override object InternalExecute(Program program, object[] arguments)
        {
            string result;

            string     uRL         = (string)arguments[0];
            TableValue fieldsTable = (TableValue)arguments[1];
            ITable     fields      = fieldsTable.OpenCursor();

            // Build the URL encoding for the body
            StringBuilder body = new StringBuilder();

            using (Row row = new Row(program.ValueManager, fields.DataType.RowType))
            {
                while (fields.Next())
                {
                    fields.Select(row);

                    if (body.Length > 0)
                    {
                        body.Append("&");
                    }

                    body.Append(HttpUtility.UrlEncode((string)row["FieldName"]));
                    body.Append("=");
                    body.Append(HttpUtility.UrlEncode((string)row["Value"]));
                }
            }

            // Prepare the request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uRL);

            request.Method          = "POST";
            request.ProtocolVersion = new Version(1, 1);
            request.KeepAlive       = false;
            request.ContentType     = "application/x-www-form-urlencoded";

            // Write the body
            using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                writer.Write(body.ToString());

            // Get and read the response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream);
                result = reader.ReadToEnd();
                reader.Close();
            }

            return(result);
        }
        public static void SetDataTableValuesFromList <T>(this Project iProject, List <T> iDataList, string iDataTableName)
        {
            //Retourne une table vide si vide
            if (iDataList.IsNullOrEmpty())
            {
                iProject.SetTableControlItems(iDataTableName, null);
            }

            //Mise en forme du tableau et de l'entête via la classe DossierView
            Type dataViewType = typeof(T);
            var  arraySize    = dataViewType.GetProperties().Count();
            var  objectArray  = new object[iDataList.Count + 1, arraySize];

            var columnIndex = 0;

            foreach (var propertyItem in dataViewType.GetProperties().Enum())
            {
                objectArray[0, columnIndex] = dataViewType.GetName(propertyItem.Name, "FR");
                columnIndex++;
            }

            //Convertion list des objects en tableau et intégration dans le tableau final
            var dataArray = iDataList.ToStringArray();

            Array.Copy(dataArray, 0, objectArray, objectArray.GetLength(1), dataArray.Length);

            //Dimension des colonnes
            var widthList = new List <string>();

            foreach (var propertyItem in dataViewType.GetProperties().Enum())
            {
                var width = dataViewType.GetWidthColumn(propertyItem.Name);
                if (width != null)
                {
                    widthList.Add(Convert.ToString(width));
                }
                else
                {
                    widthList.Add("120");
                }
            }

            //Remplissage tableau
            var tableValue = new TableValue();

            tableValue.Data = objectArray;

            iProject.SetTableControlItems(iDataTableName, tableValue, widthList);
        }
Пример #9
0
        /// <summary>
        /// Starts this instance. In derived class you have to execute this base before your overrided code.
        /// </summary>
        public override void Start()
        {
            base.Start();

            try
            {
                using (var transaction = uow.BeginTransaction())
                {
                    var storageService = ((Common)ParentEngineModule).StorageService;

                    // Get parameters
                    //var sourceFilePath = GetDataValue(EngineDataDirection.Input, "SourceFilePath").Get<string>();
                    var sourceFilePath       = GetDataValue(EngineDataDirection.Input, "SourceFilePath").Get <VirtualPath>();
                    var skipStartingDataRows = GetDataValue(EngineDataDirection.Input, "SkipStartingDataRows").GetNullable <int>();
                    var firstRowHasHeader    = GetDataValue(EngineDataDirection.Input, "FirstRowHasHeader").Get <bool>();
                    var columnDelimiter      = GetDataValue(EngineDataDirection.Input, "ColumnDelimiter").Get <char>();
                    var limitToRows          = GetDataValue(EngineDataDirection.Input, "LimitToRows").GetNullable <int>();

                    //Start parsing file
                    AddMessage("Configuring parser to read file", MessageSeverity.Debug);
                    var parser = new GenericParserAdapter(storageService.FileOpenTextReader(sourceFilePath));
                    parser.SkipStartingDataRows = skipStartingDataRows ?? 0;
                    parser.FirstRowHasHeader    = firstRowHasHeader;
                    parser.ColumnDelimiter      = columnDelimiter;
                    parser.MaxRows = limitToRows ?? 0;
                    var table = new TableValue();

                    AddMessage($"Begin parsing file: '{sourceFilePath}'.", MessageSeverity.Debug);
                    table.Set(parser.GetDataTable());

                    AddMessage($"Setting output value in element.", MessageSeverity.Debug);
                    SetDataValue(EngineDataDirection.Output, "Table", table);

                    AddMessage($"Releasing unnecessary resources.", MessageSeverity.Debug);
                    parser.Dispose();

                    AddMessage($"Parsing file completed. {table.RowCount} read.", MessageSeverity.Debug);
                }
            }
            catch (Exception e)
            {
                AddMessage($"Error reading flat file. {e.Message}", MessageSeverity.Error);
            }
        }
Пример #10
0
        public override void Start()
        {
            base.Start();

            try
            {
                var table = new TableValue();

                // Get parameters
                var connectionString = GetDataValue(EngineDataDirection.Input, "ConnectionString").Get <string>();
                var sqlQuery         = GetDataValue(EngineDataDirection.Input, "SqlQuery").Get <string>();

                var sqlErrors = new List <string>();
                if (!sqlValidationService.IsSQLQueryValid(sqlQuery, out sqlErrors))
                {
                    AddMessage($"Error/s in the sql query provided: {string.Join("; ", sqlErrors)}", MessageSeverity.Error);
                    return;
                }

                //Start connecting to SQL
                using (SqlConnection sourceConnection = new SqlConnection(connectionString))
                {
                    sourceConnection.Open();

                    // Get data from the source table as a SqlDataReader.
                    SqlCommand    commandSourceData = new SqlCommand(sqlQuery, sourceConnection);
                    SqlDataReader reader            = commandSourceData.ExecuteReader();
                    var           dataTable         = new DataTable();
                    dataTable.Load(reader);
                    table.Set(dataTable);

                    AddMessage($"Setting output value in element.", MessageSeverity.Debug);
                    SetDataValue(EngineDataDirection.Output, "Table", table);

                    AddMessage($"Importing Sql Query completed. {table.RowCount} rows read.", MessageSeverity.Debug);
                }
            }
            catch (Exception e)
            {
                AddMessage($"Error importing SQL Query. {e.Message}", MessageSeverity.Error);
            }
        }
Пример #11
0
    public void AddNewLike(string groupTableName /*Images, Posts or other*/, int groupID /*ImageID, PostID*/, int PeopleID)
    {
        TableOpreatorClass oTable = new TableOpreatorClass();

        List <TableValue> insertValues = new List <TableValue>();

        TableValue tabValue = new TableValue();

        tabValue.ValueName = "GroupTableName";
        tabValue.Value     = groupTableName;
        insertValues.Add(tabValue);

        TableValue tabValue1 = new TableValue();

        tabValue1.ValueName = "GroupID";
        tabValue1.Value     = groupID;
        insertValues.Add(tabValue1);


        TableValue tabValue2 = new TableValue();

        tabValue2.ValueName = "PeopleID";
        tabValue2.Value     = PeopleID;
        insertValues.Add(tabValue2);

        TableValue tabValue3 = new TableValue();

        tabValue3.ValueName = "UniqueID";
        tabValue3.Value     = oTable.GetMaxID("UniqueID", "Like");
        insertValues.Add(tabValue3);

        TableValue tabValue4 = new TableValue();

        tabValue4.ValueName = "IDinGroup";
        tabValue4.Value     = oTable.GetMaxIDInGroup("IDinGroup", "Like", "GroupID", groupID);
        insertValues.Add(tabValue4);

        oTable.InsertToTable(insertValues, "Like");
    }
Пример #12
0
    /// <summary>
    /// 截取出表格被下划线或者,号隔开的值
    /// </summary>
    /// <param name="str"></param>
    /// <param name="cOne"></param>
    /// <param name="cTwo"></param>
    /// <returns></returns>
    public static List <List <TableValue> > StringSplitValue(string str, char cOne, char cTwo, char cThree)
    {
        List <List <TableValue> > fs = new List <List <TableValue> >();

        string[] ss = str.Split(cOne);

        UtilsCollections.ListDoSomething(ss, (st, index) =>
        {
            List <TableValue> vs = new List <TableValue>();
            if (st.Equals(""))
            {
                return;
            }
            string[] _ss = st.Split(cTwo);
            UtilsCollections.ListDoSomething(_ss, (_st, _index) =>
            {
                string[] _s           = _st.Split(cThree);
                TableValue tableValue = new TableValue(int.Parse(_s[0]), float.Parse(_s[1]), int.Parse(_s[2]));
                vs.Add(tableValue);
            });
            fs.Add(vs);
        });
        return(fs);
    }
Пример #13
0
        // Update
        protected override void InternalExecuteUpdate(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool checkConcurrency, bool uncheckedValue)
        {
            base.InternalExecuteUpdate(program, oldRow, newRow, valueFlags, checkConcurrency, uncheckedValue);

            if (PropagateUpdate)
            {
                int columnIndex;
                for (int index = 1; index < Nodes.Count; index++)
                {
                    Schema.TableVarColumn column = TableVar.Columns[_extendColumnOffset + index - 1];
                    if (column.ColumnType == Schema.TableVarColumnType.Stored)
                    {
                        columnIndex = newRow.DataType.Columns.IndexOfName(column.Column.Name);
                        if (columnIndex >= 0)
                        {
                            TableNode tableNode = Nodes[index] as TableNode;
                            if (tableNode == null)
                            {
                                ExtractRowNode extractRowNode = Nodes[index] as ExtractRowNode;
                                if (extractRowNode != null)
                                {
                                    tableNode = (TableNode)extractRowNode.Nodes[0];
                                }
                            }

                            if (tableNode == null)
                            {
                                throw new RuntimeException(RuntimeException.Codes.InternalError, "Could not determine update path for extend column.");
                            }

                            bool referencesUpdatedColumn = ReferencesUpdatedColumn(tableNode, valueFlags);

                            // If the value is a row
                            // If the newValue is nil
                            // If the oldValue is not nil
                            // delete the table node
                            // else
                            // If the oldValue is nil
                            // insert the row
                            // else
                            // update the row

                            // If the value is a table
                            // If the newValue is nil
                            // If the oldValue is not nil
                            // delete all rows
                            // else
                            // If the oldValue is nil
                            // insert all rows
                            // else
                            // foreach row in oldvalue
                            // if there is a corresponding row in new value by the clustering key
                            // update the row
                            // else
                            // delete the row
                            // for each row in newvalue
                            // if there is no corresponding row in old value by the clustering key
                            // insert the row

                            if (column.DataType is Schema.IRowType)
                            {
                                IRow oldValue = (IRow)oldRow.GetValue(columnIndex);
                                IRow newValue = (IRow)newRow.GetValue(columnIndex);
                                if (newValue.IsNil)
                                {
                                    if (!oldValue.IsNil)
                                    {
                                        PushRow(program, oldRow);
                                        try
                                        {
                                            tableNode.Delete(program, oldValue, checkConcurrency, uncheckedValue);
                                        }
                                        finally
                                        {
                                            PopRow(program);
                                        }
                                    }
                                }
                                else
                                {
                                    if (oldValue.IsNil)
                                    {
                                        PushRow(program, newRow);
                                        try
                                        {
                                            tableNode.Insert(program, null, newValue, null, uncheckedValue);
                                        }
                                        finally
                                        {
                                            PopRow(program);
                                        }
                                    }
                                    else
                                    {
                                        if (referencesUpdatedColumn)
                                        {
                                            PushRow(program, oldRow);
                                            try
                                            {
                                                tableNode.Delete(program, oldValue, checkConcurrency, uncheckedValue);
                                            }
                                            finally
                                            {
                                                PopRow(program);
                                            }

                                            PushRow(program, newRow);
                                            try
                                            {
                                                tableNode.Insert(program, null, newValue, null, uncheckedValue);
                                            }
                                            finally
                                            {
                                                PopRow(program);
                                            }
                                        }
                                        else
                                        {
                                            PushRow(program, newRow);
                                            try
                                            {
                                                tableNode.Update(program, oldValue, newValue, null, checkConcurrency, uncheckedValue);
                                            }
                                            finally
                                            {
                                                PopRow(program);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                TableValue oldValue = (TableValue)oldRow.GetValue(columnIndex);
                                TableValue newValue = (TableValue)newRow.GetValue(columnIndex);

                                if (newValue.IsNil)
                                {
                                    if (!oldValue.IsNil)
                                    {
                                        PushRow(program, oldRow);
                                        try
                                        {
                                            using (ITable oldValueCursor = oldValue.OpenCursor())
                                            {
                                                while (oldValueCursor.Next())
                                                {
                                                    using (IRow oldValueCursorRow = oldValueCursor.Select())
                                                    {
                                                        tableNode.Delete(program, oldValueCursorRow, checkConcurrency, uncheckedValue);
                                                    }
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            PopRow(program);
                                        }
                                    }
                                }
                                else
                                {
                                    if (referencesUpdatedColumn)
                                    {
                                        PushRow(program, oldRow);
                                        try
                                        {
                                            using (ITable oldValueCursor = oldValue.OpenCursor())
                                            {
                                                while (oldValueCursor.Next())
                                                {
                                                    using (IRow oldValueCursorRow = oldValueCursor.Select())
                                                    {
                                                        tableNode.Delete(program, oldValueCursorRow, checkConcurrency, uncheckedValue);
                                                    }
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            PopRow(program);
                                        }

                                        PushRow(program, newRow);
                                        try
                                        {
                                            using (ITable newValueCursor = newValue.OpenCursor())
                                            {
                                                while (newValueCursor.Next())
                                                {
                                                    using (IRow newValueCursorRow = newValueCursor.Select())
                                                    {
                                                        tableNode.Insert(program, null, newValueCursorRow, null, uncheckedValue);
                                                    }
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            PopRow(program);
                                        }
                                    }
                                    else
                                    {
                                        PushRow(program, newRow);
                                        try
                                        {
                                            if (oldValue.IsNil)
                                            {
                                                using (ITable newValueCursor = newValue.OpenCursor())
                                                {
                                                    while (newValueCursor.Next())
                                                    {
                                                        using (IRow newValueCursorRow = newValueCursor.Select())
                                                        {
                                                            tableNode.Insert(program, null, newValueCursorRow, null, uncheckedValue);
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                using (ITable oldValueCursor = oldValue.OpenCursor())
                                                {
                                                    using (ITable newValueCursor = newValue.OpenCursor())
                                                    {
                                                        while (oldValueCursor.Next())
                                                        {
                                                            using (IRow oldValueCursorRow = oldValueCursor.Select())
                                                            {
                                                                if (newValueCursor.FindKey(oldValueCursorRow))
                                                                {
                                                                    using (IRow newValueCursorRow = newValueCursor.Select())
                                                                    {
                                                                        tableNode.Update(program, oldValueCursorRow, newValueCursorRow, null, checkConcurrency, uncheckedValue);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    tableNode.Delete(program, oldValueCursorRow, checkConcurrency, uncheckedValue);
                                                                }
                                                            }
                                                        }

                                                        newValueCursor.Reset();

                                                        while (newValueCursor.Next())
                                                        {
                                                            using (IRow newValueCursorRow = newValueCursor.Select())
                                                            {
                                                                if (!oldValueCursor.FindKey(newValueCursorRow))
                                                                {
                                                                    tableNode.Insert(program, null, newValueCursorRow, null, uncheckedValue);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            PopRow(program);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #14
0
 public ulong FromPosTableValue(TableValue value) => value.Value.ToByteArray().ToUint64();
Пример #15
0
        // Insert
        protected override void InternalExecuteInsert(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool uncheckedValue)
        {
            base.InternalExecuteInsert(program, oldRow, newRow, valueFlags, uncheckedValue);

            if (PropagateInsert != PropagateAction.False)
            {
                PushRow(program, newRow);
                try
                {
                    int columnIndex;
                    for (int index = 1; index < Nodes.Count; index++)
                    {
                        Schema.TableVarColumn column = TableVar.Columns[_extendColumnOffset + index - 1];
                        if (column.ColumnType == Schema.TableVarColumnType.Stored)
                        {
                            columnIndex = newRow.DataType.Columns.IndexOfName(column.Column.Name);
                            if (columnIndex >= 0)
                            {
                                TableNode tableNode = Nodes[index] as TableNode;
                                if (tableNode == null)
                                {
                                    ExtractRowNode extractRowNode = Nodes[index] as ExtractRowNode;
                                    if (extractRowNode != null)
                                    {
                                        tableNode = (TableNode)extractRowNode.Nodes[0];
                                    }
                                }

                                if (tableNode == null)
                                {
                                    throw new RuntimeException(RuntimeException.Codes.InternalError, "Could not determine update path for extend column.");
                                }

                                IDataValue newValue = newRow.GetValue(columnIndex);
                                if (!newValue.IsNil)
                                {
                                    IRow newRowValue = newValue as IRow;
                                    if (newRowValue != null)
                                    {
                                        PerformInsert(program, tableNode, null, newRowValue, null, uncheckedValue);
                                    }
                                    else
                                    {
                                        TableValue newTableValue = (TableValue)newValue;
                                        using (ITable newTableCursor = newTableValue.OpenCursor())
                                        {
                                            while (newTableCursor.Next())
                                            {
                                                using (IRow newTableCursorRow = newTableCursor.Select())
                                                {
                                                    PerformInsert(program, tableNode, null, newTableCursorRow, null, uncheckedValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    PopRow(program);
                }
            }
        }
Пример #16
0
 public static EnumerableRowCollection <DataRow> AsEnumerable(this TableValue source)
 {
     return(source.Значение != null?source.Значение.AsEnumerable() : null);
 }
Пример #17
0
 public VectorClock FromClockTableValue(TableValue value) => VectorClock.Parser.ParseFrom(value);
Пример #18
0
    public void InsertNewPublication(int AuthorID /*PeopleID*/, int WallID, string Text, List <int> ImageIDList)
    {
        TableOpreatorClass oTable = new TableOpreatorClass();

        TableValue value1 = new TableValue();

        value1.ValueName = "WallID";
        value1.Value     = WallID;


        TableValue value2 = new TableValue();

        value2.ValueName = "UniqueID";
        int PublicationID = oTable.GenerateNewID("UniqueID", "Publication");

        value2.Value = PublicationID;


        TableValue value3 = new TableValue();

        value3.ValueName = "IDinSequence";
        value3.Value     = oTable.GetMaxIDInGroup("IDinSequence", "Publication", "WallID", WallID);/*У стенки много публикаций
                                                                                                    * Каждая публикация имеет уникальный айди и айди (IDinSequence) в последовательности публикаций со сходным WallID                                                                                      */

        TableValue value4 = new TableValue();

        value4.ValueName = "DateTime";
        value4.Value     = DateTime.Now;

        TableValue value5 = new TableValue();

        value5.ValueName = "ImageListID";
        value5.Value     = oTable.GenerateNewID("ID", "ImageList");

        TableValue value6 = new TableValue();

        value6.ValueName = "AuthorID";
        value6.Value     = AuthorID;

        TableValue value7 = new TableValue();

        value7.ValueName = "Text";
        value7.Value     = Text;

        List <TableValue> tableValueList = new List <TableValue>();

        tableValueList.Add(value1);
        tableValueList.Add(value2);
        tableValueList.Add(value3);
        tableValueList.Add(value4);
        tableValueList.Add(value5);
        tableValueList.Add(value6);
        tableValueList.Add(value7);

        oTable.InsertToTable(tableValueList, "Wall");//CreateNewWall


        tableValueList.Clear();

        TableValue value8 = new TableValue();

        value8.ValueName = "ID";
        Wall oWall             = new Wall();
        int  PublicationListID = oWall.GetPublicationListID(WallID);//узнаем айди списка публикаций

        value8.Value = PublicationListID;

        TableValue value9 = new TableValue();

        value9.ValueName = "PublicationID";
        value9.Value     = PublicationID;


        oTable.InsertToTable(tableValueList, "PublicationList");//CreateNewWall
    }
Пример #19
0
 public TableAndValue(Table table, TableValue tableValue)
     : this()
 {
     this.Table      = table;
     this.TableValue = tableValue;
 }
Пример #20
0
 public TableColumn(string _columnName, TableValue _defaultValue)
 {
     name         = _columnName;
     defaultValue = _defaultValue;
 }
Пример #21
0
        public static object DataValueToValue(IServerProcess process, IDataValue dataValue)
        {
            if (dataValue == null)
            {
                return(null);
            }

            IScalar scalar = dataValue as IScalar;

            if (scalar != null)
            {
                return(ScalarTypeNameToValue(dataValue.DataType.Name, scalar));
            }

            ListValue list = dataValue as ListValue;

            if (list != null)
            {
                var listValue = new List <object>();
                if (!list.IsNil)
                {
                    for (int index = 0; index < list.Count(); index++)
                    {
                        listValue.Add(DataValueToValue(process, list.GetValue(index)));
                    }
                }
                return(listValue);
            }

            IRow row = dataValue as IRow;

            if (row != null)
            {
                var rowValue = new Dictionary <string, object>();

                if (!row.IsNil)
                {
                    for (int index = 0; index < row.DataType.Columns.Count; index++)
                    {
                        var data = row.GetValue(index);
                        data.DataType.Name = DataTypeToDataTypeName(process.DataTypes, row.DataType.Columns[index].DataType);
                        rowValue.Add(row.DataType.Columns[index].Name, DataValueToValue(process, data));
                    }
                }
                return(rowValue);
            }

            TableValue     tableValue = dataValue as TableValue;
            TableValueScan scan       = null;

            try
            {
                if (tableValue != null)
                {
                    scan = new TableValueScan(tableValue);
                    scan.Open();
                    dataValue = scan;
                }

                ITable table = dataValue as ITable;
                if (table != null)
                {
                    var resultTable = new List <object>();

                    if (!table.BOF())
                    {
                        table.First();
                    }

                    bool[] valueTypes = new bool[table.DataType.Columns.Count];
                    for (int index = 0; index < table.DataType.Columns.Count; index++)
                    {
                        valueTypes[index] = table.DataType.Columns[index].DataType is IScalarType;
                    }

                    while (table.Next())
                    {
                        using (IRow currentRow = table.Select())
                        {
                            object[] nativeRow = new object[table.DataType.Columns.Count];
                            for (int index = 0; index < table.DataType.Columns.Count; index++)
                            {
                                if (valueTypes[index])
                                {
                                    resultTable.Add(currentRow[index]);
                                }
                                else
                                {
                                    resultTable.Add(DataValueToValue(process, currentRow.GetValue(index)));
                                }
                            }
                        }
                    }

                    return(resultTable);
                }
            }
            finally
            {
                if (scan != null)
                {
                    scan.Dispose();
                }
            }

            throw new NotSupportedException(string.Format("Values of type \"{0}\" are not supported.", dataValue.DataType.Name));
        }
Пример #22
0
 public ReplicaCounters FromCountersTableValue(TableValue value) => ReplicaCounters.Parser.ParseFrom(value);
Пример #23
0
        private void OpenChangeValueDialog(object sender, EventArgs e)
        {
            if (!(sender is ToolStripItem menuItem))
            {
                return;
            }
            if (!(menuItem.Owner is ContextMenuStrip owner))
            {
                return;
            }
            Label senderLabel = (Label)owner.SourceControl;

            if (senderLabel == null)
            {
                return;
            }

            TableLayoutPanelCellPosition position = uiElement.GetPositionFromControl(senderLabel);
            int c = position.Column;
            int r = position.Row;

            if (r > rows.Count)
            {
                return;
            }

            List <Control> valueControls       = new List <Control>();
            List <Control> nonValueControls    = new List <Control>();
            int            valueControlsHeight = 5;
            int            tabIndexCounter     = 0;

            TableValue value = rows[r - 1].values[c];

            value.BuildValueControls(columns[c].name, 5, 300, ref valueControls, ref nonValueControls, ref valueControlsHeight, ref tabIndexCounter);

            Form prompt = new Form
            {
                StartPosition = FormStartPosition.CenterParent,
                Width         = 325,
                Height        = valueControlsHeight + 70,
                Text          = "Change value"
            };

            bool confirmed = false;

            foreach (Control valueControl in valueControls)
            {
                valueControl.KeyDown += (sender2, e2) => { if (e2.KeyCode == Keys.Return)
                                                           {
                                                               confirmed = true; prompt.Close();
                                                           }
                };
                prompt.Controls.Add(valueControl);
            }
            foreach (Control nonValueControl in nonValueControls)
            {
                prompt.Controls.Add(nonValueControl);
            }

            Button confirmation = new Button()
            {
                Text = "Add", Left = 205, Width = 100, Top = valueControlsHeight
            };

            confirmation.TabIndex = tabIndexCounter;
            confirmation.Click   += (sender2, e2) => { confirmed = true; prompt.Close(); };
            prompt.Controls.Add(confirmation);
            prompt.ShowDialog();

            if (confirmed)
            {
                value.SetValueWithControls(valueControls);
                OnTableChanged();
            }
        }
Пример #24
0
 public static Task <bool> AddOrUpdate(this LightningPersistence lmdb, Table table, TableKey key, TableValue value, bool requiresIsolation = false) =>
 lmdb.WriteAsync(txn => txn.AddOrUpdate(table, key, value), requiresIsolation);
Пример #25
0
 public KvMetadata FromTableValue(TableValue value) => KvMetadata.Parser.ParseFrom(value);
Пример #26
0
        void OpenAddRowDialog(object sender, EventArgs e)
        {
            List <List <Control> > valueControls    = new List <List <Control> >();
            List <Control>         nonValueControls = new List <Control>();
            int valueControlsHeight = 5;
            int tabIndexCounter     = 0;

            foreach (TableColumn column in columns)
            {
                List <Control> columnControls = new List <Control>();
                column.defaultValue.BuildValueControls(column.name, 5, 300, ref columnControls, ref nonValueControls, ref valueControlsHeight, ref tabIndexCounter);
                valueControls.Add(columnControls);
                valueControlsHeight += 10;
            }

            Form prompt = new Form
            {
                StartPosition = FormStartPosition.CenterParent,
                Width         = 325,
                Height        = valueControlsHeight + 70,
                Text          = "Add " + rowName
            };

            foreach (List <Control> columnControls in valueControls)
            {
                foreach (Control valueControl in columnControls)
                {
                    prompt.Controls.Add(valueControl);
                }
            }
            foreach (Control nonValueControl in nonValueControls)
            {
                prompt.Controls.Add(nonValueControl);
            }

            bool confirmed = false;

            Button confirmation = new Button()
            {
                Text = "Add", Left = 205, Width = 100, Top = valueControlsHeight
            };

            confirmation.TabIndex = tabIndexCounter;
            confirmation.Click   += (sender2, e2) => { confirmed = true; prompt.Close(); };
            prompt.Controls.Add(confirmation);
            prompt.ShowDialog();

            if (confirmed)
            {
                TableRow newRow = new TableRow();
                for (int i = 0; i < columns.Count; ++i)
                {
                    TableValue newValue = Program.DeepClone(columns[i].defaultValue);
                    newValue.SetValueWithControls(valueControls[i]);
                    newRow.values.Add(newValue);
                }
                rows.Add(newRow);

                OnTableChanged();
            }
        }
Пример #27
0
        // Delete
        protected override void InternalExecuteDelete(Program program, IRow row, bool checkConcurrency, bool uncheckedValue)
        {
            base.InternalExecuteDelete(program, row, checkConcurrency, uncheckedValue);

            if (PropagateDelete)
            {
                PushRow(program, row);
                try
                {
                    int columnIndex;
                    for (int index = 1; index < Nodes.Count; index++)
                    {
                        Schema.TableVarColumn column = TableVar.Columns[_extendColumnOffset + index - 1];
                        if (column.ColumnType == Schema.TableVarColumnType.Stored)
                        {
                            columnIndex = row.DataType.Columns.IndexOfName(column.Column.Name);
                            if (columnIndex >= 0)
                            {
                                TableNode tableNode = Nodes[index] as TableNode;
                                if (tableNode == null)
                                {
                                    ExtractRowNode extractRowNode = Nodes[index] as ExtractRowNode;
                                    if (extractRowNode != null)
                                    {
                                        tableNode = (TableNode)extractRowNode.Nodes[0];
                                    }
                                }

                                if (tableNode == null)
                                {
                                    throw new RuntimeException(RuntimeException.Codes.InternalError, "Could not determine update path for extend column.");
                                }

                                IDataValue oldValue = row.GetValue(columnIndex);
                                if (!oldValue.IsNil)
                                {
                                    IRow oldRowValue = oldValue as IRow;
                                    if (oldRowValue != null)
                                    {
                                        tableNode.Delete(program, oldRowValue, checkConcurrency, uncheckedValue);
                                    }
                                    else
                                    {
                                        TableValue oldTableValue = (TableValue)oldValue;
                                        using (ITable oldTableCursor = oldTableValue.OpenCursor())
                                        {
                                            while (oldTableCursor.Next())
                                            {
                                                using (IRow oldTableCursorRow = oldTableCursor.Select())
                                                {
                                                    tableNode.Delete(program, oldTableCursorRow, checkConcurrency, uncheckedValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    PopRow(program);
                }
            }
        }
Пример #28
0
 private bool Equals(TableValue <TState, TSymbol> other)
 {
     return(base.Equals(other) && _action.Equals(other._action));
 }
Пример #29
0
 public WriteLogEvent FromTableValue(TableValue value) => WriteLogEvent.Parser.ParseFrom(value);
Пример #30
0
        static void Main(string[] args)
        {
            #region Test1

            IAbstractValue[] Test1_InitialDataArray = new IAbstractValue[] { new IntValue(685000), new StringValue("Hello!") };
            TableValue       Test1_InitialData      = TableValue.ArrayToTable(Test1_InitialDataArray);

            Console.WriteLine("Begin Test 1");
            Console.WriteLine();

            EncoderStream Test1_EnStream = new EncoderStream();
            string        Test1_EncodeResult;

            Console.Write("Encoding...");
            Test1_EnStream.InputValue(Test1_InitialData);
            Test1_EncodeResult = Test1_EnStream.PopOutput();
            Console.WriteLine(" Done!");
            Console.WriteLine(string.Concat("Encode Result: ", Test1_EncodeResult));

            Console.WriteLine();
            Console.WriteLine("End Test 1");

            #endregion

            Console.WriteLine();

            #region Test2

            // The string that was in the Specification.odt document.
            string Test2_InitialString = "[\"My name is PC!\";800;]||[\"Data1\":0.56;\"Data2\":\"true \\| false\";]||[[\"My home.\";T;1000;F;];]||";

            Console.WriteLine("Begin Test 2");
            Console.WriteLine();
            Console.WriteLine(string.Concat("Initial String: ", Test2_InitialString));
            Console.WriteLine();

            DecoderStream    Test2_DeStream = new DecoderStream();
            EncoderStream    Test2_EnStream = new EncoderStream();
            IAbstractValue[] Test2_DecodeResult;
            string           Test2_EncodeResult;

            Console.Write("Decoding...");
            Test2_DeStream.InputValue(Test2_InitialString);
            Test2_DeStream.RunParser();
            Test2_DecodeResult = Test2_DeStream.PopOutput(); // ((TableValue)Test2_DeStream.PopOutput()[0]).Value;
            Console.WriteLine(" Done!");
            Console.Write("Encoding...");
            foreach (var item in Test2_DecodeResult)
            {
                Test2_EnStream.InputValue(item);
            }
            Test2_EncodeResult = Test2_EnStream.PopOutput();
            Console.WriteLine(" Done!");

            Console.WriteLine();
            Console.WriteLine(string.Concat("Encode Result: ", Test2_EncodeResult));
            Console.WriteLine(string.Concat("Strings Match: ", (Test2_InitialString == Test2_EncodeResult).ToString()));
            Console.WriteLine();
            Console.WriteLine("End Test 2");

            #endregion

            Console.WriteLine();
            Console.WriteLine("Exiting Program...");

            return;
        }