public ConditionWrapper createCondition()
        {
            ConditionWrapper condition = new ConditionWrapper(new LGSA.Model.dic_condition());

            condition.Id   = this.Id;
            condition.Name = this.Name;
            return(condition);
        }
        public FilterViewModel()
        {
            dic_Genre     dicGenre     = new dic_Genre();
            dic_condition dicCondition = new dic_condition();

            dicGenre.name     = "All/Any";
            dicCondition.name = "All/Any";
            _genre            = new GenreWrapper(dicGenre);
            _condition        = new ConditionWrapper(dicCondition);
            _name             = "";
            _price            = "100";
            _rating           = "1";
            _stock            = "1";
        }
Exemplo n.º 3
0
        public void RequestReload()
        {
            uint timer = Log.DebugTimerStart();

            IQueryCondition[] condition_array;

            int i = 0;

            if (untagged)
            {
                condition_array    = new IQueryCondition[conditions.Count + 1];
                condition_array[0] = new UntaggedCondition();
                i = 1;
            }
            else
            {
                condition_array = new IQueryCondition[conditions.Count + 2];
                //		condition_array[0] = new ConditionWrapper (extra_condition);
                condition_array[1] = new ConditionWrapper(terms != null ? terms.SqlCondition() : null);
                i = 2;
            }

            foreach (IQueryCondition condition in Conditions.Values)
            {
                condition_array[i] = condition;
                i++;
            }

            store.QueryToTemp(temp_table, condition_array);

            count          = -1;
            cache          = new PhotoCache(store, temp_table);
            reverse_lookup = new Dictionary <uint, int> ();

            if (Changed != null)
            {
                Changed(this);
            }

            Log.DebugTimerPrint(timer, "Reloading the query took {0}");
        }
        public void clear()
        {
            dic_Genre        dicGenre       = new dic_Genre();
            dic_Product_type dicProductType = new dic_Product_type();
            dic_condition    dicCondition   = new dic_condition();

            dicGenre.name       = "All/Any";
            dicCondition.name   = "All/Any";
            dicProductType.name = "All/Any";
            _productType        = new ProductTypeWrapper(dicProductType);
            _genre        = new GenreWrapper(dicGenre);
            _condition    = new ConditionWrapper(dicCondition);
            _name         = "";
            Price         = "";
            _rating       = "";
            _stock        = "";
            _productOwner = null;
            _soldCopies   = null;
            _id           = null;
            _buyerId      = null;
            _sellerId     = null;
            _amount       = null;
        }
