Exemple #1
0
 public void Clear()
 {
     if (_list != null)
     {
         _list.Clear();
     }
 }
 private void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (tmp_Items != null)
         {
             tmp_Items.Clear();
             tmp_Items = null;
         }
     }
     disposed = true;
 }
Exemple #3
0
 internal virtual void  clear()
 {
     // reset the state (m_props & m_msgMask are not state)
     m_startedDocument = false;
     m_msgID.Remove(0, m_msgID.Length - 0);
     m_curPath.clear();
     // will always be "less than" (according to DatumPath.numbersLessThan)
     // any sensible DatumPath:
     m_lastDumpedPath.clear().add(new System.Text.StringBuilder().ToString()).add(-42).add(-42).add(-42).add(-42).add(-42);
     m_segmentId2nextRepIdx.Clear();
     m_depthWithinUsefulElement  = -1;
     m_depthWithinUselessElement = -1;
     m_chars.Remove(0, m_chars.Length - 0);
 }
Exemple #4
0
        /// <summary>
        /// Заполнить объект данных.
        /// </summary>
        /// <param name="dobject">Объект данных.</param>
        /// <param name="values">Значения для заполнения.</param>
        /// <param name="storageStruct">Метаданные структуры хранения.</param>
        /// <param name="customizationStruct">Настройка выборки данных.</param>
        /// <param name="typesByKeys">Служебная структура, увязывающая типы мастеров и их ключи.</param>
        /// <param name="advCols">Дополнительные колонки.</param>
        /// <param name="dataObjectCache">Кэш объектов данных.</param>
        /// <param name="securityManager">Менеджер полномочий.</param>
        public static void FillRowSetToDataObject(DataObject dobject, object[] values, StorageStructForView storageStruct, LoadingCustomizationStruct customizationStruct, System.Collections.SortedList typesByKeys, AdvansedColumn[] advCols, DataObjectCache dataObjectCache, ISecurityManager securityManager)
        {
            Type dobjectType = dobject.GetType();

            /* access type */

            if (!securityManager.AccessObjectCheck(dobjectType, tTypeAccess.Full, false))
            {
                securityManager.AccessObjectCheck(dobjectType, tTypeAccess.Read, true);
            }

            /* access type */

            // Заливаем данные в объект данных.
            int customizationStructViewPropertiesLength = customizationStruct.View.Properties.Length;
            int advColsLength = advCols.Length;

            Information.SetPropValueByName(dobject, "__PrimaryKey", values[customizationStructViewPropertiesLength + advColsLength]);

            // 1. создаем структуру мастеров(свойств-объектов данных).
            System.Collections.SortedList assList = new System.Collections.SortedList();
            int index = customizationStructViewPropertiesLength + 1 + advColsLength;

            CreateMastersStruct(dobject, values, ref index, 0, storageStruct.sources, assList, typesByKeys, dataObjectCache);
            assList.Add(storageStruct.sources, new object[] { dobject, 0 });

            // 2. заливаем данные.
            System.Collections.ArrayList properiesValues = new System.Collections.ArrayList();
            StringCollection             allAdvCols      = new StringCollection();

            int masterPosition = index;

            for (int i = 0; i < advColsLength; i++)
            {
                object value = values[i + customizationStructViewPropertiesLength];
                if (value == DBNull.Value)
                {
                    value = null;
                }

                properiesValues.Add(new[] { advCols[i].Name, value, dobject });
                allAdvCols.Add(advCols[i].Name);
                dobject.DynamicProperties.Add(advCols[i].Name, null);
            }

            for (int i = 0; i < customizationStructViewPropertiesLength; i++)
            {
                StorageStructForView.PropStorage prop = storageStruct.props[i];
                if (Information.IsStoredProperty(dobjectType, prop.Name) || prop.Expression != null)
                {
                    if (prop.MastersTypes == null)
                    {
                        object[] tmp = (object[])assList[prop.source];
                        object   value;
                        if (customizationStruct.ColumnsOrder != null && customizationStruct.ColumnsOrder.Length >= customizationStructViewPropertiesLength)
                        {
                            value = values[Array.IndexOf(customizationStruct.ColumnsOrder, prop.Name)];
                        }
                        else
                        {
                            value = values[i];
                        }

                        if (value == DBNull.Value)
                        {
                            value = null;
                        }

                        if (tmp != null)
                        {
                            properiesValues.Add(
                                new[] { prop.simpleName, value, tmp[0] });
                        }
                    }
                    else
                    {
                        object[] tmp = (object[])assList[prop.source];
                        if (tmp != null)
                        {
                            // Ищем позицию.
                            int tmp1 = (int)tmp[1];
                            int curMasterPosition = masterPosition;
                            for (int j = 0; j < tmp1; j++)
                            {
                                curMasterPosition += prop.MastersTypes[j].Length;
                            }

                            int    k     = 0;
                            object value = values[curMasterPosition];
                            if (value == DBNull.Value)
                            {
                                value = null;
                            }

                            while (k < prop.MastersTypes[tmp1].Length - 1 && value == null)
                            {
                                k++;
                                value = values[curMasterPosition + k];
                                if (value == DBNull.Value)
                                {
                                    value = null;
                                }
                            }

                            object tmp0 = tmp[0];
                            if (value != null)
                            {
                                if (Information.GetPropValueByName((DataObject)tmp0, prop.simpleName) == null)
                                {
                                    DataObject no = dataObjectCache.CreateDataObject(prop.MastersTypes[tmp1][k], value);
                                    if (no.GetStatus(false) == ObjectStatus.Created)
                                    {
                                        no.SetStatus(ObjectStatus.UnAltered);
                                        no.SetLoadingState(LoadingState.LightLoaded);
                                        no.InitDataCopy(dataObjectCache);
                                    }

                                    value = no;
                                    properiesValues.Add(new[] { prop.simpleName, value, tmp0 });
                                }
                                else
                                {
                                    // changed by fat
                                    properiesValues.Add(new[] { prop.simpleName, Information.GetPropValueByName((DataObject)tmp0, prop.simpleName), tmp0 });
                                }
                            }
                            else
                            {
                                properiesValues.Add(new[] { prop.simpleName, null, tmp0 });
                            }
                        }

                        masterPosition += prop.MastersTypesCount;
                    }
                }
            }

            // 2.2 Записываем в объекты.
            System.Collections.SortedList curObjProperiesValues = new System.Collections.SortedList();
            while (properiesValues.Count > 0)
            {
                // a. Выбираем для текущего объекта все свойства.
                object[]   tmp    = (object[])properiesValues[0];
                DataObject curobj = (DataObject)tmp[2];
                dobjectType = curobj.GetType();
                curObjProperiesValues.Clear();

                List <string> loadedPropsColl = curobj.GetLoadedPropertiesList();

                for (int i = properiesValues.Count - 1; i >= 0; i--)
                {
                    tmp = (object[])properiesValues[i];
                    if (tmp[2] == curobj)
                    {
                        object tmp0 = tmp[0];
                        if (!curObjProperiesValues.ContainsKey(tmp0))
                        {
                            curObjProperiesValues.Add(tmp0, tmp[1]);
                            if (!loadedPropsColl.Contains((string)tmp0))
                            {
                                loadedPropsColl.Add((string)tmp0);
                            }
                        }

                        properiesValues.RemoveAt(i);
                    }
                }

                // b. Раскидываем согласно LoadOrder;
                string[] loadOrder       = Information.GetLoadingOrder(dobjectType);
                int      loadOrderLength = loadOrder.Length;
                for (int i = 0; i < loadOrderLength; i++)
                {
                    string propName = loadOrder[i];
                    if (curObjProperiesValues.ContainsKey(propName))
                    {
                        Information.SetPropValueByName(curobj, propName, curObjProperiesValues[propName]);
                        curObjProperiesValues.Remove(propName);
                    }
                }

                int curObjPropertiesValuesCount = curObjProperiesValues.Count;
                for (int i = 0; i < curObjPropertiesValuesCount; i++)
                {
                    Information.SetPropValueByName(curobj, (string)curObjProperiesValues.GetKey(i), curObjProperiesValues.GetByIndex(i));
                }

                if (loadedPropsColl.Count >= Information.GetAllPropertyNames(dobjectType).Length)
                {
                    curobj.SetLoadingState(LoadingState.Loaded);
                }
                else
                {
                    curobj.SetLoadingState(LoadingState.LightLoaded);
                    curobj.AddLoadedProperties(loadedPropsColl);
                }

                curobj.SetStatus(ObjectStatus.UnAltered);
            }
        }
