private void Alpha_Changed(IChangeable obj)
 {
     ParticleStyle.Target.AlphaOverLifetime.Clear();
     foreach (SyncLinearKey <float> key in Alpha)
     {
         ParticleStyle.Target.AlphaOverLifetime.Append(key);
     }
 }
 private void Colors_Changed(IChangeable obj)
 {
     ParticleStyle.Target.ColorOverLifetime.Clear();
     foreach (SyncLinearKey <color> key in Colors)
     {
         ParticleStyle.Target.ColorOverLifetime.Append(key);
     }
 }
コード例 #3
0
ファイル: Circle.cs プロジェクト: OlehKuts99/ProjectForReview
        /// <summary>
        /// Method returns new, the smallest circle which can contains two other circles inside.
        /// </summary>
        /// <param name="firstObject">First circle.</param>
        /// <param name="secondObject">Second circle.</param>
        /// <returns>New circle.</returns>
        public IChangeable BuildTheSmallest(IChangeable firstObject, IChangeable secondObject)
        {
            var circle = new Circle(this.writer)
            {
                Radius = ((Circle)firstObject).Radius + ((Circle)secondObject).Radius
            };

            return(circle);
        }
コード例 #4
0
        /// <summary>
        /// Method returns new, the smallest rectangle which can contains two other rectangles inside.
        /// </summary>
        /// <param name="rectangleFirts">First rectangle.</param>
        /// <param name="rectangleSecond">Second rectangle.</param>
        /// <returns>New rectangle.</returns>
        public IChangeable BuildTheSmallest(IChangeable rectangleFirts, IChangeable rectangleSecond)
        {
            Rectangle temp = new Rectangle(this.writer)
            {
                Height = ((Rectangle)rectangleFirts).Height + ((Rectangle)rectangleSecond).Height,
                Width  = ((Rectangle)rectangleFirts).Width > ((Rectangle)rectangleSecond).Width ?
                         ((Rectangle)rectangleFirts).Width : ((Rectangle)rectangleSecond).Width
            };

            return(temp);
        }
コード例 #5
0
        public ActionResult Change(int id, string action)
        {
            IDictionary <int, Applience> applienceDictionary = (SortedDictionary <int, Applience>)Session["Apps"];


            IChangeable app = applienceDictionary[id] as IChangeable;

            switch (action)
            {
            case "Down":
                app.Down();
                break;

            case "Up":
                app.Up();
                break;
            }

            return(RedirectToAction("Index"));
        }
コード例 #6
0
    public void Run()
    {
        TrafficLightFactory trafficLightFactory = new TrafficLightFactory();
        List <IChangeable>  trafficLights       = new List <IChangeable>();

        string[] trafficStates = Console.ReadLine().Split();
        int      changesCount  = int.Parse(Console.ReadLine());

        for (int index = 0; index < trafficStates.Length; index++)
        {
            LightColor  state        = (LightColor)Enum.Parse(typeof(LightColor), trafficStates[index]);
            IChangeable trafficLight = trafficLightFactory.CreateTrafficLight(state);
            trafficLights.Add(trafficLight);
        }
        for (int counter = 0; counter < changesCount; counter++)
        {
            trafficLights.ForEach(tl => tl.ChangeState());

            string result = string.Join(" ", trafficLights);
            Console.WriteLine(result);
        }
    }
