Пример #1
0
        static public void CreatePartition(Cube parCube)
        {
            DateTime    varNow         = DateTime.Now;
            DateTime    varDateArxCube = new DateTime(1, 1, 1);
            CultureInfo provider       = CultureInfo.InvariantCulture;

            if (parCube.Description != null && strings.GetWordNum(parCube.Description, 2, ";").Length > 5 && strings.GetWordNum(parCube.Description, 2, ";").Substring(0, 5).ToUpper() == "ARX=>")
            {
                varDateArxCube = DateTime.ParseExact(strings.GetWordNum(parCube.Description, 2, ";").Substring(5, 10).ToUpper(), "dd.MM.yyyy", provider);
            }
            foreach (MeasureGroup g in parCube.MeasureGroups)
            {
                try
                {
                    Partition  pTemplate = GetTemplatePartition(g);
                    TypePeriod varType   = GetTypePartition(g);
                    if (varType != TypePeriod.NotDefined)
                    {
                        Partition currentPartition = null;

                        if (pTemplate.Source is TableBinding)
                        {
                            throw new ApplicationException(
                                      "template partition should have query binding \"select * from tablename where 1=0\"");
                        }
                        //string table = TableNameFromQueryGet((pTemplate.Source as QueryBinding).QueryDefinition);
                        string   varStrStartDate  = GetStartDate((pTemplate.Source as QueryBinding).QueryDefinition);
                        DateTime varRealStartDate = new DateTime(Convert.ToInt32(varStrStartDate.Substring(0, 4)), Convert.ToInt32(varStrStartDate.Substring(4, 2)), Convert.ToInt32(varStrStartDate.Substring(6, 2)));
                        DateTime varStartDate;
                        if (GlobalVar.varIsArx)
                        {
                            if (GlobalVar.varArxDate == new DateTime(1, 1, 1))
                            {
                                varStartDate = varDateArxCube;
                            }
                            else
                            {
                                varStartDate = GlobalVar.varArxDate;
                            }
                        }
                        else
                        {
                            varStartDate = varRealStartDate;
                        }
                        DateTime varEndDate = varStartDate;

                        //string varDateField = "", table = "";

/*                        if (g.Partitions.FindByName("template") != null) //TMP
 *                      {
 *                          varDateField = DateFieldNameFromQueryGet((pTemplate.Source as QueryBinding).QueryDefinition);//tmp
 *                          table = TableNameFromQueryGet((pTemplate.Source as QueryBinding).QueryDefinition); //tmp
 *                      }*/
                        while (varStartDate <= varNow)
                        {
                            currentPartition = PartitionFind(g, varStartDate);
                            varEndDate       = CountNextPreviousDate(varStartDate, varType);
                            if (currentPartition == null)
                            {
                                //   if (g.Partitions.FindByName("template") == null)
                                currentPartition = PartitionCreate(pTemplate, varStartDate, varEndDate, varType);
                                // else
                                //     currentPartition = PartitionCreate(varStartDate.Year, varStartDate.Month, false, table, g, pTemplate, varDateField, varIsOracle);

                                currentPartition.Update();
                                Console.WriteLine("Створено партіцию=>" + currentPartition.Name);
                            }
                            varStartDate = varEndDate;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.log("Група мір=>" + g.Name + " Error =>" + e.Message);
                }
            }
        }
Пример #2
0
        /*        static private Partition PartitionCreate(int aYear, int aMonth, bool aForever, string aTableName,
         *  MeasureGroup aMeasugeGroup, Partition aTemplatePartition, string DateFieldName, bool isOracle)
         * {
         *  try
         *  {
         *      Partition p = aMeasugeGroup.Partitions.Add(aMeasugeGroup.Name + " " + ToYYYYMM(aYear, aMonth));
         *      p.AggregationDesignID = aTemplatePartition.AggregationDesignID;
         *      DateTime dStart = new DateTime(aYear, aMonth, 1);
         *      DateTime dEnd = new DateTime(aMonth == 12 ? aYear + 1 : aYear, aMonth == 12 ? 1 : aMonth + 1, 1);
         *
         *      string sql = "select * from " + aTableName + " where " + DateFieldName + " >= " + (isOracle ? "to_date('" + ToYYYYMMDD(dStart) + "','YYYYMMDD')" : ToYYYYMMDD(dStart));
         *      if (!aForever)
         *          sql += " AND " + DateFieldName + " < " + (isOracle ? "to_date('" + ToYYYYMMDD(dEnd) + "','YYYYMMDD')" : ToYYYYMMDD(dEnd));
         *      p.Source = new QueryBinding(aTemplatePartition.DataSource.ID, sql);
         *      p.Slice = "[Дата].[Місяць]" + ".&[" + ToYYYYMM(aYear, aMonth) + "]";
         *      return p;
         *  }
         *  catch (Exception e)
         *  {
         *      Console.WriteLine("{0} Exception caught.", e);
         *  }
         *  return null;
         * }*/


        /// <summary>
        /// Створюємо партіцию на основі шаблона.
        /// </summary>
        /// <param name="parTemplatePartition">Шаблон</param>
        /// <param name="parDStart">Початкова дата партіциї </param>
        /// <param name="parDEnd">Цінцева дата Партіциї</param>
        /// <param name="parType">Періодичність партіциї</param>
        /// <returns></returns>
        static private Partition PartitionCreate(Partition parTemplatePartition, DateTime parDStart, DateTime parDEnd, TypePeriod parType)
        {
            var MeasugeGroup = parTemplatePartition.Parent;

            try
            {
                string varSQL       = (parTemplatePartition.Source as QueryBinding).QueryDefinition;
                bool   varIsOracle  = IsOracle(varSQL);
                string varStartDate = XMLABuilder.GetStartDate(varSQL); //Початкова дата для створення партіций


                string varNewSQL;
                if (varSQL.IndexOf("1=0") > 0)
                {
                    string varDateField = DateFieldNameFromQueryGet(varSQL); //tmp
                    string table        = TableNameFromQueryGet(varSQL);     //tmp
                    varNewSQL = "select * from " + table + " where " + varDateField + " >= " + (varIsOracle ? "to_date('" + ToYYYYMMDD(parDStart) + "','YYYYMMDD')" : ToYYYYMMDD(parDStart)) + " AND " + varDateField + " < " + (varIsOracle ? "to_date('" + ToYYYYMMDD(parDEnd) + "','YYYYMMDD')" : ToYYYYMMDD(parDEnd));
                }
                else
                {
                    varNewSQL = varSQL.Replace(">= ", ">=").Replace(">= ", ">=").Replace(">= ", ">=").Replace("< ", "<").Replace("< ", "<").Replace("< ", "<").
                                Replace(">=to_date('" + varStartDate, ">= to_date('" + ToYYYYMMDD(parDStart)).Replace("<to_date('00010101", "< to_date('" + ToYYYYMMDD(parDEnd));
                }

                Partition p = MeasugeGroup.Partitions.Add(MeasugeGroup.Name + " " + (parType == TypePeriod.Week || parType == TypePeriod.Week4 ? ToYYYYMMDD(parDStart) : ToYYYYMM(parDStart)));
                p.AggregationDesignID = parTemplatePartition.AggregationDesignID;
                p.Source = new QueryBinding(parTemplatePartition.DataSource.ID, varNewSQL);
                if (parType == TypePeriod.Month)
                {
                    p.Slice = /*"[Час].[Календар].[Місяць]*/ "[Дата].[Місяць]" + ".&[" + ToYYYYMM(parDStart) + "]";
                }
                return(p);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
            return(null);
        }