Beispiel #1
0
        public void ValidateRelations()
        {
            // Our ordered dictionary class contains both a
            // dictionary and list of the same objects.
            // When copied do both sides match?

            DataModel dm = new DataModel("root");

            dm.Add(new Block("block1"));
            dm.Add(new Block("block2"));
            ((DataElementContainer)dm[0]).Add(new Block("block1_1"));
            ((DataElementContainer)dm[0]).Add(new Block("block1_2"));
            ((DataElementContainer)dm[1]).Add(new Block("block2_1"));
            ((DataElementContainer)dm[1]).Add(new Block("block2_2"));

            ((DataElementContainer)((DataElementContainer)dm[0])[0]).Add(new Dom.String("string1_1_1"));
            ((DataElementContainer)((DataElementContainer)dm[0])[0]).Add(new Dom.String("string1_1_2"));
            ((DataElementContainer)((DataElementContainer)dm[0])[1]).Add(new Dom.String("string1_2_1"));
            ((DataElementContainer)((DataElementContainer)dm[0])[1]).Add(new Dom.String("string1_2_2"));

            ((DataElementContainer)((DataElementContainer)dm[1])[0]).Add(new Dom.String("string2_1_1"));
            ((DataElementContainer)((DataElementContainer)dm[1])[0]).Add(new Dom.String("string2_1_2"));
            ((DataElementContainer)((DataElementContainer)dm[1])[1]).Add(new Dom.String("string2_2_1"));
            ((DataElementContainer)((DataElementContainer)dm[1])[1]).Add(new Dom.String("string2_2_2"));

            ((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations.Add(new SizeRelation());

            ((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations[0].OfName   = "string1_1_2";
            ((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations[0].FromName = "string1_1_1";

            var dmCopy = dm.Clone() as DataModel;

            ValidateListVsDictionary(dmCopy, null);
        }
        public void NewCopier()
        {
            DataModel dm = new DataModel("root");

            dm.Add(new Block("block1"));
            dm.Add(new Block("block2"));

            var t = new Hashtable();

            t["foo"] = "bar";

            var    mi   = typeof(Hashtable).GetMethod("get_Item");
            object ret1 = mi.Invoke(t, new object[] { "foo" });

            mi = typeof(Hashtable).GetMethod("set_Item");
            mi.Invoke(t, new object[] { "foo", "qux" });

            object ret2 = t["foo"];

            Assert.AreEqual("bar", ret1);
            Assert.AreEqual("qux", ret2);

            string f = (string)t["bunk"];

            Assert.AreEqual(f, null);

            var c = ObjectCopier.Clone(new SimpleClass(), null);

            Assert.NotNull(c);

            var ret = ObjectCopier.Clone(dm, null);

            Assert.NotNull(ret);
        }
Beispiel #3
0
        /// <summary>
        /// 修改图片,根据config的参数值确定对应的配置文件
        /// </summary>
        /// <param name="fileData"></param>
        /// <returns></returns>
        public string UpdateImage()
        {
            var userModel = AllServices.UserService.GetUserBySession();

            int    intDpiID = Request["dpi"].ToInt32();
            string strkey   = Request["key"].ToStr();
            string strTag   = Request["tag"].ToStr();
            string strSize  = Request["size"].ToStr();
            string strSysID = Request["sysID"].ToStr();
            int    intUID   = Request["uid"].ToInt32();

            if (strkey != this.strKEY)
            {
                return(new CommonResult("上传文件失败,key值对应不上").ToJson());
            }
            string    strConfig = Request["config"].ToStr("ImageUploadBaseConfig");
            DataModel dataModel = new DataModel();

            dataModel.Add("UID", intUID);
            dataModel.Add("DpiID", intDpiID);
            dataModel.Add("Size", strSize);
            CommonResult commonResult = new CommonResult();

            HttpPostedFileBase postFile = Request.Files[0];
            var configInstance          = ConfigHelper.GetConfig <Foundation.SiteConfig.Models.ImageUploadBaseConfig>(strConfig);

            commonResult = AllServices.ImageUploadService.ImageHandler(postFile, configInstance, userModel.UserName, dataModel, ActionType.Modify);        //修改文件

            if (commonResult.code < 1)
            {
                return(commonResult.ToJson());
            }
            if (string.IsNullOrEmpty(strSysID))
            {
                return(new CommonResult("请选择所属系统").ToJson());
            }
            int[]        intSysIDs     = ArrayHelper.ToIntArray(strSysID);
            CommonResult commonResult1 = AddDocumentFolder(intSysIDs, (int)commonResult.data);
            CommonResult commonResult2 = UpdateTag(strTag, intUID);

            if (commonResult1.code < 1)
            {
                commonResult = new CommonResult("文件修改成功,标签修改失败");
            }
            else if (commonResult2.code < 1)
            {
                commonResult = new CommonResult("文件修改成功,所属系统修改失败");
            }
            else if (commonResult1.code < 1 && commonResult2.code < 1)
            {
                commonResult = new CommonResult("文件修改成功,标签修改失败,所属修改失败");
            }
            return(commonResult.ToJson());           //上传成功返回图片信息
            //var res = AllServices.ImageUploadService.ImageHandler(fileData, AllConfigServices.NewsImageUploadConfig);
        }
Beispiel #4
0
        public void ValidateRelations2()
        {
            // Our ordered dictionary class contains both a
            // dictionary and list of the same objects.
            // When copied do both sides match?

            DataModel dm = new DataModel("root");

            dm.Add(new Block("block1"));
            dm.Add(new Block("block2"));
            ((DataElementContainer)dm[0]).Add(new Block("block1_1"));
            ((DataElementContainer)dm[0]).Add(new Block("block1_2"));
            ((DataElementContainer)dm[1]).Add(new Block("block2_1"));
            ((DataElementContainer)dm[1]).Add(new Block("block2_2"));

            ((DataElementContainer)((DataElementContainer)dm[0])[0]).Add(new Dom.String("string1_1_1"));
            ((DataElementContainer)((DataElementContainer)dm[0])[0]).Add(new Dom.String("string1_1_2"));
            ((DataElementContainer)((DataElementContainer)dm[0])[1]).Add(new Dom.String("string1_2_1"));
            ((DataElementContainer)((DataElementContainer)dm[0])[1]).Add(new Dom.String("string1_2_2"));

            ((DataElementContainer)((DataElementContainer)dm[1])[0]).Add(new Dom.String("string2_1_1"));
            ((DataElementContainer)((DataElementContainer)dm[1])[0]).Add(new Dom.String("string2_1_2"));
            ((DataElementContainer)((DataElementContainer)dm[1])[1]).Add(new Dom.String("string2_2_1"));
            ((DataElementContainer)((DataElementContainer)dm[1])[1]).Add(new Dom.String("string2_2_2"));

            ((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations.Add(new SizeRelation());

            ((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations[0].OfName   = "string2_1_2";
            ((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations[0].FromName = "string1_1_1";

            ((DataElementContainer)((DataElementContainer)dm[1])[0])[1].relations.Add(((DataElementContainer)((DataElementContainer)dm[0])[0])[0].relations[0], false);

            dm.find("string1_1_1").DefaultValue = new Variant("10");
            dm.find("string2_1_2").DefaultValue = new Variant("1234567890");

            // Generate the value
            var value = dm.Value;

            Assert.NotNull(value);

            var dmCopy = dm.Clone() as DataModel;

            for (int count = 0; count < 10; count++)
            {
                dmCopy = dmCopy.Clone() as DataModel;
            }

            ValidateListVsDictionary(dmCopy, null);
        }
Beispiel #5
0
        public ActionResult ModifyTasks()
        {
            int intUID = Request["UID"].ToInt32();

            //分页获取数据
            Task task = AllServices.TaskService.GetByID(intUID);

            if (task != null)
            {
                List <TaskList> listTaskList = AllServices.TaskListService.GetByTaskUID(task.UID);
                DataModel       dataModel    = new DataModel();
                dataModel.Add("Task", task);
                dataModel.Add("ListTaskList", listTaskList);
                ViewBag.CommonResult = CommonResult.Instance(1, null, dataModel).ToJson();
            }
            else
            {
                ViewBag.CommonResult = CommonResult.Instance().ToJson();
            }
            return(View("ModifyTasks"));
        }
Beispiel #6
0
        public ActionResult UploadDetial()
        {
            int      intUID   = Request["UID"].ToInt32();
            Document document = AllServices.DocumentService.GetByUID(intUID);

            if (document != null)
            {
                DocumentTag           documentTag        = AllServices.DocumentTagService.GetByDocumentUID(document.UID);
                List <DocumentFolder> listDocumentFolder = AllServices.DocumentFolderService.GetByDocumentUID(document.UID);

                DataModel dataModel = new DataModel();
                dataModel.Add("Document", document);
                dataModel.Add("DocumentTag", documentTag);
                dataModel.Add("ListDocumentFolder", listDocumentFolder);
                ViewBag.CommonResult = CommonResult.Instance(1, null, dataModel).ToJson();
            }
            else
            {
                ViewBag.CommonResult = CommonResult.Instance().ToJson();
            }
            return(View("UploadDetial"));
        }
Beispiel #7
0
        public void Find()
        {
            DataModel dm = new DataModel("root");

            dm.Add(new Block("block1"));
            dm.Add(new Block("block2"));
            ((DataElementContainer)dm[0]).Add(new Block("block1_1"));
            ((DataElementContainer)dm[0]).Add(new Block("block1_2"));
            ((DataElementContainer)dm[1]).Add(new Block("block2_1"));
            ((DataElementContainer)dm[1]).Add(new Block("block2_2"));

            ((DataElementContainer)((DataElementContainer)dm[0])[0]).Add(new Dom.String("string1_1_1"));
            ((DataElementContainer)((DataElementContainer)dm[0])[0]).Add(new Dom.String("string1_1_2"));
            ((DataElementContainer)((DataElementContainer)dm[0])[1]).Add(new Dom.String("string1_2_1"));
            ((DataElementContainer)((DataElementContainer)dm[0])[1]).Add(new Dom.String("string1_2_2"));

            ((DataElementContainer)((DataElementContainer)dm[1])[0]).Add(new Dom.String("string2_1_1"));
            ((DataElementContainer)((DataElementContainer)dm[1])[0]).Add(new Dom.String("string2_1_2"));
            ((DataElementContainer)((DataElementContainer)dm[1])[1]).Add(new Dom.String("string2_2_1"));
            ((DataElementContainer)((DataElementContainer)dm[1])[1]).Add(new Dom.String("string2_2_2"));

            Assert.NotNull(dm.find("string1_1_1"));
            Assert.NotNull(dm.find("string1_1_1").find("string2_1_2"));
        }
Beispiel #8
0
        public void CollectAllElements()
        {
            var e = new Blob("element");
            var c = new Block("block");
            var m = new DataModel("model");

            c.Add(e);
            m.Add(c);

            var items = new List <DataElement>();

            new TestStrategy().TestRecurseAllElements(m, items);

            Assert.AreEqual(3, items.Count);
            Assert.AreEqual(m, items[0]);
            Assert.AreEqual(c, items[1]);
            Assert.AreEqual(e, items[2]);
        }
Beispiel #9
0
        private void buttonStartFuzzing_Click(object sender, EventArgs e)
        {
            try
            {
                tabControl.SelectedTab          = tabPageOutput;
                buttonStartFuzzing.Enabled      = false;
                buttonSaveConfiguration.Enabled = false;
                buttonStopFuzzing.Enabled       = true;

                IterationCount             = 1;
                FaultCount                 = 0;
                textBoxIterationCount.Text = IterationCount.ToString();
                textBoxFaultCount.Text     = FaultCount.ToString();
                textBoxOutput.Text         = "";

                Dom       dom       = new Dom();
                DataModel dataModel = null;

                // Data Set
                Data fileData = new Data();
                if (Directory.Exists(textBoxTemplateFiles.Text))
                {
                    List <string> files = new List <string>();
                    foreach (string fileName in Directory.GetFiles(textBoxTemplateFiles.Text))
                    {
                        files.Add(fileName);
                    }

                    fileData.DataType = DataType.Files;
                    fileData.Files    = files;
                }
                else if (File.Exists(textBoxTemplateFiles.Text))
                {
                    fileData.DataType = DataType.File;
                    fileData.FileName = textBoxTemplateFiles.Text;
                }
                else
                {
                    MessageBox.Show("Error, Unable to locate file/folder called \"" + textBoxTemplateFiles.Text + "\".");
                    return;
                }

                // DataModel
                if (userSelectedDataModel != null)
                {
                    dataModel     = userSelectedDataModel.Clone("TheDataModel") as DataModel;
                    dataModel.dom = dom;

                    dom.dataModels.Add(dataModel.name, dataModel);
                }
                else
                {
                    dataModel = new DataModel("TheDataModel");
                    dataModel.Add(new Blob());
                    dom.dataModels.Add(dataModel.name, dataModel);
                }

                // Publisher
                Dictionary <string, Variant> args = new Dictionary <string, Variant>();
                args["FileName"] = new Variant(textBoxFuzzedFile.Text);
                Peach.Core.Publishers.FilePublisher file = new Peach.Core.Publishers.FilePublisher(args);

                // StateModel
                StateModel stateModel = new StateModel();
                stateModel.name = "TheStateModel";

                State state = new State();
                state.name   = "TheState";
                state.parent = stateModel;

                Peach.Core.Dom.Action actionOutput = new Peach.Core.Dom.Action();
                actionOutput.type      = ActionType.Output;
                actionOutput.dataModel = dataModel;
                actionOutput.dataSet   = new Peach.Core.Dom.DataSet();
                actionOutput.dataSet.Datas.Add(fileData);
                actionOutput.parent = state;

                Peach.Core.Dom.Action actionClose = new Peach.Core.Dom.Action();
                actionClose.type   = ActionType.Close;
                actionClose.parent = state;

                Peach.Core.Dom.Action actionCall = new Peach.Core.Dom.Action();
                actionCall.type      = ActionType.Call;
                actionCall.publisher = "Peach.Agent";
                actionCall.method    = "ScoobySnacks";
                actionCall.parent    = state;

                state.actions.Add(actionOutput);
                state.actions.Add(actionClose);
                state.actions.Add(actionCall);

                stateModel.states.Add(state.name, state);
                stateModel.initialState = state;

                dom.stateModels.Add(stateModel.name, stateModel);

                // Agent
                Peach.Core.Dom.Agent agent = new Peach.Core.Dom.Agent();
                agent.name = "TheAgent";
                agent.url  = "local://";

                Peach.Core.Dom.Monitor monitor = new Peach.Core.Dom.Monitor();

                switch (Platform.GetOS())
                {
                case Platform.OS.OSX:
                    if (radioButtonOSXCrashReporter.Checked)
                    {
                        monitor.cls = "CrashReporter";
                        agent.monitors.Add(monitor);

                        monitor     = new Peach.Core.Dom.Monitor();
                        monitor.cls = "Process";
                        monitor.parameters["StartOnCall"] = new Variant("ScoobySnacks");

                        if (this.checkBoxOSXCpuKill.Checked)
                        {
                            monitor.parameters["NoCpuKill"] = new Variant("false");
                        }
                        else
                        {
                            monitor.parameters["NoCpuKill"] = new Variant("true");
                        }

                        monitor.parameters["Executable"] = new Variant(this.textBoxOSXExecutable.Text);
                        monitor.parameters["Arguments"]  = new Variant(this.textBoxOSXArguments.Text);
                    }
                    else                             // Crash Wrangler
                    {
                        monitor.cls = "CrashWrangler";
                        monitor.parameters["StartOnCall"] = new Variant("ScoobySnacks");

                        if (this.checkBoxOSXCpuKill.Checked)
                        {
                            monitor.parameters["NoCpuKill"] = new Variant("false");
                        }
                        else
                        {
                            monitor.parameters["NoCpuKill"] = new Variant("true");
                        }

                        monitor.parameters["Command"]       = new Variant(this.textBoxOSXExecutable.Text);
                        monitor.parameters["Arguments"]     = new Variant(this.textBoxOSXArguments.Text);
                        monitor.parameters["CrashWrangler"] = new Variant(this.textBoxOSXCrashWrangler.Text);
                    }
                    break;

                case Platform.OS.Linux:                         // Linux
                    monitor.cls = "Process";
                    monitor.parameters["StartOnCall"] = new Variant("ScoobySnacks");
                    monitor.parameters["Executable"]  = new Variant(textBoxLinuxExecutable.Text);
                    monitor.parameters["Arguments"]   = new Variant(textBoxLinuxArguments.Text);
                    monitor.parameters["NoCpuKill"]   = new Variant("false");
                    break;

                case Platform.OS.Windows:
                    monitor.cls = "WindowsDebugger";
                    monitor.parameters["StartOnCall"] = new Variant("ScoobySnacks");
                    monitor.parameters["WinDbgPath"]  = new Variant(textBoxDebuggerPath.Text);

                    if (!checkBoxCpuKill.Checked)
                    {
                        monitor.parameters["NoCpuKill"] = new Variant("true");
                    }

                    if (radioButtonDebuggerStartProcess.Checked)
                    {
                        monitor.parameters["CommandLine"] = new Variant(textBoxDebuggerCommandLine.Text);
                    }
                    else if (radioButtonDebuggerAttachToProcess.Checked)
                    {
                        if (radioButtonAttachToProcessPID.Checked)
                        {
                            monitor.parameters["ProcessName"] = new Variant(textBoxAttachToProcessPID.Text);
                        }
                        else if (radioButtonAttachToProcessProcessName.Checked)
                        {
                            monitor.parameters["ProcessName"] = new Variant(textBoxAttachToProcessProcessName.Text);
                        }
                    }
                    else if (radioButtonDebuggerAttachToService.Checked)
                    {
                        monitor.parameters["Service"] = new Variant(comboBoxAttachToServiceServices.Text);
                    }
                    else if (radioButtonDebuggerKernelDebugger.Checked)
                    {
                        monitor.parameters["KernelConnectionString"] = new Variant(textBoxKernelConnectionString.Text);
                    }
                    break;
                }

                agent.monitors.Add(monitor);
                dom.agents.Add(agent.name, agent);

                // Send WM_CLOSE messages?
                if (checkBoxEnableWmClose.Checked)
                {
                    string windowNames = "";
                    if (!string.IsNullOrWhiteSpace(textBoxWindowTitle1.Text))
                    {
                        if (windowNames.Length > 0)
                        {
                            windowNames += ";";
                        }
                        windowNames += textBoxWindowTitle1.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(textBoxWindowTitle2.Text))
                    {
                        if (windowNames.Length > 0)
                        {
                            windowNames += ";";
                        }
                        windowNames += textBoxWindowTitle2.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(textBoxWindowTitle3.Text))
                    {
                        if (windowNames.Length > 0)
                        {
                            windowNames += ";";
                        }
                        windowNames += textBoxWindowTitle3.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(textBoxWindowTitle4.Text))
                    {
                        if (windowNames.Length > 0)
                        {
                            windowNames += ";";
                        }
                        windowNames += textBoxWindowTitle4.Text;
                    }

                    monitor     = new Peach.Core.Dom.Monitor();
                    monitor.cls = "PopupWatcher";
                    monitor.parameters["WindowNames"] = new Variant(windowNames);

                    agent.monitors.Add(monitor);
                }

                // Mutation Strategy
                MutationStrategy strat = new RandomStrategy(new Dictionary <string, Variant>());
                if (comboBoxFuzzingStrategy.Text.ToLower().IndexOf("Squencial") > -1)
                {
                    strat = new Sequential(new Dictionary <string, Variant>());
                }

                // Test
                Test test = new Test();
                test.name       = "Default";
                test.stateModel = stateModel;
                test.agents.Add(agent.name, agent);
                test.publishers.Add("FileWriter", file);
                test.strategy     = strat;
                stateModel.parent = test;

                dom.tests.Add(test.name, test);

                if (logger == null)
                {
                    Dictionary <string, Variant> loggerArgs = new Dictionary <string, Variant>();
                    loggerArgs["Path"] = new Variant(textBoxLogPath.Text);
                    logger             = new Peach.Core.Loggers.FileLogger(loggerArgs);
                }

                test.loggers.Add(logger);

                // START FUZZING!!!!!
                thread = new Thread(new ParameterizedThreadStart(Run));
                thread.Start(dom);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }
Beispiel #10
0
        /// <summary>
        /// 合并文件
        /// </summary>
        /// <returns></returns>
        public string MergeFiles()
        {
            var userModel = AllServices.UserService.GetUserBySession();

            string strTag      = Request["tag"].ToStr();
            string strSize     = Request["size"].ToStr();
            string strSysID    = Request["sysID"].ToStr();
            int    intDpiID    = Request["dpi"].ToInt32();
            string definedName = Request["definedName"].ToStr();
            string strGuid     = Request["md5"];
            string strExt      = Request["ext"];

            DataModel dataModel = new DataModel();

            dataModel.Add("DpiID", intDpiID);
            dataModel.Add("Size", strSize);
            dataModel.Add("Guid", strGuid);
            dataModel.Add("Ext", strExt);
            dataModel.Add("DefinedName", definedName);

            string strConfig      = Request["config"].ToStr("ImageUploadBaseConfig");
            var    configInstance = ConfigHelper.GetConfig <Foundation.SiteConfig.Models.ImageUploadBaseConfig>(strConfig);

            CommonResult commonResult = AllServices.ImageUploadService.ChunkImageHandler(configInstance, userModel.UserName, dataModel, ActionType.Add);         //合并保存文件

            if (commonResult.code < 0)
            {
                return(CommonResult.Instance(0, string.Empty, "{\"chunked\" : false}").ToJson());
            }
            CommonResult commonResult1 = new CommonResult("请选择所属系统");

            if (!string.IsNullOrEmpty(strSysID))
            {
                int[] intSysIDs = ArrayHelper.ToIntArray(strSysID);
                commonResult1 = AddDocumentFolder(intSysIDs, (int)commonResult.data);
            }
            CommonResult commonResult2 = new CommonResult("请选择标签");

            if (!string.IsNullOrWhiteSpace(strTag))
            {
                commonResult2 = AddTag(strTag, (int)commonResult.data);
            }
            CommonResult commonResult3 = new CommonResult("任务列表清单关联失败");

            if (commonResult.data.ToInt32() != 0)
            {
                commonResult3 = AddTaskList((int)commonResult.data);
            }
            if (commonResult1.code < 1)
            {
                commonResult = new CommonResult("文件上传成功,标签新增失败");
            }
            else if (commonResult2.code < 1)
            {
                commonResult = new CommonResult("文件上传成功,所属系统失败");
            }
            else if (commonResult3.code < 1)
            {
                commonResult = new CommonResult("文件上传成功,所属系统成功,任务列表清单关联失败");
            }
            else if (commonResult1.code < 1 && commonResult2.code < 1 && commonResult3.code < 1)
            {
                commonResult = new CommonResult("文件上传成功,标签新增失败,所属系统失败");
            }
            return(commonResult.ToJson());
        }
Beispiel #11
0
        readonly bool IsDeBug = false;        //Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsDeBug"].ToString());

        /// <summary>
        /// 文件分块上传
        /// </summary>
        /// <param name="fileData"></param>
        /// <returns></returns>
        public string ChunkUpload(HttpPostedFileBase file)
        {
            var userModel = AllServices.UserService.GetUserBySession();

            //if(IsDeBug)
            //{
            //	return CommonResult.Instance(0,string.Empty,"{\"chunked\" : true, \"ext\" : \"" + Path.GetExtension(file.FileName) + "\"}").ToJson();
            //}

            if (file == null)            //当用户在上传文件时突然刷新页面,可能造成这种情况
            {
                return(CommonResult.Instance(-1, "HttpPostedFileBase对象为null", "{\"chunked\" : " + Request.Form.AllKeys.Any(m => m == "chunk") + "}").ToJson());
            }
            string strConfig      = Request["config"].ToStr("ImageUploadBaseConfig");
            var    configInstance = ConfigHelper.GetConfig <Foundation.SiteConfig.Models.ImageUploadBaseConfig>(strConfig);

            string strRoot = PathHelper.GetMapPath(configInstance.SavePath);            //拿到保存图片绝对路径

            string strTag      = Request["tag"].ToStr();
            string strSize     = Request["size"].ToStr();
            string strSysID    = Request["sysID"].ToStr();
            int    intDpiID    = Request["dpi"].ToInt32();
            string definedName = Request["definedName"].ToStr();
            string strExt      = Request["ext"].ToStr();

            DataModel dataModel = new DataModel();

            dataModel.Add("DpiID", intDpiID);
            dataModel.Add("Size", strSize);
            dataModel.Add("DpiID", intDpiID);
            dataModel.Add("Size", strSize);
            dataModel.Add("Ext", strExt);
            dataModel.Add("DefinedName", definedName);

            //如果进行了分片
            if (Request.Form.AllKeys.Any(m => m == "chunk"))
            {
                //取得chunk和chunks
                int intChunk  = Convert.ToInt32(Request.Form["chunk"]);               //当前分片在上传分片中的顺序(从0开始)
                int intChunks = Convert.ToInt32(Request.Form["chunks"]);              //总分片数
                //根据GUID创建用该GUID命名的临时文件夹
                //string folder = Server.MapPath("~/Upload/" + Request["md5"] + "/");
                string strFolder = string.Format("{0}/{1}", strRoot, "chunk\\" + Request["md5"] + "\\");              //临时文件夹
                string strPath   = strFolder + intChunk;

                //建立临时传输文件夹
                if (!Directory.Exists(Path.GetDirectoryName(strFolder)))
                {
                    Directory.CreateDirectory(strFolder);
                }

                FileStream   addFile    = null;
                BinaryWriter AddWriter  = null;
                Stream       stream     = null;
                BinaryReader TempReader = null;

                try
                {
                    //addFile = new FileStream(path, FileMode.Append, FileAccess.Write);
                    addFile   = new FileStream(strPath, FileMode.Create, FileAccess.Write);
                    AddWriter = new BinaryWriter(addFile);
                    //获得上传的分片数据流
                    stream     = file.InputStream;
                    TempReader = new BinaryReader(stream);
                    //将上传的分片追加到临时文件末尾
                    AddWriter.Write(TempReader.ReadBytes((int)stream.Length));
                }
                finally
                {
                    if (addFile != null)
                    {
                        addFile.Close();
                        addFile.Dispose();
                    }
                    if (AddWriter != null)
                    {
                        AddWriter.Close();
                        AddWriter.Dispose();
                    }
                    if (stream != null)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                    if (TempReader != null)
                    {
                        TempReader.Close();
                        TempReader.Dispose();
                    }
                }

                //context.Response.Write("{\"chunked\" : true, \"hasError\" : false, \"f_ext\" : \"" + Path.GetExtension(file.FileName) + "\"}");
                //return CommonResult.ToJsonStr(0, string.Empty, "{\"chunked\" : true, \"ext\" : \"" + Path.GetExtension(file.FileName) + "\"}");
                return(CommonResult.Instance(0, string.Empty, new ChunkTemp()
                {
                    chunked = true,
                    ext = Path.GetExtension(file.FileName),
                }).ToJson());
            }
            else            //没有分片直接保存
            {
                CommonResult commonResult = AllServices.ImageUploadService.ImageHandler(Request.Files[0], configInstance, userModel.UserName, dataModel, ActionType.Add);
                //string path = string.Format("{0}/{1}",strRoot,Request["md5"] + Path.GetExtension(Request.Files[0].FileName));
                //Request.Files[0].SaveAs(path);

                if (commonResult.code < 0)
                {
                    //context.Response.Write("{\"chunked\" : false, \"hasError\" : false}");
                    return(CommonResult.Instance(0, string.Empty, "{\"chunked\" : false}").ToJson());
                }
                CommonResult commonResult1 = new CommonResult("请选择所属系统");
                if (!string.IsNullOrEmpty(strSysID))
                {
                    int[] intSysIDs = ArrayHelper.ToIntArray(strSysID);
                    commonResult1 = AddDocumentFolder(intSysIDs, (int)commonResult.data);
                }
                CommonResult commonResult2 = AddTag(strTag, (int)commonResult.data);
                CommonResult commonResult3 = AddTaskList((int)commonResult.data);
                if (commonResult1.code < 1)
                {
                    commonResult = new CommonResult("文件上传成功,标签新增失败");
                }
                else if (commonResult2.code < 1)
                {
                    commonResult = new CommonResult("文件上传成功,所属系统失败");
                }
                else if (commonResult3.code < 1)
                {
                    commonResult = new CommonResult("文件上传成功,所属系统成功,任务列表清单关联失败");
                }
                else if (commonResult1.code < 1 && commonResult2.code < 1 && commonResult3.code < 1)
                {
                    commonResult = new CommonResult("文件上传成功,标签新增失败,所属系统失败");
                }

                return(commonResult.ToJson());
            }
        }
Beispiel #12
0
        /// <summary>
        /// 修改图片信息
        /// </summary>
        /// <param name="fileData"></param>
        /// <returns></returns>
        public string UpdateImageInfo()
        {
            var userModel = AllServices.UserService.GetUserBySession();

            int       intDpiID  = Request["dpi"].ToInt32();
            string    strTag    = Request["tag"].ToStr();
            string    strSize   = Request["size"].ToStr();
            string    strSysID  = Request["sysID"].ToStr();
            string    strName   = Request["name"].ToStr();
            string    strPath   = Request["path"].ToStr();
            string    strType   = Request["type"].ToStr();
            int       intUID    = Request["uid"].ToInt32();
            string    strConfig = Request["config"].ToStr("ImageUploadBaseConfig");
            DataModel dataModel = new DataModel();

            dataModel.Add("UID", intUID);
            dataModel.Add("DpiID", intDpiID);
            dataModel.Add("Size", strSize);
            CommonResult commonResult;
            var          configInstance = ConfigHelper.GetConfig <Foundation.SiteConfig.Models.ImageUploadBaseConfig>(strConfig);

            if (!FileHelper.RenameFile(PathHelper.GetMapPath(strPath), strName + strType))
            {
                commonResult = new CommonResult("重命名失败,修改终止,请联系管理员");
                return(commonResult.ToJson());
            }
            //更新图片信息记录
            Document documentModel = new Document();

            documentModel.UID               = dataModel["UID"].ToInt();
            documentModel.DocumentName      = strName;
            documentModel.DocumentPath      = string.Format("{0}/{1}", configInstance.SavePath, strName + strType);
            documentModel.PictureSize       = dataModel["Size"].ToStr();
            documentModel.PictureResolution = dataModel["DpiID"].ToInt() == 0 ? "96dpi" : "72dpi";
            documentModel.Editor            = userModel.UserName;
            documentModel.EditTime          = DateTime.Now;
            documentModel.State             = Convert.ToInt32(ItemState.Enable);

            commonResult = AllServices.DocumentService.Update(documentModel);

            if (commonResult.code < 1)
            {
                return(commonResult.ToJson());
            }
            if (string.IsNullOrEmpty(strSysID))
            {
                return(new CommonResult("请选择所属系统").ToJson());
            }
            int[]        intSysIDs     = ArrayHelper.ToIntArray(strSysID);
            CommonResult commonResult1 = AddDocumentFolder(intSysIDs, intUID);
            CommonResult commonResult2 = UpdateTag(strTag, intUID);

            if (commonResult1.code < 1)
            {
                commonResult = new CommonResult("文件修改成功,标签修改失败");
            }
            else if (commonResult2.code < 1)
            {
                commonResult = new CommonResult("文件修改成功,所属系统修改失败");
            }
            else if (commonResult1.code < 1 && commonResult2.code < 1)
            {
                commonResult = new CommonResult("文件修改成功,标签修改失败,所属修改失败");
            }
            return(commonResult.ToJson());
        }