internal override void BeginReplicating() { Log.D(Tag, "beginReplicating() called"); // If we're still waiting to create the remote db, do nothing now. (This method will be // re-invoked after that request finishes; see maybeCreateRemoteDB() above.) if (creatingTarget) { Log.D(Tag, "creatingTarget == true, doing nothing"); return; } pendingSequences = new SortedSet <long>(); try { maxPendingSequence = Int64.Parse(LastSequence); } catch (Exception e) { Log.W(Tag, "Error converting lastSequence: " + LastSequence + " to long. Using 0"); maxPendingSequence = 0; } if (Filter != null) { filter = LocalDatabase.GetFilter(Filter); } if (Filter != null && filter == null) { Log.W(Tag, string.Format("{0}: No ReplicationFilter registered for filter '{1}'; ignoring" , this, Filter)); } // Process existing changes since the last push: long lastSequenceLong = 0; if (LastSequence != null) { lastSequenceLong = long.Parse(LastSequence); } var options = new ChangesOptions(); options.SetIncludeConflicts(true); var changes = LocalDatabase.ChangesSince(lastSequenceLong, options, filter); if (changes.Count > 0) { Batcher.QueueObjects(changes); Batcher.Flush(); } // Now listen for future changes (in continuous mode): if (continuous) { observing = true; LocalDatabase.Changed += OnChanged; } }
public static Panel FindPanel(FilterDelegate <Panel> filter) { if (filter == null) { return(null); } PanelManager inst = Instance; if (inst == null) { return(null); } Panel panel; panel = FindPanel(inst.mPanels, filter); if (panel != null) { return(panel); } panel = FindPanel(inst.mDialogs, filter); if (panel != null) { return(panel); } panel = FindPanel(inst.mStatus, filter); if (panel != null) { return(panel); } return(null); }
//------------------------------------------------------------------ // 部分語の最後にならないものは除外 // 조사한の한は"ひとつの"ではない。"~した"である。 static public SearchResult CheckTrail(SearchResult result) { FilterDelegate transFilter = new FilterDelegate(KJ_Filter.NotTrail); return(SearchResult.Except(result, transFilter)); }
public ArrayList documents; // DocumentData型のArrayList //=========================================================================== // // static public methods // //------------------------------------------------------------------ // 助詞に先行しない語は除く // DocumentDataを作りなおすため、SearchResultも再作成 // static public SearchResult CheckPPConnectable(SearchResult result) { // FilterDelegate transFilter = // new FilterDelegate( KJ_Filter.PPConnectable ) ; // return SearchResult.Except(result, transFilter) ; // } // //------------------------------------------------------------------ // 部分語には使わない訳語は外す // static public SearchResult CheckDividedWord(SearchResult result) { // FilterDelegate transFilter = // new FilterDelegate( KJ_Filter.NotDividedWord ) ; // return SearchResult.Except(result, transFilter) ; // } // (*1) 대한간호협회 の대한は形容詞("対する")ではなく、"大韓" //------------------------------------------------------------------ // 非部分語で使わない語は外す // (*1) 간호협회 대한 の대한は"大韓"ではなく、"対する" static public SearchResult ExceptFullWord(SearchResult result) { FilterDelegate transFilter = new FilterDelegate(KJ_Filter.NotFullWord); return(SearchResult.Except(result, transFilter)); }
//------------------------------------------------------------------ // 文章の先頭に来ないものは除外 // static public SearchResult ExceptSentenseHead(SearchResult result) { FilterDelegate transFilter = new FilterDelegate(KJ_Filter.NotSentenseHead); return(SearchResult.Except(result, transFilter)); }
//------------------------------------------------------------------ // static public SearchResult Trim(SearchResult result) { // // 翻訳系では有効でないDocumentを削除 // FilterDelegate transFilter = // new FilterDelegate( KJ_Filter.Valid ) ; // return SearchResult.Except(result, transFilter) ; // } //===================================================================== // // static private methods // //------------------------------------------------------------------ // 条件にあうものは除外(filterにかかるものを削除) // 作り直すとコストがかかるのでIsUsefulをfalseにするだけ static private SearchResult Except(SearchResult result, FilterDelegate filter) { if (result == null || result.documents == null) { return(result); // 変更なし } // result.documentsから適切でない訳語を取り除く ArrayList documents = KJ_Extracter.Except(result.documents, filter); if (documents == result.documents) { // 変更なし return(result); } // 変更あり SearchResultを作り直す SearchResult newResult = new SearchResult(); newResult.documents = documents; if (newResult.documents.Count == 0) { newResult.return_code = -1; } else { newResult.return_code = 0; } return(newResult); }
public List <TValue> FindByFilter(FilterDelegate <TValue> fd, Comparison <TValue> comparer) { if (fd == null) { return(null); } List <TValue> result = new List <TValue>(); _SyncDataCache.AcquireReaderLock(Timeout.Infinite); try { foreach (KeyValuePair <TKey, TValue> pair in _DataCache) { if (fd(pair.Value)) { result.Add(pair.Value); } } } finally { _SyncDataCache.ReleaseReaderLock(); } if ((result.Count > 0) && (comparer != null)) { result.Sort(comparer); } if (result.Count == 0) { return(null); } return(result); }
static void Main(string[] args) { Console.WriteLine(DateTime.Now.ToString("MMM")); return; Console.WriteLine(OptimizationSize(new Size(2, 100), new Size(100, 100), new Size(500, 500))); Console.WriteLine(OptimizationSize(new Size(2, 100), new Size(100, 200), new Size(500, 500))); Console.WriteLine(OptimizationSize(new Size(2, 10), new Size(100, 200), new Size(1000, 1000))); try { FilterDelegate win32Handler = new FilterDelegate(Win32Handler); _win32Handler = win32Handler; var n = SetUnhandledExceptionFilter(1); Console.WriteLine(GetLastError()); SetErrorMode(1); Console.WriteLine(HeederajiYeafalludall()); } catch (Exception) { } Console.Read(); }
public static Panel FindPanel(FilterDelegate <Panel> filter) { if (filter == null) { return(null); } PanelManager inst = Instance; if (inst == null) { return(null); } PanelStub panel; FilterDelegate <PanelStub> stubf = (x) => filter(x.Instance); panel = FindPanelStub(inst.mPanels, stubf); if (panel != null) { return(panel.Instance); } panel = FindPanelStub(inst.mDialogs, stubf); if (panel != null) { return(panel.Instance); } panel = FindPanelStub(inst.mStatus, stubf); if (panel != null) { return(panel.Instance); } return(null); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { object[] attributes = fieldInfo?.GetCustomAttributes(typeof(ObjectPathTypeAttribute), false); if (attributes == null || attributes.Length == 0) { EditorGUI.LabelField(position, "Add ObjectPathType on " + label.text); } else { ObjectPathTypeAttribute objectPathTypeAttribute = attributes[0] as ObjectPathTypeAttribute; if (objectPathTypeAttribute == null) { throw new ArgumentNullException("objectPathType"); } SerializedProperty objectProperty = property.FindPropertyRelative("_value"); Object o = objectProperty.objectReferenceValue; EditorGUI.BeginChangeCheck(); EditorGUI.ObjectField(position, objectProperty, objectPathTypeAttribute.Type, label); if (EditorGUI.EndChangeCheck() && string.IsNullOrEmpty(objectPathTypeAttribute.FilterMethod) == false) { FilterDelegate method = property.CreateDelegateFromParentMethod <FilterDelegate>(objectPathTypeAttribute.FilterMethod); if (method != null && method(objectProperty.objectReferenceValue) == false) { objectProperty.objectReferenceValue = o; } } } }
private List <Color> FilterPixels(List <Color> filterFrom, FilterDelegate filter) { var filterTo = new List <Color>(); for (var i = 0; i < filterFrom.Count; i++) { var pixel = filterFrom[i]; var shouldAdd = true; for (var index = 0; index < filterTo.Count; index++) { var filteredColor = filterTo[index]; if (filter(filteredColor, pixel)) { continue; } shouldAdd = false; break; } if (shouldAdd) { filterTo.Add(pixel); } } return(filterTo); }
public T RemoveData <T>(FilterDelegate <T> filter) where T : class { var node = mFirst; while (node != null) { T v = node.data as T; if (filter(v)) { var p = node.previous; node.Remove(); var r0 = mResize ? mResizeRow : mLastRow; int i0 = r0 == null ? 0 : r0.index; mResize = true; var r1 = p == null ? null : p.row; int i1 = r1 == null ? 0 : r1.index; if (i1 <= i0) { mResizeRow = r1; } return(v); } } return(null); }
// // DocumentDataのArrayListを入出力 // // 条件にあうものは除外 public static ArrayList Except(ArrayList inList, FilterDelegate filter) { ArrayList outList = new ArrayList(); bool changed = false; foreach (DocumentData doc in inList) { if (filter(doc)) { // filterにかかるものを削除 changed = true; } else { outList.Add(doc); } } if (changed) { // 変更があった。 return(outList); } else { // 変更なしなら、入力をそのまま返す return(inList); } }
private bool PopulateItem(TData item, int index, FilterDelegate filter, InitializeDelegate initializer, InstantiateDelegate instantiator ) { if (filter != null && !filter(item)) { return(false); } TComponent component; if (index < this.pool.Count) { component = this.pool[index]; } else { component = instantiator != null ? instantiator(this.prefab, this.root) : Object.Instantiate(this.prefab, this.root); this.pool.Add(component); } component.gameObject.SetActive(true); initializer?.Invoke(item, component); return(true); }
public void SetSelections(FilterDelegate <BehaviourNode> select) { mSelection.Clear(); for (int i = 0; i < AIGraph.ElementCount; i++) { var node = AIGraph.GetElement <BehaviourNode>(i); if (node != null) { node.selected = select(node); if (node.selected) { mSelection.Add(node); } } } UpdateSelectionAssets(); if (mSelectionAssets.Count > 0) { Selection.objects = mSelectionAssets.ToArray(); } else if (mAssetBinder != null) { mAssetBinder.SelectTarget(); } }
// 全て通すフィルタ (切り替え時にそなえ保管) //------------------------------------------------------- // constructor public KJ_DictData(string yamlfile, string arrayfile) { // 辞書本体のOpen this.dict_fs = new FileStream(yamlfile, FileMode.Open, FileAccess.Read); this.dict_reader = new StreamReader(this.dict_fs, Encoding.UTF8); // 途中で辞書ファイルが変わることがないのでstaticに設定しておく // KJ_SuffixArray.dict_fs = this.dict_fs ; // KJ_SuffixArray.dict_reader = this.dict_reader ; // StreamReaderにSeekは効かないので使えない System.IO.FileInfo fi; // Array fileのOpen fi = new System.IO.FileInfo(arrayfile); array_index_max = (fi.Length / 4) - 1; array_fs = new FileStream(arrayfile, FileMode.Open, FileAccess.Read); array_reader = new BinaryReader(array_fs); // 判定用object設定 // 文字のマッチングルール切り替えを前提に別class dictword = new KJ_dictword(); // デフォルトのフィルタを設定 dictFilter = new FilterDelegate(this.allValid); allvalid = dictFilter; // 書き換えの保管用 }
public override void Filter(List <GameObject> input) { bool include = inclusivity == IncludeOrExclude.Include; if (globalOrLocal == GlobalOrLocal.Global) { TestMethod = Global; } else { TestMethod = Local; } MinMax.Verifiy(); for (int i = 0; i < input.Count; i++) { if (TestMethod(input[i])) { if (!include) { input.RemoveAt(i); i--; } } else if (include) { input.RemoveAt(i); i--; } } base.Filter(input); }
decimal ReportEngine(FilterDelegate calculationFilter, Func <Invoice, bool> dateFilter) //Reportfiltering is made with func and delegate { //int invoiceCount = 0; //int usdInvoiceCount = 0; //int eurInvoiceCount = 0; decimal sum = 0; foreach (var invoice in SelectedInvoices) { if (dateFilter(invoice)) { if (invoice is USDInvoice) { sum += calculationFilter(invoice) * ((USDInvoice)invoice).ExchangeRate; } else if (invoice is EURInvoice) { sum += calculationFilter(invoice) * ((EURInvoice)invoice).ExchangeRate; } else { sum += calculationFilter(invoice); } } } return(sum); }
public List <T> GetFiltered(FilterDelegate <T> fd, Comparison <T> comparer) { if (fd == null) { return(null); } List <T> result = new List <T>(); foreach (KeyValuePair <long, T> pair in _index) { if (fd(pair.Value)) { result.Add(pair.Value); } } if ((result.Count > 0) && (comparer != null)) { result.Sort(comparer); } if (result.Count == 0) { return(null); } return(result); }
public TableSyncSettings(string tableName, CallbackDelegate syncCallback, FilterDelegate <T> deleteFilter) { TableName = tableName; _syncCallback = syncCallback; _deleteFilter = deleteFilter; _disabled = true; }
void OnSceneLoadBegin(string scene) { FilterDelegate <PanelStub> filter = (x) => x.Asset.AutoCloseOnLoadScene; ClosePanelFor(mDialogs, filter, true); ClosePanelFor(mPanels, filter, true); ClosePanelFor(mStatus, filter, false); }
static List<int> FilterCollection(List<int> original, FilterDelegate<int> filter) { List<int> filteredNums = new List<int>(); foreach (var item in original) { if (filter(item)) filteredNums.Add(item); } return filteredNums; }
public IAsyncEnumerable <IReceivedMessage <T> > SelectAsync <T>(FilterDelegate <IReceivedMessage <T> > filter, CancellationToken cancellationToken = default) where T : class { var messageFilter = new ReceivedMessageFilter(); messageFilter.Includes.Add(filter); return(SelectAsync(message => messageFilter.Any(message), cancellationToken).Select <IReceivedMessage, IReceivedMessage <T> >()); }
private bool CanManipulate(ITransformable node, FilterDelegate filter) { bool result = node != null && node.Cast <IVisible>().Visible && node.Cast <ILockable>().IsLocked == false && filter(node); return(result); }
/// <summary> /// A method to filter out the people you need /// </summary> /// <param name="people">A list of people</param> /// <param name="filter">A filter</param> /// <returns>A filtered list</returns> static void DisplayPeople(string title, List<Person> people, FilterDelegate filter) { Console.WriteLine(title); foreach (Person p in people) { if (filter(p)) { Console.WriteLine("{0}, {1} years old", p.Name, p.Age); } } Console.Write("\n\n"); }
public Task <bool> Any <T>(FilterDelegate <IReceivedMessage <T> > filter, CancellationToken cancellationToken = default) where T : class { var messageFilter = new ReceivedMessageFilter(); messageFilter.Includes.Add(filter); return(Any(message => messageFilter.Any(message), cancellationToken)); }
public IEnumerable <IPublishedMessage <T> > Select <T>(FilterDelegate <IPublishedMessage <T> > filter, CancellationToken cancellationToken = default) where T : class { var messageFilter = new PublishedMessageFilter(); messageFilter.Includes.Add(filter); return(Select(message => messageFilter.Any(message), cancellationToken).Cast <IPublishedMessage <T> >()); }
/// <summary> /// Iterates through all nodes in the filter. /// </summary> /// <param name="Callback">Callback method that will be called for each node in the filter.</param> /// <param name="State">State object passed on to the callback method.</param> /// <returns>If all nodes were processed (true), or if the process was broken by the callback method (false).</returns> public override bool ForAll(FilterDelegate Callback, object State) { if (!base.ForAll(Callback, State)) { return(false); } return(this.filter.ForAll(Callback, State)); }
public static void Display(List <Car> cars, FilterDelegate filter) { foreach (Car car in cars) { if (filter(car)) { Console.WriteLine(car.Name); } } }
public static IEnumerable <T> Filter <T>(this IEnumerable <T> input, FilterDelegate <T> predicate) { foreach (var item in input) { if (predicate(item)) { yield return(item); } } }
public AsyncFileFinder(String pSearchDirectory, String pSearchMask, FilterDelegate pFileFilter = null, FilterDelegate pDirectoryRecursionFilter = null, bool pIsChild = false) { _SearchDirectory = pSearchDirectory; _SearchMask = pSearchMask; FileFilter = pFileFilter; DirectoryRecursionFilter = pDirectoryRecursionFilter; isChild = pIsChild; }
static List<int> Filter(List<int> list,FilterDelegate f) { List<int> list1 = new List<int>(); foreach (int i in list) { if (f(i)) { list1.Add(i); } } return list1; }
public List<int> FilterCollection ( List<int> original , FilterDelegate filter ) { List<int> result = new List<int>(); foreach(var item in original) { if(filter(item)) { result.Add(item); } } return result; }
public static List<int> FilterCollection(List<int> original, FilterDelegate myDelegate) { for (int i = 0; i < original.Count; i++) { if (!myDelegate(original.ElementAt(i))) { original.Remove(original.ElementAt(i)); i--; } } return original; }
public static List<int> Filter(List<int> original, FilterDelegate filter) { List<int> result = new List<int>(); foreach (int element in original) { if (filter(element)) { result.Add(element); } } return result; }
public static List<int> FilterList(List<int> list, FilterDelegate f) { List<int> temp = new List<int>(); foreach (int i in list) { if (f(i)) { temp.Add(i); } } return temp; }
public static void Displaymessge(string titltmessage ,List<person> ppl, FilterDelegate f) { Console.WriteLine("*******************************************"); Console.WriteLine(titltmessage); Console.WriteLine("*******************************************"); foreach (person p in ppl) { if (f(p)) { Console.WriteLine("Name:{0} , Age: {1}", p.Name, p.Age); } } Console.WriteLine("*******************************************"); }
public List<int> FilterCollection(List<int> numbers, FilterDelegate filter) { List<int> result = new List<int>(); foreach (var item in numbers) { if (filter(item) == true) { result.Add(item); } } return result; }
internal RevisionList ChangesSince(long lastSeq, ChangesOptions options, FilterDelegate filter, IDictionary<string, object> filterParams) { RevisionFilter revFilter = null; if (filter != null) { revFilter = (rev => RunFilter(filter, filterParams, rev)); } return Storage.ChangesSince(lastSeq, options, revFilter); }
/// <summary> /// Sets the <see cref="ValidateDelegate" /> for the given name. If delegate is null, the filter /// with the given name is deleted. Before a <see cref="Couchbase.Lite.Revision" /> is replicated via a /// push <see cref="Couchbase.Lite.Replication" />, its filter delegate is called and /// given a chance to exclude it from the <see cref="Couchbase.Lite.Replication" />. /// </summary> /// <param name="name">The name of the filter delegate to set.</param> /// <param name="filterDelegate">The filter delegate to set.</param> public void SetFilter(String name, FilterDelegate filterDelegate) { Shared.SetValue("filter", name, Name, filterDelegate); }
/// <summary> /// Apply selected image to a blur filter /// </summary> private void Blur_Click(object sender, EventArgs e) { const string filterLabel = "Blur filter"; var valuePicker = new ValuePicker(5, 1, Resources.Msg_BlurIntense); if (valuePicker.ShowDialog() == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; panelEdit.Enabled = false; panelBottom.Enabled = false; filterDel = ApplyActionToFrames; filterDel.BeginInvoke(filterLabel, ActionEnum.Blur, valuePicker.Value, null, CallBackFilter, null); } valuePicker.Dispose(); }
/// <summary> /// Sets the <see cref="ValidateDelegate" /> for the given name. If delegate is null, the filter /// with the given name is deleted. Before a <see cref="Couchbase.Lite.Revision" /> is replicated via a /// push <see cref="Couchbase.Lite.Replication" />, its filter delegate is called and /// given a chance to exclude it from the <see cref="Couchbase.Lite.Replication" />. /// </summary> /// <param name="name">The name of the filter delegate to set.</param> /// <param name="filterDelegate">The filter delegate to set.</param> public void SetFilter(String name, FilterDelegate filterDelegate) { if (Filters == null) { Filters = new Dictionary<String, FilterDelegate>(); } if (filterDelegate != null) { Filters[name] = filterDelegate; } else { Collections.Remove(Filters, name); } }
internal override void BeginReplicating() { Log.D(Tag, "beginReplicating() called"); // If we're still waiting to create the remote db, do nothing now. (This method will be // re-invoked after that request finishes; see maybeCreateRemoteDB() above.) if (creatingTarget) { Log.D(Tag, "creatingTarget == true, doing nothing"); return; } pendingSequences = new SortedDictionary<long, int>(); try { maxPendingSequence = Int64.Parse(LastSequence); } catch (Exception e) { Log.W(Tag, "Error converting lastSequence: " + LastSequence + " to long. Using 0", e); maxPendingSequence = 0; } if (Filter != null) { filter = LocalDatabase.GetFilter(Filter); } else { // If not filter function was provided, but DocIds were // specified, then only push the documents listed in the // DocIds property. It is assumed that if the users // specified both a filter name and doc ids that their // custom filter function will handle that. This is // consistent with the iOS behavior. if (DocIds != null && DocIds.Any()) { filter = (rev, filterParams) => DocIds.Contains(rev.Document.Id); } } if (Filter != null && filter == null) { Log.W(Tag, string.Format("{0}: No ReplicationFilter registered for filter '{1}'; ignoring", this, Filter)); } // Process existing changes since the last push: long lastSequenceLong = 0; if (LastSequence != null) { lastSequenceLong = long.Parse(LastSequence); } // Now listen for future changes (in continuous mode): if (continuous) { observing = true; LocalDatabase.Changed += OnChanged; } var options = new ChangesOptions(); options.SetIncludeConflicts(true); var changes = LocalDatabase.ChangesSince(lastSequenceLong, options, filter, FilterParams); if (changes.Count > 0) { Batcher.QueueObjects(changes); Batcher.Flush(); } }
public void SetFilter(FilterDelegate MyFilter) { }
private bool CanManipulate(ITransformable node, FilterDelegate filter) { bool result = node != null && node.Cast<IVisible>().Visible && node.Cast<ILockable>().IsLocked == false && filter(node); return result; }
public ManipulatorActiveOperation( string name, ISelectionContext selectionContext, FilterDelegate filter, bool duplicate) { TransactionContextList = new List<ITransactionContext>(); NodeList = new List<ITransformable>(); IsDuplicating = duplicate; var selection = selectionContext.Selection; IEnumerable<DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable<DomNode>()); SetupTransactionContexts(rootDomNodes); if (duplicate) { List<DomNode> originals = new List<DomNode>(); foreach (DomNode node in rootDomNodes) { ITransformable transformable = node.As<ITransformable>(); if (!CanManipulate(transformable, filter)) continue; originals.Add(node); } if (originals.Count > 0) { DomNode[] copies = DomNode.Copy(originals); foreach (var t in TransactionContextList) t.Begin(("Copy And" + name).Localize()); List<object> newSelection = new List<object>(); // re-parent copy for (int i = 0; i < copies.Length; i++) { DomNode copy = copies[i]; DomNode original = originals[i]; ChildInfo chInfo = original.ChildInfo; if (chInfo.IsList) original.Parent.GetChildList(chInfo).Add(copy); else original.Parent.SetChild(chInfo, copy); newSelection.Add(Util.AdaptDomPath(copy)); copy.InitializeExtensions(); } selectionContext.SetRange(newSelection); NodeList.AddRange(copies.AsIEnumerable<ITransformable>()); } } else { foreach (DomNode node in rootDomNodes) { ITransformable transformable = node.As<ITransformable>(); if (!CanManipulate(transformable, filter)) continue; NodeList.Add(transformable); } if (NodeList.Count > 0) foreach (var t in TransactionContextList) t.Begin(name.Localize()); } for (int k = 0; k < NodeList.Count; k++) { IManipulatorNotify notifier = NodeList[k].As<IManipulatorNotify>(); if (notifier != null) notifier.OnBeginDrag(); } }
/// <summary> /// Apply selected image to a pixelated filter /// </summary> private void Pixelate_Click(object sender, EventArgs e) { const string filterLabel = "Pixelate filter"; //User first need to choose the intensity of the pixelate var valuePicker = new ValuePicker(100, 2, Resources.Msg_PixelSize); if (valuePicker.ShowDialog() == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; panelEdit.Enabled = false; panelBottom.Enabled = false; filterDel = ApplyActionToFrames; filterDel.BeginInvoke(filterLabel, ActionEnum.Pixelate, valuePicker.Value, null, CallBackFilter, null); } valuePicker.Dispose(); }
internal override void BeginReplicating() { Log.D(Tag, "beginReplicating() called"); // If we're still waiting to create the remote db, do nothing now. (This method will be // re-invoked after that request finishes; see maybeCreateRemoteDB() above.) if (creatingTarget) { Log.D(Tag, "creatingTarget == true, doing nothing"); return; } pendingSequences = new SortedSet<long>(); try { maxPendingSequence = Int64.Parse(LastSequence); } catch (Exception e) { Log.W(Tag, "Error converting lastSequence: " + LastSequence + " to long. Using 0"); maxPendingSequence = 0; } if (Filter != null) { filter = LocalDatabase.GetFilter(Filter); } if (Filter != null && filter == null) { Log.W(Tag, string.Format("{0}: No ReplicationFilter registered for filter '{1}'; ignoring" , this, Filter)); } // Process existing changes since the last push: long lastSequenceLong = 0; if (LastSequence != null) { lastSequenceLong = long.Parse(LastSequence); } var options = new ChangesOptions(); options.SetIncludeConflicts(true); var changes = LocalDatabase.ChangesSince(lastSequenceLong, options, filter); if (changes.Count > 0) { Batcher.QueueObjects(changes); Batcher.Flush(); } // Now listen for future changes (in continuous mode): if (continuous) { observing = true; LocalDatabase.Changed += OnChanged; } }
internal RevisionList UnpushedRevisionsSince(string sequence, FilterDelegate filter, IDictionary<string, object> filterParams) { // Include conflicts so all conflicting revisions are replicated too var options = ChangesOptions.Default; options.IncludeConflicts = true; return ChangesSince(Int64.Parse(sequence ?? "0"), options, filter, filterParams); }
/// <summary> /// Sets the <see cref="ValidateDelegate" /> for the given name. If delegate is null, the filter /// with the given name is deleted. Before a <see cref="Couchbase.Lite.Revision" /> is replicated via a /// push <see cref="Couchbase.Lite.Replication" />, its filter delegate is called and /// given a chance to exclude it from the <see cref="Couchbase.Lite.Replication" />. /// </summary> /// <param name="name">The name of the filter delegate to set.</param> /// <param name="filterDelegate">The filter delegate to set.</param> public void SetFilter(String name, FilterDelegate filterDelegate) { if (!IsOpen) { Log.W(TAG, "SetFilter called on closed database"); return; } Shared.SetValue("filter", name, Name, filterDelegate); }
internal override void BeginReplicating() { Log.D(TAG, "beginReplicating() called"); // If we're still waiting to create the remote db, do nothing now. (This method will be // re-invoked after that request finishes; see maybeCreateRemoteDB() above.) if (_creatingTarget) { Log.D(TAG, "creatingTarget == true, doing nothing"); return; } _pendingSequences = new SortedDictionary<long, int>(); try { _maxPendingSequence = Int64.Parse(LastSequence); } catch (Exception e) { Log.W(TAG, "Error converting lastSequence: " + LastSequence + " to long. Using 0", e); _maxPendingSequence = 0; } if (Filter != null) { _filter = LocalDatabase.GetFilter(Filter); } else { // If not filter function was provided, but DocIds were // specified, then only push the documents listed in the // DocIds property. It is assumed that if the users // specified both a filter name and doc ids that their // custom filter function will handle that. This is // consistent with the iOS behavior. if (DocIds != null && DocIds.Any()) { _filter = (rev, filterParams) => DocIds.Contains(rev.Document.Id); } } if (Filter != null && _filter == null) { Log.W(TAG, string.Format("{0}: No ReplicationFilter registered for filter '{1}'; ignoring", this, Filter)); } // Process existing changes since the last push: long lastSequenceLong = 0; if (LastSequence != null) { lastSequenceLong = long.Parse(LastSequence); } // Now listen for future changes (in continuous mode): // Note: This needs to happen before adding the observer // or else there is a race condition. // A document could be added between the call to // ChangesSince and adding the observer, which would result // in a document being skipped if (Continuous) { _observing = true; LocalDatabase.Changed += OnChanged; } var options = ChangesOptions.Default; options.IncludeConflicts = true; var changes = LocalDatabase.ChangesSince(lastSequenceLong, options, _filter, FilterParams); if (changes.Count > 0) { Batcher.QueueObjects(changes); Batcher.Flush(); } if (Continuous) { if (changes.Count == 0) { FireTrigger(ReplicationTrigger.WaitingForChanges); } } else { if(changes.Count == 0) { FireTrigger(ReplicationTrigger.StopGraceful); } } }
internal bool RunFilter(FilterDelegate filter, IDictionary<string, object> filterParams, RevisionInternal rev) { if (filter == null) { return true; } var publicRev = new SavedRevision(this, rev); return filter(publicRev, filterParams); }
public NotifyResultProxyFilter(FilterDelegate filter) { this.filter = new Func<CheckResult, bool>(filter); }
public static List<ReportRecord> Filter(ref XmlNodeList xmlNodes, ref HashSet<string> aliases, string metric, FilterDelegate FilterMetric) { return FilterMetric(ref xmlNodes, ref aliases, metric); }
internal override void BeginReplicating() { // If we're still waiting to create the remote db, do nothing now. (This method will be // re-invoked after that request finishes; see maybeCreateRemoteDB() above.) if (_creatingTarget) { Log.To.Sync.D(TAG, "creatingTarget == true, doing nothing"); return; } _pendingSequences = new SortedDictionary<long, int>(); if (!Int64.TryParse(LastSequence, out _maxPendingSequence)) { Log.To.Sync.W(TAG, "{0} is not a valid last sequence, using 0", LastSequence); _maxPendingSequence = 0; } if (Filter != null) { _filter = LocalDatabase.GetFilter(Filter); } else { // If not filter function was provided, but DocIds were // specified, then only push the documents listed in the // DocIds property. It is assumed that if the users // specified both a filter name and doc ids that their // custom filter function will handle that. This is // consistent with the iOS behavior. if (DocIds != null && DocIds.Any()) { _filter = (rev, filterParams) => DocIds.Contains(rev.Document.Id); } } if (Filter != null && _filter == null) { Log.To.Sync.W(TAG, "{0}: No ReplicationFilter registered for filter '{1}'; ignoring", this, Filter); } // Process existing changes since the last push: long lastSequenceLong = 0; if (LastSequence != null) { lastSequenceLong = long.Parse(LastSequence); } if (ReplicationOptions.PurgePushed) { _purgeQueue = new Batcher<RevisionInternal>(WorkExecutor, EphemeralPurgeBatchSize, EphemeralPurgeDelay, (revs) => { Log.To.Sync.I(TAG, "Purging {0} docs ('purgePushed' option)", revs.Count); var toPurge = new Dictionary<string, IList<string>>(); foreach(var rev in revs) { toPurge[rev.DocID] = new List<string> { rev.RevID.ToString() }; } var localDb = LocalDatabase; if(localDb != null && localDb.IsOpen) { var storage = localDb.Storage; if(storage != null && storage.IsOpen) { storage.PurgeRevisions(toPurge); } else { Log.To.Sync.W(TAG, "{0} storage is closed, cannot purge...", localDb); } } else { Log.To.Sync.W(TAG, "Local database is closed or null, cannot purge..."); } }, CancellationTokenSource); } // Now listen for future changes (in continuous mode): // Note: This needs to happen before adding the observer // or else there is a race condition. // A document could be added between the call to // ChangesSince and adding the observer, which would result // in a document being skipped if (Continuous) { _observing = true; LocalDatabase.Changed += OnChanged; } var options = ChangesOptions.Default; options.IncludeConflicts = true; var changes = LocalDatabase.ChangesSince(lastSequenceLong, options, _filter, FilterParams); if (changes.Count > 0) { Batcher.QueueObjects(changes); Batcher.Flush(); } if (Continuous) { if (changes.Count == 0) { Log.To.Sync.V(TAG, "No changes to push, switching to idle..."); FireTrigger(ReplicationTrigger.WaitingForChanges); } } else { if(changes.Count == 0) { Log.To.Sync.V(TAG, "No changes to push, firing StopGraceful..."); FireTrigger(ReplicationTrigger.StopGraceful); } } }
protected Vector2 FileListView(GUIContent label, Vector2 scrollPos, FilterDelegate filter, ChangeTypeDelegate changeTypeFetcher, WholeFileCommand cmd, ListSelectionState selectionCache) { int id = GUIUtility.GetControlID(FocusType.Passive); ListView state = (ListView)GUIUtility.GetStateObject(typeof(ListView), id); state.controlID = id; state.selection = selectionCache; Event current = Event.current; bool isChanged = false; GUILayout.Label(label, GitStyles.BoldLabel, GUIHelper.NoExpandWidth); Rect listPosition = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GitStyles.FileListBox); if(changes != null) { for(int i = 0; i < changes.Length; i++) { if(filter(changes[i])) { isChanged = isChanged || ShowFile(state, changes[i].path, changeTypeFetcher(changes[i]), cmd); } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); switch(current.type) { case EventType.MouseDown: if(listPosition.Contains(current.mousePosition)) { GUIUtility.hotControl = id; GUIUtility.keyboardControl = id; current.Use(); } else { if(GUIUtility.keyboardControl == id) { GUIUtility.keyboardControl = 0; } } break; case EventType.MouseUp: if(GUIUtility.hotControl == id) { // Done dragging... GUIUtility.hotControl = 0; current.Use(); } break; } state.hasFocus = GUIUtility.keyboardControl == id; if(!state.hasFocus) { state.selection.Clear(); } if(isChanged) { GUI.changed = true; current.Use(); } return scrollPos; }
internal RevisionList ChangesSince(long lastSeq, ChangesOptions options, FilterDelegate filter) { // http://wiki.apache.org/couchdb/HTTP_database_API#Changes if (options == null) { options = new ChangesOptions(); } var includeDocs = options.IsIncludeDocs() || (filter != null); var additionalSelectColumns = string.Empty; if (includeDocs) { additionalSelectColumns = ", json"; } var sql = "SELECT sequence, revs.doc_id, docid, revid, deleted" + additionalSelectColumns + " FROM revs, docs " + "WHERE sequence > ? AND current=1 " + "AND revs.doc_id = docs.doc_id " + "ORDER BY revs.doc_id, revid DESC"; var args = lastSeq; Cursor cursor = null; RevisionList changes = null; try { cursor = StorageEngine.RawQuery(sql, CommandBehavior.SequentialAccess, args); cursor.MoveToNext(); changes = new RevisionList(); long lastDocId = 0; while (!cursor.IsAfterLast()) { if (!options.IsIncludeConflicts()) { // Only count the first rev for a given doc (the rest will be losing conflicts): var docNumericId = cursor.GetLong(1); if (docNumericId == lastDocId) { cursor.MoveToNext(); continue; } lastDocId = docNumericId; } var sequence = cursor.GetLong(0); var rev = new RevisionInternal(cursor.GetString(2), cursor.GetString(3), (cursor.GetInt(4) > 0), this); rev.SetSequence(sequence); if (includeDocs) { ExpandStoredJSONIntoRevisionWithAttachments(cursor.GetBlob(5), rev, options.GetContentOptions()); } IDictionary<string, object> paramsFixMe = null; // TODO: these should not be null if (RunFilter(filter, paramsFixMe, rev)) { changes.AddItem(rev); } cursor.MoveToNext(); } } catch (SQLException e) { Log.E(Tag, "Error looking for changes", e); } finally { if (cursor != null) { cursor.Close(); } } if (options.IsSortBySequence()) { changes.SortBySequence(); } changes.Limit(options.GetLimit()); return changes; }
public void AddFilter(string name, FilterDelegate tabPage) { _filters.Add(name, tabPage); }
public NotifyResultProxyFilter(string identifier, FilterDelegate filter) { this.identifier = identifier; this.filter = new Func<CheckResult, bool>(filter); }