Example #1
0
        public static int InitBuiltinRouting(ref Config config)
        {
            if (config.routings == null)
            {
                config.routings = new List <RoutingItem>();
            }
            if (config.routings.Count <= 0)
            {
                //Bypass the mainland
                var item2 = new RoutingItem();
                item2.remarks = "绕过大陆(Whitelist)";
                item2.url     = string.Empty;
                item2.rules   = new List <RulesItem>();
                string result2 = Utils.GetEmbedText(Global.CustomRoutingFileName + "white");
                AddBatchRoutingRules(ref item2, result2);
                config.routings.Add(item2);

                config.routingIndex = 0;
            }

            if (GetLockedRoutingItem(ref config) == null)
            {
                var item1 = new RoutingItem();
                item1.remarks = "locked";
                item1.url     = string.Empty;
                item1.rules   = new List <RulesItem>();
                item1.locked  = true;
                string result1 = Utils.GetEmbedText(Global.CustomRoutingFileName + "locked");
                AddBatchRoutingRules(ref item1, result1);
                config.routings.Add(item1);
            }

            SaveRouting(ref config);
            return(0);
        }
        public async Task <IActionResult> CreateRouting([FromBody] RoutingItem routingItem)
        {
            try
            {
                var result = await _processFacade.CreateRoutingAsync(routingItem, HttpContext.RequestAborted, HttpContext.Items);

                if (result == null)
                {
                    return(NotFound(result));
                }

                return(Ok(result));
            }
            catch (AggregateException exception)
            {
                return(BadRequest(exception.Message));
            }
            catch (ArgumentException exception)
            {
                return(BadRequest(exception.Message));
            }
            catch (Exception exception)
            {
                _logger.LogError($"{HttpContext.TraceIdentifier} Unable to create the routing. Reason: {exception}");
                throw;
            }
        }
Example #3
0
        public void RoutingItem_IsValid()
        {
            RoutingItem routingItem = CreateTestItem();
            bool        result      = ValidateObject(routingItem);

            Assert.AreEqual(true, result);
        }
Example #4
0
        private bool ValidateObject(RoutingItem routingItem)
        {
            ValidationContext       validationContext = new ValidationContext(routingItem);
            List <ValidationResult> errors            = new List <ValidationResult>();

            return(Validator.TryValidateObject(routingItem, validationContext, errors));
        }
Example #5
0
        private void InsertRoutingItem(RoutingItem item, object key)
        {
            StringBuilder builder = new StringBuilder(100);

            builder.Append(string.Format("INSERT INTO RoutingItem ({0},{1},{2},{3},{4},{5}) ",
                                         TransmittalFactory.FieldNames.RoutingItemId,
                                         TransmittalFactory.FieldNames.DisciplineId,
                                         TransmittalFactory.FieldNames.RoutingOrder,
                                         TransmittalFactory.FieldNames.ProjectContactId,
                                         TransmittalFactory.FieldNames.DateSent,
                                         TransmittalFactory.FieldNames.DateReturned));
            builder.Append(string.Format("VALUES ({0},{1},{2},{3},{4},{5});",
                                         DataHelper.GetSqlValue(item.Key),
                                         DataHelper.GetSqlValue(item.Discipline.Key),
                                         DataHelper.GetSqlValue(item.RoutingOrder),
                                         DataHelper.GetSqlValue(item.Recipient.Key),
                                         DataHelper.GetSqlValue(item.DateSent),
                                         DataHelper.GetSqlValue(item.DateReturned)));

            this.Database.ExecuteNonQuery(
                this.Database.GetSqlStringCommand(builder.ToString()));

            builder = new StringBuilder(50);
            builder.Append(string.Format("INSERT INTO {0}RoutingItem ({1},{2}) ",
                                         this.EntityName,
                                         this.KeyFieldName,
                                         TransmittalFactory.FieldNames.RoutingItemId));
            builder.Append(string.Format("VALUES ({0},{1});",
                                         DataHelper.GetSqlValue(key),
                                         DataHelper.GetSqlValue(item.Key)));

            this.Database.ExecuteNonQuery(
                this.Database.GetSqlStringCommand(builder.ToString()));
        }
        private void ProcessItem(RoutingItem item)
        {
            int count = this.rules.Count;

            if (count == 0)
            {
                return;
            }

            lock (this.lockObject) {
                for (int i = 0; i < count; i++)
                {
                    var rule = this.rules[i];

                    if (item.Equals(rule))
                    {
                        if (!this.routes.ContainsKey(rule.ActionDestination))
                        {
                            continue;
                        }                                                                   // invalid destination

                        try {
                            string result = this.routes[rule.ActionDestination].RouteAction(rule.Action, rule.Args);
                            OnRuleProcessed(string.Format(CultureInfo.InvariantCulture, Properties.Resources.FMT_ROUTING_OK, result));
                        } catch {
                            OnRuleProcessed(Properties.Resources.MSG_ROUTING_ERROR);
                        }
                    }
                }  // for
            }
        }