コード例 #7
0
        /// <summary>
        /// Performs certain action on the object.
        /// </summary>
        /// <param name="obj">Object to be changed.</param>
        /// <param name="keyInfo">Code of key which user pushed.</param>
        public static void ObjectAction(IChangeable obj, int keyInfo)
        {
            UIPart.Counter = 0;
            UIPart.Writer.SetCursorPosition(0, 0);

            dynamic manageObject;

            if (obj is ICircle)
            {
                manageObject = obj as ICircle;
            }
            else
            {
                manageObject = obj as IRectangle;
            }

            if (keyInfo == (int)ConsoleKey.N)
            {
                CurrentObject++;
                if (CurrentObject == ObjectCount)
                {
                    CurrentObject = 0;
                }

                return;
            }

            if (keyInfo == (int)ConsoleKey.P)
            {
                CurrentObject--;
                if (CurrentObject < 0)
                {
                    CurrentObject = ObjectCount - 1;
                }

                return;
            }

            if (keyInfo == (int)ConsoleKey.M)
            {
                Regime = "Move";

                return;
            }

            if (keyInfo == (int)ConsoleKey.S)
            {
                Regime = "Size";

                return;
            }

            switch (keyInfo)
            {
            case (int)ConsoleKey.LeftArrow:
            {
                if (Regime == "Move")
                {
                    manageObject.Move(-1, 0);
                }
                else
                {
                    if (obj is ICircle)
                    {
                        manageObject.Resize(-1);
                    }
                    else
                    {
                        manageObject.Resize(0, -1);
                    }
                };

                break;
            }

            case (int)ConsoleKey.RightArrow:
            {
                if (Regime == "Move")
                {
                    manageObject.Move(1, 0);
                }
                else
                {
                    if (obj is ICircle)
                    {
                        manageObject.Resize(1);
                    }
                    else
                    {
                        manageObject.Resize(0, 1);
                    }
                };

                break;
            }

            case (int)ConsoleKey.UpArrow:
            {
                if (Regime == "Move")
                {
                    manageObject.Move(0, -1);
                }
                else
                {
                    if (manageObject is IRectangle)
                    {
                        manageObject.Resize(1, 0);
                    }
                };

                break;
            }

            case (int)ConsoleKey.DownArrow:
            {
                if (Regime == "Move")
                {
                    manageObject.Move(0, 1);
                }
                else
                {
                    if (manageObject is IRectangle)
                    {
                        manageObject.Resize(-1, 0);
                    }
                };

                break;
            }
            }
        }
コード例 #8
0
        private List<IChanges> GetPropertyCallbacks(IChangeable component, string property)
        {
            var componentCallbacks = GetComponentCallbacks(component);

            List<IChanges> callbacks;
            componentCallbacks.TryGetValue(property, out callbacks);

            if (null == callbacks)
            {
                callbacks = new List<IChanges>();
                componentCallbacks[property] = callbacks;
            }

            return callbacks;
        }
コード例 #9
0
 public void UnsubscribeFromComponentChange(IChangeable component, string property, IChanges callback)
 {
     GetPropertyCallbacks(component, property).Remove(callback);
 }
コード例 #10
0
 public void PublishComponentChange(IChangeable component, string property)
 {
     PrivatePublish(GetPropertyCallbacks(component, property));
 }
コード例 #11
0
ファイル: ChangeCommand.cs プロジェクト: Lenarin/CSharpExes
 public ChangeCommand(IChangeable target, int id)
 {
     _target = target;
     _id     = id;
 }
コード例 #12
0
 public ChangeableAppSettings(IAppSettings source, IChangeable changeable)
 {
     _source     = source;
     _changeable = changeable;
 }
 private void Update_Paticles(IChangeable obj)
 {
     ParticleStyle.Target.UseColorOverLifetime.Value = true;
     Colors_Changed(Colors);
     Alpha_Changed(Alpha);
 }
コード例 #14
0
ファイル: UIPart.cs プロジェクト: OlehKuts99/ProjectForReview
 /// <summary>
 /// Prints stats about object.
 /// </summary>
 /// <param name="obj">Object of IChangeable interface.</param>
 public static void PrintStats(IChangeable obj)
 {
     PrintString("Regime is : " + ObjectController.Regime + '\n');
     PrintString(obj.ToString());
 }
コード例 #15
0
 private ParameterValueReader(IChangeable obj, string param, IDataContainer owner)
 {
     Obj = obj;
     Param = param;
     Owner = owner;
 }
コード例 #16
0
 public static void Add <T>(this IChangeable <T> r, T item) => r.Change(ItemChangedArgs.Add(item));
