Beispiel #1
0
        protected override void DoTheImport()
        {
            m_numberofTagBitsadded = 0;
            CSVManagement _CSVContainer = null;

            try
            {
                _CSVContainer = CSVManagement.ReadFile(this.m_ImportTagBitsInfo.Filename);
            }
            catch (Exception ex)
            {
                AppendToLog("problem with file " + this.m_ImportTagBitsInfo.Filename + " :" + ex.Message);
                return;
            }
            //przed chwila pozbylismy sie pierwszej lini i wszystkich znakow konca lini teraz:
            string BaseTagName = "";
            string Bitnumber   = "";
            string Name        = "";

            while (_CSVContainer.ToString().Length > 0)
            {
                try
                {
                    //format: BaseTagName;Bitnumber;Name
                    //odczytujemy BaseTagName:
                    BaseTagName = _CSVContainer.GetAndMove2NextElement();
                    //odczytujemy BaseTagName:
                    Bitnumber = _CSVContainer.GetAndMove2NextElement();
                    //odczytujemy BaseTagName:
                    Name = _CSVContainer.GetAndMove2NextElement();
                    //odnajdujemy odpowiendniego taga bazowego w bazie
                    foreach (ComunicationNet.TagsRow trow in m_database.Tags)
                    {
                        if (trow.Name.Equals(BaseTagName))
                        {
                            //znalezlismy odpowiedniego base taga - dodajmy tagbita
                            ComunicationNet.TagBitRow tagbitrow = m_database.TagBit.NewTagBitRow(trow, string.Empty);
                            tagbitrow.Name      = Name;
                            tagbitrow.BitNumber = System.Convert.ToInt16(Bitnumber);
                            m_database.TagBit.AddTagBitRow(tagbitrow);
                            m_numberofTagBitsadded++;
                        }
                    }
                }
                catch (
                    Exception
#if DEBUG
                    ex
#endif
                    )
                {
                    AppendToLog("problem with: BaseTagName:" + BaseTagName + " Bitnumber:" + Bitnumber + " :"
#if DEBUG
                                + ex.Message.ToString()
#endif
                                );
                }
            }//while (sourcefile)
            AppendToLog("Number of TagBits added: " + m_numberofTagBitsadded.ToString());
        }
