private void ParseQueryItem(QueryProtocol queryItem)
        {
            // Parse DataFields
            if (queryItem.DataFields != null)
            {
                foreach (string dataField in queryItem.DataFields)
                {
                    queryItem.ClarifyGeneric.DataFields.Add(dataField);
                }
            }

            if (queryItem.Filters != null)
            {
                ParseQueryItemFilters(queryItem);
            }

            if (queryItem.FiltersInList != null)
            {
                ParseQueryItemFiltersInList(queryItem);
            }

            if (queryItem.Sorts != null)
            {
                ParseQueryItemSorts(queryItem);
            }

            if (queryItem.ChildGenerics != null)
            {
                ParseQueryItemsToGenerics(queryItem.ChildGenerics, queryItem);
            }
        }
예제 #2
0
 private string GetTableName(QueryProtocol queryItem)
 {
     return(queryItem.ResultTableName != null &&
            queryItem.ResultTableName.Trim().Length > 0
                         ? queryItem.ResultTableName.Trim()
                         : queryItem.ObjectName.Trim());
 }
        private void ParseQueryItemSorts(QueryProtocol queryItem)
        {
            foreach (SortProtocol sort in queryItem.Sorts)
            {
                if (!ClarifyApplication.Instance.SchemaCache.IsValidField(
                        queryItem.ObjectName, sort.Field))
                {
                    throw new ApplicationException(string.Format("'{0}' is not a valid field for object '{0}'.",
                                                                 sort.Field, queryItem.ObjectName));
                }

                queryItem.ClarifyGeneric.AppendSort(sort.Field, sort.IsAscending);
            }
        }
        private void ParseQueryItemFilters(QueryProtocol queryItem)
        {
            foreach (FilterProtocol filter in queryItem.Filters)
            {
                if (!ClarifyApplication.Instance.SchemaCache.IsValidField(
                        queryItem.ObjectName, filter.Field))
                {
                    throw new ApplicationException(string.Format("'{0}' is not a valid field for object '{1}'.",
                                                                 filter.Field, queryItem.ObjectName));
                }

                SchemaFieldBase field = ClarifyApplication.Instance.SchemaCache.GetField(queryItem.ObjectName, filter.Field);

                NumberOps numberOp;
                switch (field.CommonType)
                {
                case (int)SchemaCommonType.String:
                    StringOps strOp = (StringOps)GetParsedFilterOperation(typeof(StringOps), filter, queryItem.ObjectName);
                    queryItem.ClarifyGeneric.AppendFilter(filter.Field, strOp, filter.Value);
                    break;

                case (int)SchemaCommonType.Date:
                    DateOps  dateOp  = (DateOps)GetParsedFilterOperation(typeof(DateOps), filter, queryItem.ObjectName);
                    DateTime dateVal = GetParsedFilterValueToDateTime(filter, queryItem.ObjectName);

                    queryItem.ClarifyGeneric.AppendFilter(filter.Field, dateOp, dateVal);
                    break;

                case (int)SchemaCommonType.Float:
                case (int)SchemaCommonType.Double:
                case (int)SchemaCommonType.Decimal:
                    numberOp = (NumberOps)GetParsedFilterOperation(typeof(NumberOps), filter, queryItem.ObjectName);
                    Decimal decVal = GetParsedFilterValueToDecimal(filter, queryItem.ObjectName);

                    queryItem.ClarifyGeneric.AppendFilter(filter.Field, numberOp, decVal);
                    break;

                case (int)SchemaCommonType.Integer:
                    numberOp = (NumberOps)GetParsedFilterOperation(typeof(NumberOps), filter, queryItem.ObjectName);
                    int intVal = GetParsedFilterValueToInetger(filter, queryItem.ObjectName);

                    queryItem.ClarifyGeneric.AppendFilter(filter.Field, numberOp, intVal);
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Parse logic not implemented for SchemaCommonType.{0}", field.CommonType));
                }
            }
        }
        private void ParseQueryItemsToGenerics(QueryProtocol[] queryItems, QueryProtocol parentQueryItem)
        {
            bool isRootGeneric = parentQueryItem == null;

            foreach (QueryProtocol queryItem in queryItems)
            {
                if (isRootGeneric)
                {
                    if (!ClarifyApplication.Instance.SchemaCache.IsValidTableOrView(queryItem.ObjectName))
                    {
                        throw new ApplicationException(
                                  string.Format("'{0}' is not a table or view.", queryItem.ObjectName));
                    }

                    queryItem.ClarifyGeneric = this.dataSet.CreateGeneric(queryItem.ObjectName);
                }
                else
                {
                    // Link up child / parents
                    queryItem.Parent = parentQueryItem;

                    if (!ClarifyApplication.Instance.SchemaCache.IsValidRelation(parentQueryItem.ObjectName, queryItem.TraverseRelation))
                    {
                        throw new ApplicationException(
                                  string.Format("'{0}' is not a valid relation for object '{1}'.", queryItem.TraverseRelation, parentQueryItem.ObjectName));
                    }

                    SchemaRelation rel = ClarifyApplication.Instance.SchemaCache.GetRelation(
                        parentQueryItem.ObjectName, queryItem.TraverseRelation);

                    if (parentQueryItem.ObjectName.ToLower() == rel.ChildTable.Name.ToLower())
                    {
                        queryItem.ObjectName = rel.ParentTable.Name;
                    }
                    else
                    {
                        queryItem.ObjectName = rel.ChildTable.Name;
                    }

                    queryItem.ClarifyGeneric = parentQueryItem.ClarifyGeneric.Traverse(
                        queryItem.TraverseRelation);
                }

                ParseQueryItem(queryItem);
            }
        }
        private void ParseQueryItemFiltersInList(QueryProtocol queryItem)
        {
            foreach (FilterInListProtocol filter in queryItem.FiltersInList)
            {
                if (!ClarifyApplication.Instance.SchemaCache.IsValidField(
                        queryItem.ObjectName, filter.Field))
                {
                    throw new ApplicationException(string.Format("'{0}' is not a valid field for object '{1}'.",
                                                                 filter.Field, queryItem.ObjectName));
                }

                SchemaFieldBase field = ClarifyApplication.Instance.SchemaCache.GetField(queryItem.ObjectName, filter.Field);

                switch (field.CommonType)
                {
                case (int)SchemaCommonType.String:
                    queryItem.ClarifyGeneric.AppendFilterInList(filter.Field, filter.IsIn, filter.Values);
                    break;

                case (int)SchemaCommonType.Date:
                    DateTime[] dateVals = GetParsedFilterInListValueToDateTime(filter, queryItem.ObjectName);

                    queryItem.ClarifyGeneric.AppendFilterInList(filter.Field, filter.IsIn, dateVals);
                    break;

                case (int)SchemaCommonType.Float:
                case (int)SchemaCommonType.Double:
                case (int)SchemaCommonType.Decimal:
                    Decimal[] decVals = GetParsedFilterInListValueToDecimal(filter, queryItem.ObjectName);

                    queryItem.ClarifyGeneric.AppendFilterInList(filter.Field, filter.IsIn, decVals);
                    break;

                case (int)SchemaCommonType.Integer:
                    int[] intVals = GetParsedFilterInListValueToInetger(filter, queryItem.ObjectName);

                    queryItem.ClarifyGeneric.AppendFilterInList(filter.Field, filter.IsIn, intVals);
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Parse logic not implemented for SchemaCommonType.{0}", field.CommonType));
                }
            }
        }
