Пример #1
0
        protected override void HandleDocumentChange(DocumentChange change)
        {
            if (HandleAllDocs == false && Collections.Contains(change.CollectionName) == false &&
                _referencedCollections.Contains(change.CollectionName) == false)
                return;

            _mre.Set();
        }
Пример #2
0
        protected override void HandleDocumentChange(DocumentChangeNotification notification)
        {
            if (HandleAllDocs == false && Collections.Contains(notification.CollectionName) == false && _referencedCollections.Contains(notification.CollectionName) == false)
            {
                return;
            }

            _mre.Set();
        }
Пример #3
0
        protected override void HandleDocumentChange(DocumentChange change)
        {
            if (change.Type == DocumentChangeTypes.Delete && (HandleAllDocs || Collections.Contains(change.CollectionName)))
            {
                // in time series we need to subscribe only to deletions of source documents

                _mre.Set();
                return;
            }

            if (_referencedCollections.Contains(change.CollectionName))
            {
                _mre.Set();
            }
        }
Пример #4
0
        internal void Reuse()
        {
            //Can be updated by application so refill the lists
            Result             = null;
            _idBlockFun        = _magicDatabase.GetAllBlocks().Where(b => b.Name.IndexOf("Fun", StringComparison.InvariantCultureIgnoreCase) >= 0).Select(b => b.Id).First();
            _idBlockOnlineOnly = _magicDatabase.GetAllBlocks().Where(b => b.Name.IndexOf("OnlineOnly", StringComparison.InvariantCultureIgnoreCase) >= 0).Select(b => b.Id).First();
            Editions           = _magicDatabase.GetAllEditionsOrdered();
            Collections        = _magicDatabase.GetAllCollections();

            IEdition[] editions = EditionsSelected.ToArray();

            foreach (IEdition edition in editions.Where(edition => !Editions.Contains(edition)))
            {
                EditionsSelected.Remove(edition);
            }

            ICardCollection[] collections = CollectionsSelected.ToArray();

            foreach (ICardCollection collection in collections.Where(collection => !Collections.Contains(collection)))
            {
                CollectionsSelected.Remove(collection);
            }
        }
