Esempio n. 1
0
        /// <summary>
        ///     Executes a prebuilt <see cref="IScalar{T}" /> and returns a single instance of <typeparamref name="T" />
        /// </summary>
        /// <typeparam name="T">The Entity being queried</typeparam>
        /// <param name="query">The prebuilt Query Object</param>
        /// <returns>The task that will return an instance of <typeparamref name="T" /> from the query</returns>
        public virtual Task <T> FindAsync <T>(IScalar <T> query)
        {
            var task = new Task <T>(() => query.Execute(_context));

            task.Start();
            return(task);
        }
Esempio n. 2
0
        public DataTable toDataTable()
        {
            DataTable dt        = buildTable();
            int       itemCount = this.keys().Count;

            IScalar[] keys   = new IScalar[itemCount];
            IEntity[] values = new IEntity[itemCount];
            this.keys().CopyTo(keys, 0);
            this.values().CopyTo(values, 0);
            if (itemCount > 0)
            {
                if (values[0].isScalar() == false)
                {
                    throw new InvalidCastException("Only scalar value supported!");
                }
            }
            for (int i = 0; i < itemCount; i++)
            {
                DataRow dr = dt.NewRow();
                dr["dict_key"]   = keys[i].getObject();
                dr["dict_value"] = values[i].getObject();
                dt.Rows.Add(dr);
            }
            return(dt);
        }
Esempio n. 3
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_SECOND)
     {
         setSecond(index, ((BasicSecond)value).getValue());
     }
 }
Esempio n. 4
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_SHORT)
     {
         setShort(index, ((BasicShort)value).getValue());
     }
 }
 /// <summary>
 /// A xocument stored in memories.
 /// </summary>
 public MemorizedXocument(string name, IMnemonic memories)
 {
     this.name     = name;
     this.memories = memories;
     this.node     =
         new Live <XNode>(() =>
                          memories.Contents().Xml(name, () =>
                                                  new XDocument(
                                                      new XElement(this.root.Value())
                                                      )
                                                  )
                          );
     this.root =
         new ScalarOf <string>(() =>
     {
         var rootName = new Normalized(name).AsString();
         if (rootName.ToLower().EndsWith(".xml"))
         {
             rootName = rootName.Substring(0, rootName.Length - 4);
         }
         if (rootName.Contains("/"))
         {
             rootName = rootName.Substring(rootName.LastIndexOf("/"));
             rootName = rootName.TrimStart('/');
         }
         return(rootName);
     });
 }
Esempio n. 6
0
            public static IScalar TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                switch (parsedParams.Identifier)
                {
                case SCALE:
                {
                    parsedParams.RequireCount(module, 2, 3);
                    IScalar input  = Scalars.Require(module, parsedParams[0]);
                    double  scale  = Statics.Parse(module, parsedParams[1]);
                    double  offset = (parsedParams.Count > 2) ? Statics.Parse(module, parsedParams[2]) : 0.0;
                    return(Of(input, scale, offset));
                }

                case OFFSET:
                {
                    parsedParams.RequireCount(module, 2);
                    IScalar input  = Scalars.Require(module, parsedParams[0]);
                    double  offset = Statics.Parse(module, parsedParams[1]);
                    return(Offset(input, offset));
                }

                default:
                    return(null);
                }
            }
Esempio n. 7
0
        public int getPartitionKey(IScalar partitionCol)
        {
            if (partitionCol.getDataCategory() != cat)
            {
                throw new Exception("Data category incompatible.");
            }
            if (cat == DATA_CATEGORY.TEMPORAL && type != partitionCol.getDataType())
            {
                DATA_TYPE old = partitionCol.getDataType();
                partitionCol = (IScalar)Utils.castDateTime(partitionCol, type);
                if (partitionCol == null)
                {
                    throw new Exception("Can't convert type from " + old.ToString() + " to " + type.ToString());
                }
            }
            int index = 0;

            if (dict.ContainsKey(partitionCol))
            {
                index = (int)dict[partitionCol];
            }
            else
            {
                index = -1;
            }
            return(index);
        }
Esempio n. 8
0
        public BadCredentialViewModel(IScalar <Dictionary <string, string> > source, Reason reason)
        {
            var errors = source.Value();

            switch (reason)
            {
            case Reason.InvalidLogin:
                Message = errors["invalid_login"];
                break;

            case Reason.InvalidPassword:
                Message = errors["invalid_password"];
                break;

            case Reason.EmptyLogin:
                Message = errors["empty_login"];
                break;

            case Reason.EmptyPassword:
                Message = errors["empty_password"];
                break;

            default:
                break;
            }
        }