Example #7
0
        /// <summary>
        /// 刷新列表
        /// </summary>
        private void RefreshSubsView()
        {
            panCon.Controls.Clear();
            lstControls.Clear();

            for (int k = config.routingItem.Count - 1; k >= 0; k--)
            {
                RoutingItem item = config.routingItem[k];
                if (Utils.IsNullOrEmpty(item.remarks))
                {
                    config.routingItem.RemoveAt(k);
                }
            }

            foreach (RoutingItem item in config.routingItem)
            {
                RoutingSettingControl control = new RoutingSettingControl();
                control.OnButtonClicked += Control_OnButtonClicked;
                control.routingItem      = item;
                control.Dock             = DockStyle.Top;

                panCon.Controls.Add(control);
                panCon.Controls.SetChildIndex(control, 0);

                lstControls.Add(control);
            }
        }
Example #8
0
        /// <summary>
        /// AddBatchRoutingRules
        /// </summary>
        /// <param name="config"></param>
        /// <param name="clipboardData"></param>
        /// <returns></returns>
        public static int AddBatchRoutingRules(ref RoutingItem routingItem, string clipboardData, bool blReplace = true)
        {
            if (Utils.IsNullOrEmpty(clipboardData))
            {
                return(-1);
            }

            var lstRules = Utils.FromJson <List <RulesItem> >(clipboardData);

            if (lstRules == null)
            {
                return(-1);
            }
            if (routingItem.rules == null)
            {
                routingItem.rules = new List <RulesItem>();
            }
            if (blReplace)
            {
                routingItem.rules.Clear();
            }
            foreach (var item in lstRules)
            {
                routingItem.rules.Add(item);
            }
            return(0);
        }
Example #9
0
        public RoutingItemTest()
        {
            var mock = new Mock <RoutingItem> {
                CallBase = true
            };

            _baseModel = mock.Object;
        }
        private RoutingItem CreateTestRoutingItem()
        {
            var testItem = new RoutingItem {
                DocumentTypeName = "Test Routing"
            };

            return(testItem);
        }
Example #11
0
        public static int InitBuiltinRouting(ref Config config, bool blImportAdvancedRules = false)
        {
            if (config.routings == null)
            {
                config.routings = new List <RoutingItem>();
            }

            if (blImportAdvancedRules || config.routings.Count(it => it.locked != true) <= 0)
            {
                //Bypass the mainland
                var item2 = new RoutingItem()
                {
                    remarks = "绕过大陆(Whitelist)",
                    url     = string.Empty,
                };
                AddBatchRoutingRules(ref item2, Utils.GetEmbedText(Global.CustomRoutingFileName + "white"));
                config.routings.Add(item2);

                //Blacklist
                var item3 = new RoutingItem()
                {
                    remarks = "黑名单(Blacklist)",
                    url     = string.Empty,
                };
                AddBatchRoutingRules(ref item3, Utils.GetEmbedText(Global.CustomRoutingFileName + "black"));
                config.routings.Add(item3);

                //Global
                var item1 = new RoutingItem()
                {
                    remarks = "全局(Global)",
                    url     = string.Empty,
                };
                AddBatchRoutingRules(ref item1, Utils.GetEmbedText(Global.CustomRoutingFileName + "global"));
                config.routings.Add(item1);

                if (!blImportAdvancedRules)
                {
                    config.routingIndex = 0;
                }
            }

            if (GetLockedRoutingItem(ref config) == null)
            {
                var item1 = new RoutingItem()
                {
                    remarks = "locked",
                    url     = string.Empty,
                    locked  = true,
                };
                AddBatchRoutingRules(ref item1, Utils.GetEmbedText(Global.CustomRoutingFileName + "locked"));
                config.routings.Add(item1);
            }

            SaveRouting(ref config);
            return(0);
        }
