示例#1
0
        public ActionResult NewProcess(int groupid, Process pro, HttpPostedFileBase FileUpload)
        {
            string idUser = User.Identity.GetUserId();

            if (string.IsNullOrEmpty(pro.Name))
            {
                SetFlash(FlashType.error, "Process Name is required");
                return(View());
            }
            ConfigRule fileSizeRule   = db.ConfigRules.Find("filesize");
            bool       isFileOverSize = fileService.checkFileOverSize(FileUpload);

            if (isFileOverSize)
            {
                SetFlash(FlashType.error, string.Format("This file is too big ({0} {1} maximum)", fileSizeRule.Value, fileSizeRule.Unit));
                return(View());
            }
            Group group = groupService.findGroup(groupid);

            processService.createProcess(group.Id, idUser, pro);

            //create directory
            string directoryPath = String.Format("Upload/{0}/{1}", group.Id, pro.Id);

            fileService.createDirectory(directoryPath);
            //save file
            //string savePath = Server.MapPath(String.Format("~/App_Data/{0}/{1}", group.Id,pro.Id));
            string filePath = String.Format("Upload/{0}/{1}", group.Id, pro.Id);

            fileService.saveFile(group.Id, FileUpload, filePath, Direction.Process);

            SetFlash(FlashType.success, "Created Process Successfully");
            return(RedirectToAction("Draw", new { groupslug = group.groupSlug, groupid = group.Id, processid = pro.Id }));
            //return RedirectToRoute("GroupControlLocalizedDefault", new { action = "DrawProcess", groupslug = group.groupSlug, groupid = group.Id, id = pro.Id });
        }
示例#2
0
        public void ConfigReader_ParseLine_ValidCommand_Should_Return_Proper_ConfigRule()
        {
            string     testline = "CashPrem\tAverage\tMaxValue";
            ConfigRule expected = _testConfigReader.ParseLine(testline);

            Assert.IsInstanceOfType(expected, typeof(ConfigRule));
        }
示例#3
0
 internal EditableRuleView(ConfigRule rule, int index, EditableRuleSet ruleSet, ConfigValues configValues)
 {
     _configValues = configValues;
     _configValues.PropertyChanged += OnConfigValuesPropertyChanged;
     _rule = rule.Clone();
     this.UpdateIndex(index);
     this.RuleSet = ruleSet;
 }
示例#4
0
        public void ParseLine_NotMatched_Variable_Should_Skip()
        {
            string     line            = "1\tVariable1\tValue1";
            ConfigRule rule            = configRuleFactory.CreateConfigRule("var1", "maxvalue", "maxvalue");
            int        expectedColumns = 3;

            TotalTempReader.ParseReturnCodes actual = _reader.ParseLine(line, rule, expectedColumns, 1);
            Assert.AreEqual(TotalTempReader.ParseReturnCodes.Skipped, actual);
        }
示例#5
0
        public void ParseLine_ExpectedColumns_Not_Match_Actual_Fails()
        {
            string     line            = "column1\tcolumn2\tcolumn3";
            int        expectedColumns = 4;
            ConfigRule rule            = configRuleFactory.CreateConfigRule("var1", "maxvalue", "maxvalue");

            TotalTempReader.ParseReturnCodes actual = _reader.ParseLine(line, rule, expectedColumns, 1);
            Assert.AreEqual(TotalTempReader.ParseReturnCodes.ParseError, actual);
        }
示例#6
0
        static bool IsTrivial(ConfigRule rule)
        {
            if (rule.Segments.Count != 1)
            {
                return(false);
            }

            return(rule.Command is ConfigCommandArg);
        }
示例#7
0
        public void ParseLine_Parses_Variable_Invalid_Data_Returns_Error()
        {
            string     line            = "1\tVariable1\t5.63\t4.3b3";
            ConfigRule rule            = new ConfigRule("Variable1", "MaxValue", "MaxValue");
            int        expectedColumns = 4;

            TotalTempReader.ParseReturnCodes actual = _reader.ParseLine(line, rule, expectedColumns, 1);
            Assert.AreEqual(rule.ValuesToCompute.Count(), 0);
            Assert.AreEqual(TotalTempReader.ParseReturnCodes.ParseError, actual);
        }