Beispiel #2
0
        protected override void DoTheImport()
        {
            #region IMPORT

            int           changes_number = 0;
            CSVManagement _csvContainer  = CSVManagement.ReadFile(m_ImportTagMappingsInfo.Filename);
            while (_csvContainer.ToString().Length > 0)
            {
                string _baseName        = "";
                string _destinationName = "";
                try
                {
                    _baseName        = _csvContainer.GetAndMove2NextElement();
                    _destinationName = _csvContainer.GetAndMove2NextElement();
                    bool _tagHasBeenFound = false;
                    foreach (ComunicationNet.TagsRow trow in m_database.Tags)
                    {
                        if (trow.Name.Equals(_baseName))
                        {
                            trow.Name = _destinationName;
                            changes_number++;
                            _tagHasBeenFound = true;
                            break;
                        }
                    }
                    if (!_tagHasBeenFound)
                    {
                        AppendToLog("Tag " + _baseName + " -> " + _destinationName + " is not found");
                    }
                }
                catch (
                    Exception
#if DEBUG
                    ex
#endif
                    )
                {
                    AppendToLog("problem with: base:" + _baseName + " dest:" + _destinationName + " :"
#if DEBUG
                                + ex.Message.ToString()
#endif
                                );
                }
            }

            #endregion IMPORT

            AppendToLog("Number of changed tags: " + changes_number.ToString());
        }
        private void MainImportJob(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker  _BackgroundWorker  = sender as BackgroundWorker;
            ProgressBarWindow _ProgressBarWindow = e.Argument as ProgressBarWindow;
            long  _stationID = 0;
            ulong _timeScan = 0, _timeout = 0, _timeScanFast = 0, _timOutFast = 0;
            ulong _address     = 0;
            byte  _dataType    = 0;
            int   _length      = 0;
            int   _originalLen = m_CSVContainer.ToString().Length;

            _ProgressBarWindow.SetInformation("ImportingCSV");
            while (m_CSVContainer.ToString().Length > 0 && !_BackgroundWorker.CancellationPending)
            {
                _ProgressBarWindow.SetProgressValue(_originalLen - m_CSVContainer.ToString().Length);
                try
                {
                    _stationID    = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement());
                    _timeScan     = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement());
                    _timeout      = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement());
                    _timeScanFast = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement());
                    _timOutFast   = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement());
                    _address      = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement());
                    _dataType     = Convert.ToByte(m_CSVContainer.GetAndMove2NextElement());
                    _length       = Convert.ToInt32(m_CSVContainer.GetAndMove2NextElement());
                    //odczytalismy wszystkie elememty definiuj¹ce dany blok danych
                    //znajdujemy odpowiednia stacje
                    ComunicationNet.StationRow _stationRow = null;
                    try { _stationRow = m_Database.Station.FindByStationID(_stationID); }
                    catch { throw new Exception("station " + _stationID.ToString() + "not found"); }
                    ComunicationNet.GroupsRow _GroupsRow = m_Database.Groups.NewGroupsRow();
                    _GroupsRow.Name         = "GR_" + _GroupsRow.GroupID.ToString() + "_st_" + _stationRow.Name;
                    _GroupsRow.StationID    = _stationID;
                    _GroupsRow.TimeOut      = _timeout;
                    _GroupsRow.TimeOutFast  = _timOutFast;
                    _GroupsRow.TimeScan     = _timeScan;
                    _GroupsRow.TimeScanFast = _timeScanFast;
                    m_Database.Groups.AddGroupsRow(_GroupsRow);
                    ComunicationNet.DataBlocksRow _dataBlocksRow = m_Database.DataBlocks.NewDataBlocksRow();
                    _dataBlocksRow.Name     = "db" + _GroupsRow.GroupID.ToString() + "_st_" + _stationRow.Name;
                    _dataBlocksRow.GroupID  = _GroupsRow.GroupID;
                    _dataBlocksRow.Address  = _address;
                    _dataBlocksRow.DataType = _dataType;
                    m_Database.DataBlocks.AddDataBlocksRow(_dataBlocksRow);
                    for (int idx = 0; idx < _length; idx++)
                    {
                        ComunicationNet.TagsRow _tagRow = m_Database.Tags.NewTagsRow();
                        _tagRow.Name         = _stationRow.Name + "/" + _dataType.ToString() + "/" + "add" + (_address + (ulong)idx).ToString();
                        _tagRow.AccessRights = (sbyte)ItemAccessRights.ReadWrite;
                        _tagRow.StateTrigger = (sbyte)StateTrigger.None;
                        _tagRow.Alarm        = false;
                        _tagRow.AlarmMask    = 0;
                        _tagRow.StateMask    = 0;
                        _tagRow.DatBlockID   = _dataBlocksRow.DatBlockID;
                        m_Database.Tags.AddTagsRow(_tagRow);
                        m_TagsAddedNumber++;
                    }
                }
                catch (Exception ex)
                {
                    AppendToLog("Error: " + ex.Message + " at \r\n"
                                + _stationID.ToString() + ","
                                + _timeScan.ToString() + ","
                                + _timeout.ToString() + ","
                                + _timeScanFast.ToString() + ","
                                + _timOutFast.ToString() + ","
                                + _address.ToString() + ","
                                + _dataType.ToString() + ","
                                + _length.ToString());
                }
            }
        }
        protected override void DoTheImport()
        {
            m_TagsAddedNumber = 0;
            m_CSVContainer    = CSVManagement.ReadFile(m_ImportBlockCSVInfo.Filename);

            m_ProgressBarWindow = new ProgressBarWindow(new DoWorkEventHandler(MainImportJob), 0, m_CSVContainer.ToString().Length, 1);
            if (m_ProgressBarWindow.ShowDialog() != DialogResult.OK)
            {
                AppendToLog("Cancel was pressed");
            }
            AppendToLog("Number of tags added: " + m_TagsAddedNumber.ToString());
        }