Example #12
0
        private void DeleteRoutingItem(RoutingItem item)
        {
            StringBuilder query = new StringBuilder(50);

            query.Append("DELETE FROM RoutingItem ");
            query.Append(string.Format("WHERE RoutingItemID = '{0}'", item.Key));
            this.Database.ExecuteNonQuery(
                this.Database.GetSqlStringCommand(query.ToString()));
        }
Example #13
0
        public void CopyOf_CreateAsync_RoutingItem_ArgumentNullException()
        {
            RoutingItem routingItem = CreateTestRoutingItem();

            var result = _baseStore.CreateRoutingAsync(routingItem);

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(AggregateException), result.Exception.InnerException.GetType());
        }
Example #14
0
        private void DeleteRoutingItemCommandHandler(object sender,
                                                     DelegateCommandEventArgs e)
        {
            RoutingItem item = e.Parameter as RoutingItem;

            if (item != null)
            {
                this.routingItems.Remove(item);
            }
        }
Example #15
0
        internal static RoutingItem RoutingItem(string content, List<CustomProperty> properties)
        {
            RoutingItem routingItem = new RoutingItem();
            routingItem.Content = content;

            if (properties != null)
                routingItem.Properties = properties.ToArray();

            return routingItem;
        }
Example #16
0
        public void RoutingItem_NullDocumentTypeName_IsInValid()
        {
            RoutingItem routingItem = CreateTestItem();

            routingItem.DocumentTypeName = null;

            bool result = ValidateObject(routingItem);

            Assert.AreEqual(false, result);
        }
Example #17
0
        public void RoutingItem_NullApplicationItemId_IsInValid()
        {
            RoutingItem routingItem = CreateTestItem();

            routingItem.ApplicationItemId = null;

            bool result = ValidateObject(routingItem);

            Assert.AreEqual(false, result);
        }
Example #18
0
        public void RoutingItem_EmptyBeneficaryId_IsInValid()
        {
            RoutingItem routingItem = CreateTestItem();

            routingItem.BeneficiaryHanfordId = "";

            bool result = ValidateObject(routingItem);

            Assert.AreEqual(false, result);
        }
Example #19
0
        public void RoutingItem_EmptyOriginatorHanfordId_IsInValid()
        {
            RoutingItem routingItem = CreateTestItem();

            routingItem.OriginatorHanfordId = "";

            bool result = ValidateObject(routingItem);

            Assert.AreEqual(false, result);
        }
Example #20
0
        public void RoutingItem_EmptyLastChangeHanfordId_IsInValid()
        {
            RoutingItem routingItem = CreateTestItem();

            routingItem.SubmitUserHanfordId = "";

            bool result = ValidateObject(routingItem);

            Assert.AreEqual(false, result);
        }
Example #21
0
        public void RoutingItem_EmptyDocumentTitle_IsInValid()
        {
            RoutingItem routingItem = CreateTestItem();

            routingItem.DocumentTitle = "";

            bool result = ValidateObject(routingItem);

            Assert.AreEqual(false, result);
        }
Example #22
0
        private int AddBatchRoutingRules(ref RoutingItem routingItem, string clipboardData)
        {
            bool blReplace = false;

            if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == DialogResult.No)
            {
                blReplace = true;
            }
            return(ConfigHandler.AddBatchRoutingRules(ref routingItem, clipboardData, blReplace));
        }
Example #23
0
        private void AddSub(string outboundTag, string userRule)
        {
            RoutingItem RoutingItem = new RoutingItem
            {
                remarks     = outboundTag,
                outboundTag = outboundTag,
                userRules   = Utils.String2List(userRule)
            };

            config.routingItem.Add(RoutingItem);
        }
        protected List <RoutingItem> ToRoutings(List <RoutingItemDTO> list)
        {
            var os = new List <RoutingItem>();

            foreach (var vo in list)
            {
                var o = new RoutingItem();
                ClassCopier.Instance.Copy(vo, o);
                os.Add(o);
            }
            return(os);
        }
Example #25
0
        public static int AddRoutingItem(ref Config config, RoutingItem item, int index)
        {
            if (index >= 0)
            {
                config.routings[index] = item;
            }
            else
            {
                config.routings.Add(item);
            }
            ToJsonFile(config);

            return(0);
        }