示例#8
0
        public void ParseLine_Parses_Variable_Normal_Case()
        {
            string     line            = "1\tVariable1\t5.63\t4.33";
            ConfigRule rule            = configRuleFactory.CreateConfigRule("Variable1", "MaxValue", "MaxValue");
            int        expectedColumns = 4;

            TotalTempReader.ParseReturnCodes actual = _reader.ParseLine(line, rule, expectedColumns, 1);
            Assert.AreEqual(rule.ValuesToCompute[0], 5.63d);
            Assert.AreEqual(TotalTempReader.ParseReturnCodes.Processed, actual);
        }
示例#9
0
        public void ConfigReader_ParseLine_LessThan3_TabDelimited_Should_Return_Null()
        {
            string     testline = "";
            ConfigRule expected = _testConfigReader.ParseLine(testline);

            Assert.IsNull(expected);

            testline = "abab";
            expected = _testConfigReader.ParseLine(testline);
            Assert.IsNull(expected);

            testline = "test1\ttest2";
            expected = _testConfigReader.ParseLine(testline);
            Assert.IsNull(expected);
        }
示例#10
0
        /// <summary>
        /// Load the configuration from the given configSection. This replaces any
        /// existing configuration.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <param name="inputName">Used for log messages, etc.</param>
        public void load(BoostInfoTree configSection, String inputName)
        {
            if (isConfigured_)
            {
                // Reset the previous configuration.
                shouldBypass_ = false;
                ILOG.J2CsMapping.Collections.Collections.Clear(dataRules_);
                ILOG.J2CsMapping.Collections.Collections.Clear(interestRules_);

                validator_.resetAnchors();
                validator_.resetVerifiedCertificates();
            }
            isConfigured_ = true;

            ArrayList <BoostInfoTree> validatorList = configSection.get("validator");

            if (validatorList.Count != 1)
            {
                throw new ValidatorConfigError(
                          "ValidationPolicyConfig: Expected one validator section");
            }
            BoostInfoTree validatorSection = validatorList[0];

            // Get the rules.
            ArrayList <BoostInfoTree> ruleList = validatorSection.get("rule");

            for (int i = 0; i < ruleList.Count; ++i)
            {
                ConfigRule rule = net.named_data.jndn.security.v2.validator_config.ConfigRule.create(ruleList[i]);
                if (rule.getIsForInterest())
                {
                    ILOG.J2CsMapping.Collections.Collections.Add(interestRules_, rule);
                }
                else
                {
                    ILOG.J2CsMapping.Collections.Collections.Add(dataRules_, rule);
                }
            }

            // Get the trust anchors.
            ArrayList <BoostInfoTree> trustAnchorList = validatorSection
                                                        .get("trust-anchor");

            for (int i_0 = 0; i_0 < trustAnchorList.Count; ++i_0)
            {
                processConfigTrustAnchor(trustAnchorList[i_0], inputName);
            }
        }
示例#11
0
        public override void checkPolicy(Interest interest, ValidationState state,
                                         ValidationPolicy.ValidationContinuation continueValidation)
        {
            if (hasInnerPolicy())
            {
                throw new ValidatorConfigError(
                          "ValidationPolicyConfig must be a terminal inner policy");
            }

            if (shouldBypass_)
            {
                continueValidation.continueValidation(null, state);
                return;
            }

            Name keyLocatorName = net.named_data.jndn.security.v2.ValidationPolicy.getKeyLocatorName(interest, state);

            if (state.isOutcomeFailed())
            {
                // Already called state.fail() .
                return;
            }

            for (int i = 0; i < interestRules_.Count; ++i)
            {
                ConfigRule rule = interestRules_[i];

                if (rule.match(true, interest.getName()))
                {
                    if (rule.check(true, interest.getName(), keyLocatorName, state))
                    {
                        continueValidation
                        .continueValidation(new CertificateRequest(
                                                new Interest(keyLocatorName)), state);
                        return;
                    }
                    else
                    {
                        // rule.check failed and already called state.fail() .
                        return;
                    }
                }
            }

            state.fail(new ValidationError(net.named_data.jndn.security.v2.ValidationError.POLICY_ERROR,
                                           "No rule matched for interest `" + interest.getName().toUri()
                                           + "`"));
        }
        public ActionResult NewGroup(Group group, HttpPostedFileBase FileUpload)
        {
            string idUser = User.Identity.GetUserId();

            if (string.IsNullOrEmpty(group.Name))
            {
                SetFlash(FlashType.error, "Group Name is required");
                return(View());
            }
            ConfigRule fileSizeRule   = db.ConfigRules.Find("filesize");
            bool       isFileOverSize = fileService.checkFileOverSize(FileUpload);

            if (isFileOverSize)
            {
                SetFlash(FlashType.error, string.Format("This file is too big ({0} {1} maximum)", fileSizeRule.Value, fileSizeRule.Unit));
                return(View());
            }
            //create new group
            groupService.createGroup(idUser, group);

            //create directory
            string directoryPath = String.Format("Upload/{0}/run", group.Id);

            fileService.createDirectory(directoryPath);
            //save file
            //string savePath = Server.MapPath(String.Format("~/App_Data/{0}", group.Id));
            string filePath = String.Format("Upload/{0}", group.Id);

            fileService.saveFile(group.Id, FileUpload, filePath, Direction.Group);


            //create new participate
            Participate part = new Participate();

            participateService.createParticipate(idUser, group.Id, part, true);

            //set flash
            SetFlash(FlashType.success, "Created Group Successfully");
            return(RedirectToAction("index"));
        }