Beispiel #5
0
        protected override void DoTheImport()
        {
            int changes_number = 0;

            #region IMPORT
            //robimy jakies importowanie:
            long group_add  = 0;
            long server_add = 0;
            if (this.m_ImportTagsInfo.AddNew && this.m_ImportTagsInfo.CreateGroup && m_ImportTagsInfo.ServerID.HasValue)
            {
                OPCCliConfiguration.SubscriptionsRow newgroup = this.m_database.Subscriptions.NewSubscriptionsRow();
                newgroup.UpdateRate = m_ImportTagsInfo.SamplingRate;
                newgroup.Name       = "NewGroup";
                newgroup.ID_server  = (long)m_ImportTagsInfo.ServerID;
                this.m_database.Subscriptions.AddSubscriptionsRow(newgroup);
                this.m_ImportTagsInfo.GroupID = newgroup.ID;
            }
            if (this.m_ImportTagsInfo.AddNew && this.m_ImportTagsInfo.GroupID.HasValue)
            {
                group_add = (long)this.m_ImportTagsInfo.GroupID;
                //szukamy serwera
                foreach (OPCCliConfiguration.SubscriptionsRow srow in this.m_database.Subscriptions)
                {
                    if (srow.ID == group_add)
                    {
                        server_add = srow.ID_server;
                        break;
                    }
                }
            }
            CSVManagement file = CSVManagement.ReadFile(m_ImportTagsInfo.Filename);
            while (file.ToString().Length > 0)
            {
                string read;
                string name = file.GetAndMove2NextElement();
                int    type;
                read = file.GetAndMove2NextElement();
                if (read.Length > 0)
                {
                    type = System.Convert.ToByte(read);
                }
                else
                {
                    type = -1;
                }
                string conversion = file.GetAndMove2NextElement();
                bool   async;
                read = file.GetAndMove2NextElement();
                if (read.Length > 0)
                {
                    async = System.Convert.ToBoolean(System.Convert.ToInt16(read));
                }
                else
                {
                    async = false;
                }
                int maxage = -1;
                read = file.GetAndMove2NextElement();
                if (read.Length > 0)
                {
                    maxage = System.Convert.ToInt32(read);
                }
                System.Console.WriteLine("tag do zminay: " + name);
                if (this.m_ImportTagsInfo.AddNew && this.m_ImportTagsInfo.GroupID.HasValue)
                {
                    throw new Exception("Importing tools are not support new schema yet");

                    //OPCCliConfiguration.ItemsRow itrow = m_database.Items.NewItemsRow();
                    //itrow.Name = name;
                    //itrow.ID = getMaxItemID();
                    //itrow.ID_Subscription = group_add;
                    ////if ( type >= 0 )
                    ////  itrow.RequestedType = (byte)type;
                    //if ( maxage >= 0 )
                    //  itrow.MaxAge = maxage;
                    //else
                    //  itrow.SetMaxAgeNull();//=new DBNull();
                    ////TODO:fix import tool
                    ////itrow.Async = async;
                    ////if ( conversion != "" )
                    ////  itrow.Conversion = conversion;
                    //m_database.Items.AddItemsRow( itrow );
                    //changes_number++;
                }
                else
                {
                    //szukamy teraz odpowiedniego taga w liscie
                    foreach (OPCCliConfiguration.ItemsRow itrow in m_database.Items)
                    {
                        if (itrow.Name.Equals(name))
                        {
                            throw new Exception("Importing tools are not support new schema yet");
                            ////if ( type >= 0 )
                            ////  itrow.RequestedType = (byte)type;
                            //if ( maxage >= 0 )
                            //  itrow.MaxAge = maxage;
                            //else
                            //  itrow.SetMaxAgeNull();//=new DBNull();

                            ////TODO:fix import tool
                            ////itrow.Async = async;
                            ////if ( conversion != "" )
                            ////  itrow.Conversion = conversion;
                            //itrow.AcceptChanges();
                            ////System.Console.WriteLine("zmieniono: "+itrow.Name.ToString()+" numer" +zmieniono.ToString());
                            //changes_number++;
                        }
                    }
                }
                //czytamy jeszce slowo endline:
                file.GetAndMove2NextElement();
            }
            AppendToLog("changed: " + changes_number.ToString() + "of: " + m_database.Items.Count.ToString());
            #endregion IMPORT
        }
