Ejemplo n.º 1
0
        public IActionResult List(UserRequestPayload payload)
        {
            using (_dbContext)
            {
                IQueryable <DncUser> query = _dbContext.DncUser.AsQueryable();
                if (!string.IsNullOrEmpty(payload.Kw))
                {
                    query = query.Where(x => x.LoginName.Contains(payload.Kw.Trim()) || x.DisplayName.Contains(payload.Kw.Trim()));
                }
                if (payload.IsDeleted > CommonEnum.IsDeleted.All)
                {
                    query = query.Where(x => x.IsDeleted == payload.IsDeleted);
                }
                if (payload.Status > UserStatus.All)
                {
                    query = query.Where(x => x.Status == payload.Status);
                }

                if (payload.FirstSort != null)
                {
                    query = query.OrderBy(payload.FirstSort.Field, payload.FirstSort.Direct == "DESC");
                }
                System.Collections.Generic.List <DncUser> list = query.Paged(payload.CurrentPage, payload.PageSize).ToList();
                int totalCount = query.Count();
                System.Collections.Generic.IEnumerable <UserJsonModel> data = list.Select(_mapper.Map <DncUser, UserJsonModel>);
                ResponseResultModel response = ResponseModelFactory.CreateResultInstance;
                response.SetData(data, totalCount);
                return(Ok(response));
            }
        }
        public IActionResult GetFilesByContentResourceId(Guid resourceId)
        {
            try
            {
                var files = new System.Collections.Generic.List <ContractResourceFile>();
                if (resourceId != Guid.Empty)
                {
                    files = _contractRefactorService.GetFileListByContentResourceGuid(resourceId).ToList();
                }

                var listdata = files.Select(x => new
                {
                    contractResourceFileGuid = x.ContractResourceFileGuid,
                    ResourceGuid             = x.ResourceGuid,
                    UploadFileName           = x.UploadFileName,
                    Description = x.Description,
                    FilePath    = x.FilePath,
                    FileSize    = x.FileSize,
                    Keys        = x.Keys,
                    UpdatedBy   = GetUserFullName(x.UpdatedBy),
                    UpdatedOn   = x.UpdatedOn.ToString("MM/dd/yyyy")
                }).ToList();
                return(Json(listdata));
            }
            catch (Exception ex)
            {
                return(BadRequestFormatter.BadRequest(this, ex));
            }
        }