Пример #5
0
        public virtual bool Validate(ref List <string> errors, EtlType type)
        {
            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            if (string.IsNullOrWhiteSpace(Name))
            {
                errors.Add("Script name cannot be empty");
            }

            if (ApplyToAllDocuments)
            {
                if (Collections != null && Collections.Count > 0)
                {
                    errors.Add($"{nameof(Collections)} cannot be specified when {nameof(ApplyToAllDocuments)} is set. Script name: '{Name}'");
                }
            }
            else
            {
                if (Collections == null || Collections.Count == 0)
                {
                    errors.Add($"{nameof(Collections)} need be specified or {nameof(ApplyToAllDocuments)} has to be set. Script name: '{Name}'");
                }
            }

            if (string.IsNullOrWhiteSpace(Script) == false)
            {
                if (Legacy_ReplicateToMethodRegex.Matches(Script).Count > 0)
                {
                    errors.Add($"Found `replicateTo<TableName>()` method in '{Name}' script which is not supported. " +
                               "If you are using the SQL replication script from RavenDB 3.x version then please use `loadTo<TableName>()` instead.");
                }

                IsAddingAttachments  = AddAttachmentMethodRegex.Matches(Script).Count > 0;
                IsLoadingAttachments = LoadAttachmentMethodRegex.Matches(Script).Count > 0;

                IsAddingCounters = AddCounterMethodRegex.Matches(Script).Count > 0;

                if (IsAddingCounters && type == EtlType.Sql)
                {
                    errors.Add("Adding counters isn't supported by SQL ETL");
                }

                var counterBehaviors = LoadCountersBehaviorMethodRegex.Matches(Script);

                if (counterBehaviors.Count > 0)
                {
                    if (type == EtlType.Sql)
                    {
                        errors.Add("Load counter behavior functions aren't supported by SQL ETL");
                    }
                    else
                    {
                        CollectionToLoadCounterBehaviorFunction = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                        for (int i = 0; i < counterBehaviors.Count; i++)
                        {
                            var counterBehaviorFunction = counterBehaviors[i];

                            if (counterBehaviorFunction.Groups.Count != 2)
                            {
                                errors.Add(
                                    "Invalid load counters behavior function. It is expected to have the following signature: " +
                                    "loadCountersOf<CollectionName>Behavior(docId, counterName) and return 'true' if counter should be loaded to a destination");
                            }

                            var functionSignature = counterBehaviorFunction.Groups[0].Value;
                            var collection        = counterBehaviorFunction.Groups[1].Value;

                            var functionName = LoadCountersBehaviorMethodNameRegex.Match(functionSignature);

                            if (Collections.Contains(collection) == false)
                            {
                                var scriptCollections = string.Join(", ", Collections.Select(x => ($"'{x}'")));

                                errors.Add(
                                    $"There is '{functionName}' function defined in '{Name}' script while the processed collections " +
                                    $"({scriptCollections}) doesn't include '{collection}'. " +
                                    "loadCountersOf<CollectionName>Behavior() function is meant to be defined only for counters of docs from collections that " +
                                    "are loaded to the same collection on a destination side");
                            }

                            CollectionToLoadCounterBehaviorFunction[collection] = functionName.Value;
                        }
                    }
                }

                var deleteBehaviors = DeleteDocumentsBehaviorMethodRegex.Matches(Script);

                if (deleteBehaviors.Count > 0)
                {
                    if (type == EtlType.Sql)
                    {
                        errors.Add("Delete documents behavior functions aren't supported by SQL ETL");
                    }
                    else
                    {
                        CollectionToDeleteDocumentsBehaviorFunction = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                        for (int i = 0; i < deleteBehaviors.Count; i++)
                        {
                            var deleteBehaviorFunction = deleteBehaviors[i];

                            if (deleteBehaviorFunction.Groups.Count != 2)
                            {
                                errors.Add(
                                    "Invalid delete documents behavior function. It is expected to have the following signature: " +
                                    "deleteDocumentsOf<CollectionName>Behavior(docId) and return 'true' if document deletion should be sent to a destination");
                            }

                            var function   = deleteBehaviorFunction.Groups[0].Value;
                            var collection = deleteBehaviorFunction.Groups[1].Value;

                            var functionName = DeleteDocumentsBehaviorMethodNameRegex.Match(function);

                            if (Collections.Contains(collection) == false)
                            {
                                var scriptCollections = string.Join(", ", Collections.Select(x => ($"'{x}'")));

                                errors.Add(
                                    $"There is '{functionName}' function defined in '{Name}' script while the processed collections " +
                                    $"({scriptCollections}) doesn't include '{collection}'. " +
                                    "deleteDocumentsOf<CollectionName>Behavior() function is meant to be defined only for documents from collections that " +
                                    "are loaded to the same collection on a destination side");
                            }

                            CollectionToDeleteDocumentsBehaviorFunction[collection] = functionName.Value;
                        }
                    }
                }

                var genericDeleteBehavior = GenericDeleteDocumentsBehaviorMethodRegex.Matches(Script);

                if (genericDeleteBehavior.Count > 0)
                {
                    if (type == EtlType.Sql)
                    {
                        errors.Add("Delete documents behavior functions aren't supported by SQL ETL");
                    }
                    else
                    {
                        if (genericDeleteBehavior.Count > 1)
                        {
                            errors.Add("Generic delete behavior function can be defined just once in the script");
                        }
                        else
                        {
                            if (CollectionToDeleteDocumentsBehaviorFunction == null)
                            {
                                CollectionToDeleteDocumentsBehaviorFunction = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                            }

                            CollectionToDeleteDocumentsBehaviorFunction[GenericDeleteDocumentsBehaviorFunctionKey] = GenericDeleteDocumentsBehaviorFunctionName;
                        }
                    }
                }

                var collections = GetCollectionsFromScript();

                if (collections == null || collections.Length == 0)
                {
                    var actualScript = Script;

                    if (deleteBehaviors.Count > 0)
                    {
                        // let's skip all delete behavior functions to check if we have empty transformation

                        for (int i = 0; i < deleteBehaviors.Count; i++)
                        {
                            actualScript = actualScript.Replace(deleteBehaviors[i].Value, string.Empty);
                        }
                    }

                    if (genericDeleteBehavior.Count == 1)
                    {
                        actualScript = actualScript.Replace(genericDeleteBehavior[0].Value, string.Empty);
                    }

                    if (string.IsNullOrWhiteSpace(actualScript) == false)
                    {
                        string targetName;
                        switch (type)
                        {
                        case EtlType.Raven:
                            targetName = "Collection";
                            break;

                        case EtlType.Sql:
                            targetName = "Table";
                            break;

                        default:
                            throw new ArgumentException($"Unknown ETL type: {type}");
                        }

                        errors.Add($"No `loadTo<{targetName}Name>()` method call found in '{Name}' script");
                    }
                    else
                    {
                        IsEmptyScript = true;
                    }
                }
            }
            else
            {
                IsEmptyScript = true;
            }

            return(errors.Count == 0);
        }
