Ejemplo n.º 1
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string demStr = cmbDem.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(demStr))
            {
                MessageBox.Show("Dem must be specified before executing");
                return;
            }
            string unitsStr = cmbUnits.Text;

            if (unitsStr == "")
            {
                MessageBox.Show("Speed Units must be specified before executing");
                return;
            }
            string roadsStr = cmbRoad.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(roadsStr) && !frmHlp.FeatureDictionary.ContainsKey(roadsStr))
            {
                MessageBox.Show("Roads Layer or Accumulation Raster must be specified before executing");
                return;
            }
            string facilityStr = cmbFacility.Text;
            string speedFldStr = cmbSpeed.Text;

            if (chbHours.Checked)
            {
                if (!frmHlp.FeatureDictionary.ContainsKey(facilityStr))
                {
                    MessageBox.Show("Facility Layer must be specified before executing");
                    return;
                }

                if (speedFldStr == "")
                {
                    MessageBox.Show("Speed Fld must be specified before executing");
                    return;
                }
            }
            string onRateStr = cmbOnRate.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(onRateStr) && !rsUtil.isNumeric(onRateStr))
            {
                MessageBox.Show("On Road Machine Rate must be specified before executing");
                return;
            }
            float  onPay       = System.Convert.ToSingle(nudOnPayload.Value);
            string offSpeedStr = cmbOffRoadSpeed.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(offSpeedStr) && !rsUtil.isNumeric(offSpeedStr))
            {
                MessageBox.Show("Off Road Speed or Off Road hours Raster must be specified before executing");
                return;
            }
            string offRateStr = cmbOffRate.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(offRateStr) && !rsUtil.isNumeric(offRateStr))
            {
                MessageBox.Show("Off Road Machine Rate must be specified before executing");
                return;
            }
            string offBarriersStr = cmbBarrier.Text;
            float  offPay         = System.Convert.ToSingle(nudOffPayload.Value);
            string opsStr         = cmbOps.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(opsStr) && !rsUtil.isNumeric(opsStr))
            {
                MessageBox.Show("Operation Rate must be specified before executing");
                return;
            }
            string otherStr = cmbOther.Text;

            if (!frmHlp.FunctionRasterDictionary.ContainsKey(otherStr) && !rsUtil.isNumeric(otherStr))
            {
                MessageBox.Show("Other rate must be specified before executing");
                return;
            }
            string     wksStr = txtOutWks.Text;
            IWorkspace wks    = geoUtil.OpenWorkSpace(wksStr);

            if (wks == null)
            {
                MessageBox.Show("A valid file geodatabase must be specified before executing");
                return;
            }
            RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog();
            rp.addMessage("Calculating delivered cost surface...\nThis may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            DateTime dt = DateTime.Now;

            this.Visible = false;
            try
            {
                IFunctionRasterDataset  Dem   = frmHlp.FunctionRasterDictionary[demStr];
                TransRouting.SpeedUnits units = (TransRouting.SpeedUnits)Enum.Parse(typeof(TransRouting.SpeedUnits), unitsStr);
                TransRouting            tr    = new TransRouting(wks, Dem, units);
                if (rsUtil.isNumeric(onRateStr))
                {
                    tr.OnRoadMachineRate = System.Convert.ToSingle(onRateStr);
                }
                else
                {
                    tr.OnRoadMachineRateRaster = frmHlp.FunctionRasterDictionary[onRateStr];
                }
                tr.OnRoadPayLoad = onPay;
                if (rsUtil.isNumeric(offRateStr))
                {
                    tr.OffRoadMachineRate = System.Convert.ToSingle(offRateStr);
                }
                else
                {
                    tr.OffRoadMachineRateRaster = frmHlp.FunctionRasterDictionary[offRateStr];
                }
                tr.OffRoadPayLoad = offPay;
                if (rsUtil.isNumeric(opsStr))
                {
                    tr.OperationsCost = System.Convert.ToSingle(opsStr);
                }
                else
                {
                    tr.OperationsCostRaster = frmHlp.FunctionRasterDictionary[opsStr];
                }
                if (rsUtil.isNumeric(otherStr))
                {
                    tr.OtherCost = System.Convert.ToSingle(otherStr);
                }
                else
                {
                    tr.OtherCostRaster = frmHlp.FunctionRasterDictionary[otherStr];
                }
                if (chbHours.Checked)
                {
                    if (frmHlp.FeatureDictionary.ContainsKey(roadsStr))
                    {
                        tr.RoadFeatureClass = frmHlp.FeatureDictionary[roadsStr];
                    }
                    else
                    {
                        tr.RoadRaster = frmHlp.FunctionRasterDictionary[roadsStr];
                    }
                    tr.FacilityFeatureClass = frmHlp.FeatureDictionary[facilityStr];
                    tr.RoadsSpeedField      = speedFldStr;
                    if (rsUtil.isNumeric(offSpeedStr))
                    {
                        tr.OffRoadSpeed = System.Convert.ToSingle(offSpeedStr);
                    }
                    else
                    {
                        tr.OffRoadSpeedRaster = frmHlp.FunctionRasterDictionary[offSpeedStr];
                    }
                    if (frmHlp.FeatureDictionary.ContainsKey(offBarriersStr))
                    {
                        tr.BarriersFeatureClass = frmHlp.FeatureDictionary[offBarriersStr];
                    }
                    else if (frmHlp.FunctionRasterDictionary.ContainsKey(offBarriersStr))
                    {
                        tr.BarrierRaster = frmHlp.FunctionRasterDictionary[offBarriersStr];
                    }
                }
                else
                {
                    tr.FunctionAccumulatedPathAllocation   = frmHlp.FunctionRasterDictionary[roadsStr];
                    tr.FunctionAccumulatedFromPathDistance = frmHlp.FunctionRasterDictionary[offSpeedStr];
                }
                IFunctionRasterDataset DollarsPerTon = tr.OutDollarsTonsRaster;
                //IFunctionRasterDataset outraster = rsUtil.createRaster(DollarsPerTon);
                if (frmHlp.TheMap != null)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromDataset((IRasterDataset)DollarsPerTon);
                    rstLyr.Name    = "DollarsPerTon";
                    rstLyr.Visible = false;
                    frmHlp.TheMap.AddLayer(rstLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished creating delivered cost surfaces" + t);
                rp.enableClose();
                this.Close();
            }
        }
Ejemplo n.º 2
0
        public Guid StartWorkflowInfo(StartInfo_DTO startInfo, ref string errorInfos)
        {
            try
            {
                HashSet <Guid> newActivities = new HashSet <Guid>();

                NSTaskInfo nsTaskInfo = new NSTaskInfo();
                nsTaskInfo.Id         = Guid.NewGuid();
                nsTaskInfo.TaskName   = startInfo.TaskName;
                nsTaskInfo.TaskType   = startInfo.TaskType;
                nsTaskInfo.RunState   = RunStateConst.RUNNING;
                nsTaskInfo.CreateTime = DateTime.Now;

                NSInstanceInfo nsIntanceInfo = new NSInstanceInfo();
                nsIntanceInfo.Id           = Guid.NewGuid();
                nsIntanceInfo.TaskId       = nsTaskInfo.Id;
                nsIntanceInfo.StartTime    = DateTime.Now;
                nsIntanceInfo.TemplateId   = startInfo.TemplateId;
                nsIntanceInfo.TemplateName = startInfo.TemplateName;
                nsIntanceInfo.RunState     = RunStateConst.RUNNING;

                // StartWorkflow
                TemplateRepository t            = new TemplateRepository(Context);
                NSTemplateInfo     templateInfo = t.Get(startInfo.TemplateId);
                if (templateInfo == null)
                {
                    errorInfos = "模板不能为空!";
                    return(Guid.Empty);
                }

                string   templateXML = templateInfo.TemplateText;
                XElement doc         = XElement.Parse(templateInfo.TemplateText);
                var      nodeInfos   = from c in doc.Elements("DesignerItems").Elements("DesignerItem")
                                       where c.Element("BType").Value == "Start"
                                       select c;
                // start node
                var startNode = nodeInfos.First();
                // start node id
                string id = startNode.Element("ID").Value;
                // start node next nodes
                var custs = from c in doc.Elements("Connections").First().Elements("Connection")
                            where c.Element("SourceID").Value == id
                            select c.Element("SinkID").Value;

                // get all nodes startnode link
                foreach (var item in custs)
                {
                    // get nodeinfo
                    var nodeInfo = from c in doc.Elements("DesignerItems").Elements("DesignerItem")
                                   where c.Element("ID").Value == item
                                   select c;

                    //  create node info if need
                    if (TransRouting.CreateNodeInfo(nodeInfo.First()))
                    {
                        NSNodeInfo nsNodeInfo = new NSNodeInfo();
                        nsNodeInfo.Id         = Guid.NewGuid();
                        nsNodeInfo.InstanceId = nsIntanceInfo.Id;
                        nsNodeInfo.TaskId     = nsTaskInfo.Id;
                        nsNodeInfo.NodeId     = Guid.Parse(item.ToString());
                        nsNodeInfo.NodeName   = nodeInfo.First().Element("Name").Value;
                        nsNodeInfo.NodeId     = Guid.Parse(nodeInfo.First().Element("ID").Value);
                        nsNodeInfo.RunState   = RunStateConst.RUNNING;
                        nsNodeInfo.CreateTime = DateTime.Now;
                        Context.NSNodeInfos.Add(nsNodeInfo);
                    }
                    else
                    {
                        // only prepare taskid and instanceid
                        NSNodeInfo nsNodeInfo = new NSNodeInfo();
                        nsNodeInfo.Id         = Guid.NewGuid();
                        nsNodeInfo.InstanceId = nsIntanceInfo.Id;
                        nsNodeInfo.TaskId     = nsTaskInfo.Id;
                        // running routting
                        TransRouting.Routing(doc, nodeInfo.First(), nsNodeInfo, Context, newActivities);
                    }
                }

                Context.NsInstanceInfos.Add(nsIntanceInfo);
                Context.NsTaskInfos.Add(nsTaskInfo);
                Context.SaveChanges();

                errorInfos = string.Empty;
                return(nsTaskInfo.Id);
            }
            catch (Exception e)
            {
                errorInfos = e.ToString();
                return(Guid.Empty);
            }

            return(Guid.Empty);
        }