示例#13
0
        public bool checkFileOverSize(HttpPostedFileBase file)
        {
            ConfigRule fileSizeRule = db.ConfigRules.Find("filesize");

            if (fileSizeRule != null && file != null)
            {
                //get file size
                int fileSize = file.ContentLength;

                //convert to byte
                int    value = fileSizeRule.Value;
                string unit  = fileSizeRule.Unit.ToLower();
                int    pow;
                switch (unit)
                {
                case "kb":
                    pow = 1;
                    break;

                case "mb":
                    pow = 2;
                    break;

                case "gb":
                    pow = 3;
                    break;

                default:
                    pow = 0;
                    break;
                }
                double toByte = value * Math.Pow(1024, pow);
                return(fileSize > toByte ? true : false);
            }
            return(false);
        }
示例#14
0
        public JsonResult uploadFile(int groupid, int?processid, int?stepid, int?taskid, HttpPostedFileBase FileUpload, Direction direction)
        {
            HttpStatusCode status = HttpStatusCode.OK;
            string         message;
            object         response;

            if (FileUpload.ContentLength == 0)
            {
                status   = HttpStatusCode.NoContent;
                message  = "Your File is empty";
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            ConfigRule fileSizeRule   = db.ConfigRules.Find("filesize");
            bool       isFileOverSize = fileService.checkFileOverSize(FileUpload);

            if (isFileOverSize)
            {
                status   = HttpStatusCode.InternalServerError;
                message  = string.Format("This file is too big ({0} {1} maximum)", fileSizeRule.Value, fileSizeRule.Unit);
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            string filePath;

            if (direction == Direction.Process)
            {
                Process pr = processService.findProcess(processid.GetValueOrDefault());
                if (pr == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Process not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}/{1}", pr.IdGroup, pr.Id);
            }
            else if (direction == Direction.Step)
            {
                Step st = stepService.findStep(stepid.GetValueOrDefault());
                if (st == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Step not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}/{1}/{2}", st.Process.Group.Id, st.Process.Id, st.Id);
            }
            else if (direction == Direction.Task)
            {
                TaskProcess tp = taskService.findTask(taskid.GetValueOrDefault());
                if (tp == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Task not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}/{1}/{2}/{3}", tp.Step.Process.Group.Id, tp.Step.Process.Id, tp.Step.Id, tp.Id);
            }
            else
            {
                Group gr = groupService.findGroup(groupid);
                if (gr == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Group not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}", gr.Id);
            }
            FileManager f    = fileService.saveFile(groupid, FileUpload, filePath, direction);
            object      data = new
            {
                id   = f.Id,
                name = f.Name
            };

            message  = "Save File Sucessfull";
            response = new { message = message, data = data, status = status };
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
示例#15
0
        public EditableRuleView()
        {
            Debug.Assert(System.Threading.Thread.CurrentThread.ManagedThreadId == 1);

            _rule = new ConfigRule();
        }