Ejemplo n.º 3
0
        public bool IsWhiteListed(System.Collections.Generic.List <RunOn> runons)
        {
            DateTime now = DateTime.Now;

            if (!runons.Any())
            {
                return(true);
            }

            List <string> runonDays = runons.Select(a => a.Day).ToList();

            if (runonDays.Select(a => a.ToUpper()).Contains(now.DayOfWeek.ToString().ToUpper())) //day check
            {
                //time check
                foreach (var timeR in runons.Where(a => a.Day.Equals(now.DayOfWeek.ToString(), StringComparison.OrdinalIgnoreCase)).ToList())
                {
                    var start = DateTime.Parse(timeR.From, System.Globalization.CultureInfo.CurrentCulture);
                    var end   = DateTime.Parse(timeR.To, System.Globalization.CultureInfo.CurrentCulture);

                    if (start <= end)
                    {
                        return(start <= now && now <= end);
                    }
                    return(!(end <= now && now <= start));
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        public async Task <ListResultDto <DepreciationDto> > GetDepreciationsAsync()
        {
            System.Collections.Generic.List <Depreciation> items = await _depreciationRepository.GetAllListAsync();

            return(new ListResultDto <DepreciationDto>(
                       items.Select(item => ObjectMapper.Map <DepreciationDto>(item)).ToList()));
        }
    public static void Main(string[] args)
    {
        //List<int> listColumns = new List<int>(){ 1, 5, 6, 9};
        System.Collections.Generic.List <int> listColumns = new System.Collections.Generic.List <int>()
        {
            1, 5, 6, 9
        };
        string s   = String.Join(", ", listColumns.Select(x => x.ToString()));
        string sql = String.Format("SELECT * FROM Table WHERE ID IN ({0})", s);

        Console.WriteLine(sql);
    }
Ejemplo n.º 6
0
 /// <summary>
 /// 删除用户
 /// </summary>
 /// <param name="status">用户状态</param>
 /// <param name="ids">用户ID字符串,多个以逗号隔开</param>
 /// <returns></returns>
 private ResponseModel UpdateStatus(UserStatus status, string ids)
 {
     using (_dbContext)
     {
         System.Collections.Generic.List <SqlParameter> parameters = ids.Split(",").Select((id, index) => new SqlParameter(string.Format("@p{0}", index), id)).ToList();
         string parameterNames = string.Join(", ", parameters.Select(p => p.ParameterName));
         string sql            = string.Format("UPDATE DncUser SET Status=@Status WHERE Guid IN ({0})", parameterNames);
         parameters.Add(new SqlParameter("@Status", (int)status));
         _dbContext.Database.ExecuteSqlCommand(sql, parameters);
         ResponseModel response = ResponseModelFactory.CreateInstance;
         return(response);
     }
 }
Ejemplo n.º 7
0
        public async Task <PagedResultDto <DepreciationListDto> > GetDepreciationsAsync(GetDepreciationInput input)
        {
            IQueryable <Depreciation> query = _depreciationRepository.GetAll()
                                              .WhereIf(!input.Name.IsNullOrWhiteSpace(), m => m.Name.Contains(input.Name));

            int totalCount = await query.CountAsync();

            System.Collections.Generic.List <Depreciation> items = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();

            return(new PagedResultDto <DepreciationListDto>(
                       totalCount,
                       items.Select(item => ObjectMapper.Map <DepreciationListDto>(item)).ToList()));
        }
Ejemplo n.º 8
0
 protected override void SelectionChanged(System.Collections.Generic.List <Selection> sel)
 {
     if (DrawableChangedEvent != null)
     {
         if (sel != null && sel.Count > 0)
         {
             var selectedDrawables = sel.Select(i => (i.Drawable as ICanvasDrawableObject).IDrawableObject);
             DrawableChangedEvent(selectedDrawables);
         }
         else
         {
             DrawableChangedEvent(null);
         }
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 删除用户
 /// </summary>
 /// <param name="isDeleted"></param>
 /// <param name="ids">用户ID字符串,多个以逗号隔开</param>
 /// <returns></returns>
 private ResponseModel UpdateIsDelete(CommonEnum.IsDeleted isDeleted, string ids)
 {
     using (_dbContext)
     {
         //var idList = ids.Split(",").ToList();
         ////idList.ForEach(x => {
         ////  _dbContext.Database.ExecuteSqlCommand($"UPDATE DncUser SET IsDeleted=1 WHERE Id = {x}");
         ////});
         //_dbContext.Database.ExecuteSqlCommand($"UPDATE DncUser SET IsDeleted={(int)isDeleted} WHERE Id IN ({ids})");
         System.Collections.Generic.List <SqlParameter> parameters = ids.Split(",").Select((id, index) => new SqlParameter(string.Format("@p{0}", index), id)).ToList();
         string parameterNames = string.Join(", ", parameters.Select(p => p.ParameterName));
         string sql            = string.Format("UPDATE DncUser SET IsDeleted=@IsDeleted WHERE Guid IN ({0})", parameterNames);
         parameters.Add(new SqlParameter("@IsDeleted", (int)isDeleted));
         _dbContext.Database.ExecuteSqlCommand(sql, parameters);
         ResponseModel response = ResponseModelFactory.CreateInstance;
         return(response);
     }
 }
Ejemplo n.º 10
0
 public override void RetrieveCurrentValues(System.Collections.Generic.List <ConfigurationItem> configs)
 {
     foreach (string pageCode in configs.Select(x => x.DefaultKey1).Distinct())
     {
         var lstConfigs    = configs.FindAll(x => x.DefaultKey1 == pageCode);
         var currentValues = RetrieveCurrentValues(businessUnit, lstConfigs);
         AddMissingValues(lstConfigs, currentValues);
         foreach (ConfigurationItem config in lstConfigs)
         {
             string currentValue = "";
             if (currentValues.ContainsKey(config.DefaultName))
             {
                 currentValue        = currentValues[config.DefaultName];
                 config.CurrentValue = currentValue;
                 config.UpdatedValue = currentValue;
             }
         }
     }
 }
Ejemplo n.º 11
0
 public override void RetrieveCurrentValues(System.Collections.Generic.List <ConfigurationItem> configs)
 {
     // loop throguh control code --> different control code configs to be shown on the same page can create a trouble when having same attr_name value
     foreach (string controlCode in configs.Select(x => x.DefaultKey1).Distinct())
     {
         var lstConfigs    = configs.FindAll(x => x.DefaultKey1 == controlCode);
         var currentValues = RetrieveCurrentValues(businessUnit, lstConfigs);
         AddMissingValues(lstConfigs, currentValues);
         string currentValue = "";
         foreach (ConfigurationItem config in lstConfigs)
         {
             if (currentValues.ContainsKey(config.DefaultName))
             {
                 currentValue        = currentValues[config.DefaultName];
                 config.CurrentValue = currentValue;
                 config.UpdatedValue = currentValue;
             }
         }
     }
 }
Ejemplo n.º 12
0
                public static string ReadAllString(string fullpath)
                {
                    var f = Phone.IO.File7.Open(fullpath, "r");

                    int c = f.Getc();

                    var va = new System.Collections.Generic.List <byte>();

                    while (c != Phone.IO.File7.EOF)
                    {
                        va.Add((byte)c);
                        c = f.Getc();
                    }

                    var    data = va.Select(a => (char)a).ToArray();
                    string r    = new string(data);

                    f.Close();

                    return(r);
                }
Ejemplo n.º 13
0
        public void BoxRecommendedGoodsByGoodsType(System.Collections.Generic.List <SSchemeMobaGoods> _typeList, List <int> _dispositionTypeList, EMobaRecommendGoods _eRecommendType)
        {
            m_nUsedRecommendType++;
            //取显示对象挂载容器
            Transform containner = GetCurrentContainer();
            ResNode   go         = AssetBundleManager.GetAssets(AssetType.Asset_Prefab, "UI/Prefabs/" + UPath.UDynamicMobaState + "/WarGoodsStore/WarGoodsStoreRecommendComponent");
            UWarGoodsStoreRecommendComponent component;

            //取该类型标题本地化文本
            if (GetCurrentContainerTitleText() != null)
            {
                ULocalizationService.Instance.Get(GetCurrentContainerTitleText(), "UIView", "WarGoodsStore", _eRecommendType.ToString());
            }
            //移除英雄限制的装备
            int nHeroId = EntityFactory.MainHeroView.Property.GetNumProp(ENTITY_PROPERTY.PROPERTY_VOCATION);
            PersonSkinModelItem ModelItem = new PersonSkinModelItem();

            GameLogicAPI.GetPersonModel((UInt16)nHeroId, ref ModelItem);

            var list = _typeList.Select(d => d).Where(s => (s.GoodsVocationLimit != 0 && s.GoodsVocationLimit == ModelItem.nTraits)).ToList();

            foreach (var i in list)
            {
                _typeList.Remove(i);
            }

            int count = _typeList.Count >= 6 ? 6 : _typeList.Count;

            for (int i = 0; i < count; ++i) //each (var schemeGoods in _typeList)
            {
                SSchemeMobaGoods   schemeGoods = _typeList[i];
                UWarGoodsStoreItem newItem     = LogicDataCenter.warMobaGoodsDataManager.GetWarGoodsStoreItem(schemeGoods);//m_MyParent.GetWarGoodsStoreItem(schemeGoods);
                if (newItem != null)
                {
                    m_ReCommendGoodsItemList.Add(newItem);

                    component = go.InstanceMainRes <UWarGoodsStoreRecommendComponent>();
                    component.gameObject.name = newItem.SchemeGoodsInfo.GoodsName;
                    component.SetData(newItem);

                    component.Group = m_RecommendGoodsGroup;
                    component.transform.SetParent(containner, false);

                    component.onSelectedChangedEx.AddListener(OnMobaGoodsSelected);
                    component.onDoubleClick.AddListener(OnMobaGoodsBuy);
                    component.onRightClick.AddListener(OnMobaGoodsBuy);
                }
                else
                {
                    newItem = new UWarGoodsStoreItem(schemeGoods);

                    if (LogicDataCenter.warMobaGoodsDataManager.EnableGoodsFilter && newItem.IsFiltered)
                    {
                        continue;
                    }

                    newItem.GoodsComponentVisible = false;
                    m_ReCommendGoodsItemList.Add(newItem);
                    component       = go.InstanceMainRes <UWarGoodsStoreRecommendComponent>();
                    component.Group = m_RecommendGoodsGroup;
                    component.transform.SetParent(containner, false);

                    component.onSelectedChangedEx.AddListener(OnMobaGoodsSelected);
                    component.onDoubleClick.AddListener(OnMobaGoodsBuy);
                    component.onRightClick.AddListener(OnMobaGoodsBuy);

                    component.SetData(newItem);
                }
                //存下更改物品配置时需要替换的推荐类型
                if (_dispositionTypeList != null && _dispositionTypeList.Contains((int)_eRecommendType))
                {
                    LogicDataCenter.warMobaGoodsDataManager.SetHeroDefaultGoods(i, schemeGoods.GoodsID, m_nUsedRecommendType);
                }
            }
        }
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            string path, path1;

            Console.WriteLine("Enter the path:");
            path = Console.ReadLine();

            // to fetch the file paths
            var fileCount = (from file in System.IO.Directory.EnumerateFiles(@path, "*.zip", SearchOption.AllDirectories)
                             select file).Count();

            string[] filePaths = Directory.GetFiles(@path, "*.zip", SearchOption.AllDirectories);

            Console.WriteLine(fileCount);

            List <long>   filesize     = new System.Collections.Generic.List <long>();
            List <String> filepathlist = new System.Collections.Generic.List <String>();
            List <String> filesizelist = new System.Collections.Generic.List <String>();
            String        join1;

            foreach (string file in Directory.GetFiles(@path, "*.zip", SearchOption.AllDirectories))
            {
                FileInfo finfo = new FileInfo(file);
                filesize.Add(finfo.Length);
                join1 = string.Join("", filePaths);
                filepathlist.Append(join1);
            }



            string result = string.Join(", ", filesize.Select(i => i.ToString()).ToArray());

            string[] filesizearray = new string[] { "" };

            filesizearray = result.Split(',');

            long[] filesizearrayint = filesizearray.Select(long.Parse).ToArray();



            Dictionary <string, long> dictionary = new Dictionary <string, long>();

            string[] outputarray = new string[filePaths.Length + 10];
            for (int k = 0; k < filePaths.Length; k++)
            {
                //Console.WriteLine("size of files");
                //displying thr filesize and its memory
                outputarray[k] = filePaths[k] + "  Memory  " + filesizearray[k] + "Bytes";
                dictionary.Add(filePaths[k].ToString(), filesizearrayint[k]);
                Console.WriteLine(outputarray[k]);
            }

            var ordered = dictionary.OrderBy(x => x.Key);

            Console.WriteLine(" Files present and its length");
            foreach (var data in ordered)
            {
                Console.WriteLine("{0} {1}", data.Key, data.Value);
            }

            double[] mytotalsizearray = Array.ConvertAll(filesizearray, double.Parse);
            double[] mysizeless500    = new double[10000];
            double[] mysizeless1gb    = new double[10000];
            double[] mysizeless2gb    = new double[10000];
            double[] mysizeless3gb    = new double[10000];
            int      countless500     = 0;
            int      countless1gb     = 0;
            int      countless2gb     = 0;
            int      countless3gb     = 0;

            //files checking for size of memory and storing them in its respective array
            System.Collections.Generic.List <double[]> outputless500 = new System.Collections.Generic.List <double[]>();
            for (int c = 0; c < filePaths.Length; c++)
            {
                if (mytotalsizearray[c] < 500000000 && mytotalsizearray[c] != 0)
                {
                    ++countless500;

                    mysizeless500[countless500] = mytotalsizearray[c];
                }
                if (mytotalsizearray[c] > 500000000 && mytotalsizearray[c] < 1000000000)
                {
                    ++countless1gb;

                    mysizeless1gb[countless1gb] = mytotalsizearray[c];
                }
                if (mytotalsizearray[c] > 1000000000 && mytotalsizearray[c] < 2000000000)
                {
                    ++countless2gb;

                    mysizeless2gb[countless2gb] = mytotalsizearray[c];
                }
                if (mytotalsizearray[c] > 2000000000 && mytotalsizearray[c] < 3000000000)
                {
                    ++countless3gb;

                    mysizeless3gb[countless3gb] = mytotalsizearray[c];
                }
            }  //for
            mysizeless500[countless500 + 1] = countless500;
            mysizeless1gb[countless1gb + 1] = countless1gb;
            mysizeless2gb[countless2gb + 1] = countless2gb;
            mysizeless3gb[countless3gb + 1] = countless3gb;


            Console.WriteLine("Enter the path to save the CSV:");
            string fPath = Console.ReadLine();

            Console.WriteLine("Enter the filename:");
            string fileName = Console.ReadLine();
            //string pathDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string filePath = fPath + "\\" + fileName + ".csv";

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Close();
            }
            string delimter = ",";

            System.Collections.Generic.List <string[]> output  = new System.Collections.Generic.List <string[]>();
            System.Collections.Generic.List <int[]>    output1 = new System.Collections.Generic.List <int[]>();
            string[] resultlessthan500 = mysizeless500.Select(x => x.ToString()).ToArray();
            string[] resultlessthan1gb = mysizeless1gb.Select(x => x.ToString()).ToArray();
            string[] resultlessthan2gb = mysizeless2gb.Select(x => x.ToString()).ToArray();
            string[] resultlessthan3gb = mysizeless3gb.Select(x => x.ToString()).ToArray();
            resultlessthan500[0] = "countless500";
            resultlessthan1gb[0] = "countless1gb";
            resultlessthan2gb[0] = "countless2gb";
            resultlessthan3gb[0] = "countless3gb";
            string[] finalresultlessthan500 = resultlessthan500.Select(x => x.Replace("0", " ")).ToArray();
            string[] finalresultlessthan1gb = resultlessthan1gb.Select(x => x.Replace("0", " ")).ToArray();
            string[] finalresultlessthan2gb = resultlessthan2gb.Select(x => x.Replace("0", " ")).ToArray();
            string[] finalresultlessthan3gb = resultlessthan3gb.Select(x => x.Replace("0", " ")).ToArray();


            //var newresultlessthan500=metrics

            //flexible part ... add as many object as you want based on your app logic
            output.Add(filePaths);
            output.Add(finalresultlessthan500);
            output.Add(finalresultlessthan1gb);
            output.Add(finalresultlessthan2gb);
            output.Add(finalresultlessthan3gb);



            int length = output.Count;

            using (System.IO.TextWriter writer = File.CreateText(filePath))
            {
                for (int index = 0; index < length; index++)
                {
                    writer.WriteLine(string.Join(delimter, output[index]));
                }
            }
        }
Ejemplo n.º 15
0
                public static string ReadAllString(string fullpath)
                {
                    var f = Phone.IO.File7.Open(fullpath, "r");

                    int c = f.Getc();

                    var va = new System.Collections.Generic.List<byte>();

                    while (c != Phone.IO.File7.EOF)
                    {
                        va.Add((byte)c);
                        c = f.Getc();
                    }

                    var data = va.Select(a => (char)a).ToArray();
                    string r = new string(data);

                    f.Close();

                    return r;
                }
Ejemplo n.º 16
0
 public IEnumerable <RoomDTO> ConvertListEntityToListDTO(System.Collections.Generic.List <Room> entities)
 => entities.Select(entity => ConvertEntityToDTO(entity)).ToList();
 public Document[] Response(string requestId)
 {
     return(responseDocuments.Select(s => s.document).ToArray());
 }
Ejemplo n.º 18
0
        List<List<List<SubCalendarEvent>>> BuildAllPossibleSnugLists(List<CalendarEvent> SortedInterferringCalendarEvents, CalendarEvent ToBeFittedTimeLine, Dictionary<CalendarEvent, List<SubCalendarEvent>> DictionaryWithBothCalendarEventsAndListOfInterferringSubEvents, TimeLine ReferenceTimeLine, double Occupancy)
        {
            /*Name: Jerome Biotidara
             *Description: Function starts by Including all Rigid interferring schedules. Then goes on to setup tightest schedule.
             *Accomplished by:
             *1. stacking subevents of the same calendar event right next to each other.
             *2. Start Snugallotments based on deadline of Calendar Events
             *3. Try creating a snugness that has a snugness duration Greater than or Equal to start time and less than Or equal to the result generated by the difference between the CalendarEvent Deadline and Sum of Interferring subevent durations
             *4  Ensure that when you are assign subcalendar events, the sub calendar events that start within the timeline get noticed and are only allowed to start within the range
             */



            //TimeLine[] JustFreeSpots = ToBeFittedTimeLine.EventTimeLine.getAllFreeSlots();
            TimeLine[] JustFreeSpots = getAllFreeSpots_NoCompleteSchedule(ReferenceTimeLine);
            List<SubCalendarEvent>[] MyListOfSubCalendarEvents = DictionaryWithBothCalendarEventsAndListOfInterferringSubEvents.Values.ToArray();
            //TimeLine[] FreeSpotsWithOnlyRigids= ToBeFittedTimeLine.EventTimeLine.getAllFreeSlots();
            TimeLine[] FreeSpotsWithOnlyRigids = getAllFreeSpots_NoCompleteSchedule(ReferenceTimeLine);
            List<SubCalendarEvent> ListOfAllInterferringSubCalendarEvents = new List<SubCalendarEvent>();
            List<TimeSpan> ListOfAllInterferringTimeSpans = new List<TimeSpan>();

            foreach (List<SubCalendarEvent> MyList in MyListOfSubCalendarEvents)//Loop creates a List of interferring SubCalendarEvens
            {
                foreach (SubCalendarEvent MySubEvents in MyList)
                {
                    ListOfAllInterferringSubCalendarEvents.Add(MySubEvents);
                    ListOfAllInterferringTimeSpans.Add(MySubEvents.ActiveSlot.BusyTimeSpan);
                }
            }


            List<SubCalendarEvent> ListOfAlreadyAssignedSubCalendarEvents = new System.Collections.Generic.List<SubCalendarEvent>();

            /*foreach (BusyTimeLine MyBusySlot in ReferenceTimeLine.OccupiedSlots)
            {
                SubCalendarEvent MySubCalendarEvent = getSubCalendarEvent(MyBusySlot.TimeLineID);
                if (MySubCalendarEvent != null)
                {
                    ListOfAlreadyAssignedSubCalendarEvents.Add(MySubCalendarEvent);
                }
            }

            ListOfAllInterferringSubCalendarEvents = Utility.NotInList(ListOfAllInterferringSubCalendarEvents, ListOfAlreadyAssignedSubCalendarEvents);*/

            Dictionary<TimeLine, List<CalendarEvent>> DictionaryOfFreeTimeLineAndPertinentCalendarEventList = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.List<CalendarEvent>>();

            Dictionary<TimeLine, Dictionary<CalendarEvent, List<SubCalendarEvent>>> DictionaryOfFreeTimeLineAndDictionaryOfCalendarEventAndListOfSubCalendarEvent = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.Dictionary<CalendarEvent, System.Collections.Generic.List<SubCalendarEvent>>>();



            foreach (TimeLine MyFreeTimeLine in JustFreeSpots)
            {
                CalendarEvent[] MyListOfPertinentCalendarEventsForMyTimeLine = getPertinentCalendarEvents(SortedInterferringCalendarEvents.ToArray(), MyFreeTimeLine);
                Dictionary<CalendarEvent, List<SubCalendarEvent>> MyDictionaryOfCalendarEventAndPertinentSubCalendarEvent = new System.Collections.Generic.Dictionary<CalendarEvent, System.Collections.Generic.List<SubCalendarEvent>>();
                foreach (CalendarEvent MyCalendarEvent in MyListOfPertinentCalendarEventsForMyTimeLine)
                {
                    List<SubCalendarEvent> MyListwe = DictionaryWithBothCalendarEventsAndListOfInterferringSubEvents[MyCalendarEvent];
                    MyDictionaryOfCalendarEventAndPertinentSubCalendarEvent.Add(MyCalendarEvent, MyListwe);
                }
                DictionaryOfFreeTimeLineAndDictionaryOfCalendarEventAndListOfSubCalendarEvent.Add(MyFreeTimeLine, MyDictionaryOfCalendarEventAndPertinentSubCalendarEvent);
                DictionaryOfFreeTimeLineAndPertinentCalendarEventList.Add(MyFreeTimeLine, MyListOfPertinentCalendarEventsForMyTimeLine.ToList());//Next step is to call the snug array. Note: you will need to ensure that when ever a subevent gets used in a free timeline. It will have to be removed from the List so that it cannot be used in another free timeline. Also you need to create every possible permutation. Take for example a calendar event thats pertinent to two different "free timelines". you need to ensure that you have different calls to the snuglist generator that has the calendar event enabled in one and disabled in the other.
            }


            List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> EmptyIntialListOfSubCalendarEvemts = new List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>();

            for (int i = 0; i < JustFreeSpots.Length; i++)
            {
                EmptyIntialListOfSubCalendarEvemts.Add(new System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>());
            }



            Tuple<List<TimeSpanWithStringID>, List<mTuple<bool, SubCalendarEvent>>> Arg14 = ConvertSubCalendarEventToTimeSpanWitStringID(ListOfAllInterferringSubCalendarEvents);

            List<TimeSpanWithStringID> SubCalEventsAsTimeSpanWithStringID = Arg14.Item1;//ListOfAllInterferringSubCalendarEvents as TimeSpanWithStringID
            List<mTuple<bool, SubCalendarEvent>> Arg15 = Arg14.Item2;

            Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> Dict_StringTickAndCount = new System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>();
            Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> Dict_StringTickAndCount_Cpy = new System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>();

            foreach (TimeSpanWithStringID eachTimeSpanWithStringID in SubCalEventsAsTimeSpanWithStringID)
            {
                if (Dict_StringTickAndCount.ContainsKey(eachTimeSpanWithStringID.timeSpan))
                {
                    ++Dict_StringTickAndCount[eachTimeSpanWithStringID.timeSpan].Item1;
                    ++Dict_StringTickAndCount_Cpy[eachTimeSpanWithStringID.timeSpan].Item1;
                }
                else
                {
                    Dict_StringTickAndCount.Add(eachTimeSpanWithStringID.timeSpan, new mTuple<int, TimeSpanWithStringID>(1, eachTimeSpanWithStringID));
                    Dict_StringTickAndCount_Cpy.Add(eachTimeSpanWithStringID.timeSpan, new mTuple<int, TimeSpanWithStringID>(1, eachTimeSpanWithStringID));
                }
            }


            Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> TotalSum = new Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>();

            TotalSum = SnugArray.CreateCopyOFSnuPossibilities(Dict_StringTickAndCount_Cpy);

            InterferringTimeSpanWithStringID_Cpy = Dict_StringTickAndCount_Cpy;//hack to keep track of available events


            Dictionary<TimeLine, List<mTuple<bool, SubCalendarEvent>>> Dict_TimeLine_ListOfSubCalendarEvent = BuildDicitionaryOfTimeLineAndSubcalendarEvents(Arg15, DictionaryOfFreeTimeLineAndDictionaryOfCalendarEventAndListOfSubCalendarEvent, ToBeFittedTimeLine);

            Dictionary<TimeLine, List<mTuple<bool, SubCalendarEvent>>> Dict_ConstrainedList = generateConstrainedList(JustFreeSpots.ToList(), Arg15);

            Dictionary<TimeLine, List<mTuple<int, TimeSpanWithStringID>>> Dict_TimeLine_ListOfmTuple = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.List<mTuple<int, TimeSpanWithStringID>>>();

            Dictionary<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> Dict_TimeLine_Dict_string_mTple = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>();

            Dictionary<TimeLine, Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents = new Dictionary<TimeLine, Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>>();

            Dictionary<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> Dict_TimeLine_Dict_string_mTple_Constrained = new Dictionary<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>();

            foreach (TimeLine eachTimeLine in Dict_TimeLine_ListOfSubCalendarEvent.Keys)
            {
                List<mTuple<bool, SubCalendarEvent>> LisOfSubCalEvent = Dict_TimeLine_ListOfSubCalendarEvent[eachTimeLine];
                Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> myDict = new System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>();
                Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>> myDict0 = new Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>();


                foreach (mTuple<bool, SubCalendarEvent> eachmTuple in LisOfSubCalEvent)//goes Through each Subcalevent in Each timeline and generates a dict for a TimeTick To List of TimeSpanID
                {
                    if (myDict.ContainsKey(eachmTuple.Item2.ActiveDuration))
                    {
                        ++myDict[eachmTuple.Item2.ActiveDuration].Item1;
                    }
                    else
                    {
                        myDict.Add(eachmTuple.Item2.ActiveDuration, new mTuple<int, TimeSpanWithStringID>(1, new TimeSpanWithStringID(eachmTuple.Item2.ActiveDuration, eachmTuple.Item2.ActiveDuration.Ticks.ToString())));

                    }



                    if (myDict0.ContainsKey(eachmTuple.Item2.ActiveDuration))
                    {


                        myDict0[eachmTuple.Item2.ActiveDuration].Add(eachmTuple.Item2.ID, eachmTuple);
                    }
                    else
                    {
                        Dictionary<string, mTuple<bool, SubCalendarEvent>> var17 = new System.Collections.Generic.Dictionary<string, mTuple<bool, SubCalendarEvent>>();
                        var17.Add(eachmTuple.Item2.ID, eachmTuple);
                        myDict0.Add(eachmTuple.Item2.ActiveDuration, var17);
                    }

                }
                Dict_TimeLine_Dict_string_mTple.Add(eachTimeLine, myDict);
                Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents.Add(eachTimeLine, myDict0);
            }


            foreach (TimeLine eachTimeLine in Dict_ConstrainedList.Keys)
            {
                List<mTuple<bool, SubCalendarEvent>> LisOfSubCalEvent = Dict_ConstrainedList[eachTimeLine];
                Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> myDict = new System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>();
                foreach (mTuple<bool, SubCalendarEvent> eachmTuple in LisOfSubCalEvent)//goes Through each Subcalevent in Each timeline and generates a dict for a TimeTick To List of TimeSpanID
                {
                    if (myDict.ContainsKey(eachmTuple.Item2.ActiveDuration))
                    {
                        ++myDict[eachmTuple.Item2.ActiveDuration].Item1;
                    }
                    else
                    {
                        myDict.Add(eachmTuple.Item2.ActiveDuration, new mTuple<int, TimeSpanWithStringID>(1, new TimeSpanWithStringID(eachmTuple.Item2.ActiveDuration, eachmTuple.Item2.ActiveDuration.Ticks.ToString())));
                    }
                }

                Dict_TimeLine_Dict_string_mTple_Constrained.Add(eachTimeLine, myDict);
            }

            /*
            foreach (TimeLine eachTimeLine in Dict_TimeLine_Dict_string_mTple.Keys)
            {
                Dictionary<string, mTuple<int, TimeSpanWithStringID>> stringMtuple = Dict_TimeLine_Dict_string_mTple[eachTimeLine];
                List<mTuple<int, TimeSpanWithStringID>> List_mTuple = new System.Collections.Generic.List<mTuple<int, TimeSpanWithStringID>>();

                foreach (KeyValuePair<string, mTuple<int, TimeSpanWithStringID>> eachKeyValuePair in stringMtuple)
                {
                    TimeSpanWithStringID myTimeSpanWithStringID = eachKeyValuePair.Value.Item2;
                    List_mTuple.Add(new mTuple<int, TimeSpanWithStringID>(eachKeyValuePair.Value.Item1, myTimeSpanWithStringID));
                }

                Dict_TimeLine_ListOfmTuple.Add(eachTimeLine, List_mTuple);
            }

            */


            Dictionary<TimeLine, Tuple<Dictionary<string, mTuple<int, TimeSpanWithStringID>>, Dictionary<string, mTuple<int, TimeSpanWithStringID>>>> var6 = new System.Collections.Generic.Dictionary<TimeLine, Tuple<System.Collections.Generic.Dictionary<string, mTuple<int, TimeSpanWithStringID>>, System.Collections.Generic.Dictionary<string, mTuple<int, TimeSpanWithStringID>>>>();

            //Dictionary<TimeLine, Dictionary<string, mTuple<int, TimeSpanWithStringID>>>
            int i0 = 0;
            List<TimeLine> var7 = Dict_TimeLine_Dict_string_mTple_Constrained.Keys.ToList();//List Of TimeLines pertaining to COnstrained List i.e restricted elements
            Dictionary<string, mTuple<int, TimeSpanWithStringID>> var10 = new System.Collections.Generic.Dictionary<string, mTuple<int, TimeSpanWithStringID>>();
            List<KeyValuePair<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>> var11 = Dict_TimeLine_Dict_string_mTple_Constrained.ToList(); //Same as Dict_TimeLine_Dict_string_mTple_Constrained only as List of KeyValuePair
            Dictionary<TimeLine, Dictionary<string, mTuple<int, TimeSpanWithStringID>>> var14 = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.Dictionary<string, mTuple<int, TimeSpanWithStringID>>>();
            Dictionary<TimeLine, Tuple<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>> var15 = new Dictionary<TimeLine, Tuple<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>>();

            foreach (KeyValuePair<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> eachKeyValuePair in Dict_TimeLine_Dict_string_mTple_Constrained)
            {
                i0 = var7.IndexOf(eachKeyValuePair.Key);
                Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> var8 = eachKeyValuePair.Value;
                Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> var9 = new System.Collections.Generic.Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>();
                for (; i0 < var7.Count; i0++)
                {
                    Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> var12 = var11[i0].Value;
                    foreach (KeyValuePair<TimeSpan, mTuple<int, TimeSpanWithStringID>> var13 in var12)
                    {
                        if (var9.ContainsKey(var13.Key))
                        {
                            var9[var13.Key].Item1 += var13.Value.Item1;
                        }
                        else
                        {
                            var9.Add(var13.Key, new mTuple<int, TimeSpanWithStringID>(var13.Value.Item1, var13.Value.Item2));
                        }
                    }
                }
                var15.Add(eachKeyValuePair.Key, new Tuple<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>(eachKeyValuePair.Value, var9));
            }



            List<List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>> AllTImeLinesWithSnugPossibilities = generateTreeCallsToSnugArray(Dict_StringTickAndCount, JustFreeSpots.ToList(), 0, EmptyIntialListOfSubCalendarEvemts, Dict_TimeLine_Dict_string_mTple, var15);




            List<List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>> validMatches = getValidMatches(ListOfAllInterferringSubCalendarEvents, AllTImeLinesWithSnugPossibilities, Dict_TimeLine_Dict_string_mTple_Constrained);

            List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> AverageMatched = getAveragedOutTIimeLine(validMatches, 0);



            Dictionary<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> AveragedMatchAsDictWithTimeLine = new Dictionary<TimeLine, Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>();

            i0 = 0;
            for (; i0 < JustFreeSpots.Length; i0++)
            {
                AveragedMatchAsDictWithTimeLine.Add(JustFreeSpots[i0], AverageMatched[i0]);
                //TotalSum[0] = SnugArray.AddToSnugPossibilityList(TotalSum[0], AverageMatched[i0]);
            }



            Dict_ConstrainedList = stitchRestrictedSubCalendarEvent(JustFreeSpots.ToList(), 0, Dict_ConstrainedList);

            Dictionary<TimeLine, List<mTuple<bool, SubCalendarEvent>>> Dict_TimeLine_ListOfSubCalendarEvent_Cpy = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.List<mTuple<bool, SubCalendarEvent>>>(Dict_TimeLine_ListOfSubCalendarEvent);

            Dictionary<TimeLine, List<mTuple<bool, SubCalendarEvent>>> DictWithTimeLine_ArrangedOptimizedSubCalEvents = new System.Collections.Generic.Dictionary<TimeLine, System.Collections.Generic.List<mTuple<bool, SubCalendarEvent>>>()
;
            i0 = 0;
            List<mTuple<bool, SubCalendarEvent>> TotalArrangedElements = new System.Collections.Generic.List<mTuple<bool, SubCalendarEvent>>();
            List<List<SubCalendarEvent>> TotalArrangedElements_NoMTuple = new System.Collections.Generic.List<System.Collections.Generic.List<SubCalendarEvent>>();
            List<TimeLine> ListOfTimeLines = JustFreeSpots.ToList();//This will be decremented so do not reused

            Dictionary<string, SubCalendarEvent> TestDict = new System.Collections.Generic.Dictionary<string, SubCalendarEvent>();

            List<List<SubCalendarEvent>> restrictedSubCaleventsAfterScheduleUpdate = new List<List<SubCalendarEvent>>();
            Dictionary<TimeLine, Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> copyOfPossibleEvents = createCopyOfPossibleEvents(Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents);



            foreach (KeyValuePair<TimeLine, Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> eachKeyValuePair in Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents)
            {
                List<mTuple<bool, SubCalendarEvent>> var16 = Dict_ConstrainedList[eachKeyValuePair.Key];
                List<BusyTimeLine> RestrictedBusySlots = new System.Collections.Generic.List<BusyTimeLine>();
                foreach (mTuple<bool, SubCalendarEvent> eachmTuple in var16)
                {
                    eachmTuple.Item1 = true;
                    RestrictedBusySlots.Add(eachmTuple.Item2.ActiveSlot);
                    TimeSpan ActiveTimespan1 = eachmTuple.Item2.ActiveDuration;
                    string SubEventID = eachmTuple.Item2.ID;
                    eachKeyValuePair.Value[ActiveTimespan1][SubEventID] = eachmTuple;
                }
                eachKeyValuePair.Key.AddBusySlots(RestrictedBusySlots.ToArray());
                if (i0 == 9 || i0 == 12)
                {
                    ;
                }


                stageOfProgram = "stitchUnRestrictedSubCalendarEvent index io is" + i0;
                List<mTuple<bool, SubCalendarEvent>> ArrangedElements = stitchUnRestrictedSubCalendarEvent(eachKeyValuePair.Key, var16, Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents[eachKeyValuePair.Key], AverageMatched[i0], Occupancy);
                foreach (TimeLine eachTimeLine in JustFreeSpots)
                {
                    foreach (mTuple<bool, SubCalendarEvent> eachmTuple in ArrangedElements)
                    {
                        TimeSpan ActiveTimeSpan0 = eachmTuple.Item2.ActiveDuration;
                        if (Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents[eachTimeLine].ContainsKey(ActiveTimeSpan0))
                        {
                            Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents[eachTimeLine][ActiveTimeSpan0].Remove(eachmTuple.Item2.ID);
                        }
                    }
                }
                /*
                if (i0 + 1 < Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents.Count)
                {
                    Dictionary<TimeLine, Dictionary<string, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> test = Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents;
                    ArrangedElements = FurtherFillTimeLineWithSubCalEvents(ArrangedElements, JustFreeSpots[i0 + 1], AveragedMatchAsDictWithTimeLine, eachKeyValuePair.Key, test);
                    foreach (KeyValuePair<string, mTuple<int, TimeSpanWithStringID>> eachKeyValuePair0 in AveragedMatchAsDictWithTimeLine[eachKeyValuePair.Key])
                    {
                        if (AveragedMatchAsDictWithTimeLine[JustFreeSpots[i0 + 1]].ContainsKey(eachKeyValuePair0.Key))
                        {
                            AveragedMatchAsDictWithTimeLine[JustFreeSpots[i0 + 1]][eachKeyValuePair0.Key].Item1 += eachKeyValuePair0.Value.Item1;
                        }
                        else
                        {
                            AveragedMatchAsDictWithTimeLine[JustFreeSpots[i0 + 1]].Add(eachKeyValuePair0.Key, new mTuple<int, TimeSpanWithStringID>(eachKeyValuePair0.Value));
                        }
                    }

                }*/
                foreach (TimeLine eachTimeLine in JustFreeSpots)
                {
                    foreach (mTuple<bool, SubCalendarEvent> eachmTuple in ArrangedElements)
                    {


                        TimeSpan ActiveTimeSpan2 = eachmTuple.Item2.ActiveDuration;
                        if (Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents[eachTimeLine].ContainsKey(ActiveTimeSpan2))
                        {
                            Dict_TimeLine_Dict_StringID_Dict_SubEventStringID_mTuple_Bool_MatchinfSubCalevents[eachTimeLine][ActiveTimeSpan2].Remove(eachmTuple.Item2.ID);
                        }
                    }
                }



                TotalArrangedElements_NoMTuple.Add(Utility.mTupleToSubCalEvents(ArrangedElements));
                List<mTuple<bool, SubCalendarEvent>> previous = TotalArrangedElements.ToList();
                int BeforeErrorIndex = TotalArrangedElements.Count;
                TotalArrangedElements.AddRange(ArrangedElements);
                int AfterErrorIndex = TotalArrangedElements.Count;
                DictWithTimeLine_ArrangedOptimizedSubCalEvents.Add(eachKeyValuePair.Key, ArrangedElements);
                Dict_TimeLine_ListOfSubCalendarEvent_Cpy.Remove(eachKeyValuePair.Key);





                foreach (List<mTuple<bool, SubCalendarEvent>> eachList in Dict_TimeLine_ListOfSubCalendarEvent_Cpy.Values)
                {
                    int i = 0;
                    for (; i < eachList.Count; i++)
                    {
                        /*if (eachList[i].Item1)
                        {
                            eachList.RemoveAt(i);
                            --i;
                        }*/

                        foreach (mTuple<bool, SubCalendarEvent> eachmTuple in ArrangedElements)
                        {
                            if (eachList[i].Item2.ID == eachmTuple.Item2.ID)
                            {
                                eachList.RemoveAt(i);
                                --i;
                                break;
                            }


                        }


                    }
                }

               



                List<SubCalendarEvent> UnassignedSubevents = ListOfAllInterferringSubCalendarEvents.ToList();
                List<SubCalendarEvent> AlreadyAssigned = Utility.mTupleToSubCalEvents(TotalArrangedElements);


                foreach (SubCalendarEvent eachSubCalendarEvent in AlreadyAssigned)
                {
                    if (eachSubCalendarEvent.ID == "470_482")
                    {
                        ;
                    }
                    TestDict.Add(eachSubCalendarEvent.ID, eachSubCalendarEvent);//if it crashes at this point there is some possible error in your constrained list generating duplicate values. 
                }
                TestDict = new System.Collections.Generic.Dictionary<string, SubCalendarEvent>();
                /*
                UnassignedSubevents=Utility.NotInList(UnassignedSubevents, AlreadyAssigned);
                */
                List<string> MyAssignedIDs = AlreadyAssigned.Select(obj => obj.ID).ToList();

                UnassignedSubevents.RemoveAll(e => MyAssignedIDs.Contains(e.ID));
                int StartIndex = 0;
                if (Dict_ConstrainedList.Count > 1)
                {
                    restrictedSubCaleventsAfterScheduleUpdate.Add(Utility.mTupleToSubCalEvents(Dict_ConstrainedList[ListOfTimeLines[0]]));
                    StartIndex = i0 + 1;
                    ListOfTimeLines.RemoveAt(0);

                    Dict_ConstrainedList = generateConstrainedList(ListOfTimeLines, Utility.SubCalEventsTomTuple(UnassignedSubevents, false));

                    TimeLine PertinentTimeLine = Dict_TimeLine_ListOfSubCalendarEvent_Cpy.Keys.ToList()[0];
                    List<mTuple<bool, SubCalendarEvent>> beforeList = Dict_ConstrainedList[PertinentTimeLine];
                    int before = Dict_ConstrainedList[PertinentTimeLine].Count;

                    Dict_ConstrainedList[PertinentTimeLine] = stitchRestrictedSubCalendarEvent(Dict_ConstrainedList[PertinentTimeLine], PertinentTimeLine);
                    int after = Dict_ConstrainedList[PertinentTimeLine].Count;
                    List<mTuple<bool, SubCalendarEvent>> AfterList = Dict_ConstrainedList[PertinentTimeLine];
                    if (after != before)
                    {
                        ;
                    }
                    //Dict_ConstrainedList = stitchRestrictedSubCalendarEvent(Dict_TimeLine_ListOfSubCalendarEvent_Cpy.Keys.ToList(), 0, Dict_ConstrainedList);
                }
                i0++;
            }


            TimeSpan TotalBusyTimeFrame = Utility.SumOfActiveDuration(ListOfAllInterferringSubCalendarEvents);
            IEnumerable<SubCalendarEvent> JustAssignedSubCal = TotalArrangedElements.Select(obj => obj.Item2);
            IEnumerable<string> JustAssignedSubCalIDs = TotalArrangedElements.Select(obj => obj.Item2.ID);
            List<SubCalendarEvent> UnAssignedElements = ListOfAllInterferringSubCalendarEvents.Where(obj => !JustAssignedSubCal.Contains(obj)).ToList();
            ;

            foreach (BusyTimeLine OccupiedSlot in ReferenceTimeLine.OccupiedSlots)
            {
                TotalBusyTimeFrame += OccupiedSlot.BusyTimeSpan;
            }

            TimeSpan TotalTimeSpan = ReferenceTimeLine.TimelineSpan;


            double PercentageOfOccupiedSpace = (double)TotalBusyTimeFrame.Ticks / (double)TotalTimeSpan.Ticks;


            restrictedSubCaleventsAfterScheduleUpdate.Add(Utility.mTupleToSubCalEvents(Dict_ConstrainedList[ListOfTimeLines[0]]));//updates the constrained List one last time

            stageOfProgram = "before beginning spreadout";

#if EnableRestrictedLocationOptimization
            
#else
            TotalArrangedElements_NoMTuple=SpreadOutEvents(TotalArrangedElements_NoMTuple, PercentageOfOccupiedSpace, JustFreeSpots.ToList(), copyOfPossibleEvents, restrictedSubCaleventsAfterScheduleUpdate);
#endif
            //TotalArrangedElements_NoMTuple=OptimizeForLocation(TotalArrangedElements_NoMTuple, JustFreeSpots);
            ReadjustForDailySchedule(TotalArrangedElements_NoMTuple, JustFreeSpots.Select(obj => obj.CreateCopy()).ToList());


            List<List<List<SubCalendarEvent>>> ReValue = new System.Collections.Generic.List<System.Collections.Generic.List<System.Collections.Generic.List<SubCalendarEvent>>>();
            //List<List<List<SubCalendarEvent>>> ReValue = FixSubCalEventOrder(AllTImeLinesWithSnugPossibilities, JustFreeSpots);
            ReValue.Add(TotalArrangedElements_NoMTuple);

            return ReValue;
        }