Пример #6
0
        private void AfterUpdate()
        {
            if (initialSelectedDatabaseName != null &&
                (SelectedCollection.Value == null || SelectedCollection.Value.Name != initialSelectedDatabaseName || Collections.Contains(SelectedCollection.Value) == false))
            {
                SelectedCollection.Value = Collections.FirstOrDefault(x => x.Name == initialSelectedDatabaseName);
            }

            if (SelectedCollection.Value == null)
            {
                SelectedCollection.Value = Collections.FirstOrDefault();
            }
        }
Пример #7
0
        void HandleOnTextMessageRecv(string socketMessage)
        {
            if (Logging)
            {
                Debug.LogError(socketMessage);
            }

            IDictionary m = socketMessage.Deserialize() as IDictionary;

            if (m == null)
            {
                return;
            }

            var msg = m ["msg"] as string;

            switch (msg)
            {
            case AddedMessage.added:
                var collection = m ["collection"] as string;
                if (Collections.Contains(collection))
                {
                    Collections[collection].Added(socketMessage);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record add. Creating a collection to handle it.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ChangedMessage.changed:
                ChangedMessage cm = socketMessage.Deserialize <ChangedMessage>();
                if (Collections.Contains(cm.collection))
                {
                    Collections[cm.collection].Changed(cm.id, cm.cleared, cm.fields);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record change. Cannot recover this record later.\nMessage:\n{0}", socketMessage));
                }
                break;

            case RemovedMessage.removed:
                RemovedMessage rm = socketMessage.Deserialize <RemovedMessage>();
                if (Collections.Contains(rm.collection))
                {
                    Collections[rm.collection].Removed(rm.id);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record remove.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ReadyMessage.ready:
                ReadyMessage readym = socketMessage.Deserialize <ReadyMessage>();
                foreach (string sub in readym.subs)
                {
                    if (Subscriptions.Contains(sub))
                    {
                        Subscriptions [sub].ready = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: A subscription ready message was received, but the subscription could not be found.\nSubscription: {0}", sub));
                    }
                }
                break;

            case ConnectedMessage.connected:
                ConnectedMessage connm = socketMessage.Deserialize <ConnectedMessage>();

                if (WillConnect != null)
                {
                    WillConnect(connm.session);
                }

                if (DidConnect != null)
                {
                    DidConnect(connm.session);
                }

                break;

            case ResultMessage.result:
                ResultMessage resultm = null;
                resultm = socketMessage.Deserialize <ResultMessage>();
                if (methods.ContainsKey(resultm.id))
                {
                    methods[resultm.id].Callback(resultm.error, resultm.methodResult);
                }
                else
                {
                    Debug.LogError(string.Format("LiveData: A result message was received, but the method could not be found.\nMethod: {0}", resultm.id));
                }
                break;

            case UpdatedMessage.updated:
                UpdatedMessage updatedm = socketMessage.Deserialize <UpdatedMessage>();
                foreach (var method in updatedm.methods)
                {
                    if (methods.ContainsKey(method))
                    {
                        methods [method].Updated = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: An updated message was received, but the method could not be found.\nMethod: {0}", method));
                    }
                }
                break;

            default:
                if (!socketMessage.Contains("server_id"))
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled message.\nMessage:\n{0}", socketMessage));
                }
                break;
            }
        }
Пример #8
0
        void HandleOnTextMessageRecv(string socketMessage)
        {
            if (Logging)
            {
                Debug.Log(socketMessage);
            }

            IDictionary m = socketMessage.Deserialize() as IDictionary;

            if (m == null)
            {
                return;
            }

            var msg = m ["msg"] as string;

            switch (msg)
            {
            case AddedMessage.added:
                var collection = m ["collection"] as string;
                if (Collections.Contains(collection))
                {
                    Collections [collection].Added(socketMessage);
                }
                else
                {
                    var addedm = socketMessage.Deserialize <AddedMessage <Hashtable> > ();
                    if (Logging)
                    {
                        Debug.Log(string.Format("LiveData: Unhandled record add. Creating a collection to handle it.\nMessage:\n{0}", socketMessage));
                    }
                    var handlingCollection = new TemporaryCollection(collection);
                    Collections.Add(handlingCollection);
                    handlingCollection.Added(addedm.id, addedm.fields);
                }
                break;

            case ChangedMessage.changed:
                ChangedMessage cm = socketMessage.Deserialize <ChangedMessage> ();
                if (Collections.Contains(cm.collection))
                {
                    Collections [cm.collection].Changed(cm.id, cm.cleared, cm.fields);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record change. Cannot recover this record later.\nMessage:\n{0}", socketMessage));
                }
                break;

            case RemovedMessage.removed:
                RemovedMessage rm = socketMessage.Deserialize <RemovedMessage> ();
                if (Collections.Contains(rm.collection))
                {
                    Collections [rm.collection].Removed(rm.id);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record remove.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ReadyMessage.ready:
                ReadyMessage readym = socketMessage.Deserialize <ReadyMessage> ();
                foreach (string sub in readym.subs)
                {
                    if (Subscriptions.Contains(sub))
                    {
                        Subscriptions [sub].ready = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: A subscription ready message was received, but the subscription could not be found.\nSubscription: {0}", sub));
                    }
                }
                break;

            case ConnectedMessage.connected:
                ConnectedMessage connm = socketMessage.Deserialize <ConnectedMessage> ();

                if (WillConnect != null)
                {
                    WillConnect(connm.session);
                }

                if (DidConnect != null)
                {
                    DidConnect(connm.session);
                }

                break;

            case FailedMessage.failed:
                FailedMessage failedMessage = socketMessage.Deserialize <FailedMessage> ();
                SendConnectMessage(failedMessage.version);
                break;

            case ResultMessage.result:
                ResultMessage resultm = null;
                resultm = socketMessage.Deserialize <ResultMessage> ();
                if (resultm.methodError != null)
                {
                    int    code   = (int)resultm.methodError["error"];
                    string reason = (string)resultm.methodError["reason"];
                    string type   = (string)resultm.methodError["errorType"];
                    throw new MeteorException(code, reason);
                }
                if (methods.ContainsKey(resultm.id))
                {
                    methods [resultm.id].Callback(resultm.error, resultm.methodResult);
                }
                else
                {
                    Debug.LogError(string.Format("LiveData: A result message was received, but the method could not be found.\nMethod: {0}", resultm.id));
                }
                break;

            case UpdatedMessage.updated:
                UpdatedMessage updatedm = socketMessage.Deserialize <UpdatedMessage> ();
                foreach (var method in updatedm.methods)
                {
                    if (methods.ContainsKey(method))
                    {
                        methods [method].Updated = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: An updated message was received, but the method could not be found.\nMethod: {0}", method));
                    }
                }
                break;

            case PingMessage.ping:
                PingMessage pingMessage = socketMessage.Deserialize <PingMessage> ();
                var         pongMessage = new PongMessage()
                {
                    id = pingMessage.id
                };
                Send(pongMessage);
                break;

            case PongMessage.pong:
                break;

            case NosubMessage.nosub:
                NosubMessage nosubm = null;
                nosubm = socketMessage.Deserialize <NosubMessage> ();
                if (nosubm.Error != null)
                {
                    string id     = nosubm.id;
                    int    code   = (int)nosubm.Error["error"];
                    string reason = (string)nosubm.Error["reason"];
                    string type   = (string)nosubm.Error["errorType"];
                    throw new MeteorException(code, reason);
                }
                break;

            default:
                if (!socketMessage.Contains("server_id"))
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled message.\nMessage:\n{0}", socketMessage));
                }
                break;
            }
        }
Пример #9
0
        // here we simulate SQL search, sorting and paging operations
        private List <ProductViewModel> FilterProductData(ref int recordFiltered, ref int recordTotal, int start, int length, string search, int sortColumn, string sortDirection, FilterArgs Fvm)
        {
            bool Pending = false;
            bool Sample  = false;

            if (string.IsNullOrEmpty(Fvm.WizardType) || Fvm.WizardType == "Pending")
            {
                Pending = true;
            }

            if (!string.IsNullOrEmpty(Fvm.SOD) && Fvm.SOD == "Sample")
            {
                Sample = true;
            }


            string[] Collections = null;
            if (!string.IsNullOrEmpty(Fvm.ProductCollection))
            {
                Collections = Fvm.ProductCollection.Split(",".ToCharArray());
            }
            else
            {
                Collections = new string[] { "NA" };
            }

            string[] Category = null;
            if (!string.IsNullOrEmpty(Fvm.ProductCategory))
            {
                Category = Fvm.ProductCategory.Split(",".ToCharArray());
            }
            else
            {
                Category = new string[] { "NA" };
            }


            List <ProductViewModel>       list  = new List <ProductViewModel>();
            IQueryable <ProductViewModel> _data = (from p in db.ProductProcess
                                                   join rh in db.RateListHeader on p.ProcessId equals rh.ProcessId
                                                   join fp in db.FinishedProduct on p.ProductId equals fp.ProductId
                                                   join pcol in db.ProductCollections on fp.ProductCollectionId equals pcol.ProductCollectionId
                                                   join pcat in db.ProductCategory on fp.ProductCategoryId equals pcat.ProductCategoryId
                                                   join pg in db.ProductGroups on fp.ProductGroupId equals pg.ProductGroupId
                                                   join pd in db.ProductDesigns on fp.ProductDesignId equals pd.ProductDesignId
                                                   where rh.RateListHeaderId == Fvm.RateListHeaderId && (Pending ? p.ProductRateGroupId == null : 1 == 1) && (fp.IsSample == Sample) &&
                                                   (string.IsNullOrEmpty(Fvm.ProductCollection) ? 1 == 1 : Collections.Contains(fp.ProductCollectionId.ToString())) &&
                                                   (string.IsNullOrEmpty(Fvm.ProductCategory) ? 1 == 1 : Category.Contains(fp.ProductCategoryId.ToString())) &&
                                                   rh.DivisionId == fp.DivisionId && fp.IsActive == true && fp.DiscontinuedDate == null
                                                   group new { pg, fp, p, pcol, pcat, pd } by pg.ProductGroupId into g
                                                   select new ProductViewModel
            {
                ProductGroupId = g.Key,
                ProductGroupName = g.Max(m => m.pg.ProductGroupName),
                ProductDesignName = g.Max(m => m.pd.ProductDesignName),
                ImageFileName = g.Max(m => m.pg.ImageFileName),
                ImageFolderName = g.Max(m => m.pg.ImageFolderName),
                SampleName = g.Max(m => m.fp.IsSample.ToString() == "True" ? "Sample" : "Design"),
                ProductRateGroupId = g.Max(m => m.p.ProductRateGroupId),
                ProductCollectionName = g.Max(m => m.pcol.ProductCollectionName),
                ProductCategoryName = g.Max(m => m.pcat.ProductCategoryName),
            });


            recordTotal = _data.Count();

            if (string.IsNullOrEmpty(search))
            {
            }
            else
            {
                // simulate search
                _data = from m in _data
                        where (m.ProductGroupName).ToLower().Contains(search.ToLower()) || (m.ProductDesignName).ToLower().Contains(search.ToLower()) ||
                        (m.SampleName).ToLower().Contains(search.ToLower()) || (m.ProductCollectionName).ToLower().Contains(search.ToLower()) ||
                        (m.ProductCategoryName).ToLower().Contains(search.ToLower())
                        select m;
            }

            _data = _data.OrderBy(m => m.ProductGroupName);


            recordFiltered = _data.Count();

            // get just one page of data
            list = _data.Select(m => new ProductViewModel
            {
                ProductGroupId        = m.ProductGroupId,
                ProductGroupName      = m.ProductGroupName,
                ProductDesignName     = m.ProductDesignName,
                ImageFileName         = m.ImageFileName,
                ImageFolderName       = m.ImageFolderName,
                SampleName            = m.SampleName,
                ProductRateGroupId    = m.ProductRateGroupId,
                ProductCollectionName = m.ProductCollectionName,
                ProductCategoryName   = m.ProductCategoryName,
            })
                   .Skip(start).Take((start == 0) ? 90 : length).ToList();

            return(list);
        }
Пример #10
0
        private void AfterUpdate(NameAndCount[] collectionDocumentsCount)
        {
            // update documents count

            var nameToCount = collectionDocumentsCount.ToDictionary(i => i.Name, i => i.Count);
            var collections = Collections.OrderByDescending(model => model.Count).ToList();

            foreach (var collectionModel in Collections)
            {
                collectionModel.Count = nameToCount[collectionModel.Name];
            }

            if (initialSelectedDatabaseName != null &&
                (SelectedCollection.Value == null || SelectedCollection.Value.Name != initialSelectedDatabaseName || Collections.Contains(SelectedCollection.Value) == false))
            {
                SelectedCollection.Value = Collections.FirstOrDefault(x => x.Name == initialSelectedDatabaseName);
            }

            if (SelectedCollection.Value == null)
            {
                SelectedCollection.Value = Collections.FirstOrDefault();
            }

            SortedCollectionsList.View.Refresh();
        }
Пример #11
0
        private void AfterUpdate(IEnumerable <CollectionModel> collectionDocumentsCount)
        {
            // update documents count
            var nameToCount = collectionDocumentsCount.ToLookup(i => i.Name, i => i.Count);

            foreach (var collectionModel in Collections)
            {
                collectionModel.Count = nameToCount[collectionModel.Name].Sum();
            }

            initialSelectedCollectionName = initialSelectedCollectionName ?? "";

            if ((SelectedCollection.Value == null || SelectedCollection.Value.Name != initialSelectedCollectionName || Collections.Contains(SelectedCollection.Value) == false))
            {
                SelectedCollection.Value = Collections.FirstOrDefault(x => x.Name == initialSelectedCollectionName);
            }

            if (SelectedCollection.Value == null)
            {
                SelectedCollection.Value = Collections.FirstOrDefault();
            }

            SortedCollectionsList.View.Refresh();
        }