Exemple #5
0
        /// <summary>
        /// Analyzes the first <code>nLines</code> of the ascii stream.
        /// </summary>
        /// <param name="nLines">The number of lines to analyze. It is no error if the stream contains a less number of lines than provided here.</param>
        /// <param name="defaultImportOptions">The default import options.</param>
        /// <returns>Import options that can be used in a following step to read in the ascii stream. Null is returned if the stream contains no data.</returns>
        public AsciiImportOptions Analyze(int nLines, AsciiImportOptions defaultImportOptions)
        {
            string sLine;

            stream.Position = 0;
            System.IO.StreamReader       sr     = new System.IO.StreamReader(stream, System.Text.Encoding.Default, true);
            System.Collections.ArrayList result = new System.Collections.ArrayList();

            for (int i = 0; i < nLines; i++)
            {
                sLine = sr.ReadLine();
                if (null == sLine)
                {
                    break;
                }
                result.Add(new AsciiLineAnalyzer(i, sLine));
            }

            if (result.Count == 0)
            {
                return(null); // there is nothing to analyze
            }
            // now view the results
            // calc the frequency o
            System.Collections.SortedList sl = new System.Collections.SortedList();
            int nItems;

            // first the tabs

            /*
             * sl.Clear();
             * for(int i=0;i<result.Count;i++)
             * {
             * nItems = ((AsciiLineAnalyzer)result[i]).nNumberOfTabs;
             * if(0!=nItems)
             * {
             *  if(null==sl[nItems])
             *    sl.Add(nItems,1);
             *  else
             *    sl[nItems] = 1+(int)sl[nItems];
             * }
             * }
             * // get the tab count with the topmost frequency
             * int nMaxNumberOfSameTabs = 0;
             * int nMaxTabsOfSameNumber = 0;
             * for(int i=0;i<sl.Count;i++)
             * {
             * if(nMaxNumberOfSameTabs<(int)sl.GetByIndex(i))
             * {
             *  nMaxNumberOfSameTabs = (int)sl.GetByIndex(i);
             *  nMaxTabsOfSameNumber = (int)sl.GetKey(i);
             * }
             * }
             */


            // Count the commas
            sl.Clear();
            for (int i = 0; i < result.Count; i++)
            {
                nItems = ((AsciiLineAnalyzer)result[i]).nNumberOfCommas;
                if (0 != nItems)
                {
                    if (null == sl[nItems])
                    {
                        sl.Add(nItems, 1);
                    }
                    else
                    {
                        sl[nItems] = 1 + (int)sl[nItems];
                    }
                }
            }
            // get the comma count with the topmost frequency
            int nMaxNumberOfSameCommas = 0;
            int nMaxCommasOfSameNumber = 0;

            for (int i = 0; i < sl.Count; i++)
            {
                if (nMaxNumberOfSameCommas < (int)sl.GetByIndex(i))
                {
                    nMaxNumberOfSameCommas = (int)sl.GetByIndex(i);
                    nMaxCommasOfSameNumber = (int)sl.GetKey(i);
                }
            }

            // Count the semicolons
            sl.Clear();
            for (int i = 0; i < result.Count; i++)
            {
                nItems = ((AsciiLineAnalyzer)result[i]).nNumberOfSemicolons;
                if (0 != nItems)
                {
                    if (null == sl[nItems])
                    {
                        sl.Add(nItems, 1);
                    }
                    else
                    {
                        sl[nItems] = 1 + (int)sl[nItems];
                    }
                }
            }
            // get the tab count with the topmost frequency
            int nMaxNumberOfSameSemicolons = 0;
            int nMaxSemicolonsOfSameNumber = 0;

            for (int i = 0; i < sl.Count; i++)
            {
                if (nMaxNumberOfSameSemicolons < (int)sl.GetByIndex(i))
                {
                    nMaxNumberOfSameSemicolons = (int)sl.GetByIndex(i);
                    nMaxSemicolonsOfSameNumber = (int)sl.GetKey(i);
                }
            }


            NumberAndStructure[] st = new NumberAndStructure[3];

            for (int i = 0; i < 3; i++)
            {
                st[i].nLines = GetPriorityOf(result, (AsciiLineAnalyzer.Separation)i, ref st[i].structure);
            }

            // look for the top index

            int    nMaxLines      = int.MinValue;
            double maxprtylines   = 0;
            int    nBestSeparator = int.MinValue;

            for (int i = 0; i < 3; i++)
            {
                double prtylines = (double)st[i].nLines * st[i].structure.Priority;
                if (prtylines == maxprtylines)
                {
                    if (st[i].nLines > nMaxLines)
                    {
                        nMaxLines      = st[i].nLines;
                        nBestSeparator = i;
                    }
                }
                else if (prtylines > maxprtylines)
                {
                    maxprtylines   = prtylines;
                    nBestSeparator = i;
                    nMaxLines      = st[i].nLines;
                }
            }

            AsciiImportOptions opt = defaultImportOptions.Clone();

            opt.bDelimited          = true;
            opt.cDelimiter          = nBestSeparator == 0 ? '\t' : (nBestSeparator == 1 ? ',' : ';');
            opt.recognizedStructure = st[nBestSeparator].structure;


            // look how many header lines are in the file by comparing the structure of the first lines  with the recognized structure
            for (int i = 0; i < result.Count; i++)
            {
                opt.nMainHeaderLines = i;
                if (((AsciiLineAnalyzer)result[i]).structure[nBestSeparator].IsCompatibleWith(opt.recognizedStructure))
                {
                    break;
                }
            }


            // calculate the total statistics of decimal separators
            opt.m_DecimalSeparatorCommaCount = 0;
            opt.m_DecimalSeparatorDotCount   = 0;
            for (int i = 0; i < result.Count; i++)
            {
                opt.m_DecimalSeparatorDotCount   += ((AsciiLineAnalyzer)result[i]).structure[nBestSeparator].DecimalSeparatorDotCount;
                opt.m_DecimalSeparatorCommaCount += ((AsciiLineAnalyzer)result[i]).structure[nBestSeparator].DecimalSeparatorCommaCount;
            }



            return(opt);
        }
    /// <summary>
    /// Analyzes the first <code>nLines</code> of the ascii stream.
    /// </summary>
    /// <param name="nLines">The number of lines to analyze. It is no error if the stream contains a less number of lines than provided here.</param>
    /// <param name="defaultImportOptions">The default import options.</param>
    /// <returns>Import options that can be used in a following step to read in the ascii stream. Null is returned if the stream contains no data.</returns>
    public AsciiImportOptions Analyze(int nLines, AsciiImportOptions defaultImportOptions)
    {

      string sLine;

      stream.Position = 0;
      System.IO.StreamReader sr = new System.IO.StreamReader(stream,System.Text.Encoding.Default,true);
      System.Collections.ArrayList result = new System.Collections.ArrayList();
    
      for(int i=0;i<nLines;i++)
      {
        sLine = sr.ReadLine();
        if(null==sLine)
          break;
        result.Add(new AsciiLineAnalyzer(i,sLine));
      }
    
      if(result.Count==0)
        return null; // there is nothing to analyze

      // now view the results
      // calc the frequency o
      System.Collections.SortedList sl= new System.Collections.SortedList();
      int nItems;
      // first the tabs

      /*
      sl.Clear();
      for(int i=0;i<result.Count;i++)
      {
        nItems = ((AsciiLineAnalyzer)result[i]).nNumberOfTabs;
        if(0!=nItems)
        {
          if(null==sl[nItems])
            sl.Add(nItems,1);
          else 
            sl[nItems] = 1+(int)sl[nItems];
        }
      }
      // get the tab count with the topmost frequency
      int nMaxNumberOfSameTabs = 0;
      int nMaxTabsOfSameNumber = 0;
      for(int i=0;i<sl.Count;i++)
      {
        if(nMaxNumberOfSameTabs<(int)sl.GetByIndex(i))
        {
          nMaxNumberOfSameTabs = (int)sl.GetByIndex(i);
          nMaxTabsOfSameNumber = (int)sl.GetKey(i);
        }
      }
*/
      
      
      // Count the commas
      sl.Clear();
      for(int i=0;i<result.Count;i++)
      {
        nItems = ((AsciiLineAnalyzer)result[i]).nNumberOfCommas;
        if(0!=nItems)
        {
          if(null==sl[nItems])
            sl.Add(nItems,1);
          else 
            sl[nItems] = 1+(int)sl[nItems];
        }
      }
      // get the comma count with the topmost frequency
      int nMaxNumberOfSameCommas = 0;
      int nMaxCommasOfSameNumber = 0;
      for(int i=0;i<sl.Count;i++)
      {
        if(nMaxNumberOfSameCommas<(int)sl.GetByIndex(i))
        {
          nMaxNumberOfSameCommas = (int)sl.GetByIndex(i);
          nMaxCommasOfSameNumber = (int)sl.GetKey(i);
        }
      }

      // Count the semicolons
      sl.Clear();
      for(int i=0;i<result.Count;i++)
      {
        nItems = ((AsciiLineAnalyzer)result[i]).nNumberOfSemicolons;
        if(0!=nItems)
        {
          if(null==sl[nItems])
            sl.Add(nItems,1);
          else 
            sl[nItems] = 1+(int)sl[nItems];
        }
      }
      // get the tab count with the topmost frequency
      int nMaxNumberOfSameSemicolons = 0;
      int nMaxSemicolonsOfSameNumber = 0;
      for(int i=0;i<sl.Count;i++)
      {
        if(nMaxNumberOfSameSemicolons<(int)sl.GetByIndex(i))
        {
          nMaxNumberOfSameSemicolons = (int)sl.GetByIndex(i);
          nMaxSemicolonsOfSameNumber = (int)sl.GetKey(i);
        }
      }

    
      NumberAndStructure[] st = new NumberAndStructure[3];

      for(int i=0;i<3;i++)
      {
        st[i].nLines = GetPriorityOf(result,(AsciiLineAnalyzer.Separation)i,ref st[i].structure);
      }

      // look for the top index
    
      int nMaxLines = int.MinValue;
      double maxprtylines=0;
      int nBestSeparator = int.MinValue;
      for(int i=0;i<3;i++)
      {
        double prtylines = (double)st[i].nLines * st[i].structure.Priority;
        if(prtylines==maxprtylines)
        {
          if(st[i].nLines > nMaxLines)
          {
            nMaxLines = st[i].nLines;
            nBestSeparator = i;
          }
        }
        else if(prtylines>maxprtylines)
        {
          maxprtylines = prtylines;
          nBestSeparator = i;
          nMaxLines=st[i].nLines;
        }
      }

      AsciiImportOptions opt = defaultImportOptions.Clone();
      
      opt.bDelimited = true;
      opt.cDelimiter = nBestSeparator==0 ? '\t' : (nBestSeparator==1 ? ',' : ';');
      opt.recognizedStructure = st[nBestSeparator].structure;


      // look how many header lines are in the file by comparing the structure of the first lines  with the recognized structure
      for(int i=0;i<result.Count;i++)
      {
        opt.nMainHeaderLines=i;
        if(((AsciiLineAnalyzer)result[i]).structure[nBestSeparator].IsCompatibleWith(opt.recognizedStructure))
          break;
      }


      // calculate the total statistics of decimal separators
      opt.m_DecimalSeparatorCommaCount=0;
      opt.m_DecimalSeparatorDotCount=0;
      for(int i=0;i<result.Count;i++)
      {
        opt.m_DecimalSeparatorDotCount += ((AsciiLineAnalyzer)result[i]).structure[nBestSeparator].DecimalSeparatorDotCount;
        opt.m_DecimalSeparatorCommaCount += ((AsciiLineAnalyzer)result[i]).structure[nBestSeparator].DecimalSeparatorCommaCount;
      }



      return opt;

    }