Beispiel #1
0
            byte[] DDMWriteCallback.getRecordData(DDMCallbackEvent ddmce, int i)
            {
                String data = _reader.ReadLine();

                byte[] returnData = ddmce.getFile().getRecordDataBuffer();

                for (int idx = 0; idx < _format.getFieldCount(); idx++)
                {
                    DDMField fld = _format.getField(idx);

                    // SRCSEQ/SRCDAT have to be handled differently
                    if ("SRCSEQ".Equals(fld.getName(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        fld.setString(String.Format("{0}", _sequence), returnData);
                        _sequence += 1;
                    }
                    else if ("SRCDAT".Equals(fld.getName(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        fld.setString(String.Format("{0}", 0), returnData);
                    }
                    //if ("SRCDTA".Equals(fld.getName(), StringComparison.InvariantCultureIgnoreCase))
                    else
                    {
                        fld.setString(data, returnData);
                    }
                }
                return(returnData);
            }
        public override void newRecord(int recordNumber, byte[] recordData, bool[] nullFieldMap)
        {
            StringBuilder sb = new StringBuilder();

            if (_format == null || _writer == null)
            {
                return;
            }
            //
            // Get in field order if specified.

            if (_fieldsLookup != null && _fieldsLookup.Count() > 0)
            {
                for (int fldidx = 0; fldidx < _fields.Length; fldidx++)
                {
                    for (int idx = 0; idx < _format.getFieldCount(); idx++)
                    {
                        DDMField fld = _format.getField(idx);
                        if (fld.getName().Equals(_fields[fldidx],
                                                 StringComparison.InvariantCultureIgnoreCase))
                        {
                            switch (fld.getType())
                            {
                            case DDMField.TYPE_CHARACTER:
                            case DDMField.TYPE_DBCS_OPEN:
                            case DDMField.TYPE_DBCS_EITHER:
                            case DDMField.TYPE_DBCS_GRAPHIC:
                            case DDMField.TYPE_DBCS_ONLY:
                                sb.Append(fld.getString(recordData).PadRight(fld.getLength()));
                                break;

                            default:
                                //
                                // Numeric, leading zero padded.
                                sb.Append(fld.getString(recordData).PadLeft(fld.getNumberOfDigits(), '0'));
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                //
                // Just process fields in order in file.

                for (int idx = 0; idx < _format.getFieldCount(); idx++)
                {
                    DDMField fld = _format.getField(idx);
                    //
                    // Process fields if no fields specified or
                    // field name is in list passed.
                    //if (_fieldsLookup == null || _fieldsLookup.Count() == 0 ||
                    //       _fieldsLookup.ContainsKey(fld.getName()))
                    {
                        switch (fld.getType())
                        {
                        case DDMField.TYPE_CHARACTER:
                        case DDMField.TYPE_DBCS_OPEN:
                        case DDMField.TYPE_DBCS_EITHER:
                        case DDMField.TYPE_DBCS_GRAPHIC:
                        case DDMField.TYPE_DBCS_ONLY:
                            sb.Append(fld.getString(recordData).PadRight(fld.getLength()));
                            break;

                        default:
                            //
                            // Numeric, leading zero padded.
                            sb.Append(fld.getString(recordData).PadLeft(fld.getNumberOfDigits(), '0'));
                            break;
                        }
                    }
                }
            }
            _writer.WriteLine(sb.ToString());
        }
Beispiel #3
0
        //Returns true if successful
        public static bool UploadFile(string Local, string Remote)
        {
            if (ClientDDM != null && !ClientDDM.isClosed())
            {
                string[] parts      = Remote.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string   remotelib  = parts[1].Replace(".lib", "");
                string   remotefile = parts[2].Replace(".file", "");
                string   remotembr  = parts[3].Replace(".mbr", "");

                try
                {
                    DDMRecordFormat remotefmt = ClientDDM.getRecordFormat(remotelib, remotefile);
                    if (remotefmt != null)
                    {
                        // At this stage - file does exist, we have to clear member first
                        // Cross fingers we finish this out!
                        if (!RemoteCommand("CLRPFM FILE(" + remotelib + "/" + remotefile + ") MBR(" + remotembr + ")"))
                        {
                            return(false);
                        }

                        DDMFile remote = ClientDDM.open(remotelib, remotefile, remotembr, remotefmt.getName(),
                                                        DDMFile.WRITE_ONLY, false, 1, 1);
                        if (remote != null)
                        {
                            // Open local file and pass to Writer
                            StreamReader sr       = new StreamReader(Local, Encoding.ASCII);
                            int          sequence = 1;
                            //MyDDMWriteCallback writer = new MyDDMWriteCallback(sr, remotefmt);
                            String data = sr.ReadLine();
                            while (data != null)
                            {
                                //ClientDDM.write(remote, writer);

                                byte[] returnData = remote.getRecordDataBuffer(); // new byte[_format.getLength() + _format.getFieldCount()];

                                for (int idx = 0; idx < remotefmt.getFieldCount(); idx++)
                                {
                                    DDMField fld = remotefmt.getField(idx);

                                    // SRCSEQ/SRCDAT have to be handled differently (as not stored locally yet)
                                    if ("SRCSEQ".Equals(fld.getName(), StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        fld.setString(sequence.ToString("000000"), returnData);
                                        sequence = sequence + 1;
                                    }
                                    else if ("SRCDAT".Equals(fld.getName(), StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        int dummyDate = 0;
                                        fld.setString(dummyDate.ToString("000000"), returnData);
                                    }
                                    //if ("SRCDTA".Equals(fld.getName(), StringComparison.InvariantCultureIgnoreCase))
                                    else
                                    {
                                        fld.setString(data, returnData);
                                    }
                                }

                                bool[] nulls = new bool[remotefmt.getFieldCount()];
                                for (int idx = 0; idx < remotefmt.getFieldCount(); idx++)
                                {
                                    nulls[idx] = false;
                                }


                                ClientDDM.write(remote, returnData, 0, nulls, null);

                                data = sr.ReadLine();
                            }
                            ClientDDM.close(remote);
                            sr.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Exception in writing
                    return(false);
                }

                return(true);
            }

            else
            {
                return(false);
            }
        }