public override void ExecuteSimple()
            {
                /* PetrelLogger.InfoOutputWindow(string.Format("Well Log: {0},Grid: {1}",
                 *   arguments.NovozhentsevWellLog.Name,
                 *   arguments.NovozhentsevGrid.Name));
                 * PetrelLogger.InfoOutputWindow("Runtime contex: "+ context.GetType().FullName
                 *   );*/

                Property prop  = null;
                int      count = 0;

                // все действия по изменению данных строго внутри транзакции
                using (ITransaction trans = DataManager.NewTransaction())//объект удалением которого будет  с#
                {
                    // запрашиваем исключительный доступ к свойствам сетки
                    trans.Lock(arguments.NovozhentsevGrid.PropertyCollection);//подождать пока
                    // создаем новое свойство и задаем его имя
                    prop      = arguments.NovozhentsevGrid.PropertyCollection.CreateProperty(arguments.NovozhentsevWellLog.WellLogVersion.Template);
                    prop.Name = string.Format("{0} ({1}) upscaled", arguments.NovozhentsevWellLog.Name, arguments.NovozhentsevWellLog.Borehole.Description.Name);
                    arguments.NovozhentsevResultProperty = prop;
                    // получаем перечислитель замеров каротажки в явном виде
                    IEnumerator <WellLogSample> enumSamples = arguments.NovozhentsevWellLog.Samples.GetEnumerator();                                                      //<> generic type тип элемента коллекции нумератор которой имеет этот тип,итератор
                    // получаем доступ к штатному сервису Petrel:
                    IPillarGridIntersectionService pgIntersection = CoreSystem.GetService <IPillarGridIntersectionService>();                                             //статический метод пиллар- пилоны -вид сетки
                    // получаем траекторию скважины в виде линии и запрашиваем список пересечений этой линии с ячейками сетки
                    IPolyline3 polyline = arguments.NovozhentsevWellLog.Borehole.Trajectory.Polyline;                                                                     //
                    IEnumerable <SegmentCellIntersection> intersectionsegments = pgIntersection.GetPillarGridPolylineIntersections(arguments.NovozhentsevGrid, polyline); //набор пересечений полилайна с сеткой грида/коллекция
                    // проходим в цикле по найденным точкам пересечения
                    SegmentCellIntersection enteringSegment = new SegmentCellIntersection();
                    SegmentCellIntersection leavingSegment;
                    double enteringMD = double.NaN;//measure depth, true vertical depth
                    double leavingMD  = double.NaN;
                    bool   FirstTime  = true;
                    foreach (SegmentCellIntersection segment in intersectionsegments)
                    {
                        // на первой итерации нужно только инициализировать внутренние переменные
                        if (FirstTime)
                        {
                            FirstTime       = false;
                            enteringSegment = segment;
                            enteringMD      = arguments.NovozhentsevWellLog.Borehole.Transform(arguments.NovozhentsevGrid.Domain, segment.IntersectionPoint.Z, Domain.MD);//домен - система координат, отсчета
                            // проматываем цикл по замерам, пока не дойдем до нужной глубины
                            while (enumSamples.MoveNext())
                            {
                                if (enumSamples.Current.MD >= enteringMD)
                                {
                                    break;
                                }
                            }
                            continue;
                        }
                        leavingSegment = segment;
                        // находим измеренные глубины точек пересечения вдоль ствола скважины
                        enteringMD = arguments.NovozhentsevWellLog.Borehole.Transform(arguments.NovozhentsevGrid.Domain, enteringSegment.IntersectionPoint.Z, Domain.MD);
                        leavingMD  = arguments.NovozhentsevWellLog.Borehole.Transform(arguments.NovozhentsevGrid.Domain, leavingSegment.IntersectionPoint.Z, Domain.MD);
                        // находим индекс ячейки
                        Index3 cellIndex = enteringSegment.EnteringCell;
                        float  avg       = float.NaN;
                        // если текущее значение глубины замера внутри текущей ячейки
                        if (enumSamples.Current.MD <= leavingMD)
                        {
                            int   numSamples = 1;
                            float total      = enumSamples.Current.Value;
                            // вручную проматываем замеры каротажной кривой в этой ячейке
                            while (enumSamples.MoveNext())
                            {
                                if (enumSamples.Current.MD <= leavingMD)
                                {
                                    numSamples++;
                                    total += enumSamples.Current.Value;
                                }
                                else
                                {
                                    break;
                                }
                            }
                            // теперь вычисляем усредненное значение свойства
                            avg = (float)(total / numSamples);
                            PetrelLogger.InfoOutputWindow(string.Format("сell= {0}, value={1} ({2})", cellIndex.ToString(), avg, prop.Description.Name));
                            prop[cellIndex] = avg;
                            count++;
                            enteringSegment = leavingSegment;
                        }
                        // и записываем его в новое свойство сетки
                    }
                    // если проблем нет, следующая строчка создаст наше свойство
                    arguments.NovozhentsevNumCells = count;
                    trans.Commit();
                }


                // TODO: Implement the workstep logic here.
            }
        //Method that finds the distance from Face1 to Face2 of a cell passing through the center if both faces are directly opposite
        //public static double Plane2Plane_AvgDist(Plane3 Face1, Plane3 Face2, Point3 center)
        //{
        //     double dist;
        //     dist = Face1.AbsoluteDistance(center);
        //     dist = Face2.AbsoluteDistance(center) + dist;
        //     return dist;
        //}
        //Method to get all the CellSides from which the well entered the selected grid cells. The selected grid cells must intersect the well in order for the method to work.
        public static List<CellSide> GetListOfEnteringSidesOfIntersectedCells(IPillarGridIntersectionService pgiservice, Grid gridInContext, Borehole bh, List<Index3> ListOfSelectedIntersectingGridCells, bool PerforatedZonesOnly)
        {
            bool indx3_LeavingCell;
            List<CellSide> ListOfEnteringSides = new List<CellSide>();

            if (PerforatedZonesOnly) //If the user wants only perforated zones
            {
                if (bh.Completions.PerforationCount <= 0)
                {
                    IPolyline3 pline = bh.Trajectory.Polyline;

                    IEnumerable<SegmentCellIntersection> intersectionSegments;
                    intersectionSegments = pgiservice.GetPillarGridPolylineIntersections(gridInContext, pline);
                    foreach (SegmentCellIntersection sci in intersectionSegments)
                    {
                        Index3 indx3 = sci.EnteringCell;
                        if (indx3 != null)
                        {
                            indx3_LeavingCell = false;
                        }
                        else
                        {
                            indx3 = sci.LeavingCell;
                            indx3_LeavingCell = true;
                        }

                        foreach (Index3 cell in ListOfSelectedIntersectingGridCells)
                        {
                            if (cell == indx3)
                            {
                                if (!indx3_LeavingCell)
                                {
                                    ListOfEnteringSides.Add(sci.EnteringCellSide);
                                }
                                else
                                {
                                    ListOfEnteringSides.Add(sci.LeavingCellSide);
                                }
                            }
                        }
                    }

                }
                else
                {
                    List<IPolyline3> plineList = CreatingPolyLineListWhenWellHasPerforations(bh);

                    foreach (IPolyline3 poly in plineList)
                    {
                        IEnumerable<SegmentCellIntersection> intersectionSegments;
                        intersectionSegments = pgiservice.GetPillarGridPolylineIntersections(gridInContext, poly);

                        foreach (SegmentCellIntersection sci in intersectionSegments)
                        {
                            Index3 indx3 = sci.EnteringCell;
                            if (indx3 != null)
                            {
                                indx3_LeavingCell = false;
                            }
                            else
                            {
                                indx3 = sci.LeavingCell;
                                indx3_LeavingCell = true;
                            }

                            foreach (Index3 cell in ListOfSelectedIntersectingGridCells)
                            {
                                if (cell == indx3)
                                {
                                    if (!indx3_LeavingCell)
                                    {
                                        ListOfEnteringSides.Add(sci.EnteringCellSide);
                                    }
                                    else
                                    {
                                        ListOfEnteringSides.Add(sci.LeavingCellSide);
                                    }
                                }
                            }
                        }
                    }

                }
            }
            else
            {
                IPolyline3 pline = bh.Trajectory.Polyline;

                IEnumerable<SegmentCellIntersection> intersectionSegments;
                intersectionSegments = pgiservice.GetPillarGridPolylineIntersections(gridInContext, pline);
                foreach (SegmentCellIntersection sci in intersectionSegments)
                {
                    Index3 indx3 = sci.EnteringCell;
                    if (indx3 != null)
                    {
                        indx3_LeavingCell = false;
                    }
                    else
                    {
                        indx3 = sci.LeavingCell;
                        indx3_LeavingCell = true;
                    }

                    foreach (Index3 cell in ListOfSelectedIntersectingGridCells)
                    {
                        if (cell == indx3)
                        {
                            if (!indx3_LeavingCell)
                            {
                                ListOfEnteringSides.Add(sci.EnteringCellSide);
                            }
                            else
                            {
                                ListOfEnteringSides.Add(sci.LeavingCellSide);
                            }
                        }
                    }
                }

            }
            if (ListOfEnteringSides.Count != ListOfSelectedIntersectingGridCells.Count)
            { MessageBox.Show("One or more of the cells are not intersected by the borehole");
            return ListOfEnteringSides = null;
            }
            return ListOfEnteringSides;
        }
        private static void AddingWellGridIntersectionCellIndices(IPillarGridIntersectionService pgiservice, Grid gridInContext, IPolyline3 pline, List<Index3> ListOfIntersectingGridCells)
        {
            IEnumerable<SegmentCellIntersection> intersectionSegments;
            intersectionSegments = pgiservice.GetPillarGridPolylineIntersections(gridInContext, pline);

            if (intersectionSegments != null)
            {
                foreach (SegmentCellIntersection sci in intersectionSegments)
                {
                    Index3 indx3 = sci.EnteringCell;
                    if (indx3 != null)
                    {
                        ListOfIntersectingGridCells.Add(indx3);
                    }
                    else
                    {
                        indx3 = sci.LeavingCell;
                        ListOfIntersectingGridCells.Add(indx3);
                    }
                }
            }
            else
            {         IEnumerator<Point3> Point3Enumerator = pline.GetEnumerator();

                while (Point3Enumerator.MoveNext())
                {
                    Index3 indx3 = gridInContext.GetCellAtPoint(Point3Enumerator.Current);
                    break;
                }

            }
        }
        public static Point3 GetIntersectingPoint(IPillarGridIntersectionService pgiservice, Grid GridInContext,Borehole bh, Index3 CellIndex, bool PerforatedZonesOnly)
        {
            Point3 IntersectionPoint;

            if (PerforatedZonesOnly) //if the user wants only perforated zones
            {
                if (bh.Completions.PerforationCount <= 0)
                {
                    IPolyline3 pline = bh.Trajectory.Polyline;

                    IEnumerable<SegmentCellIntersection> intersectionsegments;
                    intersectionsegments = pgiservice.GetPillarGridPolylineIntersections(GridInContext, pline);
                    foreach (SegmentCellIntersection sci in intersectionsegments)
                    {
                        if (CellIndex == sci.EnteringCell || CellIndex == sci.LeavingCell)
                        {
                            IntersectionPoint = sci.IntersectionPoint;
                            return IntersectionPoint;
                        }

                    }

                }
                else
                {
                    List<IPolyline3> plinelist = CreatingPolyLineListWhenWellHasPerforations(bh);

                    foreach (IPolyline3 poly in plinelist)
                    {
                        IEnumerable<SegmentCellIntersection> intersectionsegments;
                        intersectionsegments = pgiservice.GetPillarGridPolylineIntersections(GridInContext, poly);

                        foreach (SegmentCellIntersection sci in intersectionsegments)
                        {
                            if (CellIndex == sci.EnteringCell || CellIndex == sci.LeavingCell)
                            {
                                IntersectionPoint = sci.IntersectionPoint;
                                return IntersectionPoint;
                            }
                        }
                    }

                }
            }
            else
            {
                IPolyline3 pline = bh.Trajectory.Polyline;

                IEnumerable<SegmentCellIntersection> IntersectionSegments;
                IntersectionSegments = pgiservice.GetPillarGridPolylineIntersections(GridInContext, pline);
                foreach (SegmentCellIntersection sci in IntersectionSegments)
                {
                    if (CellIndex == sci.EnteringCell || CellIndex == sci.LeavingCell)
                    {
                        IntersectionPoint = sci.IntersectionPoint;
                        return IntersectionPoint;
                    }
                }

            }

            return null;
        }