예제 #7
0
        private void CreateDataTable(DataSet ds, QueryProtocol queryItem)
        {
            queryItem.ResultDataTable = new DataTable(GetTableName(queryItem));
            ds.Tables.Add(queryItem.ResultDataTable);

            SchemaFieldBase[] fields = GetTableFields(queryItem.ObjectName, queryItem.DataFields);

            DataColumn column;

            foreach (SchemaFieldBase field in fields)
            {
                column = queryItem.ResultDataTable.Columns.Add(field.Name, field.ObjectType);
                column.ColumnMapping = MappingType.Attribute;
            }

            column = queryItem.ResultDataTable.Columns.Add("_id", typeof(int));
            column.ColumnMapping = MappingType.Hidden;
            column.AutoIncrement = true;
            column.Unique        = true;

            if (queryItem.Parent != null)
            {
                column = queryItem.ResultDataTable.Columns.Add("_parentid", typeof(int));
                column.ColumnMapping = MappingType.Hidden;

                DataRelation dataRel = new DataRelation(
                    queryItem.TraverseRelation,
                    queryItem.Parent.ResultDataTable.Columns["_id"],
                    queryItem.ResultDataTable.Columns["_parentid"], false);

                dataRel.Nested = true;
                ds.Relations.Add(dataRel);
            }

            if (queryItem.ChildGenerics != null)
            {
                CreateDataTables(ds, queryItem.ChildGenerics);
            }
        }
