Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things before you start heading down that road. Is the code working now? Do you have unit tests? I only ask because before starting on any refactoring, it is great if you have tests cases.</p> <p>On the topic of enumerators, one line of code stands out to me:</p> <pre><code>LCycleTimeShift(TimeLineInit[i], ReplaceStage);//passing refernce j = 0; k = 0; l = 0; m = 0; n = 0;//Counter Reset to validate the new arrangment </code></pre> <p>You are not allowed to modify a collection inside of an enumeration operation, so you might find that whatever magic you were doing inside that function that was working fine with for(...), it may no longer work with a foreach(...) or LINQ enumeration. This is true only if it is deleting, adding items to the collection, which it appears to be doing. I had to make some changes below since I assume the enumeration will change after each pass, this means I re-evaluate the duplicates each time.</p> <p>As you said, it seems you want to find any two stages (not belonging to the same LCycle) that contain the same tool being used at the same time. You then make some changes to the time for that stage and then modify the parent. Makes sense to me. This is what I have come up with. I don't have any test cases, but maybe it gets you in the right direction.</p> <pre><code>var toolsInUse = TimeLineInit .SelectMany(cycle =&gt; cycle.Stage .SelectMany(stage =&gt; stage.ToolList.Select(tool =&gt; new { Cycle = cycle, Stage = stage, Tool = tool.ToolName }))); var duplicateUse = toolsInUse.Join(toolsInUse, x =&gt; x.Tool, x =&gt; x.Tool, (a, b) =&gt; new { Use = a, Duplicate = b }) .Where(x =&gt; x.Use.Cycle != x.Duplicate.Cycle &amp;&amp; IsTimeOverLaps(x.Use.Stage.StageSpan, x.Duplicate.Stage.StageSpan)); while (duplicateUse.Count() &gt; 0) { var item = duplicateUse.First(); Stage ReplaceStage = item.Use.Stage.DeepCopy();//Taking Copy of stage Span to make time shift Double TimeDifference = (ReplaceStage.StageSpan.ToTime - ReplaceStage.StageSpan.FromTime).TotalMinutes;//Calculating required time shift ReplaceStage.StageSpan.FromTime = item.Duplicate.Stage.StageSpan.ToTime;//FromTime changed accordingly ReplaceStage.StageSpan.ToTime = ReplaceStage.StageSpan.ToTime.AddMinutes(TimeDifference);//To Time Changed accordingly LCycleTimeShift(item.Use.Cycle, ReplaceStage);//passing refernce } </code></pre> <p>I make no claims about performance, accuracy. This is just to point you in a direction. I hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload