コード例 #1
0
        /// <summary>
        /// Create a new batch operation to handle results of the BulkEdit action
        /// </summary>
        public CswNbtObjClassBatchOp makeBatchOp(DataTable excelData)
        {
            BulkEditBatchData batchData = new BulkEditBatchData(string.Empty);

            batchData.excelData  = excelData;
            batchData.CurrentRow = 0;

            return(CswNbtBatchManager.makeNew(_CswNbtResources, _BatchOpName, batchData.ToString()));
        } // makeBatchOp()
コード例 #2
0
        } // getPercentDone()

        /// <summary>
        /// Run the next iteration of this batch operation
        /// </summary>
        public void runBatchOp(CswNbtObjClassBatchOp BatchNode)
        {
            if (BatchNode != null && BatchNode.OpNameValue == CswEnumNbtBatchOpName.BulkEdit)
            {
                try
                {
                    bool NoErrors = true;
                    BatchNode.start();

                    BulkEditBatchData BatchData = new BulkEditBatchData(BatchNode.BatchData.Text);

                    if (BatchData.CurrentRow < BatchData.TotalRows)
                    {
                        if (null != BatchData.excelData.Columns["nodeid"])
                        {
                            int   NodesProcessedPerIteration = CswConvert.ToInt32(_CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumConfigurationVariableNames.NodesProcessedPerCycle));
                            Int32 r;
                            for (r = BatchData.CurrentRow; r < BatchData.excelData.Rows.Count && (r - BatchData.CurrentRow) < NodesProcessedPerIteration && NoErrors; r++)
                            {
                                try
                                {
                                    DataRow row = BatchData.excelData.Rows[r];

                                    CswPrimaryKey NodeId = new CswPrimaryKey();
                                    NodeId.FromString(row["nodeid"].ToString());
                                    if (CswTools.IsPrimaryKey(NodeId))
                                    {
                                        CswNbtNode Node = _CswNbtResources.Nodes[NodeId];
                                        if (null != Node)
                                        {
                                            foreach (DataColumn col in BatchData.excelData.Columns)
                                            {
                                                if (NoErrors)
                                                {
                                                    try
                                                    {
                                                        if (col.ColumnName != "nodeid")
                                                        {
                                                            CswNbtMetaDataNodeTypeProp Prop = Node.getNodeType().getNodeTypeProp(col.ColumnName);
                                                            CswNbtSubField             SubField;
                                                            if (null != Prop)
                                                            {
                                                                SubField = Prop.getFieldTypeRule().SubFields.Default;
                                                            }
                                                            else
                                                            {
                                                                string propName     = col.ColumnName.Substring(0, col.ColumnName.LastIndexOf(" "));
                                                                string subFieldName = col.ColumnName.Substring(col.ColumnName.LastIndexOf(" ") + 1);
                                                                Prop     = Node.getNodeType().getNodeTypeProp(propName);
                                                                SubField = Prop.getFieldTypeRule().SubFields[(CswEnumNbtSubFieldName)subFieldName];
                                                            }
                                                            Node.Properties[Prop].SetSubFieldValue(SubField, row[col.ColumnName]);
                                                        } // if( col.ColumnName != "nodeid" )
                                                    }     // try
                                                    catch (Exception ex)
                                                    {
                                                        BatchNode.error(ex, "Error on row: " + (r + 1).ToString() + ", column: " + col.ColumnName + "; ");
                                                        NoErrors = false;
                                                    }
                                                }
                                            } // foreach( DataColumn col in BatchData.excelData.Columns )
                                        }     // if( null != Node )
                                        Node.postChanges(false);
                                    }         // if( CswTools.IsPrimaryKey( NodeId ) )
                                }             // try
                                catch (Exception ex)
                                {
                                    BatchNode.error(ex, "Error on row: " + (r + 1).ToString() + "; ");
                                    NoErrors = false;
                                }
                            } // for

                            if (NoErrors)
                            {
                                // Setup for next iteration
                                BatchData.CurrentRow        = r;
                                BatchNode.BatchData.Text    = BatchData.ToString();
                                BatchNode.PercentDone.Value = getPercentDone(BatchNode);
                            }
                        } // if( null != BatchData.excelData.Columns["nodeid"] )
                    }     // if(BatchData.CurrentRow < BatchData.TotalRows)
                    else
                    {
                        BatchNode.finish();
                    }
                    BatchNode.postChanges(false);
                }
                catch (Exception ex)
                {
                    BatchNode.error(ex);
                }
            } // if( BatchNode != null && BatchNode.OpNameValue == NbtBatchOpName.MultiEdit )
        }     // runBatchOp()