Ejemplo n.º 1
0
 public Supervisor(ActorPaths actorPaths
                   , long time
                   , bool debug
                   , ProductionDomainContext productionDomainContext
                   , IMessageHub messageHub
                   , Configuration configuration
                   , List <FSetEstimatedThroughputTime> estimatedThroughputTimes
                   , IActorRef principal
                   )
     : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal)
 {
     _productionDomainContext = productionDomainContext;
     _dataBaseConnection      = _productionDomainContext.Database.GetDbConnection();
     _articleCache            = new ArticleCache(connectionString: _dataBaseConnection.ConnectionString);
     _messageHub     = messageHub;
     _orderGenerator = new OrderGenerator(simConfig: configuration, productionDomainContext: _productionDomainContext
                                          , productIds: estimatedThroughputTimes.Select(x => x.ArticleId).ToList());
     _orderCounter     = new OrderCounter(maxQuantity: configuration.GetOption <OrderQuantity>().Value);
     _configID         = configuration.GetOption <SimulationId>().Value;
     _simulationType   = configuration.GetOption <SimulationKind>().Value;
     _transitionFactor = configuration.GetOption <TransitionFactor>().Value;
     estimatedThroughputTimes.ForEach(SetEstimatedThroughputTime);
     Send(instruction: Instruction.PopOrder.Create(message: "Pop", target: Self), waitFor: 1);
     Send(instruction: Instruction.EndSimulation.Create(message: true, target: Self), waitFor: configuration.GetOption <SimulationEnd>().Value);
     Send(instruction: Instruction.SystemCheck.Create(message: "CheckForOrders", target: Self), waitFor: 1);
     DebugMessage(msg: "Agent-System ready for Work");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// When an article has been processed and gets notified, may be we can remove an article from the list or from textbox,
        /// Tell that one item from the list has been processed.
        /// </summary>
        /// <param name="articleCache"></param>
        private void C_OnArticleProcessed(ArticleCache articleCache)
        {
            if (dataSourceForListItem != null)
            {
                if (dataSourceForListItem.Count > 0)
                {
                    dataSourceForListItem.RemoveAt(0);
                }

                if (articlelistBox.InvokeRequired)
                {
                    articlelistBox.DataSource = null;
                    articlelistBox.DataSource = dataSourceForListItem;
                }
            }

            if (articleCache != null)
            {
                if (statusStrip1.InvokeRequired)
                {
                    toolStripStatusLabel1.Text = "Processed " + articleCache.ArticleName + "       ";
                    OnArticleCacheReady(articleCache);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Perform the following task when when the translation of the article(template) has been completed
        /// </summary>
        /// <param name="articleCache"></param>
        private void C_OnArticleCacheReady(ArticleCache articleCache)
        {
            if (formMainWindow.InvokeRequired)
            {
                //formMainWindow.GetDiff(articleCache.TranslatedArticle_Content,articleCache.Article_WikiContent);
                //do nothing
                //MessageBox.Show("Invoke required");

                formMainWindow.GetDifferences(articleCache.TranslatedArticle_Content, articleCache.Article_WikiContent);
            }
            else
            {
                formMainWindow.GetDifferences(articleCache.TranslatedArticle_Content, articleCache.Article_WikiContent);
            }
        }
Ejemplo n.º 4
0
 private void Save(Models.Article record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.DateAdded = DateTime.Now;
     record.Save();
     // delete all keyword for this article and its related urls and documents.
     AutocompletePhrase.AddPhrase("Article", record.ID, record.MetaKeywords, true);
     // save subform or related checkboxes here eg record.Lines.Save();
     //ifsubform: record.example.Save();
     foreach (var articleDocument in record.ArticleDocuments)
     {
         BewebCore.ThirdParty.SearchTextExtractor.CheckAttachmentsForDocOrPDFText(articleDocument);
     }
     CheckLock(record);
     lockobj.UnLockTable(record.GetTableName(), record.ID);
     ArticleCache.Rebuild();
 }
Ejemplo n.º 5
0
 public Default(ProductionDomainContext productionDomainContext
                , IMessageHub messageHub
                , Configuration configuration
                , List <FSetEstimatedThroughputTimes.FSetEstimatedThroughputTime> estimatedThroughputTimes)
 {
     _productionDomainContext = productionDomainContext;
     _dataBaseConnection      = _productionDomainContext.Database.GetDbConnection();
     _articleCache            = new ArticleCache(connectionString: new DbConnectionString(_dataBaseConnection.ConnectionString));
     _messageHub     = messageHub;
     _orderGenerator = new OrderGenerator(simConfig: configuration, productionDomainContext: _productionDomainContext
                                          , productIds: estimatedThroughputTimes.Select(x => x.ArticleId).ToList());
     _orderCounter     = new OrderCounter(maxQuantity: configuration.GetOption <OrderQuantity>().Value);
     _configID         = configuration.GetOption <SimulationId>().Value;
     _simulationEnds   = configuration.GetOption <SimulationEnd>().Value;
     _simulationType   = configuration.GetOption <SimulationKind>().Value;
     _transitionFactor = configuration.GetOption <TransitionFactor>().Value;
     estimatedThroughputTimes.ForEach(SetEstimatedThroughputTime);
 }
Ejemplo n.º 6
0
        private HttpResponse DeleteArticle(HttpRequest r, X509Certificate2 c)
        {
            switch (VerifyRequest(r, c))
            {
            case Reasons.BadSignature: return(HttpResponse.Unauthorized);

            case Reasons.BadTime: return(HttpResponse.RequestTimeout);

            case Reasons.HeaderMissing: return(HttpResponse.Unauthorized);
            }

            if (!r.QueryString.ContainsKey("id"))
            {
                return(HttpResponse.BadRequest);
            }

            if (ArticleCache.Remove(uint.Parse(r.QueryString["id"])))
            {
                return(HttpResponse.Ok);
            }
            return(HttpResponse.Forbidden);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Deletes the given record or displays validation errors if cannot delete
        /// GET: /Admin/Article/Delete/5
        /// </summary>
        public ActionResult Delete(int id, string returnPage)
        {
            var record = Models.Article.LoadID(id);

            // first delete any child records that are OK to delete
            //ifsubform: record.example.DeleteAll();
            record.ArticleURLs.DeleteAll(false);
            record.ArticleDocuments.DeleteAll(false);
            // then prevent deletion if any other related records exist
            string issues = record.CheckForDependentRecords();

            if (issues.IsNotBlank())
            {
                Web.ErrorMessage = "Cannot delete this record. " + issues;
                return(RedirectToEdit(record.ID));
            }
            CheckLock(record);
            lockobj.UnLockTable(record.GetTableName(), record.ID);
            //ifsubform: record.example.Save();  // is this needed?
            // delete the keywords DeletePhrase(string tableName, int recordID) {
            AutocompletePhrase.DeletePhrase("Article", record.ID);
            // do the same for the document titles
            foreach (var document in record.ArticleDocuments)
            {
                AutocompletePhrase.DeletePhrase("ArticleDocument", document.ID);
            }
            // do the same for the url titles
            foreach (var url in record.ArticleURLs)
            {
                AutocompletePhrase.DeletePhrase("ArticleURL", url.ID);
            }
            record.ArticleURLs.Save();
            record.ArticleDocuments.Save();
            record.Delete();
            ArticleCache.Rebuild();
            Web.InfoMessage = "Record deleted.";
            return(Redirect(returnPage));
        }
Ejemplo n.º 8
0
        public async Task <ArticleCache?> Get(ArticleId articleId)
        {
            if (_articles.TryGetValue((string)articleId, out CacheObject <ArticleCache>?cache))
            {
                if (cache.TryGetValue(out ArticleCache? cachedInternal))
                {
                    return(cachedInternal);
                }
            }

            ArticlePayload?payload = await _articleClient.Get(articleId);

            if (payload == null)
            {
                return(null);
            }

            var articleCache = new ArticleCache(payload);

            _articles.AddOrUpdate((string)articleId, x => new CacheObject <ArticleCache>(TimeSpan.FromMinutes(5)).Set(articleCache), (k, x) => x.Set(articleCache));

            return(articleCache);
        }
Ejemplo n.º 9
0
        private HttpResponse NewOrReplaceArticle(HttpRequest r, X509Certificate2 c, bool isReplace)
        {
            switch (VerifyRequest(r, c))
            {
            case Reasons.BadSignature: return(HttpResponse.Unauthorized);

            case Reasons.BadTime: return(HttpResponse.RequestTimeout);

            case Reasons.HeaderMissing: return(HttpResponse.Unauthorized);
            }

            if (!r.QueryString.ContainsKey("id") ||
                !r.QueryString.ContainsKey("title") ||
                !r.QueryString.ContainsKey("image") ||
                !r.QueryString.ContainsKey("time") ||
                !r.QueryString.ContainsKey("author") ||
                !r.QueryString.ContainsKey("platform") ||
                !r.QueryString.ContainsKey("intro") ||
                !r.QueryString.ContainsKey("link"))
            {
                return(HttpResponse.BadRequest);
            }

            var newArticle = new ArticleInfo
            {
                Id       = uint.Parse(r.QueryString["id"]),
                Title    = r.QueryString["title"],
                Image    = r.QueryString["image"],
                Time     = long.Parse(r.QueryString["time"]),
                Author   = r.QueryString["author"],
                Platform = r.QueryString["platform"],
                Intro    = r.QueryString["intro"],
                Link     = r.QueryString["link"]
            };

            var isExists = ArticleCache.Memory.ContainsKey(newArticle.Id);

            if (!isReplace && isExists)
            {
                return(HttpResponse.Forbidden);
            }
            if (isReplace && !isExists)
            {
                return(HttpResponse.Forbidden);
            }

            if (isReplace)
            {
                if (!ArticleCache.Update(newArticle.Id, newArticle))
                {
                    return(HttpResponse.Forbidden);
                }
            }
            else
            {
                if (!ArticleCache.Add(newArticle.Id, newArticle))
                {
                    return(HttpResponse.Forbidden);
                }
            }

            return(HttpResponse.Ok);
        }