Example #26
0
        private void RoutingRuleSettingForm_Load(object sender, EventArgs e)
        {
            routingItem = EditIndex >= 0 ? config.routings[EditIndex] : new RoutingItem();
            if (routingItem.rules == null)
            {
                routingItem.rules = new List <RulesItem>();
            }

            txtRemarks.Text    = routingItem.remarks ?? string.Empty;
            txtUrl.Text        = routingItem.url ?? string.Empty;
            txtCustomIcon.Text = routingItem.customIcon ?? string.Empty;

            InitRoutingsView();
            RefreshRoutingsView();
        }
Example #27
0
        private void BindingLockedData()
        {
            lockedItem = ConfigHandler.GetLockedRoutingItem(ref config);
            if (lockedItem != null)
            {
                txtProxyDomain.Text = Utils.List2String(lockedItem.rules[0].domain, true);
                txtProxyIp.Text     = Utils.List2String(lockedItem.rules[0].ip, true);

                txtDirectDomain.Text = Utils.List2String(lockedItem.rules[1].domain, true);
                txtDirectIp.Text     = Utils.List2String(lockedItem.rules[1].ip, true);

                txtBlockDomain.Text = Utils.List2String(lockedItem.rules[2].domain, true);
                txtBlockIp.Text     = Utils.List2String(lockedItem.rules[2].ip, true);
            }
        }
Example #28
0
        private RoutingItem CreateTestItem()
        {
            var testItem = new RoutingItem {
                DocumentTypeName        = "Required"
                , ApplicationItemId     = 12345
                , BeneficiaryHanfordId  = "1234567"
                , OriginatorHanfordId   = "1234567"
                , DocumentEditUrl       = null
                , DocumentId            = "Required"
                , DocumentTitle         = "Required"
                , RecordsClassification = null
                , RecordsContainer      = null
                , SubmitUserHanfordId   = "1234567"
                , Document = new RoutingDocument()
                {
                }
            };

            return(testItem);
        }
Example #29
0
        /// <summary>
        /// Asynchronously routes an item for approvals
        /// </summary>
        /// <param name="routingItem">The information necessary to instantiate a new routing.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <param name="context">The optional execution context that applies to this operation.</param>
        /// <returns>An integer that contains the new process id.</returns>
        public virtual async Task <int?> CreateRoutingAsync(RoutingItem routingItem, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (routingItem == null)
            {
                throw new ArgumentNullException(nameof(routingItem));
            }

            ValidationContext       validationContext = new ValidationContext(routingItem);
            List <ValidationResult> errors            = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(routingItem, validationContext, errors);

            if (!isValid)
            {
                throw new AggregateException(errors.Select(e => new ValidationException(e.ErrorMessage)));
            }

            return(await OnCreateRoutingAsync(routingItem, cancellationToken, context ?? new Dictionary <object, object>()));
        }
Example #30
0
        /// <summary>
        /// Asynchronously routes an item for approvals
        /// </summary>
        /// <param name="routingItem">The information necessary to instantiate a new routing.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <param name="context">The optional execution context that applies to this operation.</param>
        /// <returns>An integer that contains the new process id.</returns>
        public async Task <Process> CreateRoutingAsync(RoutingItem routingItem, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null)
        {
            try
            {
                int?id = await _approvalsLegacyStore.CreateRoutingAsync(routingItem, cancellationToken, context);

                IList <int> list = new List <int>
                {
                    id.GetValueOrDefault()
                };

                var result = await _processStore.GetAsync(list, 0, 10, cancellationToken, context);

                return(result.First());
            }
            catch (Exception exception)
            {
                _logger.LogError($"Unable to process routing request: {exception}");
                throw;
            }
        }
Example #31
0
        public static int AddRoutingItem(ref Config config, RoutingItem item, int index)
        {
            if (index >= 0)
            {
                config.routings[index] = item;
            }
            else
            {
                config.routings.Add(item);
                int indexLocked = config.routings.FindIndex(it => it.locked == true);
                if (indexLocked != -1)
                {
                    var itemLocked = Utils.DeepCopy(config.routings[indexLocked]);
                    config.routings.RemoveAt(indexLocked);
                    config.routings.Add(itemLocked);
                }
            }
            ToJsonFile(config);

            return(0);
        }