Esempio n. 9
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_MINUTE)
     {
         setMinute(index, ((BasicMinute)value).getValue());
     }
 }
Esempio n. 10
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_DATETIME)
     {
         setDateTime(index, ((BasicDateTime)value).getValue());
     }
 }
Esempio n. 11
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_FLOAT)
     {
         setFloat(index, ((BasicFloat)value).getValue());
     }
 }
Esempio n. 12
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_DOUBLE)
     {
         setDouble(index, ((BasicDouble)value).getValue());
     }
 }
Esempio n. 13
0
        IList <IDataListItem> ConvertToIDataListItem(IScalar scalar)
        {
            IList <IDataListItem> result = new List <IDataListItem>();
            var item = scalar;

            if (item != null)
            {
                IDataListItem singleRes = new DataListItem();
                singleRes.IsRecordset  = false;
                singleRes.Field        = item.Name;
                singleRes.DisplayValue = item.Name;
                try
                {
                    singleRes.Value = item.Value;
                }
                catch (Exception)
                {
                    singleRes.Value = null;
                }
                var desc = item.Description;
                singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
                result.Add(singleRes);
            }
            return(result);
        }
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_STRING)
     {
         values[index] = ((BasicString)value).getString();
     }
 }
Esempio n. 15
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_MONTH)
     {
         setMonth(index, ((BasicMonth)value).getValue());
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Adds a <see cref="System.Uri"/> to a request.
 /// </summary>
 public Address(IScalar <System.Uri> uri) : base(() =>
                                                 new Joined(
                                                     new Scheme(uri.Value().Scheme),
                                                     new Conditional(() =>
                                                                     uri.Value().UserInfo != string.Empty,
                                                                     new User(uri.Value().UserInfo)
                                                                     ),
                                                     new Host(uri.Value().Host),
                                                     new Conditional(() =>
                                                                     uri.Value().Port != 0,
                                                                     new Port(uri.Value().Port)
                                                                     ),
                                                     new Conditional(() =>
                                                                     uri.Value().AbsolutePath != string.Empty,
                                                                     new Path(uri.Value().AbsolutePath)
                                                                     ),
                                                     new Conditional(() =>
                                                                     uri.Value().Query != string.Empty,
                                                                     new QueryParams(uri.Value().Query)
                                                                     ),
                                                     new Conditional(() =>
                                                                     uri.Value().Fragment != string.Empty,
                                                                     new Fragment(uri.Value().Fragment)
                                                                     )
                                                     )
                                                 )
 {
 }
Esempio n. 17
0
        /// <summary>
        /// Determines whether a specified value matches any value in a view or a list.
        /// </summary>
        /// <param name="test">Is a test expression.</param>
        /// <param name="collectionOfValues">Specified list of scalar values. The list is any collection. The value is any QueryTalk compliant CLR type.</param>
        public static Expression In <T>(this IScalar test, IEnumerable <T> collectionOfValues)
        {
            QueryTalkException exception;

            return(new Expression(Operator.In, new ScalarArgument(test),
                                  Expression.BuildSequence <T>(collectionOfValues, out exception), exception));
        }
Esempio n. 18
0
        public override int asof(IScalar value)
        {
            int target;

            try
            {
                target = value.getNumber().intValue();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            int start = 0;
            int end   = values.Count - 1;
            int mid;

            while (start <= end)
            {
                mid = (start + end) / 2;
                if (values[mid] <= target)
                {
                    start = mid + 1;
                }
                else
                {
                    end = mid - 1;
                }
            }
            return(end);
        }
Esempio n. 19
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Xambler to modify xml </param>
 public XMLPatched(IScalar <XNode> xml, Xambler xambler) : this(
         new ScalarOf <IXML>(() =>
                             new XMLCursor(xambler.Apply(xml.Value()))
                             )
         )
 {
 }
Esempio n. 20
0
 public override void set(int index, IScalar value)
 {
     if (value.getDataType() == DATA_TYPE.DT_NANOTIMESTAMP)
     {
         setNanoTimestamp(index, ((BasicNanoTimestamp)value).getValue());
     }
 }
        IList <IDataListItem> ConvertToIDataListItem(IScalar scalar)
        {
            IList <IDataListItem> result = new List <IDataListItem>();
            var item = scalar;

            if (item != null)
            {
                IDataListItem singleRes = new DataListItem
                {
                    CanHaveMutipleRows = false,
                    Field        = item.Name,
                    DisplayValue = item.Name
                };
                try
                {
                    singleRes.Value = item.Value.UnescapeString();
                }
                catch (Exception)
                {
                    singleRes.Value = null;
                }
                var desc = item.Description;
                singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
                result.Add(singleRes);
            }
            return(result);
        }
Esempio n. 22
0
        /// <summary>
        ///     Executes a prebuilt <see cref="IScalar{T}" /> and returns a single instance of <typeparamref name="T" />
        /// </summary>
        /// <typeparam name="T">The Entity being queried</typeparam>
        /// <param name="query">The prebuilt Query Object</param>
        /// <returns>The instance of <typeparamref name="T" /> returned from the query</returns>
        public virtual T Find <T>(IScalar <T> scalar)
        {
            OnBeforeScalar(new BeforeScalar(scalar));
            var result = scalar.Execute(_context);

            OnAfterScalar(new AfterScalar(result));
            return(result);
        }
Esempio n. 23
0
        public override T1 Find <T1>(IScalar <T1> query)
        {
            OnBeforeScalar(new BeforeScalar());
            var result = base.Find(query);

            OnAfterScalar(new AfterScalar());
            return(result);
        }
Esempio n. 24
0
 public LoginViewModel(INavigationRoot root, string childName) : base(root, childName)
 {
     _api = new LazyScalar <IInstaApi>(() =>
                                       new WrapApi(
                                           new SessionData(Login, Password), _http
                                           ).Value()
                                       );
 }
Esempio n. 25
0
        /// <summary>
        ///     Executes a prebuilt <see cref="IScalar{T}" /> and returns a single instance of <typeparamref name="T" />
        /// </summary>
        /// <typeparam name="T">The Entity being queried</typeparam>
        /// <param name="query">The prebuilt Query Object</param>
        /// <returns>The instance of <typeparamref name="T" /> returned from the query</returns>
        public virtual T Find <T>(IScalar <T> query)
        {
            OnBeforeScalar(new BeforeScalar(query));
            var result = query.Execute(_context);

            OnAfterScalar(new AfterScalar(query));
            return(result);
        }
Esempio n. 26
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(IScalar <string> xml, Xambler xambler) : this(
         new ScalarOf <XNode>(() =>
 {
     return(XDocument.Parse(xml.Value()));
 }
                              ),
         xambler
         )
 { }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of <see cref="InferredName"/>.
 /// </summary>
 /// <param name="assembly">The assembly to get types from.</param>
 /// <param name="source">The name to infer.</param>
 /// <param name="handleDuplicatesIndex">If there are duplicate type names in an assembly, this index used to access a particular item from an array.</param>
 public InferredName(IScalar <Assembly> assembly, string source, int handleDuplicatesIndex = 0)
     : this(
         new SimpleNameTypeCache(
             new AssemblyTypeCache(assembly)
             ),
         source,
         handleDuplicatesIndex
         )
 {
 }
Esempio n. 28
0
 /// <summary>
 /// Number extracted from an xml using xpath.
 /// </summary>
 public XMLNumber(IXML xml, string xpath, IFormatProvider provider)
 {
     this.number =
         new ScalarOf <INumber>(() =>
                                new NumberOf(
                                    new XMLString(xml, xpath).Value(),
                                    provider
                                    )
                                );
 }
Esempio n. 29
0
 private Range(IScalar input, double minimum, double maximum)
 {
     if (minimum > maximum)
     {
         throw new ArgumentException("minimum can't exceed maximum");
     }
     this.input   = input;
     this.minimum = minimum;
     this.maximum = maximum;
 }
Esempio n. 30
0
 public override void set(int index, IScalar value)
 {
     if (value.getNumber() == null)
     {
         values[index] = (byte)0;
     }
     else
     {
         values[index] = value.getNumber().byteValue();
     }
 }
Esempio n. 31
0
 IList<IDataListItem> ConvertToIDataListItem(IScalar scalar)
 {
     IList<IDataListItem> result = new List<IDataListItem>();
     var item = scalar;
     if (item != null)
     {
         IDataListItem singleRes = new DataListItem();
         singleRes.IsRecordset = false;
         singleRes.Field = item.Name;
         singleRes.DisplayValue = item.Name;
         try
         {
             singleRes.Value = item.Value;
         }
         catch (Exception)
         {
             singleRes.Value = null;
         }
         var desc = item.Description;
         singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
         result.Add(singleRes);
     }
     return result;
 }
        internal static void DoScalarAppending(StringBuilder result, IScalar val)
        {

            var fName = val.Name;
            result.Append("<");
            result.Append(fName);
            result.Append(">");
            try
            {
                result.Append(val.Value);
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch (Exception)
            // ReSharper restore EmptyGeneralCatchClause
            {
            }
            result.Append("</");
            result.Append(fName);
            result.Append(">");
        }