コード例 #17
0
 internal static ParameterValueReader GetParameterValueReader(IChangeable obj, string param, IDataContainer owner)
 {
     Func<ParameterValueReader> create = new Func<ParameterValueReader>(() => new ParameterValueReader(obj, param, owner));
     return DoubleDictionary<object, string, ParameterValueReader>.GetItem(obj, param, create);
 }
コード例 #18
0
 public static void Remove <T>(this IChangeable <T> r, T item) => r.Change(ItemChangedArgs.Remove(item));
コード例 #19
0
 public void PublishComponentChange(IChangeable component)
 {
     foreach (var callbacks in GetComponentCallbacks(component))
     {
         PrivatePublish(callbacks.Value);
     }
 }
コード例 #20
0
 public static void Remove <T>(this IChangeable <T> r, int id) => r.Change(ItemChangedArgs.Remove <T>(id));
コード例 #21
0
 public void SubscribeToComponentChange(IChangeable component, string property, IChanges callback)
 {
     GetPropertyCallbacks(component, property).Add(callback);
 }
コード例 #22
0
 public static void Update <T>(this IChangeable <T> r, T item) => r.Change(ItemChangedArgs.Update(item));
コード例 #23
0
        private Dictionary<string, List<IChanges>> GetComponentCallbacks(IChangeable component)
        {
            Dictionary<string, List<IChanges>> callbacks;
            allComponentCallbacks.TryGetValue(component, out callbacks);

            if (null == callbacks)
            {
                callbacks = new Dictionary<string, List<IChanges>>();
                allComponentCallbacks[component] = callbacks;
            }

            return callbacks;
        }
コード例 #24
0
 public static void Reset <T>(this IChangeable <T> r, IEnumerable <T> newItems) => r.Change(ItemChangedArgs.Reset(newItems, null));
コード例 #25
0
        public void ExceptionInEventHandler(Func <ReadedFileInfo, IChangeable> checkerCreator, string[] workflow)
        {
            string file = Path.GetTempFileName();

            File.WriteAllBytes(file, new byte[] { 1, 2, 3 });
            var fileInfo = ReadedFileInfo.Create(file, _ => _.CopyTo(Stream.Null));

            IChangeable monitor = null;

            var       wait = new ManualResetEvent(false);
            Exception unhandledException           = null;
            UnhandledExceptionEventHandler handler = (sender, args) =>
            {
                unhandledException = (Exception)args.ExceptionObject;
                wait.Set();
            };

            AppDomain.CurrentDomain.UnhandledException += handler;
            try
            {
                foreach (var op in workflow)
                {
                    switch (op)
                    {
                    case "create":
                        monitor = checkerCreator(fileInfo);
                        break;

                    case "subscribe":
                        monitor.Changed += (a, e) =>
                        {
                            throw new Exception("test");
                        };
                        break;

                    case "delete":
                        SafeDelete(file);
                        break;

                    case "modify":
                        Task.Factory.StartNew(() =>
                        {
                            Thread.Sleep(150);
                            using (var fs = new FileStream(file, FileMode.Open, FileAccess.Write, FileShare.ReadWrite))
                            {
                                fs.Position = 2;
                                fs.WriteByte(1);
                                fs.Close();
                            };
                        }, TaskCreationOptions.LongRunning);
                        break;

                    case "delay":
                        Thread.Sleep(75);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                Assert.IsTrue(wait.WaitOne(10000), "10 sec elapsed");
            }
            finally
            {
                AppDomain.CurrentDomain.UnhandledException -= handler;
            }

            Console.WriteLine(unhandledException);

            Assert.That(unhandledException.Message, Is.EqualTo("Error while file checking."));
            Assert.That(unhandledException.InnerException, Is.Not.Null);
            Assert.That(unhandledException.InnerException.Message, Is.EqualTo("test"));
        }
コード例 #26
0
 private void Colors_Changed(IChangeable obj) => UpdateGradient();