Beispiel #6
0
        protected override void DoTheImport()
        {
            #region IMPORT

            int changes_number = 0;
            //odczytanie pliku:
            CSVManagement file           = CSVManagement.ReadFile(m_ImportScanSettingsInfo.Filename);
            string        value_to_parse = "";
            //przegladamy linia po lini:
            //przegl¹damy tak d³ugo plik jak jest jeszcze jakaœ zawartoœæ
            while (file.ToString().Length > 0)
            {
                try
                {
                    // file format:
                    //tag_name;writable(0/1);StateHighTriger(0/1);StateLowTrigger(0/1);Alarm(0/1);AlarmMask;StateMask;DataTypeConv
                    //tagname:
                    string tag_name = file.GetAndMove2NextElement();
                    //lets read the rest of data:
                    string writable_s        = file.GetAndMove2NextElement();
                    string StateHighTriger_s = file.GetAndMove2NextElement();
                    string StateLowTriger_s  = file.GetAndMove2NextElement();
                    string Alarm_s           = file.GetAndMove2NextElement();
                    string AlarmMask_s       = file.GetAndMove2NextElement();
                    string StateMask_s       = file.GetAndMove2NextElement();
                    string DataTypeConv_s    = file.GetAndMove2NextElement();
                    value_to_parse = string.Format("{0};{1};{2};{3};{4};{5};{6}", tag_name, writable_s, StateHighTriger_s, Alarm_s, AlarmMask_s, StateMask_s, DataTypeConv_s);
                    //writable
                    bool writable = false;
                    if (System.Convert.ToInt16(writable_s) > 0)
                    {
                        writable = true;
                    }
                    //StateHighTriger
                    bool StateHighTriger = false;
                    if (System.Convert.ToInt16(StateHighTriger_s) > 0)
                    {
                        StateHighTriger = true;
                    }
                    //StateLowTriger
                    bool StateLowTriger = false;
                    if (System.Convert.ToInt16(StateLowTriger_s) > 0)
                    {
                        StateLowTriger = true;
                    }
                    //Alarm
                    bool Alarm = false;
                    if (System.Convert.ToInt16(Alarm_s) > 0)
                    {
                        Alarm = true;
                    }
                    //AlarmMask
                    uint AlarmMask = 0;
                    AlarmMask = System.Convert.ToUInt16(AlarmMask_s);
                    //StateMask
                    uint StateMask = 0;
                    StateMask = System.Convert.ToUInt16(StateMask_s);
                    //DataConversion
                    string DataTypeConv        = "System.Object";
                    bool   DataTypeConvertable = true;
                    if (DataTypeConv_s != null && DataTypeConv_s != "")
                    {
                        try
                        {
                            DataTypeConv = DataTypeConv_s;
                        }
                        catch (Exception)
                        {
                            DataTypeConvertable = false;
                        }
                    }
                    else
                    {
                        DataTypeConvertable = false;
                    }
                    //odczytano wszyskie dane - czas wprowadzic je to bazy konfiguracji
                    bool taghasbeenfound = false;
                    foreach (ComunicationNet.TagsRow tagrow in m_database.Tags)
                    {
                        if (tagrow.Name.Equals(tag_name))
                        {
                            //zlokalizowalismy odpoiweidni tag wiec zmieniamy go:
                            tagrow.Alarm = Alarm;
                            if (StateHighTriger)
                            {
                                tagrow.StateTrigger = (sbyte)StateTrigger.StateHigh;
                            }
                            if (StateLowTriger)
                            {
                                tagrow.StateTrigger = (sbyte)StateTrigger.StateLow;
                            }
                            if (writable)
                            {
                                tagrow.AccessRights = (sbyte)ItemAccessRights.ReadWrite;
                            }
                            else
                            {
                                tagrow.AccessRights = (sbyte)ItemAccessRights.ReadOnly;
                            }
                            if (DataTypeConvertable)
                            {
                                tagrow.DataTypeConversion = DataTypeConv;
                            }
                            if (Alarm)
                            {
                                tagrow.AlarmMask = AlarmMask;
                            }
                            if (StateHighTriger || StateLowTriger)
                            {
                                tagrow.StateMask = StateMask;
                            }
                            changes_number++;
                            taghasbeenfound = true;
                        }
                    }
                    if (!taghasbeenfound)
                    {
                        AppendToLog("Tag " + tag_name + " is not found");
                    }
                }
                catch (Exception e)
                {
                    AppendToLog(e.Message + " near to:" + value_to_parse);
                }
            }

            #endregion IMPORT

            AppendToLog("Number of changed lines: " + changes_number.ToString());
        }