예제 #8
0
        private void FillDataTable(DataSet ds, QueryProtocol queryItem, ClarifyDataRow parentClarifyRow, DataRow parentRow)
        {
            IEnumerator clarifyRowEnumerator;

            if (parentClarifyRow == null)
            {
                clarifyRowEnumerator = queryItem.ClarifyGeneric.Rows.GetEnumerator();
            }
            else
            {
                clarifyRowEnumerator = parentClarifyRow.RelatedRows(queryItem.ClarifyGeneric).GetEnumerator();
            }

            while (clarifyRowEnumerator.MoveNext())
            {
                ClarifyDataRow clarifyRow = (ClarifyDataRow)clarifyRowEnumerator.Current;

                DataRow row = queryItem.ResultDataTable.NewRow();
                queryItem.ResultDataTable.Rows.Add(row);

                for (int t = 0; t < row.Table.Columns.Count; t++)
                {
                    if (row.Table.Columns[t].ColumnName == "_parentid")
                    {
                        row[t] = parentRow["_id"];
                    }
                    else if (row.Table.Columns[t].ColumnName != "_id")
                    {
                        row[t] = clarifyRow[row.Table.Columns[t].ColumnName];
                    }
                }

                if (queryItem.ChildGenerics != null)
                {
                    FillDataTables(ds, queryItem.ChildGenerics, clarifyRow, row);
                }
            }
        }
예제 #9
0
        bool ProcessResponses()
        {
            bool receivedany = false;

            while (_browseSocket.Poll(0, SelectMode.SelectRead))
            {
                int len;
                try
                {
                    len = _browseSocket.Receive(_buffer);
                }
                catch (SocketException)
                {
                    // "An existing connection was forcibly closed by the remote host"
                    break;
                }
                if (len == 0)
                {
                    break;
                }

                var gameInfo = QueryProtocol.ExtractGameInfo(_buffer, len);
                if (gameInfo == null)
                {
                    continue;
                }

                OnFoundServer(gameInfo.Value);

                receivedany = true;
                ModifyGameName(_buffer);
                ModifyGamePort(_buffer, len, _proxyPort);
                _browseSocket.SendTo(_buffer, len, SocketFlags.None, _clientEP);
            }

            return(receivedany);
        }
예제 #10
0
 void UpdateBrowsePacket()
 {
     _browsePacket = QueryProtocol.GetBrowsePacket(_expansion, _version);
 }
예제 #11
0
 // The client wont update the player count unless this is sent
 void SendGameAnnounce(GameInfo gameInfo)
 {
     byte[] packet = QueryProtocol.GetGameAnnouncePacket(gameInfo);
     _browseSocket.SendTo(packet, _clientEP);
 }
예제 #12
0
 public void SendGameCancelled(int gameId)
 {
     byte[] packet = QueryProtocol.GetGameCancelledPacket(gameId);
     _browseSocket.SendTo(packet, _clientEP);
 }