public IEnumerable <MessageTemplate> GetAllSettings() { IEnumerable <MessageTemplate> result = null; string key = MessageTemplateAllCacheDependencyKey.FormatString(SystemSettings.ApplicationId); if (this.CacheEnabled && this.cacheManager.IsAdded(key)) { Debug.WriteLine("Get Message Template from Cache"); result = this.cacheManager.Get(key) as IEnumerable <MessageTemplate>; return(result.Clone()); } result = this.messageTemplateRepository.GetAll().ToList(); if (this.CacheEnabled) { Debug.WriteLine("Insert Message Template on Cache"); this.cacheManager.Add(key, result); } return(result.Clone()); }
public IEnumerable <Setting> GetAllSettings() { IEnumerable <Setting> result = null; string key = SettingsAllCacheDependencyKey.FormatString(SystemSettings.ApplicationId); if (this.CacheEnabled && this.cacheManager.IsAdded(key)) { Debug.WriteLine("Get Settings from Cache"); // it seems result is NULL // result = this.cacheManager.Get(key) as IEnumerable<Setting>; result = (IEnumerable <Setting>) this.cacheManager.Get(key); return(result.Clone()); } result = this.settingRepository.GetAll().ToList(); if (this.CacheEnabled) { Debug.WriteLine("Insert Settings on Cache"); this.cacheManager.Add(key, result); } return(result.Clone()); }
public List <Person> GetAnonymizedData(IEnumerable <Person> people) { if (people == null || !people.Any()) { return(new List <Person>()); } if (people.Select(_anonymyzedProperty).Any(p => !int.TryParse(p.ToString(), out _))) { throw new Exception("Anonymyzed property has to be integer"); } var groups = GetGroupedPeople(people); foreach (var algorithms in _algorithmsEnumerator) { var anonymzedData = algorithms.Aggregate(people.Clone(), (acc, algo) => algo.GetAnonymizedData(acc)); groups = GetGroupedPeople(anonymzedData); if (IsListAnonymized(groups)) { break; } } return(groups.SelectMany(x => x.People).ToList()); }
public static BlockTableRecord ToBlock(this IEnumerable <Entity> _entityList, string _blockName, Point3d _origin = default, bool redefine = false) { Document doc = Application.DocumentManager.MdiActiveDocument; using (var tr = doc.TransactionManager.StartTransaction()) { BlockTableRecord btr; var bt = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable; if (bt.Has(_blockName)) { btr = bt[_blockName].GetObject(OpenMode.ForRead) as BlockTableRecord; } else { btr = new BlockTableRecord() { Name = _blockName, Origin = _origin }; foreach (var e in _entityList.Clone()) { btr.AppendEntity(e); } bt.UpgradeOpen(); bt.Add(btr); tr.AddNewlyCreatedDBObject(btr, true); tr.Commit(); } return(btr); } }
public static ICollection<TValue> ToCollection<TValue, TCollectionType>(this IEnumerable<TValue> source, object[] newCollectionArgs = null) where TCollectionType : ICollection<TValue> { TCollectionType coll = source.Clone(newCollectionArgs).Parse<TCollectionType>(); source.ToList().ForEach(model => coll.Add(model)); return coll; }
public static bool Compare(IEnumerable <T> first, IEnumerable <T> second, out string message) { if (ReferenceEquals(first, second)) { message = equalString; return(true); } if ((first == null) || (second == null)) { message = prepareMessage(first, second); return(false); } //IEnumerable<T> UniqueItemsFromFirst = first.Except(second); //IEnumerable<T> UniqueItemsFromSecond = second.Except(first); var UniqueItemsFromFirst = first.Clone(); var UniqueItemsFromSecond = second.Clone(); foreach (T item in first) { if (second.Contains(item)) { UniqueItemsFromFirst.Remove(item); UniqueItemsFromSecond.Remove(item); } } message = prepareMessage(UniqueItemsFromFirst, UniqueItemsFromSecond); return(UniqueItemsFromFirst.Count() == 0 && UniqueItemsFromSecond.Count() == 0); }
public static ISet <TValue> ToSet <TValue, TSetType>(this IEnumerable <TValue> source, object[] newSetArgs = null) where TSetType : ISet <TValue> { TSetType set = source.Clone(newSetArgs).Parse <TSetType>(); source.ToList().ForEach(model => set.Add(model)); return(set); }
public static IList <TValue> ToList <TValue, TListType>(this IEnumerable <TValue> source, object[] newListArgs = null) where TListType : IList <TValue> { TListType list = source.Clone(newListArgs).Parse <TListType>(); source.ToList().ForEach(model => list.Add(model)); return(list); }
public LogItem(ActionType actionType, IEnumerable <T> data) { CreateDate = DateTime.Now; ActionType = actionType; if (data != null) { OldData = (T)data.Clone(); } }
public EntittiesJig(IEnumerable <Entity> _entities, Point3d _originPoint, Point3d _basePoint = default, IEnumerable <IEntityConverter> _converters = null) : base() { buffer = _entities; entities = _entities.Clone(); originPoint = _originPoint; basePoint = _basePoint; converters = _converters; if (converters != null) { converters.ForEach(x => entities = x.Convert(entities)); } transforms = new List <Matrix3d>(); }
public Tooltip(string text, Direction arrowsDirection, params int[] arrowsOffset) : base("tooltip") { this.arrowsDirection = arrowsDirection; this.arrowsOffset = arrowsOffset.Clone(); Control container = new Control("tooltip-container"); label = new Label("tooltip-label") { Text = text }; label.HtmlElement.Style.MinWidth = String.Format("{0}px", arrowsOffset.Max() + 8); this.AppendChild(container); this.AppendChild(label); arrows = arrowsOffset.Select(offset => new Control("tooltip-arrow")).ToArray(); foreach (Control arrow in arrows) { this.AppendChild(arrow); } this.HtmlElement.Style.Visibility = "hidden"; this.HtmlElement.Style.Opacity = "0"; int topMargin = arrowsDirection == Direction.Top ? -15 : (arrowsDirection == Direction.Bottom ? 15 : 0); int leftMargin = arrowsDirection == Direction.Left ? -15 : (arrowsDirection == Direction.Right ? 15 : 0); string appearMargin = String.Format("{0}px 0px 0px {1}px", topMargin, leftMargin); string disappearMargin = String.Format("{0}px 0px 0px {1}px", -topMargin, -leftMargin); this.HtmlElement.AddEventListener("mousedown", () => StartDisappearAnimation()); appearTransition = new SequentialTransition( new Keyframe(this.HtmlElement, "visibility", "visible"), new ParallelTransition( new Transition(this.HtmlElement, "opacity", new DoubleValueBounds(0, 1), new TransitionTiming(AppearDuration, TimingCurve.EaseIn)), new Transition(this.HtmlElement, "margin", new ValueBounds(appearMargin, "0px 0px 0px 0px"), new TransitionTiming(AppearDuration, TimingCurve.EaseOut)))); disappearTransition = new SequentialTransition( new ParallelTransition( new Transition(this.HtmlElement, "opacity", new DoubleValueBounds(1, 0), new TransitionTiming(DisappearDuration, TimingCurve.EaseOut)), new Transition(this.HtmlElement, "margin", new ValueBounds("0px 0px 0px 0px", disappearMargin), new TransitionTiming(DisappearDuration, TimingCurve.EaseOut))), new Keyframe(this.HtmlElement, "visibility", "hidden")); }
public static IEnumerable <SecretSantaPair> CreatePairs(this IEnumerable <Person> people) { Random random = new Random(); int index = -1; List <Person> secondList = people.Clone().ToList(); List <SecretSantaPair> list = new List <SecretSantaPair>(); foreach (Person person in people) { index = random.Next(0, secondList.Count); list.Add(new SecretSantaPair(person, secondList[index])); secondList.RemoveAt(index); } return(list); }
public List <Person> GetAnonymizedData(IEnumerable <Person> people) { if (people == null || !people.Any()) { return(new List <Person>()); } var groups = GetGroupedPeople(people); foreach (var algorithms in _algorithmsEnumerator) { var anonymzedData = algorithms.Aggregate(people.Clone(), (acc, algo) => algo.GetAnonymizedData(acc)); groups = GetGroupedPeople(anonymzedData); if (IsListAnonymized(groups)) { break; } } return(groups.SelectMany(x => x.People).ToList()); }
/// <summary> /// Returns a <see cref="T:System.IO.Stream"/> which contains specified streams list compressed. The <paramref name="itemNames"/> contains the names for every stream entry in streams list. /// </summary> /// <param name="items">Elements to compress.</param> /// <param name="itemNames">The names for every stream entry in streams list.</param> /// <returns> /// A <see cref="T:System.String" /> than contains the path to created file. /// </returns> public static Stream AsZipStream(this IEnumerable <Stream> items, IEnumerable <string> itemNames) { IList <Stream> elementList = items as IList <Stream> ?? items.Clone().ToList(); SentinelHelper.ArgumentNull(elementList, nameof(elementList)); IList <string> elementNamesList = itemNames as IList <string> ?? itemNames.ToList(); SentinelHelper.ArgumentNull(elementNamesList, nameof(elementNamesList)); SentinelHelper.IsTrue(elementList.Count != elementNamesList.Count, "The parameter 'itemsNames' must have the same number of elements as the 'items' list"); try { Stream zippedStream = new MemoryStream(); string tempDirectory = iTinIO.File.TempDirectoryFullName; Uri tempFilenameUri = iTinIO.File.GetUniqueTempRandomFile(); string tempFilename = Path.GetFileName(tempFilenameUri.AbsolutePath); string fullTempPath = Path.Combine(tempDirectory, tempFilename); using (ZipFile zip = new ZipFile(fullTempPath)) { int currentFile = 0; foreach (Stream element in elementList) { element.Position = 0; zip.AddEntry(elementNamesList[currentFile], element); currentFile++; } zip.Save(zippedStream); } return(zippedStream); } catch { return(Stream.Null); } }
public BlockDetailsForm(IEnumerable<SaveBlock> blocks, Point popupLocation, BlockViewWrapperControl Wrapper) { this.oldBlocks.AddRange(blocks.Clone()); this.blocks.AddRange(blocks); this.wrapper = Wrapper; StartPosition = FormStartPosition.Manual; Location = popupLocation; InitializeComponent(); blockTypesDropDown.Items.AddRange(Enum.GetNames(typeof(BlockType))); blockTypesDropDown.Items.Remove(Enum.GetName(typeof(BlockType), BlockType.OUT_OF_BOUNDS)); blockTypesDropDown.Items.Remove(Enum.GetName(typeof(BlockType), BlockType.EMPTY)); if (this.blocks.All(block => block.Type == this.blocks.First().Type)) { oldBlockType.Text = blockTypesDropDown.Text = System.Enum.GetName(typeof(BlockType), this.blocks.First().Type); } else { oldBlockType.Text = blockTypesDropDown.Text = MULTIPLE_ENTRY_TEXT; } if (this.blocks.All(block => string.IsNullOrWhiteSpace(block.Script))) { scriptNameBox.Text = ""; oldScriptName.Text = NO_SCRIPT_NAME_TEXT; } else if (this.blocks.All(block => block.Script == this.blocks.First().Script)) { oldScriptName.Text = scriptNameBox.Text = this.blocks.First().Script; } else { oldScriptName.Text = scriptNameBox.Text = MULTIPLE_ENTRY_TEXT; } setupDone = true; updateBlocks(); }
/// <summary> /// 从传入的元素集合 fullItems 中随机选择出 count 个元素,并组成新的泛型列表来返回。 /// </summary> /// <param name="fullItems">将要从中随机选择元素的泛型集合。</param> /// <param name="count">最终要保留的元素个数。</param> /// <returns></returns> private IEnumerable <string> RandomSelectSomeItems(IEnumerable <string> fullItems, int count) { if (fullItems == null || fullItems.Count() < 1) { throw new ArgumentNullException("fullItems"); } if (count < 1) { throw new ArgumentOutOfRangeException("count", "要求保留的元素个数不能少于 1 个!"); } if (count > fullItems.Count()) { throw new ArgumentOutOfRangeException("count", "要求保留的元素个数不能超过源集合的元素总数!"); } List <string> remainItems = fullItems.Clone().ToList();// new List<string>(fullItems); Random r = new Random(); while (remainItems.Count() > count) { remainItems.RemoveAt(r.Next(0, remainItems.Count)); } return(remainItems); }
public void ScheduleByAddingConstraints() { bool disableTrace = true; var engine = (null as IConferenceOptimizer).Create(disableTrace); var sessions = new SessionsCollection(); var rooms = new List <Room>(); var timeslots = new List <Timeslot>(); #region Presenters // No restrictions on when they present var presenterJustinJames = Presenter.Create(10, "Justin James"); var presenterWendySteinman = Presenter.Create(12, "Wendy Steinman"); var presenterHattanShobokshi = Presenter.Create(16, "Hattan Shobokshi"); var presenterRyanMilbourne = Presenter.Create(22, "Ryan Milbourne"); var presenterIotLaboratory = Presenter.Create(27, "IOT Laboratory"); // Prefers the last 2 sessions of the day var preferredTimeslotsMaxNodland = new int[] { 3, 4 }; var presenterMaxNodland = Presenter.Create(23, "Max Nodland", new int[] { }, preferredTimeslotsMaxNodland); // Doesn't like morning sessions var preferredTimeslotsBarryStahl = new int[] { 3, 4 }; var presenterBarryStahl = Presenter.Create(24, "Barry Stahl", new int[] { }, preferredTimeslotsBarryStahl); // Doesn't like 1st session of morning & afternoon var preferredTimeslotsJustineCocci = new int[] { 2, 4 }; var presenterJustineCocci = Presenter.Create(25, "Justine Cocci", new int[] { }, preferredTimeslotsJustineCocci); // Prefers 1st session of the day var preferredTimeslotsChrisGriffith = new int[] { 1 }; var presenterChrisGriffith = Presenter.Create(26, "Chris Griffith", new int[] { }, preferredTimeslotsChrisGriffith); // Flying in and out so only available during the middle of the day var unavailableTimeslotsScottGu = new int[] { 1, 4 }; var presenterScottGu = Presenter.Create(28, "Scott Guthrie", unavailableTimeslotsScottGu); // Flying in together so only available toward the end of the day var unavailableTimeslotsScottHanselman = new int[] { 1, 2 }; var presenterScottHanselman = Presenter.Create(29, "Scott Hanselman", unavailableTimeslotsScottHanselman); var unavailableTimeslotsDamianEdwards = new int[] { 1, 2 }; var presenterDamianEdwards = Presenter.Create(30, "Damian Edwards", unavailableTimeslotsDamianEdwards); #endregion #region Sessions var sessionPublicSpeaking = sessions.Add(12, "Everyone is Public Speaker", (int)Topic.None, presenterJustinJames); var sessionTimeyWimey = sessions.Add(14, "Timey-Wimey Stuff", null, presenterWendySteinman); var sessionBitcoin101 = sessions.Add(24, "Bitcoin 101", (int)Topic.None, presenterRyanMilbourne); var sessionBlockchain101 = sessions.Add(25, "Blockchain 101", (int)Topic.None, presenterRyanMilbourne); var sessionRapidRESTDev = sessions.Add(26, "Rapid REST Dev w/Node & Sails", (int)Topic.None, presenterJustinJames); var sessionNativeMobileDev = sessions.Add(27, "Native Mobile Dev With TACO", (int)Topic.None, presenterJustinJames); var sessionReduxIntro = sessions.Add(28, "Redux:Introduction", (int)Topic.None, presenterMaxNodland); var sessionReactGettingStarted = sessions.Add(29, "React:Getting Started", (int)Topic.None, presenterMaxNodland); var sessionDevSurveyOfAI = sessions.Add(30, "Devs Survey of AI", (int)Topic.None, presenterBarryStahl); var sessionMLIntro = sessions.Add(31, "ML:Intro to Image & Text Analysis", (int)Topic.None, presenterJustineCocci); var sessionChatbotsIntroInNode = sessions.Add(32, "ChatBots:Intro using Node", (int)Topic.None, presenterJustineCocci); var sessionAccidentalDevOps = sessions.Add(33, "Accidental DevOps:CI for .NET", (int)Topic.None, presenterHattanShobokshi); var sessionWhatIsIonic = sessions.Add(34, "What is Ionic", (int)Topic.None, presenterChrisGriffith); var sessionEverythingCloud = sessions.Add(41, "Everything about Cloud", (int)Topic.None, presenterScottGu); var sessionFunnyMobileDev = sessions.Add(42, "Funny Mobile Development", (int)Topic.None, presenterScottHanselman); var sessionMobileForNerdz = sessions.Add(43, "Mobile for Nerdz", (int)Topic.None, presenterScottHanselman); var sessionDotNetCoreAwesomeness = sessions.Add(44, ".NET Core Awesomeness", (int)Topic.None, presenterDamianEdwards); var sessionDotNetStandard20 = sessions.Add(45, ".NET Standard 2.0", (int)Topic.None, presenterDamianEdwards); #endregion #region Session dependencies sessionBlockchain101.AddDependency(sessionBitcoin101); #endregion #region Timeslots timeslots.Add(Timeslot.Create(1, 9.5)); timeslots.Add(Timeslot.Create(2, 11)); timeslots.Add(Timeslot.Create(3, 13)); timeslots.Add(Timeslot.Create(4, 14.5)); #endregion #region Rooms rooms.Add(Room.Create(1, 10)); // Unex 127 rooms.Add(Room.Create(2, 10)); // Unex 126 rooms.Add(Room.Create(3, 10, new int[] { 3, 4 })); // Unex 110 -- Only available in AM rooms.Add(Room.Create(4, 10)); // Unex 107 rooms.Add(Room.Create(5, 10)); // Unex 106 #endregion #region Timeslots out-of-favor for each presenter var presenterUnfavoredTimeslots = new List <Tuple <Presenter, int> >(); // This list is built separately so it maintains the order // in which the requests were submitted. It could also be built // by negating the list of preferred timeslots for each presenter // Prefers the last 2 sessions of the day presenterUnfavoredTimeslots.Add(presenterMaxNodland, 1); presenterUnfavoredTimeslots.Add(presenterMaxNodland, 2); // Doesn't like morning sessions presenterUnfavoredTimeslots.Add(presenterBarryStahl, 1); presenterUnfavoredTimeslots.Add(presenterBarryStahl, 2); // Doesn't like 1st session of morning & afternoon presenterUnfavoredTimeslots.Add(presenterJustineCocci, 1); presenterUnfavoredTimeslots.Add(presenterJustineCocci, 3); // Prefers 1st session of the day presenterUnfavoredTimeslots.Add(presenterChrisGriffith, 2); presenterUnfavoredTimeslots.Add(presenterChrisGriffith, 3); presenterUnfavoredTimeslots.Add(presenterChrisGriffith, 4); #endregion #region Create the schedule // Note: We want this to throw an exception here if it is infeasible // since this is the least restrictive it could ever be. IEnumerable <Assignment> assignments = engine.Process(sessions, rooms, timeslots); var lastSuccessfulAssignments = assignments.Clone(); foreach (var unfavoredTimeslot in presenterUnfavoredTimeslots) { int currentPresenterId = unfavoredTimeslot.Item1.Id; var currentPresenter = sessions.First(s => s.Presenters.Any(p => p.Id == currentPresenterId)).Presenters.First(p => p.Id == currentPresenterId); int unfavoredTimeslotId = unfavoredTimeslot.Item2; try { currentPresenter.UnavailableForTimeslots = currentPresenter.UnavailableForTimeslots.Add(unfavoredTimeslotId); assignments = engine.Process(sessions, rooms, timeslots); lastSuccessfulAssignments = assignments; Console.WriteLine($"Successfully prevented assignment of {unfavoredTimeslot.Item1.Name} to Timeslot {unfavoredTimeslotId}"); } catch (NoFeasibleSolutionsException nfs) { Console.WriteLine($"Unable to prevent assignment of {unfavoredTimeslot.Item1.Name} to Timeslot {unfavoredTimeslotId}"); lastSuccessfulAssignments.WriteSchedule(sessions); Console.WriteLine(); currentPresenter.UnavailableForTimeslots = currentPresenter.UnavailableForTimeslots.Remove(unfavoredTimeslotId); } } #endregion // Display the results lastSuccessfulAssignments.WriteSchedule(sessions); }
/// <summary> /// Bind this instance to a new DomFragment created from a sequence of elements. /// </summary> /// /// <param name="elements"> /// The elements to provide the source for this object's DOM. /// </param> protected void CreateNewFragment(IEnumerable <IDomObject> elements) { Document = DomDocument.Create(elements.Clone(), HtmlParsingMode.Fragment); AddSelection(Document.ChildNodes); }
public void AddRange(IEnumerable <T> entities) { this.storage.AddRange(entities.Clone()); }
/// <summary> /// Return a non memory reference copy of enumeration. <b>The type must be serializables</b>. /// </summary> public static IEnumerable <T> Copy <T>(this IEnumerable <T> @this) => @this.Clone();
private static IEnumerable <T> CloneEntities <T>(this IEnumerable <T> items) where T : class, ITrackable { return(items.Clone()); }
/// <summary> /// Bind this instance to a new DomFragment created from a sequence of elements. /// </summary> /// /// <param name="elements"> /// The elements to provide the source for this object's DOM. /// </param> protected void CreateNewFragment(IEnumerable <IDomObject> elements) { Document = new DomFragment(elements.Clone()); AddSelection(Document.ChildNodes); FinishCreatingNewDocument(); }
public StoreModel RefillStock(StoreModel currentStore, IEnumerable <ItemModel> initialStock) { _logger.WriteLog("Refilling all stock items."); currentStore.Items = initialStock.Clone(); return(currentStore); }
public void SetNewData(IEnumerable <T> data) { NewData = (T)data.Clone(); }
public void SetOldData(IEnumerable <T> data) { OldData = (T)data.Clone(); }
/// <summary> /// Bind this instance to a new DomFragment created from a sequence of elements. /// </summary> /// /// <param name="elements"> /// The elements to provide the source for this object's DOM. /// </param> protected void CreateNewFragment(IEnumerable<IDomObject> elements) { Document = DomDocument.Create(elements.Clone(), HtmlParsingMode.Fragment); AddSelection(Document.ChildNodes); }
/// <summary> /// Bind this instance to a new DomFragment created from a sequence of elements. /// </summary> /// /// <param name="elements"> /// The elements to provide the source for this object's DOM. /// </param> protected void CreateNewFragment(IEnumerable<IDomObject> elements) { Document = new DomFragment(elements.Clone()); AddSelection(Document.ChildNodes); FinishCreatingNewDocument(); }