Exemplo n.º 5
0
        public bool HasDuplicate(IPhoto item)
        {
            var uri = item.DefaultVersion.Uri;

            // Check if the exact given uri already exists.
            const string query = "SELECT COUNT(*) AS count FROM photo_versions WHERE base_uri = ? AND filename = ?";

            using (var reader = Database.Query(new HyenaSqliteCommand(query, uri.GetBaseUri().ToString(), uri.GetFilename()))) {
                reader.Read();
                int count = Convert.ToInt32(reader["count"]);
                if (count > 0)
                {
                    return(true);
                }
            }

            // Check by MD5. Won't import if there are photos with the same ImportMD5.
            string hash          = item.DefaultVersion.ImportMD5;
            var    condition     = new ConditionWrapper($"import_md5 = \"{hash}\"");
            var    dupes_by_hash = Count("photo_versions", condition);

            if (dupes_by_hash > 0)
            {
                return(true);
            }

            // This is a very lame check to overcome the lack of duplicate detect data right after transition.
            //
            // Does filename matching if there are files with no hash for the original version.
            condition = new ConditionWrapper("version_id = 1 AND (import_md5 = \"\" OR import_md5 IS NULL)");
            var have_no_hashes = Count("photo_versions", condition);

            if (have_no_hashes <= 0)
            {
                // No matches
                return(false);
            }

            var      name = uri.GetFilename();
            DateTime?time = null;

            // Look for a filename match.
            using (var reader = Database.Query(new HyenaSqliteCommand("SELECT photos.id, photos.time, pv.filename FROM photos LEFT JOIN photo_versions AS pv ON pv.photo_id = photos.id WHERE pv.filename = ?", name))) {
                while (reader.Read())
                {
                    Log.Debug($"Found one possible duplicate for {reader["filename"]}");
                    if (!time.HasValue)
                    {
                        // Only read time when needed
                        time = item.Time;
                    }

                    if (reader["time"].ToString() == DateTimeUtil.FromDateTime(time.Value).ToString())
                    {
                        Log.Debug("Skipping duplicate", uri.ToString());

                        // Schedule a hash calculation job on the existing file.
                        CalculateHashJob.Create(Db.Jobs, Convert.ToUInt32(reader["id"]));

                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the result of evaluating the specified path in the current data context.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public BindingResult EvaluatePath(string path)
        {
            var result = new BindingResult();

            // Return the current context if a path was not specified
            if (String.IsNullOrEmpty(path))
            {
                result.Value   = Context.DataItem;
                result.IsValid = true;
                if (Context.DataItem is Adapter)
                {
                    var adapter = (Adapter)Context.DataItem;
                    result.Source   = adapter.Source;
                    result.Property = adapter.Property;
                }
                return(result);
            }

            // Default the context to the current template context data item
            var context = Context.DataItem;

            // First see if the binding expression represents a model level source
            if (path.StartsWith("window.context.model."))
            {
                path = path.Substring(7);
            }

            if (path.StartsWith("context.model."))
            {
                path = path.Substring(14);
                var index = path.IndexOf('.');
                var model = index > 0 ? path.Substring(0, index) : path;

                // Attempt to fetch the specified model value
                if (Model.TryGetValue(model, out context) && context != null)
                {
                    // Immediately return if this is the end of the path
                    if (index < 0)
                    {
                        result.IsValid = true;
                        result.Value   = context;
                        return(result);
                    }

                    // Trim the path down to the unevaluated portion
                    path = path.Substring(index + 1);
                }
                else
                {
                    return(result);
                }
            }

            // Transform grouping
            if (context is Transform.Grouping)
            {
                object groupResult;
                if (((Transform.Grouping)context).TryGetValue(path, out path, out groupResult))
                {
                    context = result.Value = groupResult;

                    if (string.IsNullOrEmpty(path))
                    {
                        result.IsValid = true;
                        return(result);
                    }
                }
            }

            // ModelInstance
            if (context is ModelInstance)
            {
                result.Source = context as ModelInstance;

                // Exit immediately if the path is not valid
                ModelPath modelPath;
                if (result.Source.Type.TryGetPath(path, out modelPath))
                {
                    bool pathWalked = false;

                    // Walk the path, honoring only first steps
                    for (var step = FirstApplicableStep(result.Source, modelPath.FirstSteps); step != null; step = FirstApplicableStep(result.Source, step.NextSteps))
                    {
                        pathWalked = true;

                        if (step.NextSteps.Any())
                        {
                            // Exit immediately if an intermediary step is a list
                            if (step.Property.IsList)
                            {
                                return(result);
                            }

                            // Attempt to walk the instance path if the current step is valid
                            if (result.Source != null)
                            {
                                result.Source = result.Source.Type.Properties.Contains(step.Property) ? result.Source.GetReference((ModelReferenceProperty)step.Property) : null;
                            }
                        }
                        else
                        {
                            result.Property = step.Property;
                        }
                    }

                    if (!pathWalked)
                    {
                        return(result);
                    }

                    // Indicate that the result is now considered valid since the path could be walked
                    result.IsValid = true;

                    // Attempt to evaluate the last step along the path
                    if (result.Source != null)
                    {
                        // Evaluate the last step along the path
                        if (result.Property is ModelValueProperty)
                        {
                            result.Value = result.Source.GetValue((ModelValueProperty)result.Property);
                        }
                        else if (result.Property.IsList)
                        {
                            result.Value = result.Source.GetList((ModelReferenceProperty)result.Property);
                        }
                        else
                        {
                            result.Value = result.Source.GetReference((ModelReferenceProperty)result.Property);
                        }
                    }

                    return(result);
                }
            }

            // Condition
            if (context is Condition)
            {
                return(ConditionWrapper.Evaluate((Condition)context, path));
            }

            // IBindable
            if (context is IBindable)
            {
                result = ((IBindable)context).Evaluate(path);
            }

            // As a last resort, see if this is a static path
            if (!result.IsValid)
            {
                ModelSource source;
                // Return immediately if the path does not represent a valid static property
                if (!ModelSource.TryGetSource(null, path, out source))
                {
                    return(result);
                }

                result.IsValid  = true;
                result.Property = ModelContext.Current.GetModelType(source.SourceType).Properties[source.SourceProperty];
                result.Value    =
                    result.Property is ModelValueProperty?source.GetValue(null) :
                        result.Property.IsList ? (object)source.GetList(null) :
                        source.GetReference(null);

                return(result);
            }

            // Invalid
            return(result);
        }